[pypy-svn] r15145 - in pypy/dist/pypy/module/__builtin__: . test
rxe at codespeak.net
rxe at codespeak.net
Tue Jul 26 20:13:13 CEST 2005
Author: rxe
Date: Tue Jul 26 20:13:12 2005
New Revision: 15145
Modified:
pypy/dist/pypy/module/__builtin__/importing.py
pypy/dist/pypy/module/__builtin__/test/test_import.py
Log:
Disable write_compiled_module() and use OsFileWrapper throughout.
Modified: pypy/dist/pypy/module/__builtin__/importing.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/importing.py (original)
+++ pypy/dist/pypy/module/__builtin__/importing.py Tue Jul 26 20:13:12 2005
@@ -17,10 +17,10 @@
try:
BIN_READMASK = os.O_BINARY | os.O_RDONLY
- BIN_WRITEMASK = os.O_BINARY | os.O_RDWR
+ BIN_WRITEMASK = os.O_BINARY | os.O_RDWR | os.O_CREAT
except AttributeError:
BIN_READMASK = os.O_RDONLY
- BIN_WRITEMASK = os.O_RDWR
+ BIN_WRITEMASK = os.O_RDWR | os.O_CREAT
NOFILE = 0
PYFILE = 1
@@ -49,7 +49,7 @@
if os.path.exists(pycfile):
pyc_state = check_compiled_module(pyfile, pyfile_ts, pycfile)
pycfile_exists = pyc_state >= 0
- pycfile_ts_valid = pyc_state > 0 and pyfile_exists
+ pycfile_ts_valid = pyc_state > 0 and pyfile_exist
else:
pycfile_exists = False
pycfile_ts_valid = False
@@ -107,11 +107,15 @@
space.setattr(w_mod, w('__path__'), space.newlist([w(pkgdir)]))
try:
- if modtype == PYFILE:
- load_source_module(space, w_modulename, w_mod, filename, fd)
- else:
- load_compiled_module(space, w_modulename, w_mod, filename, fd)
-
+ try:
+ osfile = OsFileWrapper(fd)
+ if modtype == PYFILE:
+ load_source_module(space, w_modulename, w_mod, filename, osfile)
+ else:
+ load_compiled_module(space, w_modulename, w_mod, filename, osfile)
+ finally:
+ osfile.close()
+
except OperationError, e:
if e.match(space, space.w_SyntaxError):
w_mods = space.sys.get('modules')
@@ -331,15 +335,11 @@
pyc_magic = MAGIC
-def parse_source_module(space, pathname, fd):
+def parse_source_module(space, pathname, osfile):
""" Parse a source file and return the corresponding code object """
w = space.wrap
- try:
- size = os.fstat(fd)[stat.ST_SIZE]
- source = os.read(fd, size)
- finally:
- os.close(fd)
-
+ size = os.fstat(osfile.fd)[stat.ST_SIZE]
+ source = osfile.read(size)
w_source = w(source)
w_mode = w("exec")
w_pathname = w(pathname)
@@ -347,13 +347,13 @@
pycode = space.interpclass_w(w_code)
return pycode
-def load_source_module(space, w_modulename, w_mod, pathname, fd):
+def load_source_module(space, w_modulename, w_mod, pathname, osfile):
"""
Load a source module from a given file and return its module
object.
"""
w = space.wrap
- pycode = parse_source_module(space, pathname, fd)
+ pycode = parse_source_module(space, pathname, osfile)
w_dict = space.getattr(w_mod, w('__dict__'))
space.call_method(w_dict, 'setdefault',
@@ -361,9 +361,9 @@
w(space.builtin))
pycode.exec_code(space, w_dict, w_dict)
- mtime = os.fstat(fd)[stat.ST_MTIME]
+ mtime = os.fstat(osfile.fd)[stat.ST_MTIME]
cpathname = pathname + 'c'
- write_compiled_module(space, pycode, cpathname, mtime)
+ #XXXwrite_compiled_module(space, pycode, cpathname, mtime)
return w_mod
@@ -415,12 +415,12 @@
os.close(fd)
return 1
-def read_compiled_module(space, cpathname, fd):
+def read_compiled_module(space, cpathname, osfile):
""" Read a code object from a file and check it for validity """
w_marshal = space.getbuiltinmodule('marshal')
w_U = space.getattr(w_marshal, space.wrap('_Unmarshaller'))
- w_unmarshaller = space.call_function(w_U, space.wrap(fd))
+ w_unmarshaller = space.call_function(w_U, space.wrap(osfile.fd))
w_code = space.call_method(w_unmarshaller, 'load')
pycode = space.interpclass_w(w_code)
if pycode is None:
@@ -428,19 +428,18 @@
"Non-code object in %.200s" % cpathname))
return pycode
-def load_compiled_module(space, w_modulename, w_mod, cpathname, fd):
+def load_compiled_module(space, w_modulename, w_mod, cpathname, osfile):
"""
Load a module from a compiled file, execute it, and return its
module object.
"""
- osfile = OsFileWrapper(fd)
magic = _r_long(osfile)
if magic != pyc_magic:
raise OperationError(space.w_ImportError, space.wrap(
"Bad magic number in %.200s" % cpathname))
return NULL;
_r_long(osfile) # skip time stamp
- code_w = read_compiled_module(space, cpathname, fd)
+ code_w = read_compiled_module(space, cpathname, osfile)
#if (Py_VerboseFlag)
# PySys_WriteStderr("import %s # precompiled from %s\n",
# name, cpathname);
Modified: pypy/dist/pypy/module/__builtin__/test/test_import.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/test/test_import.py (original)
+++ pypy/dist/pypy/module/__builtin__/test/test_import.py Tue Jul 26 20:13:12 2005
@@ -5,6 +5,7 @@
from pypy.tool.udir import udir
import sys, os
import tempfile, marshal
+from pypy.tool.osfilewrapper import OsFileWrapper
from pypy.module.__builtin__.importing import BIN_READMASK
@@ -204,7 +205,7 @@
cpathname = _testfile(importing.pyc_magic, mtime, co)
fd = os.open(cpathname, BIN_READMASK, 0777)
os.lseek(fd, 8, 0)
- code_w = importing.read_compiled_module(space, cpathname, fd)
+ code_w = importing.read_compiled_module(space, cpathname, OsFileWrapper(fd))
os.close(fd)
assert type(code_w) is pypy.interpreter.pycode.PyCode
w_dic = space.newdict([])
@@ -222,7 +223,7 @@
w_modulename = space.wrap('somemodule')
fd = os.open(cpathname, BIN_READMASK, 0777)
w_mod = space.wrap(Module(space, w_modulename))
- w_ret = importing.load_compiled_module(space, w_modulename, w_mod, cpathname, fd)
+ w_ret = importing.load_compiled_module(space, w_modulename, w_mod, cpathname, OsFileWrapper(fd))
os.close(fd)
assert w_mod is w_ret
w_ret = space.getattr(w_mod, space.wrap('x'))
More information about the Pypy-commit
mailing list