Author: Antonio Cuni <[email protected]>
Branch:
Changeset: r58665:d839e92c1304
Date: 2012-11-02 14:22 +0100
http://bitbucket.org/pypy/pypy/changeset/d839e92c1304/
Log: merge
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):
diff --git a/pypy/module/_file/test/test_file_extra.py
b/pypy/module/_file/test/test_file_extra.py
--- a/pypy/module/_file/test/test_file_extra.py
+++ b/pypy/module/_file/test/test_file_extra.py
@@ -354,7 +354,7 @@
class AppTestAFewExtra:
def setup_class(cls):
- space = gettestobjspace(usemodules=('array',))
+ space = gettestobjspace(usemodules=('array', '_socket'))
cls.space = space
def setup_method(self, method):
@@ -606,3 +606,16 @@
repr(unicode(self.temptestfile)))
f.close()
+ def test_EAGAIN(self):
+ import _socket, posix
+ s1, s2 = _socket.socketpair()
+ s2.setblocking(False)
+ s1.send("hello")
+
+ f2 = posix.fdopen(posix.dup(s2.fileno()), 'rb', 0)
+ data = f2.read(12)
+ assert data == "hello"
+
+ f2.close()
+ s2.close()
+ s1.close()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit