cpython: 770ffc91a82e (original) (raw)
Mercurial > cpython
changeset 78608:770ffc91a82e 3.2
#11062: Fix universal newline support in Babyl._install_message() When adding a message from a binary file, \r\n was translated to \r\r\n in the message body. [#11062]
Petri Lehtinen petri@digip.org | |
---|---|
date | Thu, 16 Aug 2012 07:22:15 +0300 |
parents | 8ff172a1b679 |
children | 5206b9dbf1ac ce49599b9fdf |
files | Lib/mailbox.py |
diffstat | 1 files changed, 10 insertions(+), 3 deletions(-)[+] [-] Lib/mailbox.py 13 |
line wrap: on
line diff
--- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -1450,10 +1450,17 @@ class Babyl(_singlefileMailbox): else: break while True:
buffer = message.read(4096) # Buffer size is arbitrary.[](#l1.7)
if not buffer:[](#l1.8)
line = message.readline()[](#l1.9)
if not line:[](#l1.10) break[](#l1.11)
self._file.write(buffer.replace(b'\n', linesep))[](#l1.12)
# Universal newline support.[](#l1.13)
if line.endswith(b'\r\n'):[](#l1.14)
line = line[:-2] + linesep[](#l1.15)
elif line.endswith(b'\r'):[](#l1.16)
line = line[:-1] + linesep[](#l1.17)
elif line.endswith(b'\n'):[](#l1.18)
line = line[:-1] + linesep[](#l1.19)
self._file.write(line)[](#l1.20) else:[](#l1.21) raise TypeError('Invalid message type: %s' % type(message))[](#l1.22) stop = self._file.tell()[](#l1.23)