[pypy-svn] r79181 - in pypy/branch/fast-forward/pypy/module/_io: . test
afa at codespeak.net
afa at codespeak.net
Wed Nov 17 11:54:02 CET 2010
Author: afa
Date: Wed Nov 17 11:54:01 2010
New Revision: 79181
Modified:
pypy/branch/fast-forward/pypy/module/_io/interp_bufferedio.py
pypy/branch/fast-forward/pypy/module/_io/test/test_bufferedio.py
Log:
Fix in BufferedReader.read() when the underlying stream.read() must be called twice
Modified: pypy/branch/fast-forward/pypy/module/_io/interp_bufferedio.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_io/interp_bufferedio.py (original)
+++ pypy/branch/fast-forward/pypy/module/_io/interp_bufferedio.py Wed Nov 17 11:54:01 2010
@@ -497,8 +497,8 @@
data = self._raw_read(space, length)
size = len(data)
if size > 0:
- for i in range(start, start + size):
- self.buffer[i] = data[i]
+ for i in range(size):
+ self.buffer[start + i] = data[i]
self.read_end = self.raw_pos = start + size
return size
Modified: pypy/branch/fast-forward/pypy/module/_io/test/test_bufferedio.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_io/test/test_bufferedio.py (original)
+++ pypy/branch/fast-forward/pypy/module/_io/test/test_bufferedio.py Wed Nov 17 11:54:01 2010
@@ -32,6 +32,20 @@
assert f.read(3) == ""
f.close()
+ def test_slow_provider(self):
+ import _io
+ class MockIO(_io._IOBase):
+ def readable(self):
+ return True
+ def read(self, n=-1): # PyPy uses read()
+ return "abc"
+ def readinto(self, buf): # CPython uses readinto()
+ buf[:3] = "abc"
+ return 3
+ bufio = _io.BufferedReader(MockIO())
+ r = bufio.read(5)
+ assert r == "abcab"
+
def test_peek(self):
import _io
raw = _io.FileIO(self.tmpfile)
More information about the Pypy-commit
mailing list