From 6cc0b56d51d13e2a8553f7abffa06e9fbaf795db Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Mon, 7 Mar 2016 09:05:43 +0000 Subject: [PATCH] Switch to treat files without tell() as zero-length --- requests/utils.py | 6 ++++-- tests/test_utils.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/requests/utils.py b/requests/utils.py index c9746d64..16f7b98f 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -87,8 +87,10 @@ def super_len(o): current_position = o.tell() except (OSError, IOError): # This can happen in some weird situations, such as when the file - # is actually a special file descriptor like stdin. - current_position = 0 + # is actually a special file descriptor like stdin. In this + # instance, we don't know what the length is, so set it to zero and + # let requests chunk it instead. + current_position = total_length return max(0, total_length - current_position) diff --git a/tests/test_utils.py b/tests/test_utils.py index afb38315..24b40b96 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -44,7 +44,7 @@ class TestSuperLen: def tell(self): raise error() - assert super_len(BoomFile()) == 5 + assert super_len(BoomFile()) == 0 class TestGetEnvironProxies: