summaryrefslogtreecommitdiffstats
path: root/Lib/email/Parser.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2004-10-03 03:16:19 (GMT)
committerBarry Warsaw <barry@python.org>2004-10-03 03:16:19 (GMT)
commitbb113867305f8ab70947bffb77961a60d10730dc (patch)
tree0af1fbf0fbbd95170636205343ba827cf768bb38 /Lib/email/Parser.py
parent2cdd608601071df8e557beaaa78b54884c80e8de (diff)
downloadcpython-bb113867305f8ab70947bffb77961a60d10730dc.zip
cpython-bb113867305f8ab70947bffb77961a60d10730dc.tar.gz
cpython-bb113867305f8ab70947bffb77961a60d10730dc.tar.bz2
Big email 3.0 API changes, with updated unit tests and documentation.
Briefly (from the NEWS file): - Updates for the email package: + All deprecated APIs that in email 2.x issued warnings have been removed: _encoder argument to the MIMEText constructor, Message.add_payload(), Utils.dump_address_pair(), Utils.decode(), Utils.encode() + New deprecations: Generator.__call__(), Message.get_type(), Message.get_main_type(), Message.get_subtype(), the 'strict' argument to the Parser constructor. These will be removed in email 3.1. + Support for Python earlier than 2.3 has been removed (see PEP 291). + All defect classes have been renamed to end in 'Defect'. + Some FeedParser fixes; also a MultipartInvariantViolationDefect will be added to messages that claim to be multipart but really aren't. + Updates to documentation.
Diffstat (limited to 'Lib/email/Parser.py')
-rw-r--r--Lib/email/Parser.py34
1 files changed, 23 insertions, 11 deletions
diff --git a/Lib/email/Parser.py b/Lib/email/Parser.py
index 8c5661d..0c05224 100644
--- a/Lib/email/Parser.py
+++ b/Lib/email/Parser.py
@@ -4,17 +4,15 @@
"""A parser of RFC 2822 and MIME email messages."""
-import re
+import warnings
from cStringIO import StringIO
from email.FeedParser import FeedParser
from email.Message import Message
-NLCRE = re.compile('\r\n|\r|\n')
-
class Parser:
- def __init__(self, _class=Message, strict=False):
+ def __init__(self, *args, **kws):
"""Parser of RFC 2822 and MIME email messages.
Creates an in-memory object tree representing the email message, which
@@ -29,14 +27,28 @@ 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.
-
- Optional strict tells the parser to be strictly RFC compliant or to be
- more forgiving in parsing of ill-formatted MIME documents. When
- non-strict mode is used, the parser will try to make up for missing or
- erroneous boundaries and other peculiarities seen in the wild.
- Default is non-strict parsing.
"""
- self._class = _class
+ if len(args) >= 1:
+ if '_class' in kws:
+ raise TypeError("Multiple values for keyword arg '_class'")
+ kws['_class'] = args[0]
+ if len(args) == 2:
+ if 'strict' in kws:
+ raise TypeError("Multiple values for keyword arg 'strict'")
+ kws['strict'] = args[1]
+ if len(args) > 2:
+ raise TypeError('Too many arguments')
+ if '_class' in kws:
+ self._class = kws['_class']
+ del kws['_class']
+ else:
+ self._class = Message
+ if 'strict' in kws:
+ warnings.warn("'strict' argument is deprecated (and ignored)",
+ DeprecationWarning, 2)
+ del kws['strict']
+ if kws:
+ raise TypeError('Unexpected keyword arguments')
def parse(self, fp, headersonly=False):
"""Create a message structure from the data in a file.