mirror of
https://github.com/kennethreitz/requests3.git
synced 2026-06-05 23:10:16 +00:00
Switch to treat files without tell() as zero-length
This commit is contained in:
+4
-2
@@ -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)
|
||||
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ class TestSuperLen:
|
||||
def tell(self):
|
||||
raise error()
|
||||
|
||||
assert super_len(BoomFile()) == 5
|
||||
assert super_len(BoomFile()) == 0
|
||||
|
||||
|
||||
class TestGetEnvironProxies:
|
||||
|
||||
Reference in New Issue
Block a user