[Python-3000-checkins] r56475 - python/branches/py3k-struni/Lib/io.py

guido.van.rossum python-3000-checkins at python.org
Sat Jul 21 02:25:15 CEST 2007


Author: guido.van.rossum
Date: Sat Jul 21 02:25:15 2007
New Revision: 56475

Modified:
   python/branches/py3k-struni/Lib/io.py
Log:
SF patch# 1757683 by Alexandre Vassalotti.  Add support for
seeking/writing beyond EOF to io.BytesIO.


Modified: python/branches/py3k-struni/Lib/io.py
==============================================================================
--- python/branches/py3k-struni/Lib/io.py	(original)
+++ python/branches/py3k-struni/Lib/io.py	Sat Jul 21 02:25:15 2007
@@ -659,6 +659,11 @@
             raise ValueError("write to closed file")
         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


More information about the Python-3000-checkins mailing list