[pypy-svn] rev 727 - in pypy/trunk/src/pypy/module: . test
mwh at codespeak.net
mwh at codespeak.net
Fri May 30 13:20:50 CEST 2003
Author: mwh
Date: Fri May 30 13:20:50 2003
New Revision: 727
Modified:
pypy/trunk/src/pypy/module/builtin.py
pypy/trunk/src/pypy/module/test/test_builtin.py
Log:
first cut at importing from the file system!
there aren't many modules out there that we can actually import
successfully, but that's another story...
Modified: pypy/trunk/src/pypy/module/builtin.py
==============================================================================
--- pypy/trunk/src/pypy/module/builtin.py (original)
+++ pypy/trunk/src/pypy/module/builtin.py Fri May 30 13:20:50 2003
@@ -35,6 +35,7 @@
def __import__(self, w_modulename, w_locals, w_globals, w_fromlist):
space = self.space
+ w = space.wrap
try:
w_mod = space.getitem(space.w_modules, w_modulename)
return w_mod
@@ -45,6 +46,23 @@
if w_mod is not None:
space.setitem(space.w_modules,w_modulename,w_mod)
return w_mod
+
+ import os, __future__
+ for path in space.unwrap(space.getattr(space.w_sys, w('path'))):
+ f = os.path.join(path, space.unwrap(w_modulename) + '.py')
+ if os.path.exists(f):
+ w_mod = space.newmodule(w_modulename)
+ space.setitem(space.w_modules, w_modulename, w_mod)
+ space.setattr(w_mod, w('__file__'), w(f))
+ w_source = w(open(f, 'r').read())
+ # wrt the __future__.generators.compiler_flag, "um" -- mwh
+ w_code = self.compile(w_source, w(f), w('exec'),
+ w(__future__.generators.compiler_flag))
+ w_dict = space.getattr(w_mod, w('__dict__'))
+ space.unwrap(w_code).eval_code(space, w_dict, w_dict)
+
+ return w_mod
+
w_exc = space.call_function(space.w_ImportError, w_modulename)
raise executioncontext.OperationError(
space.w_ImportError, w_exc)
Modified: pypy/trunk/src/pypy/module/test/test_builtin.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_builtin.py (original)
+++ pypy/trunk/src/pypy/module/test/test_builtin.py Fri May 30 13:20:50 2003
@@ -28,6 +28,16 @@
self.assertWRaises_w(s.w_TypeError,
w_chr,
w('a'))
+
+ def test_import(self):
+ s = self.space
+ w = s.wrap
+ w_import = self.get_builtin('__import__')
+ w_dict = s.newdict([])
+ w_fromlist = s.newlist([])
+ # finding a module to import is an odd game; quopri is
+ # sufficiently simple
+ s.call_function(w_import, w('quopri'), w_dict, w_dict, w_fromlist)
class TestCmp(testsupport.TestCase):
More information about the Pypy-commit
mailing list