[pypy-svn] r45517 - in pypy/dist/pypy/module: _file posix posix/test
fijal at codespeak.net
fijal at codespeak.net
Mon Aug 6 15:56:47 CEST 2007
Author: fijal
Date: Mon Aug 6 15:56:47 2007
New Revision: 45517
Modified:
pypy/dist/pypy/module/_file/app_file.py
pypy/dist/pypy/module/posix/__init__.py
pypy/dist/pypy/module/posix/interp_posix.py
pypy/dist/pypy/module/posix/test/test_posix2.py
Log:
os.tmpfile, app-level implementation, including simple hack to app-level file
to create file from stream.
Modified: pypy/dist/pypy/module/_file/app_file.py
==============================================================================
--- pypy/dist/pypy/module/_file/app_file.py (original)
+++ pypy/dist/pypy/module/_file/app_file.py Mon Aug 6 15:56:47 2007
@@ -38,6 +38,14 @@
return f
fdopen = classmethod(fdopen)
+ def tmpfile(cls, stream):
+ f = cls.__new__(cls)
+ fd = stream.try_to_find_file_descriptor()
+ assert fd != -1
+ f._fdopenstream(fd, "w+b", -1, "<tmpfile>", stream)
+ return f
+ tmpfile = classmethod(tmpfile)
+
def _fdopenstream(self, fd, mode, buffering, name, stream):
self.fd = fd
self._name = name
Modified: pypy/dist/pypy/module/posix/__init__.py
==============================================================================
--- pypy/dist/pypy/module/posix/__init__.py (original)
+++ pypy/dist/pypy/module/posix/__init__.py Mon Aug 6 15:56:47 2007
@@ -50,6 +50,7 @@
#'getuid' : 'interp_posix.getuid',
#'geteuid' : 'interp_posix.geteuid',
'utime' : 'interp_posix.utime',
+ 'tmpfile' : 'interp_posix.tmpfile',
}
if hasattr(os, 'ftruncate'):
interpleveldefs['ftruncate'] = 'interp_posix.ftruncate'
Modified: pypy/dist/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/dist/pypy/module/posix/interp_posix.py (original)
+++ pypy/dist/pypy/module/posix/interp_posix.py Mon Aug 6 15:56:47 2007
@@ -3,6 +3,7 @@
from pypy.rlib import ros
from pypy.interpreter.error import OperationError, wrap_oserror
from pypy.rpython.module.ll_os import RegisterOs
+from pypy.module._file.interp_file import W_Stream, wrap_oserror_as_ioerror
import os
@@ -527,3 +528,13 @@
except OSError, e:
raise wrap_oserror(space, e)
ttyname.unwrap_spec = [ObjSpace, int]
+
+def tmpfile(space):
+ try:
+ stream = ros.tmpfile()
+ w_stream = space.wrap(W_Stream(space, stream))
+ w_fobj = space.getattr(space.getbuiltinmodule('__builtin__'), space.wrap('file'))
+ return space.call_function(space.getattr(w_fobj, space.wrap('tmpfile')), w_stream)
+ except OSError, e:
+ raise wrap_oserror_as_ioerror(space, e)
+tmpfile.unwrap_spec = [ObjSpace]
Modified: pypy/dist/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/dist/pypy/module/posix/test/test_posix2.py (original)
+++ pypy/dist/pypy/module/posix/test/test_posix2.py Mon Aug 6 15:56:47 2007
@@ -262,6 +262,15 @@
res = os.system(cmd)
assert res == 0
+ def test_tmpfile(self):
+ os = self.os
+ f = os.tmpfile()
+ f.write("xxx")
+ f.flush()
+ f.seek(0, 0)
+ assert isinstance(f, file)
+ assert f.read() == 'xxx'
+
class TestPexpect(object):
# XXX replace with AppExpectTest class as soon as possible
def setup_class(cls):
More information about the Pypy-commit
mailing list