[pypy-svn] r15131 - in pypy/dist/pypy/module/__builtin__: . test
rxe at codespeak.net
rxe at codespeak.net
Tue Jul 26 17:42:29 CEST 2005
Author: rxe
Date: Tue Jul 26 17:42:27 2005
New Revision: 15131
Modified:
pypy/dist/pypy/module/__builtin__/importing.py
pypy/dist/pypy/module/__builtin__/test/test_import.py
Log:
Added BIN_READMASK (linnx doesnt have O_BINARY).
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 17:42:27 2005
@@ -15,6 +15,11 @@
# XXX a frozen version of some routines of only one of the
# XXX posixpath/ntpath/macpath modules.
+try:
+ BIN_READMASK = os.O_BINARY | os.O_RDONLY
+except AttributeError:
+ BIN_READMASK = os.O_RDONLY
+
def try_import_mod(space, w_modulename, filename, w_parent, w_name, pkgdir=None):
if os.path.exists(filename):
w = space.wrap
@@ -262,6 +267,7 @@
header is skipped
check for valid code object
- load_compiled_module
+- parse_source_module
- load_source_module
- write_compiled_module
called by load_source_module (maybe also optional)
@@ -281,11 +287,8 @@
its module object.
"""
-def load_source_module(space, w_modulename, w_mod, pathname, fd):
- """
- Load a source module from a given file and return its module
- object. XXX Wrong: If there's a matching byte-compiled file, use that instead.
- """
+def parse_source_module(space, pathname, fd):
+ """ Parse a source file and return the corresponding code object """
w = space.wrap
try:
size = os.fstat(fd)[6]
@@ -298,6 +301,15 @@
w_pathname = w(pathname)
w_code = space.builtin.call('compile', w_source, w_pathname, w_mode)
pycode = space.interpclass_w(w_code)
+ return pycode
+
+def load_source_module(space, w_modulename, w_mod, pathname, fd):
+ """
+ Load a source module from a given file and return its module
+ object. XXX Wrong: If there's a matching byte-compiled file, use that instead.
+ """
+ w = space.wrap
+ pycode = parse_source_module(space, pathname, fd)
w_dict = space.getattr(w_mod, w('__dict__'))
space.call_method(w_dict, 'setdefault',
@@ -329,7 +341,7 @@
the header; if not, return NULL.
Doesn't set an exception.
"""
- fd = os.open(cpathname, os.O_BINARY | os.O_RDONLY, 0777) # using no defaults
+ fd = os.open(cpathname, BIN_READMASK, 0777) # using no defaults
osfile = OsFileWrapper(fd)
magic = _r_long(osfile)
if magic != pyc_magic:
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 17:42:27 2005
@@ -6,6 +6,8 @@
import sys, os
import tempfile, marshal
+from pypy.module.__builtin__.importing import BIN_READMASK
+
def _setup(space):
dn=os.path.abspath(os.path.join(os.path.dirname(__file__), 'impsubdir'))
return space.appexec([space.wrap(dn)], """
@@ -200,7 +202,7 @@
mtime = 12345
co = compile('x = 42', '?', 'exec')
cpathname = _testfile(importing.pyc_magic, mtime, co)
- fd = os.open(cpathname, os.O_BINARY | os.O_RDONLY, 0777)
+ fd = os.open(cpathname, BIN_READMASK, 0777)
os.lseek(fd, 8, 0)
code_w = importing.read_compiled_module(space, cpathname, fd)
os.close(fd)
@@ -218,7 +220,7 @@
co = compile('x = 42', '?', 'exec')
cpathname = _testfile(importing.pyc_magic, mtime, co)
w_modulename = space.wrap('somemodule')
- fd = os.open(cpathname, os.O_BINARY | os.O_RDONLY, 0777)
+ 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)
os.close(fd)
More information about the Pypy-commit
mailing list