Merge pull request #3873 from nateprewitt/super_len_fix

properly handled failed seek
This commit is contained in:
Ian Cordasco
2017-02-14 09:43:19 -06:00
committed by GitHub
2 changed files with 10 additions and 8 deletions
+9 -7
View File
@@ -92,14 +92,16 @@ def super_len(o):
else:
if hasattr(o, 'seek') and total_length is None:
# StringIO and BytesIO have seek but no useable fileno
try:
# seek to end of file
o.seek(0, 2)
total_length = o.tell()
# seek to end of file
o.seek(0, 2)
total_length = o.tell()
# seek back to current position to support
# partially read file-like objects
o.seek(current_position or 0)
# seek back to current position to support
# partially read file-like objects
o.seek(current_position or 0)
except (OSError, IOError):
total_length = 0
if total_length is None:
total_length = 0
+1 -1
View File
@@ -1546,7 +1546,7 @@ class TestRequests:
def tell(self):
return 0
def seek(self, pos):
def seek(self, pos, whence=0):
raise OSError()
def __iter__(self):