Message397595
Changing the repro to:
```
import zipfile
try:
import zipp
except ImportError:
import zipfile as zipp
zip_file = zipfile.ZipFile('zipfile.zip')
name = zip_file.namelist()[0]
zipp.Path(zip_file)
zip_file.open(name)
```
I'm able now to test against zipfile or zipp. And I notice that the issue occurs only on zipp<3.2 or Python<3.10.
```
draft $ pip-run -q 'zipp<3.3' -- issue44638.py
draft $ pip-run -q 'zipp<3.2' -- issue44638.py
Traceback (most recent call last):
File "/Users/jaraco/draft/issue44638.py", line 11, in <module>
zip_file.open(name)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/zipfile.py", line 1518, in open
fheader = zef_file.read(sizeFileHeader)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/zipfile.py", line 741, in read
self._file.seek(self._pos)
ValueError: seek of closed file
```
```
draft $ python3.10 issue44638.py
draft $ python3.9 issue44638.py
Traceback (most recent call last):
File "/Users/jaraco/draft/issue44638.py", line 11, in <module>
zip_file.open(name)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/zipfile.py", line 1518, in open
fheader = zef_file.read(sizeFileHeader)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/zipfile.py", line 741, in read
self._file.seek(self._pos)
ValueError: seek of closed file
```
Looking at the changelog (https://zipp.readthedocs.io/en/latest/history.html#v3-2-0), it's clear now that this issue is a duplicate of bpo-40564 and the problem goes away using the original repro and Python 3.10:
```
draft $ cat > issue44638.py
import zipfile
class TestClass:
def __init__(self, path):
self.zip_file = zipfile.ZipFile(path)
def iter_dir(self):
return [each.name for each in zipfile.Path(self.zip_file).iterdir()]
def read(self, filename):
with self.zip_file.open(filename) as file:
print(file.read())
root = "zipfile.zip"
test = TestClass(root)
files = test.iter_dir()
test.read(files[0])
draft $ python3.10 issue44638.py
b'import zipfile\n\n\nclass TestClass:\n def __init__(self, path):\n self.zip_file = zipfile.ZipFile(path)\n\n def iter_dir(self):\n return [each.name for each in zipfile.Path(self.zip_file).iterdir()]\n\n def read(self, filename):\n with self.zip_file.open(filename) as file:\n print(file.read())\n\nroot = "zipfile.zip"\ntest = TestClass(root)\nfiles = test.iter_dir()\ntest.read(files[0])\n'
```
The solution is to use zipp>=3.2 or Python 3.10. |
|
Date |
User |
Action |
Args |
2021-07-16 01:11:49 | jaraco | set | recipients:
+ jaraco, xtreak, jack__d, christian.steinmeyer |
2021-07-16 01:11:49 | jaraco | set | messageid: <1626397909.46.0.914439089156.issue44638@roundup.psfhosted.org> |
2021-07-16 01:11:49 | jaraco | link | issue44638 messages |
2021-07-16 01:11:49 | jaraco | create | |
|