Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r58661:de9dbd9479cd
Date: 2012-11-02 11:41 +0100
http://bitbucket.org/pypy/pypy/changeset/de9dbd9479cd/

Log:    Fix.

diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -179,7 +179,17 @@
         else:
             result = StringBuilder(n)
             while n > 0:
-                data = stream.read(n)
+                try:
+                    data = stream.read(n)
+                except OSError, e:
+                    # a special-case only for read() (similar to CPython, which
+                    # also looses partial data with other methods): if we get
+                    # EAGAIN after already some data was received, return it.
+                    if is_wouldblock_error(e):
+                        got = result.build()
+                        if len(got) > 0:
+                            return got
+                    raise
                 if not data:
                     break
                 n -= len(data)
@@ -570,6 +580,16 @@
 def getopenstreams(space):
     return space.fromcache(FileState).openstreams
 
+MAYBE_EAGAIN      = getattr(errno, 'EAGAIN',      None)
+MAYBE_EWOULDBLOCK = getattr(errno, 'EWOULDBLOCK', None)
+
+def is_wouldblock_error(e):
+    if MAYBE_EAGAIN is not None and e.errno == MAYBE_EAGAIN:
+        return True
+    if MAYBE_EWOULDBLOCK is not None and e.errno == MAYBE_EWOULDBLOCK:
+        return True
+    return False
+
 
 @unwrap_spec(file=W_File, encoding="str_or_None", errors="str_or_None")
 def set_file_encoding(space, file, encoding=None, errors=None):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to