[pypy-svn] pypy default: make sure that the code objects have a co_filename in the form 'zipfile.zip/pyfile.py'

antocuni commits-noreply at bitbucket.org
Tue Feb 15 18:19:18 CET 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r41984:088b8b251525
Date: 2011-02-15 16:48 +0100
http://bitbucket.org/pypy/pypy/changeset/088b8b251525/

Log:	make sure that the code objects have a co_filename in the form
	'zipfile.zip/pyfile.py'

diff --git a/pypy/module/zipimport/interp_zipimport.py b/pypy/module/zipimport/interp_zipimport.py
--- a/pypy/module/zipimport/interp_zipimport.py
+++ b/pypy/module/zipimport/interp_zipimport.py
@@ -237,6 +237,7 @@
         last_exc = None
         for compiled, is_package, ext in ENUMERATE_EXTS:
             fname = filename + ext
+            co_filename = self.filename + os.path.sep + fname
             try:
                 zip_file = RZipFile(self.filename, 'r')
                 try:
@@ -253,10 +254,10 @@
                     pkgpath = None
                 try:
                     if compiled:
-                        return self.import_pyc_file(space, fullname, fname,
+                        return self.import_pyc_file(space, fullname, co_filename,
                                                     buf, pkgpath)
                     else:
-                        return self.import_py_file(space, fullname, fname,
+                        return self.import_py_file(space, fullname, co_filename,
                                                    buf, pkgpath)
                 except OperationError, e:
                     last_exc = e

diff --git a/pypy/module/zipimport/test/test_zipimport.py b/pypy/module/zipimport/test/test_zipimport.py
--- a/pypy/module/zipimport/test/test_zipimport.py
+++ b/pypy/module/zipimport/test/test_zipimport.py
@@ -338,6 +338,18 @@
         import zipimport
         assert sys.path_hooks.count(zipimport.zipimporter) == 1
 
+    def test_co_filename(self):
+        self.writefile('mymodule.py', """
+def fn():
+    return fn.func_code.co_filename
+""")
+        import os
+        import mymodule
+        co_filename = mymodule.fn()
+        expected = self.zipfile + os.sep + 'mymodule.py'
+        assert co_filename == expected
+
+
 class AppTestZipimportDeflated(AppTestZipimport):
     compression = ZIP_DEFLATED
 


More information about the Pypy-commit mailing list