Skip to content
Myr

Merge pull request #3873 from nateprewitt/super_len_fix

Before adoption: this commit came in with the history the project adopted, so no landing records it.

properly handled failed seek

authored by Ian Cordasco · committed by GitHub · parents 90f3842, f47aff6 · Browse files · 2 files+10 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−8 removed

  • tests:+1 added−1 removed
  • other:+9 added−7 removed

2 files+10 added−8 removed

modified:requests/utils.py+9 added-7 removed
90 unmodified lines
91 current_position = total_length92 else:93 if hasattr(o, 'seek') and total_length is None:94 # StringIO and BytesIO have seek but no useable fileno95 try:96 # seek to end of file97 o.seek(0, 2)98 total_length = o.tell()9996 # seek to end of file97 o.seek(0, 2)98 total_length = o.tell()100 # seek back to current position to support101 # partially read file-like objects102 o.seek(current_position or 0)103 except (OSError, IOError):104 total_length = 0105100 # seek back to current position to support101 # partially read file-like objects102 o.seek(current_position or 0)103106 if total_length is None:107 total_length = 0108109 return max(0, total_length - current_position)
746 unmodified lines
modified:tests/test_requests.py+1 added-1 removed
1544 unmodified lines
15451546 def tell(self):1547 return 015481549 def seek(self, pos):1549 def seek(self, pos, whence=0):1550 raise OSError()15511552 def __iter__(self):1553 return
785 unmodified lines