[Python-checkins] r63000 - python/trunk/Lib/io.py
alexandre.vassalotti
python-checkins at python.org
Sat May 10 21:59:16 CEST 2008
Author: alexandre.vassalotti
Date: Sat May 10 21:59:16 2008
New Revision: 63000
Log:
Cleaned up io._BytesIO.write().
I am amazed that the old code, for inserting null-bytes, actually
worked. Who wrote that thing? Oh, it is me... doh.
Modified:
python/trunk/Lib/io.py
Modified: python/trunk/Lib/io.py
==============================================================================
--- python/trunk/Lib/io.py (original)
+++ python/trunk/Lib/io.py Sat May 10 21:59:16 2008
@@ -826,14 +826,14 @@
n = len(b)
if n == 0:
return 0
- newpos = self._pos + n
- if newpos > len(self._buffer):
+ pos = self._pos
+ if pos > len(self._buffer):
# Inserts null bytes between the current end of the file
# and the new write position.
- padding = b'\x00' * (newpos - len(self._buffer) - n)
- self._buffer[self._pos:newpos - n] = padding
- self._buffer[self._pos:newpos] = b
- self._pos = newpos
+ padding = b'\x00' * (pos - len(self._buffer))
+ self._buffer += padding
+ self._buffer[pos:pos + n] = b
+ self._pos += n
return n
def seek(self, pos, whence=0):
More information about the Python-checkins
mailing list