Switch to treat files without tell() as zero-length

This commit is contained in:
Cory Benfield
2016-03-07 09:05:43 +00:00
parent e034dd1140
commit 6cc0b56d51
2 changed files with 5 additions and 3 deletions
+4 -2
View File
@@ -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
View File
@@ -44,7 +44,7 @@ class TestSuperLen:
def tell(self):
raise error()
assert super_len(BoomFile()) == 5
assert super_len(BoomFile()) == 0
class TestGetEnvironProxies: