properly handled failed seek

This commit is contained in:
Nate Prewitt
2017-02-14 07:45:41 -07:00
parent 6cbebf782a
commit f47aff68f1
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):