MCPcopy
hub / github.com/urllib3/urllib3 / set_file_position

Function set_file_position

src/urllib3/util/request.py:142–159  ·  view source on GitHub ↗

If a position is provided, move file to that point. Otherwise, we'll attempt to record a position for future use.

(
    body: typing.Any, pos: _TYPE_BODY_POSITION | None
)

Source from the content-addressed store, hash-verified

140
141
142def set_file_position(
143 body: typing.Any, pos: _TYPE_BODY_POSITION | None
144) -> _TYPE_BODY_POSITION | None:
145 """
146 If a position is provided, move file to that point.
147 Otherwise, we'll attempt to record a position for future use.
148 """
149 if pos is not None:
150 rewind_body(body, pos)
151 elif getattr(body, "tell", None) is not None:
152 try:
153 pos = body.tell()
154 except OSError:
155 # This differentiates from None, allowing us to catch
156 # a failed `tell()` later when trying to rewind the body.
157 pos = _FAILEDTELL
158
159 return pos
160
161
162def rewind_body(body: typing.IO[typing.AnyStr], body_pos: _TYPE_BODY_POSITION) -> None:

Callers 1

urlopenMethod · 0.85

Calls 2

rewind_bodyFunction · 0.85
tellMethod · 0.45

Tested by

no test coverage detected