[pypy-svn] pypy interplevel-exception-classes: add space.new_exception_class(), and use it to remove applevel code in _rawffi

amauryfa commits-noreply at bitbucket.org
Fri Feb 18 11:49:10 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: interplevel-exception-classes
Changeset: r42140:607197252e64
Date: 2011-02-18 10:57 +0100
http://bitbucket.org/pypy/pypy/changeset/607197252e64/

Log:	add space.new_exception_class(), and use it to remove applevel code
	in _rawffi

diff --git a/pypy/module/_rawffi/error.py b/pypy/module/_rawffi/error.py
deleted file mode 100644
--- a/pypy/module/_rawffi/error.py
+++ /dev/null
@@ -1,2 +0,0 @@
-class SegfaultException(Exception):
-    pass

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -3,6 +3,7 @@
 from pypy.interpreter.executioncontext import ExecutionContext, ActionFlag
 from pypy.interpreter.executioncontext import UserDelAction, FrameTraceAction
 from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import new_exception_class
 from pypy.interpreter.argument import Arguments
 from pypy.interpreter.miscutils import ThreadLocals
 from pypy.tool.cache import Cache
@@ -958,6 +959,10 @@
     def exception_issubclass_w(self, w_cls1, w_cls2):
         return self.is_true(self.issubtype(w_cls1, w_cls2))
 
+    def new_exception_class(self, *args, **kwargs):
+        "NOT_RPYTHON; convenience method to create excceptions in modules"
+        return new_exception_class(self, *args, **kwargs)
+
     # end of special support code
 
     def eval(self, expression, w_globals, w_locals, hidden_applevel=False):

diff --git a/pypy/module/_socket/interp_socket.py b/pypy/module/_socket/interp_socket.py
--- a/pypy/module/_socket/interp_socket.py
+++ b/pypy/module/_socket/interp_socket.py
@@ -7,7 +7,6 @@
 from pypy.rlib.rsocket import RSocket, AF_INET, SOCK_STREAM
 from pypy.rlib.rsocket import SocketError, SocketErrorWithErrno
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.error import new_exception_class
 from pypy.interpreter import gateway
 
 class SignalChecker:
@@ -435,14 +434,14 @@
 
 class SocketAPI:
     def __init__(self, space):
-        self.w_error = new_exception_class(
-            space, "_socket.error", space.w_IOError)
-        self.w_herror = new_exception_class(
-            space, "_socket.herror", self.w_error)
-        self.w_gaierror = new_exception_class(
-            space, "_socket.gaierror", self.w_error)
-        self.w_timeout = new_exception_class(
-            space, "_socket.timeout", self.w_error)
+        self.w_error = space.new_exception_class(
+            "_socket.error", space.w_IOError)
+        self.w_herror = space.new_exception_class(
+            "_socket.herror", self.w_error)
+        self.w_gaierror = space.new_exception_class(
+            "_socket.gaierror", self.w_error)
+        self.w_timeout = space.new_exception_class(
+            "_socket.timeout", self.w_error)
 
         self.errors_w = {'error': self.w_error,
                          'herror': self.w_herror,

diff --git a/pypy/module/_rawffi/__init__.py b/pypy/module/_rawffi/__init__.py
--- a/pypy/module/_rawffi/__init__.py
+++ b/pypy/module/_rawffi/__init__.py
@@ -30,6 +30,7 @@
         'get_libc'           : 'interp_rawffi.get_libc',
         'get_errno'          : 'interp_rawffi.get_errno',
         'set_errno'          : 'interp_rawffi.set_errno',
+        'SegfaultException'  : 'space.new_exception_class("_rawffi.SegfaultException")',
     }
 
     if sys.platform == 'win32':
@@ -37,7 +38,6 @@
         interpleveldefs['set_last_error'] = 'interp_rawffi.set_last_error'
 
     appleveldefs = {
-        'SegfaultException'  : 'error.SegfaultException',
     }
 
     def buildloaders(cls):

diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -1,5 +1,5 @@
 from pypy.rpython.lltypesystem import rffi, lltype
-from pypy.interpreter.error import OperationError, new_exception_class
+from pypy.interpreter.error import OperationError
 from pypy.interpreter.baseobjspace import W_Root, ObjSpace, Wrappable
 from pypy.interpreter.typedef import TypeDef
 from pypy.interpreter.gateway import interp2app, unwrap_spec
@@ -554,8 +554,8 @@
 class Cache:
     def __init__(self, space):
         w_socketerror = interp_socket.get_error(space, "error")
-        self.w_error = new_exception_class(
-            space, "_ssl.SSLError", w_socketerror)
+        self.w_error = space.new_exception_class(
+            "_ssl.SSLError", w_socketerror)
 
 def get_error(space):
     return space.fromcache(Cache).w_error


More information about the Pypy-commit mailing list