cpython
cpython copied to clipboard
bpo-40506: add support for path-like filenames in ZipFile.writestr
ZipFile.writestr doesn't work when a pathlike filename is used, the other methods do.
Example:
>>> a = ZipFile(Path('test.zip'), 'w') # this works
>>> a.write(Path('./foo.jpeg'), arcname=PurePath('/some/thing.jpeg')) # this works
>>> a.writestr(PurePath('/test.txt'), 'idk') # this doesn't
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/zipfile.py", line 1788, in writestr
zinfo = ZipInfo(filename=zinfo_or_arcname,
File "/usr/lib/python3.8/zipfile.py", line 349, in __init__
null_byte = filename.find(chr(0))
AttributeError: 'PurePosixPath' object has no attribute 'find'
https://bugs.python.org/issue40506