[issue28436] GzipFile doesn't properly handle short reads and writes on the underlying stream

Martin Panter report at bugs.python.org
Fri Oct 14 17:34:58 EDT 2016


Martin Panter added the comment:

I would fix the documentation to say the underlying stream should do “exact” reads and writes, e.g. one that implements io.BufferedIOBase.read(size) or write(). In my experience, most APIs in Python’s library assume or require this, rather than the “raw” behaviour.

Is it likely that people are passing raw FileIO or similar objects to GzipFile, or is this just a theoretical problem?

Also related: In Issue 24291 and Issue 26721, we realized that all the servers based on socketserver could unexpectedly do short writes, which was a practical bug (not just theoretical). I changed socketserver over to doing exact writes, and added a workaround in the wsgiref module to handle partial writes. See <https://docs.python.org/3.5/library/wsgiref.html#wsgiref.handlers.SimpleHandler> for the altered documentation.

Other APIs that come to mind are shutil.copyfileobj() (documentation proposed in Issue 24291), and io.TextIOWrapper (documented as requiring BufferedIOBase). Also, the bzip and LZMA modules seem equally affected as gzip.

----------
assignee:  -> docs at python
components: +Documentation -Library (Lib)
nosy: +docs at python
stage:  -> needs patch
versions: +Python 3.6, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28436>
_______________________________________


More information about the Python-bugs-list mailing list