Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r75888:af52d1553f8f
Date: 2015-02-15 11:18 +0100
http://bitbucket.org/pypy/pypy/changeset/af52d1553f8f/

Log:    Add a clearer interface

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
@@ -209,9 +209,9 @@
                     # Note that we can get EAGAIN while there is buffered data
                     # waiting; read that too.
                     if is_wouldblock_error(e):
-                        pos, buf = stream.peek()
-                        if len(buf) > pos:
-                            result.append(stream.read(min(n, len(buf) - pos)))
+                        m = stream.count_buffered_bytes()
+                        if m > 0:
+                            result.append(stream.read(min(n, m)))
                         got = result.build()
                         if len(got) > 0:
                             return got
diff --git a/rpython/rlib/streamio.py b/rpython/rlib/streamio.py
--- a/rpython/rlib/streamio.py
+++ b/rpython/rlib/streamio.py
@@ -295,6 +295,10 @@
     def peek(self):
         return (0, '')
 
+    def count_buffered_bytes(self):
+        pos, buf = self.peek()
+        return len(buf) - pos
+
     def try_to_find_file_descriptor(self):
         return -1
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to