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

afa at codespeak.net afa at codespeak.net
Tue Oct 19 19:29:13 CEST 2010


Author: afa
Date: Tue Oct 19 19:29:11 2010
New Revision: 78098

Modified:
   pypy/branch/fast-forward/pypy/module/_io/interp_fileio.py
   pypy/branch/fast-forward/pypy/module/_io/test/test_fileio.py
Log:
_io.FileIO.write()


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	Tue Oct 19 19:29:11 2010
@@ -277,6 +277,20 @@
     # ______________________________________________
 
     @unwrap_spec('self', ObjSpace, W_Root)
+    def write_w(self, space, w_data):
+        self._check_closed(space)
+        # XXX self._check_writable(space)
+        data = space.str_w(w_data)
+
+        try:
+            n = os.write(self.fd, data)
+        except OSError, e:
+            raise wrap_oserror(space, e,
+                               exception_name='w_IOError')
+
+        return space.wrap(n)
+
+    @unwrap_spec('self', ObjSpace, W_Root)
     def read_w(self, space, w_size=None):
         self._check_closed(space)
         # XXX self._check_readable(space)
@@ -326,6 +340,7 @@
     __init__  = interp2app(W_FileIO.descr_init),
 
     seek = interp2app(W_FileIO.seek_w),
+    write = interp2app(W_FileIO.write_w),
     read = interp2app(W_FileIO.read_w),
     readall = interp2app(W_FileIO.readall_w),
     close = interp2app(W_FileIO.close_w),

Modified: pypy/branch/fast-forward/pypy/module/_io/test/test_fileio.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_io/test/test_fileio.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_io/test/test_fileio.py	Tue Oct 19 19:29:11 2010
@@ -46,3 +46,15 @@
         import _io
         f = _io.FileIO(self.tmpfile, 'rb')
         assert f.readall() == "a\nb\nc"
+        f.close()
+
+    def test_write(self):
+        import _io
+        filename = self.tmpfile + '_w'
+        f = _io.FileIO(filename, 'wb')
+        f.write("test")
+        # try without flushing
+        f2 = _io.FileIO(filename, 'rb')
+        assert f2.read() == "test"
+        f.close()
+        f2.close()



More information about the Pypy-commit mailing list