]> granicus.if.org Git - python/commitdiff
Issue #25758: Prevents zipimport from unnecessarily encoding a filename (patch by...
authorSteve Dower <steve.dower@microsoft.com>
Sat, 10 Sep 2016 00:27:33 +0000 (17:27 -0700)
committerSteve Dower <steve.dower@microsoft.com>
Sat, 10 Sep 2016 00:27:33 +0000 (17:27 -0700)
Lib/test/test_zipimport.py
Misc/NEWS
Modules/zipimport.c

index 8e5e12d4377dc778df40a55c22c5bfd5057b5634..2bb7230c26af03dde46ceaa192e349419a9dedeb 100644 (file)
@@ -596,7 +596,7 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
         z.writestr(zinfo, test_src)
         z.close()
         try:
-            zipimport.zipimporter(filename)
+            zipimport.zipimporter(filename).load_module(TESTMOD)
         finally:
             os.remove(filename)
 
index 6ef92f7af855d6cbad2b3ad135d249143c067e85..c1420e1bd8b58cdcb1f8070565a13dd17911263e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ Release date: TBA
 Core and Builtins
 -----------------
 
+- Issue #25758: Prevents zipimport from unnecessarily encoding a filename
+  (patch by Eryk Sun)
+
 - Issue #27812: Properly clear out a generator's frame's backreference to the
   generator to prevent crashes in frame.clear().
 
index 6d5c68a61e8f9a2da3a87cf2bde773e55d8a2aaa..92a82e6df269bb41f35ee48e3d5c33eed24c9219 100644 (file)
@@ -1362,22 +1362,16 @@ normalize_line_endings(PyObject *source)
 static PyObject *
 compile_source(PyObject *pathname, PyObject *source)
 {
-    PyObject *code, *fixed_source, *pathbytes;
-
-    pathbytes = PyUnicode_EncodeFSDefault(pathname);
-    if (pathbytes == NULL)
-        return NULL;
+    PyObject *code, *fixed_source;
 
     fixed_source = normalize_line_endings(source);
     if (fixed_source == NULL) {
-        Py_DECREF(pathbytes);
         return NULL;
     }
 
-    code = Py_CompileString(PyBytes_AsString(fixed_source),
-                            PyBytes_AsString(pathbytes),
-                            Py_file_input);
-    Py_DECREF(pathbytes);
+    code = Py_CompileStringObject(PyBytes_AsString(fixed_source),
+                                  pathname, Py_file_input, NULL, 1);
+
     Py_DECREF(fixed_source);
     return code;
 }