[pypy-svn] r69229 - in pypy/branch/faster-raise/pypy: interpreter lib module/exceptions module/exceptions/test module/tempexceptions objspace/std

arigo at codespeak.net arigo at codespeak.net
Thu Nov 12 15:04:51 CET 2009


Author: arigo
Date: Thu Nov 12 15:04:51 2009
New Revision: 69229

Added:
   pypy/branch/faster-raise/pypy/module/exceptions/
      - copied from r69227, pypy/branch/faster-raise/pypy/module/tempexceptions/
Removed:
   pypy/branch/faster-raise/pypy/lib/_exceptions.py
   pypy/branch/faster-raise/pypy/module/tempexceptions/
Modified:
   pypy/branch/faster-raise/pypy/interpreter/baseobjspace.py
   pypy/branch/faster-raise/pypy/module/exceptions/__init__.py
   pypy/branch/faster-raise/pypy/module/exceptions/test/test_exc.py
   pypy/branch/faster-raise/pypy/objspace/std/objspace.py
Log:
Progress.  Now we are entering the land of real obscureness.


Modified: pypy/branch/faster-raise/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/faster-raise/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/faster-raise/pypy/interpreter/baseobjspace.py	Thu Nov 12 15:04:51 2009
@@ -389,12 +389,19 @@
     def make_builtins(self):
         "NOT_RPYTHON: only for initializing the space."
 
+        from pypy.module.exceptions import Module
+        w_name_exceptions = self.wrap('exceptions')
+        self.exceptions_module = Module(self, w_name_exceptions)
+
         from pypy.module.sys import Module
         w_name = self.wrap('sys')
         self.sys = Module(self, w_name)
         w_modules = self.sys.get('modules')
         self.setitem(w_modules, w_name, self.wrap(self.sys))
 
+        self.setitem(w_modules, w_name_exceptions,
+                     self.wrap(self.exceptions_module))
+
         from pypy.module.__builtin__ import Module
         w_name = self.wrap('__builtin__')
         self.builtin = Module(self, w_name)
@@ -405,6 +412,8 @@
         bootstrap_modules = ['sys', '__builtin__', 'exceptions']
         installed_builtin_modules = bootstrap_modules[:]
 
+        self.export_builtin_exceptions()
+
         # initialize with "bootstrap types" from objspace  (e.g. w_None)
         for name, value in self.__dict__.items():
             if name.startswith('w_') and not name.endswith('Type'):
@@ -430,6 +439,18 @@
         self.setitem(self.sys.w_dict, self.wrap('builtin_module_names'),
                      w_builtin_module_names)
 
+    def export_builtin_exceptions(self):
+        """NOT_RPYTHON"""
+        w_dic = self.exceptions_module.getdict()
+        names_w = self.unpackiterable(self.call_function(self.getattr(w_dic, self.wrap("keys"))))
+
+        for w_name in names_w:
+            name = self.str_w(w_name)
+            if not name.startswith('__'):
+                excname = name
+                w_exc = self.getitem(w_dic, w_name)
+                setattr(self, "w_"+excname, w_exc)
+
     def install_mixedmodule(self, mixedname, installed_builtin_modules):
         """NOT_RPYTHON"""
         modname = self.setbuiltinmodule(mixedname)

Modified: pypy/branch/faster-raise/pypy/module/exceptions/__init__.py
==============================================================================
--- pypy/branch/faster-raise/pypy/module/tempexceptions/__init__.py	(original)
+++ pypy/branch/faster-raise/pypy/module/exceptions/__init__.py	Thu Nov 12 15:04:51 2009
@@ -2,8 +2,6 @@
 from pypy.interpreter.mixedmodule import MixedModule
 
 class Module(MixedModule):
