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
)
| 140 | |
| 141 | |
| 142 | def 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 | |
| 162 | def rewind_body(body: typing.IO[typing.AnyStr], body_pos: _TYPE_BODY_POSITION) -> None: |
no test coverage detected