[issue1395] py3k: duplicated line endings when using read(1)
Raghuram Devarakonda
report at bugs.python.org
Tue Nov 6 05:36:32 CET 2007
Raghuram Devarakonda added the comment:
I think the solution is to do the translation on a bigger chunk than on
the string being returned in each read call. For example, the following
patch correctly returns "a" and "\n" (instead of "a" and two "\n"s).
Index: Lib/io.py
===================================================================
--- Lib/io.py (revision 58874)
+++ Lib/io.py (working copy)
@@ -1253,8 +1253,9 @@
res += pending
if not readahead:
break
+ res = self._replacenl(res)
self._pending = res[n:]
- return self._replacenl(res[:n])
+ return res[:n]
def __next__(self):
self._telling = False
-----------------
Of course, we need to take care of the case when the last character in
"res" is "\r" to be followed by "\n" in the next read. I just wanted to
see if I am on the right track and if so, I can spend more time on this.
----------
nosy: +draghuram
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1395>
__________________________________
More information about the Python-bugs-list
mailing list