[pypy-svn] pypy interplevel-exception-classes: rewrite binascii.Error, binascii.Incomplete at interp-level

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


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

Log:	rewrite binascii.Error, binascii.Incomplete at interp-level

diff --git a/pypy/module/binascii/interp_binascii.py b/pypy/module/binascii/interp_binascii.py
--- a/pypy/module/binascii/interp_binascii.py
+++ b/pypy/module/binascii/interp_binascii.py
@@ -1,11 +1,14 @@
 from pypy.interpreter.error import OperationError
 
+class Cache:
+    def __init__(self, space):
+        self.w_error = space.new_exception_class("binascii.Error")
+        self.w_incomplete = space.new_exception_class("binascii.Incomplete")
+
 def raise_Error(space, msg):
-    w_module = space.getbuiltinmodule('binascii')
-    w_Error = space.getattr(w_module, space.wrap('Error'))
-    raise OperationError(w_Error, space.wrap(msg))
+    w_error = space.fromcache(Cache).w_error
+    raise OperationError(w_error, space.wrap(msg))
 
 def raise_Incomplete(space, msg):
-    w_module = space.getbuiltinmodule('binascii')
-    w_Error = space.getattr(w_module, space.wrap('Incomplete'))
-    raise OperationError(w_Error, space.wrap(msg))
+    w_error = space.fromcache(Cache).w_incomplete
+    raise OperationError(w_error, space.wrap(msg))

diff --git a/pypy/module/binascii/app_binascii.py b/pypy/module/binascii/app_binascii.py
deleted file mode 100644
--- a/pypy/module/binascii/app_binascii.py
+++ /dev/null
@@ -1,6 +0,0 @@
-
-class Error(Exception):
-    pass
-
-class Incomplete(Exception):
-    pass

diff --git a/pypy/module/binascii/__init__.py b/pypy/module/binascii/__init__.py
--- a/pypy/module/binascii/__init__.py
+++ b/pypy/module/binascii/__init__.py
@@ -12,8 +12,6 @@
     """binascii - Conversion between binary data and ASCII"""
 
     appleveldefs = {
-        'Error': 'app_binascii.Error',
-        'Incomplete': 'app_binascii.Incomplete',
         }
 
     interpleveldefs = {
@@ -33,4 +31,6 @@
         'hexlify': 'interp_hexlify.hexlify',
         'a2b_hex': 'interp_hexlify.unhexlify',
         'unhexlify': 'interp_hexlify.unhexlify',
+        'Error'     : 'space.fromcache(interp_binascii.Cache).w_error',
+        'Incomplete': 'space.fromcache(interp_binascii.Cache).w_incomplete',
         }


More information about the Pypy-commit mailing list