diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-12-04 00:46:23 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2017-12-04 00:46:23 (GMT) |
commit | a87ba60fe56ae2ebe80ab9ada6d280a6a1f3d552 (patch) | |
tree | 5df8f13d6f9f61999dd9de67981b3228bfb97257 /Lib/email/headerregistry.py | |
parent | 30a6bc842945e3e9c9c7db887ab495c428ec7074 (diff) | |
download | cpython-a87ba60fe56ae2ebe80ab9ada6d280a6a1f3d552.zip cpython-a87ba60fe56ae2ebe80ab9ada6d280a6a1f3d552.tar.gz cpython-a87ba60fe56ae2ebe80ab9ada6d280a6a1f3d552.tar.bz2 |
bpo-27240 Rewrite the email header folding algorithm. (GH-3488) (#4693)
The original algorithm tried to delegate the folding to the tokens so
that those tokens whose folding rules differed could specify the
differences. However, this resulted in a lot of duplicated code because
most of the rules were the same.
The new algorithm moves all folding logic into a set of functions
external to the token classes, but puts the information about which
tokens can be folded in which ways on the tokens...with the exception of
mime-parameters, which are a special case (which was not even
implemented in the old folder).
This algorithm can still probably be improved and hopefully simplified
somewhat.
Note that some of the test expectations are changed. I believe the
changes are toward more desirable and consistent behavior: in general
when (re) folding a line the canonical version of the tokens is
generated, rather than preserving errors or extra whitespace.
(cherry picked from commit 85d5c18c9d83a1d54eecc4c2ad4dce63194107c6)
Diffstat (limited to 'Lib/email/headerregistry.py')
-rw-r--r-- | Lib/email/headerregistry.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/email/headerregistry.py b/Lib/email/headerregistry.py index 0fc2231..f5be87f 100644 --- a/Lib/email/headerregistry.py +++ b/Lib/email/headerregistry.py @@ -245,13 +245,16 @@ class BaseHeader(str): the header name and the ': ' separator. """ - # At some point we need to only put fws here if it was in the source. + # At some point we need to put fws here iif it was in the source. header = parser.Header([ parser.HeaderLabel([ parser.ValueTerminal(self.name, 'header-name'), parser.ValueTerminal(':', 'header-sep')]), - parser.CFWSList([parser.WhiteSpaceTerminal(' ', 'fws')]), - self._parse_tree]) + ]) + if self._parse_tree: + header.append( + parser.CFWSList([parser.WhiteSpaceTerminal(' ', 'fws')])) + header.append(self._parse_tree) return header.fold(policy=policy) |