Message349101
Hello,
#!/usr/bin/python3.8
from zipfile import ZipFile, Path
import io
def recurse_print(parent):
for child in parent.iterdir():
if child.is_file():
print(child, child.read_text())
if child.is_dir():
recurse_print(child)
data = io.BytesIO()
zf = ZipFile(data, "w")
zf.writestr("a.txt", "content of a")
zf.writestr("b/c.txt", "content of c")
zf.writestr("b/d/e.txt", "content of e")
zf.writestr("b/f.txt", "content of f")
zf.filename = "abcde.zip"
root = Path(zf)
recurse_print(root)
Expected result:
abcde.zip/a.txt content of a
abcde.zip/b/c.txt content of c
abcde.zip/b/f.txt content of f
abcde.zip/b/d/e.txt content of e
Actual result:
abcde.zip/a.txt content of a
abcde.zip/b/c.txt content of c
abcde.zip/b/f.txt content of f
abcde.zip/b/d/e.txt content of e
abcde.zip/b/c.txt content of c
abcde.zip/b/f.txt content of f
abcde.zip/b/d/e.txt content of e
Path._add_implied_dirs adds the sub directory "b/" twice: once for each direct child (i.e. "c.txt" and "f.txt")
And similarly:
data = io.BytesIO()
zf = ZipFile(data, "w")
zf.writestr("a.txt", "content of a")
zf.writestr("b/d/e.txt", "content of e")
zf.filename = "abcde.zip"
root = Path(zf)
recurse_print(root)
Expected result:
abcde.zip/a.txt content of a
abcde.zip/b/d/e.txt content of e
Actual result:
abcde.zip/a.txt content of a
Here, Path._add_implied_dirs doesn't add "b/" at all, because there are no direct childs of "b". |
|
Date |
User |
Action |
Args |
2019-08-06 06:57:30 | joernheissler | set | recipients:
+ joernheissler |
2019-08-06 06:57:30 | joernheissler | set | messageid: <1565074650.65.0.762547380277.issue37772@roundup.psfhosted.org> |
2019-08-06 06:57:30 | joernheissler | link | issue37772 messages |
2019-08-06 06:57:30 | joernheissler | create | |
|