[pypy-svn] r15016 - pypy/dist/pypy/module/__builtin__

hpk at codespeak.net hpk at codespeak.net
Mon Jul 25 14:06:15 CEST 2005


Author: hpk
Date: Mon Jul 25 14:06:14 2005
New Revision: 15016

Modified:
   pypy/dist/pypy/module/__builtin__/importing.py
Log:
(rxe,hpk) 

remove the implicit usage of file objects (through a 
call to the applevel "execfile") from the importing 
code.  Instead we use os.* calls to get at the file
content. 



Modified: pypy/dist/pypy/module/__builtin__/importing.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/importing.py	(original)
+++ pypy/dist/pypy/module/__builtin__/importing.py	Mon Jul 25 14:06:14 2005
@@ -27,7 +27,7 @@
         w_dict = space.getattr(w_mod, w('__dict__'))
         e = None
         try:
-            space.builtin.call('execfile', w(fn), 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')
@@ -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