Author: Ronan Lamy <[email protected]>
Branch: utf8-io
Changeset: r93181:8a64a04eb505
Date: 2017-11-26 02:37 +0000
http://bitbucket.org/pypy/pypy/changeset/8a64a04eb505/
Log: Convert stringio to utf8
diff --git a/pypy/module/_io/interp_stringio.py
b/pypy/module/_io/interp_stringio.py
--- a/pypy/module/_io/interp_stringio.py
+++ b/pypy/module/_io/interp_stringio.py
@@ -17,20 +17,20 @@
if len(self.data) > newlength:
self.data = self.data[:newlength]
if len(self.data) < newlength:
- self.data.extend([u'\0'] * (newlength - len(self.data)))
+ self.data.extend(['\0'] * (newlength - len(self.data)))
def read(self, size):
start = self.pos
available = len(self.data) - start
if available <= 0:
- return u''
+ return ''
if size >= 0 and size <= available:
end = start + size
else:
end = len(self.data)
assert 0 <= start <= end
self.pos = end
- return u''.join(self.data[start:end])
+ return ''.join(self.data[start:end])
def _convert_limit(self, limit):
if limit < 0 or limit > len(self.data) - self.pos:
@@ -58,7 +58,7 @@
else:
break
self.pos = pos
- result = u''.join(self.data[start:pos])
+ result = ''.join(self.data[start:pos])
return result
def readline(self, marker, limit):
@@ -79,7 +79,7 @@
if not found:
pos = end
self.pos = pos
- result = u''.join(self.data[start:pos])
+ result = ''.join(self.data[start:pos])
return result
def write(self, string):
@@ -99,7 +99,7 @@
self.resize(size)
def getvalue(self):
- return u''.join(self.data)
+ return ''.join(self.data)
class W_StringIO(W_TextIOBase):
@@ -118,10 +118,10 @@
if space.is_w(w_newline, space.w_None):
newline = None
else:
- newline = space.unicode_w(w_newline)
+ newline = space.utf8_w(w_newline)
- if (newline is not None and newline != u"" and newline != u"\n" and
- newline != u"\r" and newline != u"\r\n"):
+ if (newline is not None and newline != "" and newline != "\n" and
+ newline != "\r" and newline != "\r\n"):
# Not using oefmt() because I don't know how to use it
# with unicode
raise OperationError(space.w_ValueError,
@@ -131,9 +131,9 @@
)
if newline is not None:
self.readnl = newline
- self.readuniversal = newline is None or newline == u""
+ self.readuniversal = newline is None or newline == ""
self.readtranslate = newline is None
- if newline and newline[0] == u"\r":
+ if newline and newline[0] == "\r":
self.writenl = newline
if self.readuniversal:
self.w_decoder = space.call_function(
@@ -152,7 +152,7 @@
if self.readnl is None:
w_readnl = space.w_None
else:
- w_readnl = space.str(space.newunicode(self.readnl)) # YYY
+ w_readnl = space.str(space.new_from_utf8(self.readnl)) # YYY
return space.newtuple([
w_initialval, w_readnl, space.newint(self.buf.pos), w_dict
])
@@ -179,7 +179,7 @@
# because the string value in the state tuple has already been
# translated once by __init__. So we do not take any chance and replace
# object's buffer completely
- initval = space.unicode_w(w_initval)
+ initval = space.utf8_w(w_initval)
pos = space.getindex_w(w_pos, space.w_TypeError)
if pos < 0:
raise oefmt(space.w_ValueError,
@@ -215,8 +215,8 @@
if self.writenl:
w_decoded = space.call_method(
w_decoded, "replace",
- space.newtext("\n"), space.newunicode(self.writenl))
- string = space.unicode_w(w_decoded)
+ space.newtext("\n"), space.new_from_utf8(self.writenl))
+ string = space.utf8_w(w_decoded)
if string:
self.buf.write(string)
@@ -225,7 +225,7 @@
def read_w(self, space, w_size=None):
self._check_closed(space)
size = convert_size(space, w_size)
- return space.newunicode(self.buf.read(size))
+ return space.new_from_utf8(self.buf.read(size))
def readline_w(self, space, w_limit=None):
self._check_closed(space)
@@ -235,11 +235,11 @@
else:
if self.readtranslate:
# Newlines are already translated, only search for \n
- newline = u'\n'
+ newline = '\n'
else:
newline = self.readnl
result = self.buf.readline(newline, limit)
- return space.newunicode(result)
+ return space.new_from_utf8(result)
@unwrap_spec(pos=int, mode=int)
@@ -276,7 +276,7 @@
def getvalue_w(self, space):
self._check_closed(space)
- return space.newunicode(self.buf.getvalue())
+ return space.new_from_utf8(self.buf.getvalue())
def readable_w(self, space):
self._check_closed(space)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit