[Python-checkins] cpython (merge 3.2 -> default): #11062: Fix universal newline support in Babyl._install_message()
petri.lehtinen
python-checkins at python.org
Thu Aug 16 06:30:16 CEST 2012
http://hg.python.org/cpython/rev/5206b9dbf1ac
changeset: 78609:5206b9dbf1ac
parent: 78607:1b6a7fc45772
parent: 78608:770ffc91a82e
user: Petri Lehtinen <petri at digip.org>
date: Thu Aug 16 07:27:47 2012 +0300
summary:
#11062: Fix universal newline support in Babyl._install_message()
files:
Lib/mailbox.py | 13 ++++++++++---
1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/Lib/mailbox.py b/Lib/mailbox.py
--- a/Lib/mailbox.py
+++ b/Lib/mailbox.py
@@ -1447,10 +1447,17 @@
else:
break
while True:
- buffer = message.read(4096) # Buffer size is arbitrary.
- if not buffer:
+ line = message.readline()
+ if not line:
break
- self._file.write(buffer.replace(b'\n', linesep))
+ # Universal newline support.
+ if line.endswith(b'\r\n'):
+ line = line[:-2] + linesep
+ elif line.endswith(b'\r'):
+ line = line[:-1] + linesep
+ elif line.endswith(b'\n'):
+ line = line[:-1] + linesep
+ self._file.write(line)
else:
raise TypeError('Invalid message type: %s' % type(message))
stop = self._file.tell()
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list