Kaydet (Commit) 095a421b authored tarafından Oren Milman's avatar Oren Milman Kaydeden (comit) Serhiy Storchaka

[3.6] bpo-31291: Fixed an assertion failure in zipimport.zipimporter.get_data() (GH-3226) (#3243)

if pathname.replace('/', '\\') returns non-string.
(cherry picked from commit 631fdee6)
üst 2d1653aa
......@@ -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():
......
Fix an assertion failure in `zipimport.zipimporter.get_data` on Windows,
when the return value of ``pathname.replace('/','\\')`` isn't a string.
Patch by Oren Milman.
......@@ -580,7 +580,8 @@ zipimporter_get_data(PyObject *obj, PyObject *args)
return NULL;
#ifdef ALTSEP
path = _PyObject_CallMethodId(path, &PyId_replace, "CC", ALTSEP, SEP);
path = _PyObject_CallMethodId((PyObject *)&PyUnicode_Type, &PyId_replace,
"OCC", path, ALTSEP, SEP);
if (!path)
return NULL;
#else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment