Commits

Alex Gaynor committed 12b8999

Added in the new behavior for RawIOBase.readall, if read() returns None then readall() also returns None

Comments (0)

Files changed (2)

pypy/module/_io/interp_iobase.py

         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(

pypy/module/_io/test/test_io.py

         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'])