summaryrefslogtreecommitdiffstats
path: root/Lib/email/message.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-08-17 20:23:46 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-08-17 20:23:46 (GMT)
commit4cd6a95dfeb06950a2566e23e7e2bc9eb8c59775 (patch)
tree829f2adbc38288b3b7ca9c5703ad78d6100c5fe7 /Lib/email/message.py
parent9209138ff9f38f227a72a39308c482f59856329e (diff)
downloadcpython-4cd6a95dfeb06950a2566e23e7e2bc9eb8c59775.zip
cpython-4cd6a95dfeb06950a2566e23e7e2bc9eb8c59775.tar.gz
cpython-4cd6a95dfeb06950a2566e23e7e2bc9eb8c59775.tar.bz2
Merged revisions 65659,65693,65700,65702,65706-65707,65761 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r65659 | martin.v.loewis | 2008-08-12 15:45:21 -0500 (Tue, 12 Aug 2008) | 2 lines Add Hirokazu Yamamoto. ........ r65693 | georg.brandl | 2008-08-15 13:35:09 -0500 (Fri, 15 Aug 2008) | 2 lines #3558: Attribute reference binds more tightly than subscription and call. ........ r65700 | antoine.pitrou | 2008-08-15 16:03:21 -0500 (Fri, 15 Aug 2008) | 3 lines #2676: email/message.py [Message.get_content_type]: Trivial regex hangs on pathological input ........ r65702 | gregory.p.smith | 2008-08-15 18:14:00 -0500 (Fri, 15 Aug 2008) | 2 lines document that waitpid raises OSError ........ r65706 | benjamin.peterson | 2008-08-15 22:02:41 -0500 (Fri, 15 Aug 2008) | 1 line fix markup ........ r65707 | benjamin.peterson | 2008-08-15 22:13:07 -0500 (Fri, 15 Aug 2008) | 1 line note how os.utime should be used for emulating touch ........ r65761 | antoine.pitrou | 2008-08-17 08:06:29 -0500 (Sun, 17 Aug 2008) | 3 lines fix ZipFile.testzip() to work with very large embedded files ........
Diffstat (limited to 'Lib/email/message.py')
-rw-r--r--Lib/email/message.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/Lib/email/message.py b/Lib/email/message.py
index ff262c7..471d46b 100644
--- a/Lib/email/message.py
+++ b/Lib/email/message.py
@@ -20,18 +20,22 @@ from email.charset import Charset
SEMISPACE = '; '
-# Regular expression used to split header parameters. BAW: this may be too
-# simple. It isn't strictly RFC 2045 (section 5.1) compliant, but it catches
-# most headers found in the wild. We may eventually need a full fledged
-# parser eventually.
-paramre = re.compile(r'\s*;\s*')
# Regular expression that matches `special' characters in parameters, the
# existance of which force quoting of the parameter value.
tspecials = re.compile(r'[ \(\)<>@,;:\\"/\[\]\?=]')
-
# Helper functions
+def _splitparam(param):
+ # Split header parameters. BAW: this may be too simple. It isn't
+ # strictly RFC 2045 (section 5.1) compliant, but it catches most headers
+ # found in the wild. We may eventually need a full fledged parser
+ # eventually.
+ a, sep, b = param.partition(';')
+ if not sep:
+ return a.strip(), None
+ return a.strip(), b.strip()
+
def _formatparam(param, value=None, quote=True):
"""Convenience function to format and return a key=value pair.
@@ -443,7 +447,7 @@ class Message:
if value is missing:
# This should have no parameters
return self.get_default_type()
- ctype = paramre.split(value)[0].lower().strip()
+ ctype = _splitparam(value)[0].lower()
# RFC 2045, section 5.2 says if its invalid, use text/plain
if ctype.count('/') != 1:
return 'text/plain'