summaryrefslogtreecommitdiffstats
path: root/Lib/email/feedparser.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2014-02-07 15:44:16 (GMT)
committerR David Murray <rdmurray@bitdance.com>2014-02-07 15:44:16 (GMT)
commitaa21297457ef0e5647602e19a89c4b797183c16e (patch)
treec670249e97be11f526b9df3c5443dfd7f8e39f53 /Lib/email/feedparser.py
parent11c5afd1383656e78d35a8405729c207d2287bdd (diff)
downloadcpython-aa21297457ef0e5647602e19a89c4b797183c16e.zip
cpython-aa21297457ef0e5647602e19a89c4b797183c16e.tar.gz
cpython-aa21297457ef0e5647602e19a89c4b797183c16e.tar.bz2
#20476: use EmailMessage as factory if non-compat32 policy is used.
In 3.5 I will fix this right by adding a message_factory attribute to the policy.
Diffstat (limited to 'Lib/email/feedparser.py')
-rw-r--r--Lib/email/feedparser.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/Lib/email/feedparser.py b/Lib/email/feedparser.py
index eb75fe3..6cf9b91 100644
--- a/Lib/email/feedparser.py
+++ b/Lib/email/feedparser.py
@@ -126,7 +126,7 @@ class BufferedSubFile(object):
class FeedParser:
"""A feed-style parser of email."""
- def __init__(self, _factory=message.Message, *, policy=compat32):
+ def __init__(self, _factory=None, *, policy=compat32):
"""_factory is called with no arguments to create a new message obj
The policy keyword specifies a policy object that controls a number of
@@ -134,14 +134,23 @@ class FeedParser:
backward compatibility.
"""
- self._factory = _factory
self.policy = policy
- try:
- _factory(policy=self.policy)
- self._factory_kwds = lambda: {'policy': self.policy}
- except TypeError:
- # Assume this is an old-style factory
- self._factory_kwds = lambda: {}
+ self._factory_kwds = lambda: {'policy': self.policy}
+ if _factory is None:
+ # What this should be:
+ #self._factory = policy.default_message_factory
+ # but, because we are post 3.4 feature freeze, fix with temp hack:
+ if self.policy is compat32:
+ self._factory = message.Message
+ else:
+ self._factory = message.EmailMessage
+ else:
+ self._factory = _factory
+ try:
+ _factory(policy=self.policy)
+ except TypeError:
+ # Assume this is an old-style factory
+ self._factory_kwds = lambda: {}
self._input = BufferedSubFile()
self._msgstack = []
self._parse = self._parsegen().__next__