diff options
author | R David Murray <rdmurray@bitdance.com> | 2016-09-11 21:23:33 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2016-09-11 21:23:33 (GMT) |
commit | 29097d5a6aa13729583f98cd09923f97addb7819 (patch) | |
tree | d0d0fe07c5c4575493aad29a72868277b6b33a19 /Lib/email | |
parent | 727cc9337fe6b2f33e53922a75d329de3c8b4000 (diff) | |
download | cpython-29097d5a6aa13729583f98cd09923f97addb7819.zip cpython-29097d5a6aa13729583f98cd09923f97addb7819.tar.gz cpython-29097d5a6aa13729583f98cd09923f97addb7819.tar.bz2 |
Merge: #19003: Only replace \r and/or \n line endings in email.generator.
Diffstat (limited to 'Lib/email')
-rw-r--r-- | Lib/email/generator.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Lib/email/generator.py b/Lib/email/generator.py index 51109f9..ae670c2 100644 --- a/Lib/email/generator.py +++ b/Lib/email/generator.py @@ -18,6 +18,7 @@ from email.utils import _has_surrogates UNDERSCORE = '_' NL = '\n' # XXX: no longer used by the code below. +NLCRE = re.compile(r'\r\n|\r|\n') fcre = re.compile(r'^From ', re.MULTILINE) @@ -149,14 +150,17 @@ class Generator: # We have to transform the line endings. if not lines: return - lines = lines.splitlines(True) + lines = NLCRE.split(lines) for line in lines[:-1]: - self.write(line.rstrip('\r\n')) - self.write(self._NL) - laststripped = lines[-1].rstrip('\r\n') - self.write(laststripped) - if len(lines[-1]) != len(laststripped): + self.write(line) self.write(self._NL) + if lines[-1]: + self.write(lines[-1]) + # XXX logic tells me this else should be needed, but the tests fail + # with it and pass without it. (NLCRE.split ends with a blank element + # if and only if there was a trailing newline.) + #else: + # self.write(self._NL) def _write(self, msg): # We can't write the headers yet because of the following scenario: |