Skip to content

Commit c8c984b

Browse files
refactor: improve StringIO handling code readability
- Expand compressed logic into clearer if/else blocks - Add explanatory comment for remaining bytes calculation - Maintain same functionality with better code structure
1 parent 73a9a4e commit c8c984b

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/requests/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,15 @@ def super_len(o):
154154
o.seek(0)
155155
content = o.read()
156156
total_length = len(content.encode("utf-8"))
157+
# Calculate remaining bytes from current position
158+
if current_pos > 0:
159+
consumed_content = content[:current_pos]
160+
consumed_bytes = len(consumed_content.encode("utf-8"))
161+
return max(0, total_length - consumed_bytes)
162+
else:
163+
return total_length
157164
finally:
158165
o.seek(current_pos)
159-
return max(0, total_length - (len(content[:current_pos].encode("utf-8")) if current_pos > 0 else 0))
160166

161167
if hasattr(o, "__len__"):
162168
total_length = len(o)

0 commit comments

Comments
 (0)