File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ def dict_to_sequence(d):
45
45
46
46
47
47
def super_len (o ):
48
- total_length = 0
48
+ total_length = None
49
49
current_position = 0
50
50
51
51
if hasattr (o , '__len__' ):
@@ -54,10 +54,6 @@ def super_len(o):
54
54
elif hasattr (o , 'len' ):
55
55
total_length = o .len
56
56
57
- elif hasattr (o , 'getvalue' ):
58
- # e.g. BytesIO, cStringIO.StringIO
59
- total_length = len (o .getvalue ())
60
-
61
57
elif hasattr (o , 'fileno' ):
62
58
try :
63
59
fileno = o .fileno ()
@@ -89,6 +85,13 @@ def super_len(o):
89
85
# let requests chunk it instead.
90
86
current_position = total_length
91
87
88
+ if hasattr (o , 'seek' ) and total_length is None :
89
+ # StringIO has a notimplemented fileno
90
+ # BytesIO has seek and not fileno
91
+ total_length = o .seek (0 , 2 )
92
+ # seek back to current position to support partially read file-like
93
+ o .seek (current_position )
94
+
92
95
return max (0 , total_length - current_position )
93
96
94
97
You can’t perform that action at this time.
0 commit comments