[pypy-svn] r52311 - in pypy/branch/buffer/pypy/module/_file: . test

arigo at codespeak.net arigo at codespeak.net
Sat Mar 8 22:01:56 CET 2008


Author: arigo
Date: Sat Mar  8 22:01:55 2008
New Revision: 52311

Modified:
   pypy/branch/buffer/pypy/module/_file/interp_file.py
   pypy/branch/buffer/pypy/module/_file/test/test_file_extra.py
Log:
A saner (but still not most efficient) implementation of file.readinto().


Modified: pypy/branch/buffer/pypy/module/_file/interp_file.py
==============================================================================
--- pypy/branch/buffer/pypy/module/_file/interp_file.py	(original)
+++ pypy/branch/buffer/pypy/module/_file/interp_file.py	Sat Mar  8 22:01:55 2008
@@ -361,24 +361,15 @@
         return self.getrepr(self.space, info)
     file__repr__.unwrap_spec = ['self']
 
-    def file_readinto(self, w_array):
+    def file_readinto(self, w_rwbuffer):
         """readinto() -> Undocumented.  Don't use this; it may go away."""
-        # completely inefficient and incomplete for now
+        # XXX not the most efficient solution as it doesn't avoid the copying
         space = self.space
-        w_len = space.appexec([space.wrap(self), w_array], """(self, a):
-            from array import array
-            if not isinstance(a, array):
-                raise TypeError('Can only read into array objects')
-            length = len(a)
-            data = self.read(length)
-            n = len(data)
-            if n < length:
-                data += a.tostring()[len(data):]
-            del a[:]
-            a.fromstring(data)
-            return n
-        """)
-        return w_len
+        rwbuffer = space.rwbuffer_w(w_rwbuffer)
+        w_data = self.file_read(rwbuffer.len)
+        data = space.str_w(w_data)
+        rwbuffer.setslice(0, data)
+        return space.wrap(len(data))
     file_readinto.unwrap_spec = ['self', W_Root]
 
 

Modified: pypy/branch/buffer/pypy/module/_file/test/test_file_extra.py
==============================================================================
--- pypy/branch/buffer/pypy/module/_file/test/test_file_extra.py	(original)
+++ pypy/branch/buffer/pypy/module/_file/test/test_file_extra.py	Sat Mar  8 22:01:55 2008
@@ -1,6 +1,7 @@
 import os, random, sys
 import pypy.tool.udir
 import py
+from pypy.conftest import gettestobjspace
 
 udir = pypy.tool.udir.udir.ensure('test_file_extra', dir=1)
 
@@ -349,6 +350,9 @@
 
 class AppTestAFewExtra:
 
+    def setup_class(cls):
+        cls.space = gettestobjspace(usemodules=['array'])
+
     def setup_method(self, method):
         fn = str(udir.join('temptestfile'))
         self.w_temptestfile = self.space.wrap(fn)



More information about the Pypy-commit mailing list