Skip to content
Myr

Fix super_len for partially read files

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

Closes #2872

authored by Ian Cordasco · committed by Ian Cordasco · parent 0a1aaca · Browse files · 1 file+15 added−9 removed
This commit

State

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

Diff stats

1 file+15 added−9 removed

  • other:+15 added−9 removed

1 file+15 added−9 removed

modified:requests/utils.py+15 added-9 removed
46 unmodified lines
47 return d484950def super_len(o):51 total_length = 052 current_position = 05354 if hasattr(o, '__len__'):52 return len(o)55 total_length = len(o)5654 if hasattr(o, 'len'):55 return o.len57 elif hasattr(o, 'len'):58 total_length = o.len5960 elif hasattr(o, 'getvalue'):61 # e.g. BytesIO, cStringIO.StringIO62 total_length = len(o.getvalue())6357 if hasattr(o, 'fileno'):64 elif hasattr(o, 'fileno'):65 try:66 fileno = o.fileno()67 except io.UnsupportedOperation:68 pass69 else:63 filesize = os.fstat(fileno).st_size70 total_length = os.fstat(fileno).st_size7172 # Having used fstat to determine the file length, we need to73 # confirm that this file was opened up in binary mode.74 if 'b' not in o.mode:
6 unmodified lines
81 "for files in text mode."),82 FileModeWarning83 )8478 return filesize85 if hasattr(o, 'tell'):86 current_position = o.tell()8780 if hasattr(o, 'getvalue'):81 # e.g. BytesIO, cStringIO.StringIO82 return len(o.getvalue())88 return max(0, total_length - current_position)899091def get_netrc_auth(url, raise_errors=False):92 """Returns the Requests tuple auth for a given url from netrc."""
625 unmodified lines