[pypy-commit] pypy py3k: support the TextIOWrapper write_through option

pjenvey noreply at buildbot.pypy.org
Tue Nov 8 03:14:47 CET 2011


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r48896:a94eb72cdc3f
Date: 2011-11-07 15:57 -0800
http://bitbucket.org/pypy/pypy/changeset/a94eb72cdc3f/

Log:	support the TextIOWrapper write_through option

diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py
--- a/pypy/module/_io/interp_textio.py
+++ b/pypy/module/_io/interp_textio.py
@@ -334,9 +334,10 @@
                                               # of the stream
         self.snapshot = None
 
-    @unwrap_spec(encoding="str_or_None", line_buffering=int)
+    @unwrap_spec(encoding="str_or_None", line_buffering=int, write_through=int)
     def descr_init(self, space, w_buffer, encoding=None,
-                   w_errors=None, w_newline=None, line_buffering=0):
+                   w_errors=None, w_newline=None, line_buffering=0,
+                   write_through=0):
         self.state = STATE_ZERO
 
         self.w_buffer = w_buffer
@@ -379,6 +380,7 @@
                 "illegal newline value: %s" % (r,)))
 
         self.line_buffering = line_buffering
+        self.write_through = write_through
 
         self.readuniversal = not newline # null or empty
         self.readtranslate = newline is None
@@ -415,6 +417,8 @@
         self.seekable = space.is_true(space.call_method(w_buffer, "seekable"))
         self.telling = self.seekable
 
+        self.has_read1 = space.findattr(w_buffer, space.wrap("read1"))
+
         self.encoding_start_of_stream = False
         if self.seekable and self.w_encoder:
             self.encoding_start_of_stream = True
@@ -553,7 +557,8 @@
             dec_flags = 0
 
         # Read a chunk, decode it, and put the result in self._decoded_chars
-        w_input = space.call_method(self.w_buffer, "read1",
+        w_input = space.call_method(self.w_buffer,
+                                    "read1" if self.has_read1 else "read",
                                     space.wrap(self.chunk_size))
         eof = space.len_w(w_input) == 0
         w_decoded = space.call_method(self.w_decoder, "decode",
@@ -723,7 +728,9 @@
             text = space.unicode_w(w_text)
 
         needflush = False
-        if self.line_buffering and (haslf or text.find(u'\r') >= 0):
+        if self.write_through:
+            needflush = True
+        elif self.line_buffering and (haslf or text.find(u'\r') >= 0):
             needflush = True
 
         # XXX What if we were just reading?


More information about the pypy-commit mailing list