Author: Alex Gaynor <[email protected]>
Branch: merge-2.7.2
Changeset: r51655:12b899970671
Date: 2012-01-22 12:31 -0600
http://bitbucket.org/pypy/pypy/changeset/12b899970671/
Log: Added in the new behavior for RawIOBase.readall, if read() returns
None then readall() also returns None
diff --git a/pypy/module/_io/interp_iobase.py b/pypy/module/_io/interp_iobase.py
--- a/pypy/module/_io/interp_iobase.py
+++ b/pypy/module/_io/interp_iobase.py
@@ -282,6 +282,10 @@
while True:
w_data = space.call_method(self, "read",
space.wrap(DEFAULT_BUFFER_SIZE))
+ if space.is_w(w_data, space.w_None):
+ if not builder.getlength():
+ return w_data
+ break
if not space.isinstance_w(w_data, space.w_str):
raise OperationError(space.w_TypeError, space.wrap(
diff --git a/pypy/module/_io/test/test_io.py b/pypy/module/_io/test/test_io.py
--- a/pypy/module/_io/test/test_io.py
+++ b/pypy/module/_io/test/test_io.py
@@ -135,10 +135,27 @@
assert r.read(2) == 'ab'
assert r.read(2) == 'c'
assert r.read(2) == 'de'
- assert r.read(2) == None
+ assert r.read(2) is None
assert r.read(2) == 'fg'
assert r.read(2) == ''
+ def test_rawio_readall_none(self):
+ import _io
+ class MockRawIO(_io._RawIOBase):
+ read_stack = [None, None, "a"]
+ def readinto(self, buf):
+ v = self.read_stack.pop()
+ if v is None:
+ return v
+ buf[:len(v)] = v
+ return len(v)
+
+ r = MockRawIO()
+ s = r.readall()
+ assert s =="a"
+ s = r.readall()
+ assert s is None
+
class AppTestOpen:
def setup_class(cls):
cls.space = gettestobjspace(usemodules=['_io', '_locale'])
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit