cpython: 8375b8d54bf7 (original) (raw)

Mercurial > cpython

changeset 103547:8375b8d54bf7

#20476: Deal with the message_factory circular import differently. It turns out we can't depend on email.message getting imported every place message_factory is needed, so to avoid a circular import we need to special case Policy.message_factory=None in the parser instead of using monkey patching. I had a feeling that was a bad idea when I did it. [#20476]

R David Murray rdmurray@bitdance.com
date Sat, 10 Sep 2016 00:22:25 -0400
parents 3934e070c9db
children c73daf1dcc0c
files Doc/library/email.policy.rst Lib/email/_policybase.py Lib/email/feedparser.py Lib/email/message.py Lib/test/test_email/test_policy.py
diffstat 5 files changed, 9 insertions(+), 8 deletions(-)[+] [-] Doc/library/email.policy.rst 4 Lib/email/_policybase.py 2 Lib/email/feedparser.py 6 Lib/email/message.py 3 Lib/test/test_email/test_policy.py 2

line wrap: on

line diff

--- a/Doc/library/email.policy.rst +++ b/Doc/library/email.policy.rst @@ -224,8 +224,8 @@ added matters. To illustrate:: .. attribute:: message_factory A factory function for constructing a new empty message object. Used

.. versionadded:: 3.6

--- a/Lib/email/_policybase.py +++ b/Lib/email/_policybase.py @@ -155,6 +155,7 @@ class Policy(_PolicyBase, metaclass=abc. serialized by a generator. Default: True. message_factory -- the class to use to create new message objects.

""" @@ -163,7 +164,6 @@ class Policy(PolicyBase, metaclass=abc. cte_type = '8bit' max_line_length = 78 mangle_from = False

--- a/Lib/email/feedparser.py +++ b/Lib/email/feedparser.py @@ -147,7 +147,11 @@ class FeedParser: self.policy = policy self._old_style_factory = False if _factory is None:

--- a/Lib/email/message.py +++ b/Lib/email/message.py @@ -1162,6 +1162,3 @@ class EmailMessage(MIMEPart): super().set_content(*args, **kw) if 'MIME-Version' not in self: self['MIME-Version'] = '1.0' - -# Set message_factory on Policy here to avoid a circular import. -Policy.message_factory = Message

--- a/Lib/test/test_email/test_policy.py +++ b/Lib/test/test_email/test_policy.py @@ -24,7 +24,7 @@ class PolicyAPITests(unittest.TestCase): 'cte_type': '8bit', 'raise_on_defect': False, 'mangle_from_': True,