bpo-31291: Fixed an assertion failure in zipimport.zipimporter.get_data() (#3226)

if pathname.replace('/', '\\') returns non-string.
This commit is contained in:
Oren Milman 2017-08-29 20:40:15 +03:00 committed by Serhiy Storchaka
parent 006617ff7d
commit 631fdee6e6
3 changed files with 22 additions and 1 deletions

View file

@ -521,6 +521,23 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
z.close()
os.remove(TEMP_ZIP)
def test_issue31291(self):
# There shouldn't be an assertion failure in get_data().
class FunnyStr(str):
def replace(self, old, new):
return 42
z = ZipFile(TEMP_ZIP, "w")
try:
name = "test31291.dat"
data = b'foo'
z.writestr(name, data)
z.close()
zi = zipimport.zipimporter(TEMP_ZIP)
self.assertEqual(data, zi.get_data(FunnyStr(name)))
finally:
z.close()
os.remove(TEMP_ZIP)
def testImporterAttr(self):
src = """if 1: # indent hack
def get_file():