cpython: df81f9b67736 (original) (raw)

Mercurial > cpython

changeset 96117:df81f9b67736

#20098: add mangle_from_ policy option. This defaults to True in the compat32 policy for backward compatibility, but to False for all new policies. Patch by Milan Oberkirch, with a few tweaks. [#20098]

R David Murray rdmurray@bitdance.com
date Sun, 17 May 2015 14:24:33 -0400
parents 9f0d5e33230f
children c060d20651fa
files Doc/library/email.policy.rst Doc/whatsnew/3.5.rst Lib/email/_policybase.py Lib/email/generator.py Lib/test/test_email/test_generator.py Lib/test/test_email/test_policy.py Misc/NEWS
diffstat 7 files changed, 76 insertions(+), 5 deletions(-)[+] [-] Doc/library/email.policy.rst 27 Doc/whatsnew/3.5.rst 6 Lib/email/_policybase.py 8 Lib/email/generator.py 13 Lib/test/test_email/test_generator.py 22 Lib/test/test_email/test_policy.py 2 Misc/NEWS 3

line wrap: on

line diff

--- a/Doc/library/email.policy.rst +++ b/Doc/library/email.policy.rst @@ -187,6 +187,18 @@ added matters. To illustrate:: :const:False (the default), defects will be passed to the :meth:register_defect method. + +

+

+ The following :class:Policy method is intended to be called by code using the email library to create policy instances with custom settings: @@ -319,6 +331,13 @@ added matters. To illustrate:: :const:compat32, that is used as the default policy. Thus the default behavior of the email package is to maintain compatibility with Python 3.2.

+ The class provides the following concrete implementations of the abstract methods of :class:Policy: @@ -356,6 +375,14 @@ added matters. To illustrate:: line breaks and any (RFC invalid) binary data it may contain. +An instance of :class:Compat32 is provided as a module constant: + +.. data:: compat32 +

+ .. note:: The documentation below describes new policies that are included in the

--- a/Doc/whatsnew/3.5.rst +++ b/Doc/whatsnew/3.5.rst @@ -351,6 +351,12 @@ doctest email ----- +* A new policy option :attr:~email.policy.Policy.mangle_from_ controls

--- a/Lib/email/_policybase.py +++ b/Lib/email/_policybase.py @@ -149,12 +149,18 @@ class Policy(_PolicyBase, metaclass=abc. during serialization. None or 0 means no line wrapping is done. Default is 78.

+ """ raise_on_defect = False linesep = '\n' cte_type = '8bit' max_line_length = 78

def handle_defect(self, obj, defect): """Based on policy, either raise defect or call register_defect. @@ -266,6 +272,8 @@ class Compat32(Policy): replicates the behavior of the email package version 5.1. """

+ def _sanitize_header(self, name, value): # If the header value contains surrogates, return a Header using # the unknown-8bit charset to encode the bytes as encoded words.

--- a/Lib/email/generator.py +++ b/Lib/email/generator.py @@ -32,16 +32,16 @@ class Generator: # Public interface #

outfp is the output file-like object for writing the message to. It must have a write() method.

Optional maxheaderlen specifies the longest length for a non-continued header. When a header line is longer (in characters, with tabs @@ -56,6 +56,9 @@ class Generator: flatten method is used. """ +

@@ -449,7 +452,7 @@ class DecodedGenerator(Generator): Like the Generator base class, except that non-text parts are substituted with a format string representing the part. """

--- a/Lib/test/test_email/test_generator.py +++ b/Lib/test/test_email/test_generator.py @@ -140,6 +140,28 @@ class TestGeneratorBase: g.flatten(msg, linesep='\n') self.assertEqual(s.getvalue(), self.typ(expected))

+

+ class TestGenerator(TestGeneratorBase, TestEmailBase):

--- a/Lib/test/test_email/test_policy.py +++ b/Lib/test/test_email/test_policy.py @@ -22,6 +22,7 @@ class PolicyAPITests(unittest.TestCase): 'linesep': '\n', 'cte_type': '8bit', 'raise_on_defect': False,

# For each policy under test, we give here what we expect the defaults to

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -47,6 +47,9 @@ Core and Builtins Library ------- +- Issue #20098: New mangle_from_ policy option for email, default True