diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2008-08-19 17:56:33 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2008-08-19 17:56:33 (GMT) |
commit | fd036451bf0e0ade8783e21df801abf7be96d020 (patch) | |
tree | e70ff65a9e641d8e790bc091f0dc2507baf344ca /Lib/email | |
parent | 3ad7ba10a20827b24d4b1aa9dd49474db8affbdd (diff) | |
download | cpython-fd036451bf0e0ade8783e21df801abf7be96d020.zip cpython-fd036451bf0e0ade8783e21df801abf7be96d020.tar.gz cpython-fd036451bf0e0ade8783e21df801abf7be96d020.tar.bz2 |
#2834: Change re module semantics, so that str and bytes mixing is forbidden,
and str (unicode) patterns get full unicode matching by default. The re.ASCII
flag is also introduced to ask for ASCII matching instead.
Diffstat (limited to 'Lib/email')
-rw-r--r-- | Lib/email/quoprimime.py | 12 | ||||
-rw-r--r-- | Lib/email/utils.py | 17 |
2 files changed, 15 insertions, 14 deletions
diff --git a/Lib/email/quoprimime.py b/Lib/email/quoprimime.py index 68dc11c..ca91631 100644 --- a/Lib/email/quoprimime.py +++ b/Lib/email/quoprimime.py @@ -70,7 +70,7 @@ for c in (b' !"#$%&\'()*+,-./0123456789:;<>' _QUOPRI_BODY_MAP[c] = chr(c) - + # Helpers def header_check(octet): """Return True if the octet should be escaped with header quopri.""" @@ -125,7 +125,7 @@ def quote(c): return '=%02X' % ord(c) - + def header_encode(header_bytes, charset='iso-8859-1'): """Encode a single header line with quoted-printable (like) encoding. @@ -149,7 +149,7 @@ def header_encode(header_bytes, charset='iso-8859-1'): return '=?%s?q?%s?=' % (charset, EMPTYSTRING.join(encoded)) - + def body_encode(body, maxlinelen=76, eol=NL): """Encode with quoted-printable, wrapping at maxlinelen characters. @@ -225,7 +225,7 @@ def body_encode(body, maxlinelen=76, eol=NL): return encoded_body - + # BAW: I'm not sure if the intent was for the signature of this function to be # the same as base64MIME.decode() or not... def decode(encoded, eol=NL): @@ -280,7 +280,7 @@ body_decode = decode decodestring = decode - + def _unquote_match(match): """Turn a match in the form =AB to the ASCII character with value 0xab""" s = match.group(0) @@ -296,4 +296,4 @@ def header_decode(s): the high level email.Header class for that functionality. """ s = s.replace('_', ' ') - return re.sub(r'=\w{2}', _unquote_match, s) + return re.sub(r'=\w{2}', _unquote_match, s, re.ASCII) diff --git a/Lib/email/utils.py b/Lib/email/utils.py index 35275f6..465903f 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -52,7 +52,7 @@ specialsre = re.compile(r'[][\\()<>@,:;".]') escapesre = re.compile(r'[][\\()"]') - + # Helpers def formataddr(pair): @@ -73,7 +73,7 @@ def formataddr(pair): return address - + def getaddresses(fieldvalues): """Return a list of (REALNAME, EMAIL) for each fieldvalue.""" all = COMMASPACE.join(fieldvalues) @@ -81,7 +81,7 @@ def getaddresses(fieldvalues): return a.addresslist - + ecre = re.compile(r''' =\? # literal =? (?P<charset>[^?]*?) # non-greedy up to the next ? is the charset @@ -93,7 +93,7 @@ ecre = re.compile(r''' ''', re.VERBOSE | re.IGNORECASE) - + def formatdate(timeval=None, localtime=False, usegmt=False): """Returns a date string as specified by RFC 2822, e.g.: @@ -146,7 +146,7 @@ def formatdate(timeval=None, localtime=False, usegmt=False): zone) - + def make_msgid(idstring=None): """Returns a string suitable for RFC 2822 compliant Message-ID, e.g: @@ -168,7 +168,7 @@ def make_msgid(idstring=None): return msgid - + # These functions are in the standalone mimelib version only because they've # subsequently been fixed in the latest Python versions. We use this to worm # around broken older Pythons. @@ -202,7 +202,7 @@ def unquote(str): return str - + # RFC2231-related functions - parameter encoding and decoding def decode_rfc2231(s): """Decode string according to RFC 2231""" @@ -227,7 +227,8 @@ def encode_rfc2231(s, charset=None, language=None): return "%s'%s'%s" % (charset, language, s) -rfc2231_continuation = re.compile(r'^(?P<name>\w+)\*((?P<num>[0-9]+)\*?)?$') +rfc2231_continuation = re.compile(r'^(?P<name>\w+)\*((?P<num>[0-9]+)\*?)?$', + re.ASCII) def decode_params(params): """Decode parameters list according to RFC 2231. |