diff options
author | Alexandre Vassalotti <alexandre@peadrop.com> | 2008-05-10 19:59:16 (GMT) |
---|---|---|
committer | Alexandre Vassalotti <alexandre@peadrop.com> | 2008-05-10 19:59:16 (GMT) |
commit | 844f757aae9b2e4975d4b98f8dc8b5f5fbd69608 (patch) | |
tree | 4f8776e771ef59ab4230b068494975836107a5de | |
parent | cd8001c8ed8ea11b13a57be7f0e524133177c2f8 (diff) | |
download | cpython-844f757aae9b2e4975d4b98f8dc8b5f5fbd69608.zip cpython-844f757aae9b2e4975d4b98f8dc8b5f5fbd69608.tar.gz cpython-844f757aae9b2e4975d4b98f8dc8b5f5fbd69608.tar.bz2 |
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.
-rw-r--r-- | Lib/io.py | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -826,14 +826,14 @@ class _BytesIO(BufferedIOBase): 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): |