[pypy-svn] r15023 - pypy/branch/pypy-translation-snapshot/module/__builtin__
hpk at codespeak.net
hpk at codespeak.net
Mon Jul 25 15:40:24 CEST 2005
Author: hpk
Date: Mon Jul 25 15:40:23 2005
New Revision: 15023
Modified:
pypy/branch/pypy-translation-snapshot/module/__builtin__/importing.py
Log:
merge 15000:15017 pypy/module/__builtin__
(use os-functions for importing)
Modified: pypy/branch/pypy-translation-snapshot/module/__builtin__/importing.py
==============================================================================
--- pypy/branch/pypy-translation-snapshot/module/__builtin__/importing.py (original)
+++ pypy/branch/pypy-translation-snapshot/module/__builtin__/importing.py Mon Jul 25 15:40:23 2005
@@ -15,19 +15,19 @@
# XXX posixpath/ntpath/macpath modules.
-def try_import_mod(space, w_modulename, f, w_parent, w_name, pkgdir=None):
+def try_import_mod(space, w_modulename, fn, w_parent, w_name, pkgdir=None):
w = space.wrap
- if os.path.exists(f):
+ if os.path.exists(fn):
w_mod = space.wrap(Module(space, w_modulename))
space.sys.setmodule(w_mod)
- space.setattr(w_mod, w('__file__'), w(f))
+ space.setattr(w_mod, w('__file__'), w(fn))
space.setattr(w_mod, w('__doc__'), space.w_None)
if pkgdir is not None:
space.setattr(w_mod, w('__path__'), space.newlist([w(pkgdir)]))
w_dict = space.getattr(w_mod, w('__dict__'))
e = None
try:
- space.builtin.call('execfile', w(f), w_dict, w_dict)
+ imp_execfile(space, fn, w_dict, w_dict)
except OperationError, e:
if e.match(space, space.w_SyntaxError):
w_mods = space.sys.get('modules')
@@ -180,13 +180,13 @@
for path in space.unpackiterable(w_path):
dir = os.path.join(space.str_w(path), partname)
if os.path.isdir(dir):
- f = os.path.join(dir,'__init__.py')
- w_mod = try_import_mod(space, w_modulename, f, w_parent,
+ fn = os.path.join(dir,'__init__.py')
+ w_mod = try_import_mod(space, w_modulename, fn, w_parent,
w(partname), pkgdir=dir)
if w_mod is not None:
return w_mod
- f = os.path.join(space.str_w(path), partname + '.py')
- w_mod = try_import_mod(space, w_modulename, f, w_parent,
+ fn = os.path.join(space.str_w(path), partname + '.py')
+ w_mod = try_import_mod(space, w_modulename, fn, w_parent,
w(partname))
if w_mod is not None:
return w_mod
@@ -198,3 +198,22 @@
w_failing = w_modulename
w_exc = space.call_function(space.w_ImportError, w_failing)
raise OperationError(space.w_ImportError, w_exc)
+
+
+def imp_execfile(space, fn, w_globals, w_locals):
+ fd = os.open(fn, os.O_RDONLY) # XXX newlines?
+ try:
+ size = os.fstat(fd)[6]
+ source = os.read(fd, size)
+ finally:
+ os.close(fd)
+ w_source = space.wrap(source)
+ w_mode = space.wrap("exec")
+ w_fn = space.wrap(fn)
+ w_code = space.builtin.call('compile', w_source, w_fn, w_mode)
+ pycode = space.interpclass_w(w_code)
+ space.call_method(w_globals, 'setdefault',
+ space.wrap('__builtins__'),
+ space.wrap(space.builtin))
+ pycode.exec_code(space, w_globals, w_locals)
+
More information about the Pypy-commit
mailing list