[pypy-commit] pypy utf8-unicode2: Fix translation
waedt
noreply at buildbot.pypy.org
Tue Aug 12 18:35:12 CEST 2014
Author: Tyler Wade <wayedt at gmail.com>
Branch: utf8-unicode2
Changeset: r72766:50441033e543
Date: 2014-08-12 11:34 -0500
http://bitbucket.org/pypy/pypy/changeset/50441033e543/
Log: Fix translation
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
@@ -27,11 +27,10 @@
newline = None
else:
newline = space.unicode_w(w_newline)
+ newline = newline.bytes
- if (newline is not None and len(newline) != 0 and
- utf8.NE(newline, Utf8Str('\n')) and
- utf8.NE(newline, Utf8Str('\r\n')) and
- utf8.NE(newline, Utf8Str('\r'))):
+ if (newline and newline != '\n' and newline != '\r\n' and
+ newline != '\r'):
# Not using oefmt() because I don't know how to ues it
# with unicode
raise OperationError(space.w_ValueError,
@@ -39,12 +38,12 @@
space.wrap("illegal newline value: %s"), space.wrap(newline)
)
)
+
if newline is not None:
self.readnl = newline
- self.readuniversal = newline is None or len(newline) == 0
+ self.readuniversal = not newline
self.readtranslate = newline is None
- if (newline is not None and len(newline) > 0 and
- utf8ord(newline) == ord("\r")):
+ if newline and newline[0] == '\r':
self.writenl = newline
if self.readuniversal:
self.w_decoder = space.call_function(
@@ -146,7 +145,8 @@
if self.writenl:
w_decoded = space.call_method(
- w_decoded, "replace", space.wrap("\n"), space.wrap(self.writenl)
+ w_decoded, "replace", space.wrap("\n"),
+ space.wrap(Utf8Str(self.writenl))
)
string = space.unicode_w(w_decoded)
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
@@ -372,17 +372,14 @@
newline = None
else:
newline = space.unicode_w(w_newline)
+ # newline is guaranteed to be either empty or ascii
+ newline = newline.bytes
- if (newline is not None and len(newline) > 0 and
- not (utf8.EQ(newline, Utf8Str('\n')) or
- utf8.EQ(newline, Utf8Str('\r\n')) or
- utf8.EQ(newline, Utf8Str('\r')))):
+ if (newline and newline != '\n' and newline != '\r\n' and
+ newline != '\r'):
r = space.str_w(space.repr(w_newline))
raise OperationError(space.w_ValueError, space.wrap(
"illegal newline value: %s" % (r,)))
- elif newline is not None:
- # newline is guaranteed to be either empty or ascii
- newline = newline.bytes
self.line_buffering = line_buffering
More information about the pypy-commit
mailing list