summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2002-10-07 17:27:35 (GMT)
committerBarry Warsaw <barry@python.org>2002-10-07 17:27:35 (GMT)
commit487fe6ac398b38b604d56285f2afb71e3ddbeb91 (patch)
treea384279d447a796c3dce12433b9a37c5affa1170 /Lib
parent45bb87bc135a36d9359eb0106f8e950cee5574d9 (diff)
downloadcpython-487fe6ac398b38b604d56285f2afb71e3ddbeb91.zip
cpython-487fe6ac398b38b604d56285f2afb71e3ddbeb91.tar.gz
cpython-487fe6ac398b38b604d56285f2afb71e3ddbeb91.tar.bz2
_parsebody(): Use get_content_type() instead of the deprecated
get_type(). Also, one of the regular expressions is constant so might as well make it a module global. And, when splitting up digests, handle lineseps that are longer than 1 character in length (e.g. \r\n).
Diffstat (limited to 'Lib')
-rw-r--r--Lib/email/Parser.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/Lib/email/Parser.py b/Lib/email/Parser.py
index 119a90d..5fea3c3 100644
--- a/Lib/email/Parser.py
+++ b/Lib/email/Parser.py
@@ -20,6 +20,8 @@ except NameError:
True = 1
False = 0
+nlcre = re.compile('\r\n|\r|\n')
+
class Parser:
@@ -137,7 +139,7 @@ class Parser:
# Parse the body, but first split the payload on the content-type
# boundary if present.
boundary = container.get_boundary()
- isdigest = (container.get_type() == 'multipart/digest')
+ isdigest = (container.get_content_type() == 'multipart/digest')
# If there's a boundary, split the payload text into its constituent
# parts and parse each separately. Otherwise, just parse the rest of
# the body as a single message. Note: any exceptions raised in the
@@ -167,8 +169,7 @@ class Parser:
preamble = payload[0:start]
# Find out what kind of line endings we're using
start += len(mo.group('sep')) + len(mo.group('ws'))
- cre = re.compile('\r\n|\r|\n')
- mo = cre.search(payload, start)
+ mo = nlcre.search(payload, start)
if mo:
start += len(mo.group(0))
# We create a compiled regexp first because we need to be able to
@@ -209,12 +210,12 @@ class Parser:
payload[start:terminator])
for part in parts:
if isdigest:
- if part[0] == linesep:
+ if part.startswith(linesep):
# There's no header block so create an empty message
# object as the container, and lop off the newline so
# we can parse the sub-subobject
msgobj = self._class()
- part = part[1:]
+ part = part[len(linesep):]
else:
parthdrs, part = part.split(linesep+linesep, 1)
# msgobj in this case is the "message/rfc822" container