Author: Matti Picus <[email protected]>
Branch: py3.6
Changeset: r96573:5420cbd1f137
Date: 2019-05-06 22:18 -0400
http://bitbucket.org/pypy/pypy/changeset/5420cbd1f137/
Log: merge default into py3.6, fix test
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
@@ -105,16 +105,10 @@
# desired, all in one pass.
seennl = self.seennl
- # If, up to now, newlines are consistently \n, do a quick check
- # for the \r
- only_lf = False
- if seennl == SEEN_LF or seennl == 0:
- only_lf = (output.find('\r') < 0)
-
- if only_lf:
- # If not already seen, quick scan for a possible "\n" character.
+ if output.find('\r') < 0:
+ # If no \r, quick scan for a possible "\n" character.
# (there's nothing else to be done, even when in translation mode)
- if seennl == 0 and output.find('\n') >= 0:
+ if output.find('\n') >= 0:
seennl |= SEEN_LF
# Finished: we have scanned for newlines, and none of them
# need translating.
diff --git a/pypy/module/_io/test/test_textio.py
b/pypy/module/_io/test/test_textio.py
--- a/pypy/module/_io/test/test_textio.py
+++ b/pypy/module/_io/test/test_textio.py
@@ -566,3 +566,13 @@
_check(dec)
dec = _io.IncrementalNewlineDecoder(None, translate=True)
_check(dec)
+
+ def test_newlines2(self):
+ import _io, codecs
+ inner_decoder = codecs.getincrementaldecoder("utf-8")()
+ decoder = _io.IncrementalNewlineDecoder(inner_decoder, translate=True)
+ msg = b"abc\r\n\n\r\r\n\n"
+ decoded = ''
+ for ch in msg:
+ decoded += decoder.decode(bytes([ch]))
+ assert set(decoder.newlines) == {"\r", "\n", "\r\n"}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit