import libarchive
import sys
def test1(path):
"""Normal iteration"""
print("Test 1");
with libarchive.file_reader(path) as ar:
for e in ar:
print(" ", e)
def test2(path):
"""Try saving an entry and using ouside of for loop"""
print("Test 2");
with libarchive.file_reader(path) as ar:
for e in ar:
e2 = e
print(" First entry:", e2)
break
print(" First entry (outside):", e2)
def test3(path):
"""Try making a list of ArchiveEntry objects"""
print("Test 3");
with libarchive.file_reader(path) as ar:
for e in list(ar):
print(" ", e)
path = sys.argv[1]
test1(path)
test2(path)
#test3(path)
Output:
Test 1
test.txt
Test 2
First entry: test.txt
First entry (outside): Traceback (most recent call last):
File "bug.py", line 30, in <module>
test2(path)
File "bug.py", line 19, in test2
print(" First entry (outside):", e2)
TypeError: __str__ returned non-string (type NoneType)
This error happens because ._getpathname() returns None.
Test code:
Output:
This error happens because
._getpathname()
returnsNone
.