diff options
author | R David Murray <rdmurray@bitdance.com> | 2015-05-17 18:24:33 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2015-05-17 18:24:33 (GMT) |
commit | fdb23c2fe5499d26701fa34873c1cdc347adcb80 (patch) | |
tree | 1f65d6f676b2feb7ee7c0e24068ca67160d91407 /Lib/test/test_email | |
parent | 224ef3ec3b0758956789c4c98e6cc93704304419 (diff) | |
download | cpython-fdb23c2fe5499d26701fa34873c1cdc347adcb80.zip cpython-fdb23c2fe5499d26701fa34873c1cdc347adcb80.tar.gz cpython-fdb23c2fe5499d26701fa34873c1cdc347adcb80.tar.bz2 |
#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.
Diffstat (limited to 'Lib/test/test_email')
-rw-r--r-- | Lib/test/test_email/test_generator.py | 22 | ||||
-rw-r--r-- | Lib/test/test_email/test_policy.py | 2 |
2 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_email/test_generator.py b/Lib/test/test_email/test_generator.py index 920f870..b1cbce2 100644 --- 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)) + def test_set_mangle_from_via_policy(self): + source = textwrap.dedent("""\ + Subject: test that + from is mangeld in the body! + + From time to time I write a rhyme. + """) + variants = ( + (None, True), + (policy.compat32, True), + (policy.default, False), + (policy.default.clone(mangle_from_=True), True), + ) + for p, mangle in variants: + expected = source.replace('From ', '>From ') if mangle else source + with self.subTest(policy=p, mangle_from_=mangle): + msg = self.msgmaker(self.typ(source)) + s = self.ioclass() + g = self.genclass(s, policy=p) + g.flatten(msg) + self.assertEqual(s.getvalue(), self.typ(expected)) + class TestGenerator(TestGeneratorBase, TestEmailBase): diff --git a/Lib/test/test_email/test_policy.py b/Lib/test/test_email/test_policy.py index 4b0a04e..9bb32f0 100644 --- 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, + 'mangle_from_': True, } # These default values are the ones set on email.policy.default. # If any of these defaults change, the docs must be updated. @@ -32,6 +33,7 @@ class PolicyAPITests(unittest.TestCase): 'header_factory': email.policy.EmailPolicy.header_factory, 'refold_source': 'long', 'content_manager': email.policy.EmailPolicy.content_manager, + 'mangle_from_': False, }) # For each policy under test, we give here what we expect the defaults to |