Message353244
Currently (as of df69e75) it checks only the initial letter (via `mode.startswith`) of "mode" in gzip.GzipFile.__init__. See also: https://github.com/python/cpython/blob/df69e75/Lib/gzip.py#L183
I'd personally suggest that it takes also "+" into consideration, which shall be regarded as writable.
One common (hm.. at least I've observed more than once recently) case where people may make mistakes is to use a tempfile.NamedTemporaryFile as the file object without specifying explicitly a mode, while expecting the GzipFile to be writable.
A quick example (in Python 3.7.11):
```
>>> import tempfile
>>> tempfile.NamedTemporaryFile().mode
'rb+'
>>> import gzip
>>> gzip.GzipFile(fileobj=tempfile.NamedTemporaryFile(mode='rb+')).writable()
False
>>> gzip.GzipFile(fileobj=tempfile.NamedTemporaryFile(mode='wb')).writable()
True
```
Unfortunately this change request may be backward-incompatible, since previously modes like "r+b" have been treated as read-only. See also: https://github.com/python/cpython/blob/df69e75/Lib/test/test_gzip.py#L464 |
|
Date |
User |
Action |
Args |
2019-09-26 00:49:11 | __starrify__ | set | recipients:
+ __starrify__ |
2019-09-26 00:49:11 | __starrify__ | set | messageid: <1569458951.07.0.462687490568.issue38281@roundup.psfhosted.org> |
2019-09-26 00:49:11 | __starrify__ | link | issue38281 messages |
2019-09-26 00:49:10 | __starrify__ | create | |
|