Commits

Amaury Forgeot d'Arc committed a7d7bcd

more bytes/str distinction in _io

Comments (0)

Files changed (1)

pypy/module/_io/interp_textio.py

             w_buffer, w_flag = space.unpackiterable(w_state, 2)
             flag = space.r_longlong_w(w_flag)
         else:
-            w_buffer = space.wrap("")
+            w_buffer = space.wrapbytes("")
             flag = 0
         flag <<= 1
         if self.pendingcr:
                     raise
                 self.w_encoding = space.wrap("ascii")
             else:
-                if not space.isinstance_w(self.w_encoding, space.w_str):
+                if not space.isinstance_w(self.w_encoding, space.w_unicode):
                     self.w_encoding = None
         if self.w_encoding:
             pass
             # Given this, we know there was a valid snapshot point
             # len(dec_buffer) bytes ago with decoder state (b'', dec_flags).
             w_dec_buffer, w_dec_flags = space.unpackiterable(w_state, 2)
-            dec_buffer = space.str_w(w_dec_buffer)
+            dec_buffer = space.bytes_w(w_dec_buffer)
             dec_flags = space.int_w(w_dec_flags)
         else:
             dec_buffer = None
         if self.telling:
             # At the snapshot point, len(dec_buffer) bytes before the read,
             # the next input to be decoded is dec_buffer + input_chunk.
-            next_input = dec_buffer + space.str_w(w_input)
+            next_input = dec_buffer + space.bytes_w(w_input)
             self.snapshot = PositionSnapshot(dec_flags, next_input)
 
         return not eof
         else:
             w_bytes = space.call_method(self.w_encoder, "encode", w_text)
 
-        b = space.str_w(w_bytes)
+        b = space.bytes_w(w_bytes)
         if not self.pending_bytes:
             self.pending_bytes = []
             self.pending_bytes_count = 0
         self.pending_bytes = None
         self.pending_bytes_count = 0
 
-        space.call_method(self.w_buffer, "write", space.wrap(pending_bytes))
+        space.call_method(self.w_buffer, "write",
+                          space.wrapbytes(pending_bytes))
 
     def detach_w(self, space):
         self._check_init(space)
             space.call_method(self.w_decoder, "reset")
         else:
             space.call_method(self.w_decoder, "setstate",
-                              space.newtuple([space.wrap(""),
+                              space.newtuple([space.wrapbytes(""),
                                               space.wrap(cookie.dec_flags)]))
 
     def _encoder_setstate(self, space, cookie):
             w_chunk = space.call_method(self.w_buffer, "read",
                                         space.wrap(cookie.bytes_to_feed))
             self.snapshot = PositionSnapshot(cookie.dec_flags,
-                                             space.str_w(w_chunk))
+                                             space.bytes_w(w_chunk))
 
             w_decoded = space.call_method(self.w_decoder, "decode",
                                           w_chunk, space.wrap(cookie.need_eof))
 
                 w_state = space.call_method(self.w_decoder, "getstate")
                 w_dec_buffer, w_flags = space.unpackiterable(w_state, 2)
-                dec_buffer_len = len(space.str_w(w_dec_buffer))
+                dec_buffer_len = space.len_w(w_dec_buffer)
 
                 if dec_buffer_len == 0 and chars_decoded <= chars_to_skip:
                     # Decoder buffer is empty, so this is a safe start point.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.