[Python-checkins] cpython (merge 3.5 -> default): Issue #25758: Prevents zipimport from unnecessarily encoding a filename (patch

steve.dower python-checkins at python.org
Fri Sep 9 20:33:59 EDT 2016


https://hg.python.org/cpython/rev/ead30e7262d5
changeset:   103509:ead30e7262d5
parent:      103507:efd692c86429
parent:      103508:663a62bcf9c9
user:        Steve Dower <steve.dower at microsoft.com>
date:        Fri Sep 09 17:33:37 2016 -0700
summary:
  Issue #25758: Prevents zipimport from unnecessarily encoding a filename (patch by Eryk Sun)

files:
  Lib/test/test_zipimport.py |   2 +-
  Misc/NEWS                  |   3 +++
  Modules/zipimport.c        |  14 ++++----------
  3 files changed, 8 insertions(+), 11 deletions(-)


diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py
--- a/Lib/test/test_zipimport.py
+++ b/Lib/test/test_zipimport.py
@@ -615,7 +615,7 @@
         z.writestr(zinfo, test_src)
         z.close()
         try:
-            zipimport.zipimporter(filename)
+            zipimport.zipimporter(filename).load_module(TESTMOD)
         finally:
             os.remove(filename)
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #25758: Prevents zipimport from unnecessarily encoding a filename
+  (patch by Eryk Sun)
+
 - Issue #25856: The __module__ attribute of extension classes and functions
   now is interned. This leads to more compact pickle data with protocol 4.
 
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -1362,22 +1362,16 @@
 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;
 }

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list