-    applevel_name = 'tempexceptions'
-
     appleveldefs = {}
     
     interpleveldefs = {

Modified: pypy/branch/faster-raise/pypy/module/exceptions/test/test_exc.py
==============================================================================
--- pypy/branch/faster-raise/pypy/module/tempexceptions/test/test_exc.py	(original)
+++ pypy/branch/faster-raise/pypy/module/exceptions/test/test_exc.py	Thu Nov 12 15:04:51 2009
@@ -3,10 +3,10 @@
 
 class AppTestExc(object):
     def setup_class(cls):
-        cls.space = gettestobjspace(usemodules=('tempexceptions',))
+        cls.space = gettestobjspace(usemodules=('exceptions',))
 
     def test_baseexc(self):
-        from tempexceptions import BaseException
+        from exceptions import BaseException
 
         assert str(BaseException()) == ''
         assert repr(BaseException()) == 'BaseException()'
@@ -25,7 +25,7 @@
         assert x.xyz == 3
 
     def test_exc(self):
-        from tempexceptions import Exception, BaseException
+        from exceptions import Exception, BaseException
 
         assert issubclass(Exception, BaseException)
         assert isinstance(Exception(), Exception)
@@ -33,7 +33,7 @@
         assert repr(Exception(3, "x")) == "Exception(3, 'x')"
 
     def test_custom_class(self):
-        from tempexceptions import Exception
+        from exceptions import Exception
 
         class MyException(Exception):
             def __init__(self, x):
@@ -46,7 +46,7 @@
         assert str(MyException("x")) == "x"
 
     def test_unicode_translate_error(self):
-        from tempexceptions import UnicodeTranslateError
+        from exceptions import UnicodeTranslateError
         ut = UnicodeTranslateError(u"x", 1, 5, "bah")
         assert ut.object == u'x'
         assert ut.start == 1
@@ -62,12 +62,12 @@
         assert str(ut) == "can't translate character u'\\x34' in position 4: bah"
 
     def test_key_error(self):
-        from tempexceptions import KeyError
+        from exceptions import KeyError
 
         assert str(KeyError('s')) == "'s'"
 
     def test_environment_error(self):
-        from tempexceptions import EnvironmentError
+        from exceptions import EnvironmentError
         ee = EnvironmentError(3, "x", "y")
         assert str(ee) == "[Errno 3] x: y"
         assert str(EnvironmentError(3, "x")) == "[Errno 3] x"
@@ -77,7 +77,7 @@
         assert EnvironmentError(3, "x").filename is None
 
     def test_syntax_error(self):
-        from tempexceptions import SyntaxError
+        from exceptions import SyntaxError
         s = SyntaxError(3)
         assert str(s) == '3'
         assert str(SyntaxError("a", "b", 123)) == "a"
@@ -88,13 +88,13 @@
         assert str(SyntaxError("msg", ("file.py", 2, 3, 4))) == "msg (file.py, line 2)"
 
     def test_system_exit(self):
-        from tempexceptions import SystemExit
+        from exceptions import SystemExit
         assert SystemExit().code is None
         assert SystemExit("x").code == "x"
         assert SystemExit(1, 2).code == (1, 2)
 
     def test_unicode_decode_error(self):
-        from tempexceptions import UnicodeDecodeError
+        from exceptions import UnicodeDecodeError
         ud = UnicodeDecodeError("x", "y", 1, 5, "bah")
         assert ud.encoding == 'x'
         assert ud.object == 'y'
@@ -110,7 +110,7 @@
         assert str(ud) == "'x' codec can't decode byte 0x39 in position 1: bah"
 
     def test_unicode_encode_error(self):
-        from tempexceptions import UnicodeEncodeError
+        from exceptions import UnicodeEncodeError
         ue = UnicodeEncodeError("x", u"y", 1, 5, "bah")
         assert ue.encoding == 'x'
         assert ue.object == u'y'

Modified: pypy/branch/faster-raise/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/faster-raise/pypy/objspace/std/objspace.py	(original)
+++ pypy/branch/faster-raise/pypy/objspace/std/objspace.py	Thu Nov 12 15:04:51 2009
@@ -322,9 +322,7 @@
             setattr(self, 'w_' + typedef.name, w_type)
 
         # exceptions & builtins
-        w_mod = self.setup_exceptions()
         self.make_builtins()
-        self.sys.setmodule(w_mod)
 
         # the type of old-style classes
         self.w_classobj = self.builtin.get('__metaclass__')
@@ -358,61 +356,6 @@
             self.setattr(w___pypy__, self.wrap('get_tproxy_controller'),
                           self.wrap(app_proxy_controller))
 
-    def create_builtin_module(self, pyname, publicname):
-        """NOT_RPYTHON
-        helper function which returns the wrapped module and its dict.
-        """
-        # generate on-the-fly
-        class Fake: pass
-        fake = Fake()
-        from pypy import lib
-        fname = os.path.join(os.path.split(lib.__file__)[0], pyname)
-        fake.filename = fname
-        fake.code = compile(file(fname).read(), fname, "exec")
-        fake.modname = publicname
-        w_dic = PyPyCacheDir.build_applevelinterp_dict(fake, self)
-        from pypy.interpreter.module import Module
-        mod = Module(self, self.wrap(publicname), w_dic)
-        w_mod = self.wrap(mod)
-        return w_mod, w_dic
-
-    def setup_exceptions(self):
-        """NOT_RPYTHON"""
-        ## hacking things in
-        def call(w_type, w_args):
-            space = self
-            # too early for unpackiterable as well :-(
-            name  = space.unwrap(space.getitem(w_args, space.wrap(0)))
-            bases = space.viewiterable(space.getitem(w_args, space.wrap(1)))
-            dic   = space.unwrap(space.getitem(w_args, space.wrap(2)))
-            dic = dict([(key,space.wrap(value)) for (key, value) in dic.items()])
-            bases = list(bases)
-            if not bases:
-                bases = [space.w_object]
-            res = W_TypeObject(space, name, bases, dic)
-            res.ready()
-            return res
-        try:
-            # note that we hide the real call method by an instance variable!
-            self.call = call
-            mod, w_dic = self.create_builtin_module('_exceptions.py', 'exceptions')
-
-            self.w_IndexError = self.getitem(w_dic, self.wrap("IndexError"))
-            self.w_StopIteration = self.getitem(w_dic, self.wrap("StopIteration"))
-        finally:
-            del self.call # revert
-
-        names_w = self.unpackiterable(self.call_function(self.getattr(w_dic, self.wrap("keys"))))
-
-        for w_name in names_w:
-            name = self.str_w(w_name)
-            if not name.startswith('__'):
-                excname = name
-                w_exc = self.getitem(w_dic, w_name)
-                setattr(self, "w_"+excname, w_exc)
-
-        return mod
-
     def createexecutioncontext(self):
         # add space specific fields to execution context
         # note that this method must not call space methods that might need an



More information about the Pypy-commit mailing list