mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merge pull request #3873 from nateprewitt/super_len_fix
properly handled failed seek
This commit is contained in:
+9
-7
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user