[pypy-svn] pypy interplevel-exception-classes: zipimport.ZipImportError at interp-level

amauryfa commits-noreply at bitbucket.org
Fri Feb 18 14:03:44 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: interplevel-exception-classes
Changeset: r42167:af791a1b3462
Date: 2011-02-18 14:00 +0100
http://bitbucket.org/pypy/pypy/changeset/af791a1b3462/

Log:	zipimport.ZipImportError at interp-level

diff --git a/pypy/module/zipimport/app_zipimport.py b/pypy/module/zipimport/app_zipimport.py
deleted file mode 100644
--- a/pypy/module/zipimport/app_zipimport.py
+++ /dev/null
@@ -1,4 +0,0 @@
-
-class ZipImportError(ImportError):
-    pass
-

diff --git a/pypy/module/zipimport/__init__.py b/pypy/module/zipimport/__init__.py
--- a/pypy/module/zipimport/__init__.py
+++ b/pypy/module/zipimport/__init__.py
@@ -8,11 +8,11 @@
 
     interpleveldefs = {
         'zipimporter':'interp_zipimport.W_ZipImporter',
-        '_zip_directory_cache' : 'space.wrap(interp_zipimport.zip_cache)'
+        '_zip_directory_cache' : 'space.wrap(interp_zipimport.zip_cache)',
+        'ZipImportError': 'space.fromcache(interp_zipimport.Cache).w_error',
     }
 
     appleveldefs = {
-        'ZipImportError'      : 'app_zipimport.ZipImportError',
     }
 
     def setup_after_space_initialization(self):

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
@@ -22,6 +22,14 @@
      (True, False, '.pyo'),
      (False, False, '.py')])
 
+class Cache:
+    def __init__(self, space):
+        self.w_error = space.new_exception_class("zipimport.ZipImportError",
+                                                 space.w_ImportError)
+
+def get_error(space):
+    return space.fromcache(Cache).w_error
+
 class W_ZipCache(Wrappable):
     def __init__(self):
         self.cache = {}
@@ -113,9 +121,6 @@
         self.filename = filename
         self.dir = dir
         self.prefix = prefix
-        self.w_ZipImportError = space.getattr(
-            space.getbuiltinmodule('zipimport'),
-            space.wrap('ZipImportError'))
 
     def getprefix(self, space):
         return space.wrap(self.prefix)
@@ -265,7 +270,7 @@
                     w_mods = space.sys.get('modules')
                 space.call_method(w_mods, 'pop', w(fullname), space.w_None)
         if last_exc:
-            raise OperationError(self.w_ZipImportError, last_exc.get_w_value(space))
+            raise OperationError(get_error(space), last_exc.get_w_value(space))
         # should never happen I think
         return space.w_None
 
@@ -303,7 +308,7 @@
                     code_w = importing.parse_source_module(
                         space, co_filename, source)
                 return space.wrap(code_w)
-        raise operationerrfmt(self.w_ZipImportError,
+        raise operationerrfmt(get_error(space),
             "Cannot find source or code for %s in %s", filename, self.name)
 
     @unwrap_spec(fullname=str)
@@ -319,7 +324,7 @@
                     found = True
         if found:
             return space.w_None
-        raise operationerrfmt(self.w_ZipImportError,
+        raise operationerrfmt(get_error(space),
             "Cannot find source for %s in %s", filename, self.name)
 
     @unwrap_spec(fullname=str)
@@ -329,7 +334,7 @@
             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,
+        raise operationerrfmt(get_error(space),
             "Cannot find module %s in %s", filename, self.name)
 
     @unwrap_spec(fullname=str)
@@ -338,7 +343,7 @@
         for _, is_package, ext in ENUMERATE_EXTS:
             if self.have_modulefile(space, filename + ext):
                 return space.wrap(is_package)
-        raise operationerrfmt(self.w_ZipImportError,
+        raise operationerrfmt(get_error(space),
             "Cannot find module %s in %s", filename, self.name)
 
     def getarchive(self, space):


More information about the Pypy-commit mailing list