Skip to content
Myr

Use seek from end rather than getvalue

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

authored by Skipper Seabold · committed by Nate Prewitt · parent f12166a · Browse files · 1 file+8 added−5 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+8 added−5 removed

  • other:+8 added−5 removed

1 file+8 added−5 removed

modified:requests/utils.py+8 added-5 removed
43 unmodified lines
44 return d454647def super_len(o):48 total_length = 048 total_length = None49 current_position = 05051 if hasattr(o, '__len__'):52 total_length = len(o)5354 elif hasattr(o, 'len'):55 total_length = o.len5657 elif hasattr(o, 'getvalue'):58 # e.g. BytesIO, cStringIO.StringIO59 total_length = len(o.getvalue())6057 elif hasattr(o, 'fileno'):58 try:59 fileno = o.fileno()60 except io.UnsupportedOperation:
23 unmodified lines
84 # instance, we don't know what the length is, so set it to zero and85 # let requests chunk it instead.86 current_position = total_length8788 if hasattr(o, 'seek') and total_length is None:89 # StringIO has a notimplemented fileno90 # BytesIO has seek and not fileno91 total_length = o.seek(0, 2)92 # seek back to current position to support partially read file-like93 o.seek(current_position)9495 return max(0, total_length - current_position)969798def get_netrc_auth(url, raise_errors=False):
722 unmodified lines