[pypy-svn] rev 458 - pypy/trunk/src/pypy/module

tomek at codespeak.net tomek at codespeak.net
Mon May 26 17:08:46 CEST 2003


Author: tomek
Date: Mon May 26 17:08:45 2003
New Revision: 458

Modified:
   pypy/trunk/src/pypy/module/builtin.py
Log:
A simple __import__ hook


Modified: pypy/trunk/src/pypy/module/builtin.py
==============================================================================
--- pypy/trunk/src/pypy/module/builtin.py	(original)
+++ pypy/trunk/src/pypy/module/builtin.py	Mon May 26 17:08:45 2003
@@ -1,5 +1,6 @@
 from pypy.interpreter.extmodule import *
 from pypy.interpreter.pycode import PyByteCode
+from pypy.interpreter.executioncontext import OperationError
 
 #######################
 ####  __builtin__  ####
@@ -7,6 +8,9 @@
 
 import __builtin__ as _b
 
+##compile.__doc__ = _b.compile.__doc__
+
+
 class Builtin(BuiltinModule):
     __pythonname__ = '__builtin__'
 
@@ -19,18 +23,35 @@
         return self.space.len(w_obj)
     len = appmethod(len)
 
-    def str(self, w_obj):
-        return self.space.str(w_obj)
-    str = appmethod(str)
 
-    def compile(self, w_str, w_filename, w_startstr,
-                w_supplied_flags, w_dont_inherit):
+    def __import__(self,w_modulename,w_locals,w_globals,w_fromlist):
         space = self.space
+        try:
+            w_mod = space.getitem(space.w_modules,w_modulename)
+            return w_mod
+        except OperationError,e:
+            if not e.match(space,space.w_KeyError):
+                raise
+            raise OperationError(space.w_ImportError)
+            
+        
+
+    __import__ = appmethod(__import__)
+
+    def compile(self, w_str, w_filename, w_startstr,
+                w_supplied_flags=None, w_dont_inherit=None):
         str = space.unwrap(w_str)
         filename = space.unwrap(w_filename)
         startstr = space.unwrap(w_startstr)
-        supplied_flags = space.unwrap(w_supplied_flags)
-        dont_inherit = space.unwrap(w_dont_inherit)
+        if w_supplied_flags is None:
+            supplied_flags = 0
+        else:
+            supplied_flags = space.unwrap(w_supplied_flags)
+        if w_dont_inherit is None:
+            dont_inherit = False
+        else:
+            dont_inherit = space.unwrap(w_dont_inherit)
+
         c = _b.compile(str, filename, startstr, supplied_flags, dont_inherit)
         res = PyByteCode()
         res._from_code(c)


More information about the Pypy-commit mailing list