Don't use the file descriptor size for multipart file lengths
PA
5h ago+31+31+01234567890123456789-14-14-01234567890123456789
Summary
peek_filelike_length() takes os.fstat().st_size when the object has a fileno(). That's wrong for anything where read() doesn't return the raw file bytes:
gzip.open(path, "rb")reports the compressed size- a pipe (
Popen(...).stdout,sys.stdin.buffer) reports 0
So files={"f": gzip.open(...)} sends a too small Content-Length and fails with LocalProtocolError: Too much data for declared Content-Length.
This drops the fstat branch and keeps the tell()/seek() fallback, the same thing #1214 did for content=. Gzip files now get the right length, pipes go out chunked. Regular files are unchanged.
Checklist
- I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
- I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
- I've updated the documentation accordingly.