[pypy-svn] r78009 - in pypy/branch/fast-forward/pypy/module/_io: . test

afa at codespeak.net afa at codespeak.net
Fri Oct 15 22:47:55 CEST 2010


Author: afa
Date: Fri Oct 15 22:47:54 2010
New Revision: 78009

Modified:
   pypy/branch/fast-forward/pypy/module/_io/interp_fileio.py
   pypy/branch/fast-forward/pypy/module/_io/interp_iobase.py
   pypy/branch/fast-forward/pypy/module/_io/test/test_io.py
Log:
More progress in the _io module,
one more instruction passed by some functions of the test suite.


Modified: pypy/branch/fast-forward/pypy/module/_io/interp_fileio.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_io/interp_fileio.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_io/interp_fileio.py	Fri Oct 15 22:47:54 2010
@@ -3,6 +3,7 @@
 from pypy.interpreter.gateway import interp2app, unwrap_spec, Arguments
 from pypy.interpreter.baseobjspace import ObjSpace, W_Root
 from pypy.interpreter.error import OperationError, wrap_oserror2
+from pypy.rlib.rarithmetic import r_longlong
 from os import O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC
 import os
 
@@ -118,6 +119,12 @@
             raise OperationError(space.w_ValueError, space.wrap(
                 "I/O operation on closed file"))
 
+    @unwrap_spec('self', ObjSpace, r_longlong, int)
+    def seek_w(self, space, pos, whence):
+        self._check_closed(space)
+        pos = os.lseek(self.fd, pos, whence)
+        return space.wrap(pos)
+
     @unwrap_spec('self', ObjSpace)
     def readable_w(self, space):
         self._check_closed(space)
@@ -128,11 +135,27 @@
         self._check_closed(space)
         return space.wrap(self.writable)
 
+    @unwrap_spec('self', ObjSpace)
+    def seekable_w(self, space):
+        self._check_closed(space)
+        if self.seekable < 0:
+            try:
+                pos = os.lseek(self.fd, 0, os.SEEK_CUR)
+            except OSError:
+                self.seekable = 0
+            else:
+                self.seekable = 1
+        return space.newbool(self.seekable)
+
 W_FileIO.typedef = TypeDef(
     'FileIO', W_RawIOBase.typedef,
     __new__  = interp2app(W_FileIO.descr_new.im_func),
     __init__  = interp2app(W_FileIO.descr_init),
+
+    seek = interp2app(W_FileIO.seek_w),
+
     readable = interp2app(W_FileIO.readable_w),
     writable = interp2app(W_FileIO.writable_w),
+    seekable = interp2app(W_FileIO.seekable_w),
     )
 

Modified: pypy/branch/fast-forward/pypy/module/_io/interp_iobase.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_io/interp_iobase.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_io/interp_iobase.py	Fri Oct 15 22:47:54 2010
@@ -87,6 +87,13 @@
     def seekable_w(self, space):
         return space.w_False
 
+    @unwrap_spec('self', ObjSpace)
+    def check_seekable_w(self, space):
+        if not space.is_true(space.call_method(self, 'seekable')):
+            raise OperationError(
+                space.w_IOError,
+                space.wrap("file or stream is not seekable"))
+
 W_IOBase.typedef = TypeDef(
     '_IOBase',
     __new__ = generic_new_descr(W_IOBase),
@@ -100,6 +107,7 @@
     readable = interp2app(W_IOBase.readable_w),
     writable = interp2app(W_IOBase.writable_w),
     seekable = interp2app(W_IOBase.seekable_w),
+    _checkSeekable = interp2app(W_IOBase.check_seekable_w),
     closed = GetSetProperty(W_IOBase.closed_get_w),
     )
 

Modified: pypy/branch/fast-forward/pypy/module/_io/test/test_io.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_io/test/test_io.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_io/test/test_io.py	Fri Oct 15 22:47:54 2010
@@ -52,6 +52,12 @@
         f = io.open(self.tmpfile, "rb")
         f.close()
 
+    def test_open_writable(self):
+        import io
+        f = io.open(self.tmpfile, "w+b")
+        f.seek(0)
+        f.close()
+
     def test_open_fd(self):
         import io
         os = self.posix



More information about the Pypy-commit mailing list