Message327226
If a change is made, it would be nice to bring the “gzip”, “bzip” and LZMA modules closer together. The current “bzip” and LZMA modules rely on the underlying “seekable” method without a fallback implementation, but also have a check for read mode.
I think the seeking functionality in these modules is a misfeature. But since it is already here, it is probably best to leave it alone, and just document it.
My comment about making “seekable” stricter is at <https://bugs.python.org/review/23529/diff/14296/Lib/gzip.py#oldcode550>. Even if the underlying stream is not seekable, GzipFile can still fast-forward. Here is a demonstration:
>>> z = BytesIO(bytes.fromhex(
... "1F8B08000000000002FFF348CD29D051F05448CC55282E294DCE56C8CC53485448AFCA"
... "2C5048CBCC490500F44BF0A01F000000"
... ))
>>> def seek(*args): raise UnsupportedOperation()
...
>>> z.seek = seek # Make the underlying stream not seekable
>>> f = GzipFile(fileobj=z)
>>> f.read(10)
b'Help, I am'
>>> f.seek(20) # Fast forward
20
>>> f.read()
b'a gzip file'
>>> f.seek(0) # Rewind
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/proj/python/cpython/Lib/gzip.py", line 368, in seek
return self._buffer.seek(offset, whence)
File "/home/proj/python/cpython/Lib/_compression.py", line 137, in seek
self._rewind()
File "/home/proj/python/cpython/Lib/gzip.py", line 515, in _rewind
super()._rewind()
File "/home/proj/python/cpython/Lib/_compression.py", line 115, in _rewind
self._fp.seek(0)
File "/home/proj/python/cpython/Lib/gzip.py", line 105, in seek
return self.file.seek(off)
File "<stdin>", line 1, in seek
io.UnsupportedOperation |
|
Date |
User |
Action |
Args |
2018-10-06 06:03:22 | martin.panter | set | recipients:
+ martin.panter, pitrou, cheryl.sabella, Walt Askew, xtreak |
2018-10-06 06:03:22 | martin.panter | set | messageid: <1538805802.85.0.545547206417.issue33173@psf.upfronthosting.co.za> |
2018-10-06 06:03:22 | martin.panter | link | issue33173 messages |
2018-10-06 06:03:22 | martin.panter | create | |
|