On 6/23/07, Guido van Rossum <[EMAIL PROTECTED]> wrote:
On 6/23/07, Alexandre Vassalotti <[EMAIL PROTECTED]> wrote:
> I agree with this. I will try to write a patch to fix io.BytesIO.

Great!

I got the patch (it's attached to this email). The fix was simpler
than I thought.

I would like to write a unittest for it, but I am not sure where it
should go in test_io.py. From what I see, MemorySeekTestMixin is for
testing read/seek operation common to BytesIO and StringIO, so I can't
put it there. And I don't really like the idea of adding another test
in IOTest.test_raw_bytes_io.

By the way, I am having the same problem for the tests of _string_io
and _bytes_io -- i.e., I don't know exactly how to organize them with
the rest of the tests in test_io.py.

> Free the resources held by the object, and make all methods of the
> object raise a ValueError if they are used.

I'm not sure what the use case for that is (even though the 2.x
StringIO does this).


It seem the close method on TextIOWrapper objects is broken too (or at
least, bizarre):

   >>> f = open('test', 'w')
   >>> f.write('hello')
   5
   >>> f.close()
   >>> f.write('hello')
   5
   >>> ^D
   $ hd test
   00000000  68 65 6c 6c 6f                                    |hello|
   00000005


-- Alexandre
Index: Lib/io.py
===================================================================
--- Lib/io.py	(revision 56080)
+++ Lib/io.py	(working copy)
@@ -597,6 +597,11 @@
     def write(self, b):
         n = len(b)
         newpos = self._pos + n
+        if newpos > len(self._buffer):
+            # Inserts null bytes between the current end of the file
+            # and the new write position.
+            padding = '\x00' * (newpos - len(self._buffer) - n)
+            self._buffer[self._pos:newpos - n] = padding
         self._buffer[self._pos:newpos] = b
         self._pos = newpos
         return n
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to