diff options
| author | Skipper Seabold <sseabold@civisanalytics.com> | 2016-06-17 10:43:10 -0500 |
|---|---|---|
| committer | Nate Prewitt <Nate.Prewitt@gmail.com> | 2016-08-24 09:59:33 -0600 |
| commit | d4965a4ec6fc205f6a35aa2ff33514e4903fd3c4 (patch) | |
| tree | 776dc835e6c0dfacb6db222d9f0fca66953e647f /requests/utils.py | |
| parent | af7729f64a97ab35e83a1a7971781e69d124d99e (diff) | |
| download | python-requests-d4965a4ec6fc205f6a35aa2ff33514e4903fd3c4.tar.gz | |
Python 2 compatibility
Diffstat (limited to 'requests/utils.py')
| -rw-r--r-- | requests/utils.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/requests/utils.py b/requests/utils.py index 0982ca41..f1e40bde 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -89,8 +89,14 @@ def super_len(o): # StringIO has a notimplemented fileno # BytesIO has seek and not fileno total_length = o.seek(0, 2) + # StringIO objects in py2 returns None + if total_length is None and hasattr(o, 'tell'): + total_length = o.tell() + elif total_length is None: + total_length = 0 + # seek back to current position to support partially read file-like - o.seek(current_position) + o.seek(current_position or 0) return max(0, total_length - current_position) |
