removing use of seek to set total_length

This commit is contained in:
Nate Prewitt
2016-08-24 10:25:37 -06:00
parent 8873a09097
commit 99364b6b0b
+9 -11
View File
@@ -86,18 +86,16 @@ def super_len(o):
if total_length is not None:
current_position = total_length
if hasattr(o, 'seek') and total_length is None:
# 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
if hasattr(o, 'seek') and total_length is None:
# StringIO and BytesIO have seek but no useable fileno
# seek back to current position to support partially read file-like
o.seek(current_position or 0)
# seek to end of file
o.seek(0, 2)
total_length = o.tell()
# seek back to current position to support
# partially read file-like objects
o.seek(current_position or 0)
if total_length is None:
total_length = 0