diff options
author | R David Murray <rdmurray@bitdance.com> | 2011-04-18 17:59:37 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2011-04-18 17:59:37 (GMT) |
commit | 3edd22ac950d3a2bcc1ad2e5a83554970aef3369 (patch) | |
tree | b4661afc1be45e0d072c1c83ab354b2362f05afb /Lib/email/parser.py | |
parent | ce16be91dc68597b0c5bfc7b4b1c5136fe5697a6 (diff) | |
download | cpython-3edd22ac950d3a2bcc1ad2e5a83554970aef3369.zip cpython-3edd22ac950d3a2bcc1ad2e5a83554970aef3369.tar.gz cpython-3edd22ac950d3a2bcc1ad2e5a83554970aef3369.tar.bz2 |
#11731: simplify/enhance parser/generator API by introducing policy objects.
This new interface will also allow for future planned enhancements
in control over the parser/generator without requiring any additional
complexity in the parser/generator API.
Patch reviewed by Éric Araujo and Barry Warsaw.
Diffstat (limited to 'Lib/email/parser.py')
-rw-r--r-- | Lib/email/parser.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/email/parser.py b/Lib/email/parser.py index fc5090b..0f92160 100644 --- a/Lib/email/parser.py +++ b/Lib/email/parser.py @@ -11,11 +11,12 @@ from io import StringIO, TextIOWrapper from email.feedparser import FeedParser from email.message import Message +from email import policy class Parser: - def __init__(self, _class=Message): + def __init__(self, _class=Message, *, policy=policy.default): """Parser of RFC 2822 and MIME email messages. Creates an in-memory object tree representing the email message, which @@ -30,8 +31,14 @@ class Parser: _class is the class to instantiate for new message objects when they must be created. This class must have a constructor that can take zero arguments. Default is Message.Message. + + The policy keyword specifies a policy object that controls a number of + aspects of the parser's operation. The default policy maintains + backward compatibility. + """ self._class = _class + self.policy = policy def parse(self, fp, headersonly=False): """Create a message structure from the data in a file. @@ -41,7 +48,7 @@ class Parser: parsing after reading the headers or not. The default is False, meaning it parses the entire contents of the file. """ - feedparser = FeedParser(self._class) + feedparser = FeedParser(self._class, policy=self.policy) if headersonly: feedparser._set_headersonly() while True: |