[pypy-svn] r78330 - in pypy/branch/fast-forward/pypy/module/zipimport: . test

afa at codespeak.net afa at codespeak.net
Wed Oct 27 00:58:54 CEST 2010


Author: afa
Date: Wed Oct 27 00:58:52 2010
New Revision: 78330

Modified:
   pypy/branch/fast-forward/pypy/module/zipimport/interp_zipimport.py
   pypy/branch/fast-forward/pypy/module/zipimport/test/test_zipimport.py
Log:
Implement zipimporter._get_filename()


Modified: pypy/branch/fast-forward/pypy/module/zipimport/interp_zipimport.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/zipimport/interp_zipimport.py	(original)
+++ pypy/branch/fast-forward/pypy/module/zipimport/interp_zipimport.py	Wed Oct 27 00:58:52 2010
@@ -303,6 +303,16 @@
             "Cannot find source for %s in %s", filename, self.name)
     get_source.unwrap_spec = ['self', ObjSpace, str]
 
+    def get_filename(self, space, fullname):
+        filename = self.mangle(fullname)
+        for _, is_package, ext in ENUMERATE_EXTS:
+            if self.have_modulefile(space, filename + ext):
+                return space.wrap(self.filename + os.path.sep +
+                                  self.corr_zname(filename + ext))
+        raise operationerrfmt(self.w_ZipImportError,
+            "Cannot find module %s in %s", filename, self.name)
+    get_filename.unwrap_spec = ['self', ObjSpace, str]
+
     def is_package(self, space, fullname):
         filename = self.mangle(fullname)
         for _, is_package, ext in ENUMERATE_EXTS:
@@ -373,6 +383,7 @@
     get_data    = interp2app(W_ZipImporter.get_data),
     get_code    = interp2app(W_ZipImporter.get_code),
     get_source  = interp2app(W_ZipImporter.get_source),
+    _get_filename = interp2app(W_ZipImporter.get_filename),
     is_package  = interp2app(W_ZipImporter.is_package),
     load_module = interp2app(W_ZipImporter.load_module),
     archive     = GetSetProperty(W_ZipImporter.getarchive),

Modified: pypy/branch/fast-forward/pypy/module/zipimport/test/test_zipimport.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/zipimport/test/test_zipimport.py	(original)
+++ pypy/branch/fast-forward/pypy/module/zipimport/test/test_zipimport.py	Wed Oct 27 00:58:52 2010
@@ -269,6 +269,8 @@
         assert z.get_code('xx')
         assert z.get_source('xx') == "5"
         assert z.archive == self.zipfile
+        mod = z.load_module('xx')
+        assert z._get_filename('xx') == mod.__file__
 
     def test_archive(self):
         """



More information about the Pypy-commit mailing list