Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r74298:2b5071286e03
Date: 2014-10-30 17:17 +0100
http://bitbucket.org/pypy/pypy/changeset/2b5071286e03/

Log:    fix for CPython compatibility

diff --git a/rpython/rlib/streamio.py b/rpython/rlib/streamio.py
--- a/rpython/rlib/streamio.py
+++ b/rpython/rlib/streamio.py
@@ -238,7 +238,14 @@
         bufsize = 8192
         result = []
         while True:
-            data = self.read(bufsize)
+            try:
+                data = self.read(bufsize)
+            except OSError:
+                # like CPython < 3.4, partial results followed by an error
+                # are returned as data
+                if not result:
+                    raise
+                break
             if not data:
                 break
             result.append(data)
@@ -657,8 +664,8 @@
             try:
                 data = self.do_read(bufsize)
             except OSError, o:
-                if o.errno != errno.EAGAIN:
-                    raise
+                # like CPython < 3.4, partial results followed by an error
+                # are returned as data
                 if not chunks:
                     raise
                 break
diff --git a/rpython/rlib/test/test_streamio.py 
b/rpython/rlib/test/test_streamio.py
--- a/rpython/rlib/test/test_streamio.py
+++ b/rpython/rlib/test/test_streamio.py
@@ -1136,6 +1136,24 @@
         assert x.tell() == 0    # detected in this case.  not always.
         # the point of the test is that we don't crash in an assert.
 
+    def test_ignore_ioerror_in_readall_if_nonempty_result(self):
+        # this is the behavior of regular files in CPython 2.7, as
+        # well as of _io.FileIO at least in CPython 3.3.  This is
+        # *not* the behavior of _io.FileIO in CPython 3.4 or 3.5;
+        # see CPython's issue #21090.
+        try:
+            from os import openpty
+        except ImportError:
+            pytest.skip('no openpty on this platform')
+        read_fd, write_fd = openpty()
+        os.write(write_fd, 'Abc\n')
+        os.close(write_fd)
+        x = streamio.DiskFile(read_fd)
+        s = x.readall()
+        assert s == 'Abc\r\n'
+        pytest.raises(OSError, x.readall)
+        x.close()
+
 
 # Speed test
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to