From d4965a4ec6fc205f6a35aa2ff33514e4903fd3c4 Mon Sep 17 00:00:00 2001 From: Skipper Seabold Date: Fri, 17 Jun 2016 10:43:10 -0500 Subject: [PATCH] Python 2 compatibility --- requests/utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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)