[Python-checkins] python/dist/src/Lib/email Message.py,1.32,1.33
bwarsaw at users.sourceforge.net
bwarsaw at users.sourceforge.net
Mon Aug 18 21:53:05 EDT 2003
Update of /cvsroot/python/python/dist/src/Lib/email
In directory sc8-pr-cvs1:/tmp/cvs-serv13213
Modified Files:
Message.py
Log Message:
get_param(): Update the docstring to explain how CHARSET and LANGUAGE
can be None, and what to do in that situation.
get_filename(), get_boundary(), get_content_charset(): Make sure these
handle RFC 2231 headers without a CHARSET field.
Backport candidate (as was the Utils.py 1.25 change) to both Python
2.3.1 and 2.2.4 -- will do momentarily.
Index: Message.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/Message.py,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** Message.py 10 Jun 2003 16:31:55 -0000 1.32
--- Message.py 19 Aug 2003 03:53:02 -0000 1.33
***************
*** 572,582 ****
value can either be a string, or a 3-tuple if the parameter was RFC
2231 encoded. When it's a 3-tuple, the elements of the value are of
! the form (CHARSET, LANGUAGE, VALUE), where LANGUAGE may be the empty
! string. Your application should be prepared to deal with these, and
! can convert the parameter to a Unicode string like so:
param = msg.get_param('foo')
if isinstance(param, tuple):
! param = unicode(param[2], param[0])
In any case, the parameter value (either the returned string, or the
--- 572,585 ----
value can either be a string, or a 3-tuple if the parameter was RFC
2231 encoded. When it's a 3-tuple, the elements of the value are of
! the form (CHARSET, LANGUAGE, VALUE). Note that both CHARSET and
! LANGUAGE can be None, in which case you should consider VALUE to be
! encoded in the us-ascii charset. You can usually ignore LANGUAGE.
!
! Your application should be prepared to deal with 3-tuple return
! values, and can convert the parameter to a Unicode string like so:
param = msg.get_param('foo')
if isinstance(param, tuple):
! param = unicode(param[2], param[0] or 'us-ascii')
In any case, the parameter value (either the returned string, or the
***************
*** 709,713 ****
# It's an RFC 2231 encoded parameter
newvalue = _unquotevalue(filename)
! return unicode(newvalue[2], newvalue[0])
else:
newvalue = _unquotevalue(filename.strip())
--- 712,716 ----
# It's an RFC 2231 encoded parameter
newvalue = _unquotevalue(filename)
! return unicode(newvalue[2], newvalue[0] or 'us-ascii')
else:
newvalue = _unquotevalue(filename.strip())
***************
*** 726,730 ****
if isinstance(boundary, TupleType):
# RFC 2231 encoded, so decode. It better end up as ascii
! return unicode(boundary[2], boundary[0]).encode('us-ascii')
return _unquotevalue(boundary.strip())
--- 729,734 ----
if isinstance(boundary, TupleType):
# RFC 2231 encoded, so decode. It better end up as ascii
! charset = boundary[0] or 'us-ascii'
! return unicode(boundary[2], charset).encode('us-ascii')
return _unquotevalue(boundary.strip())
***************
*** 793,797 ****
if isinstance(charset, TupleType):
# RFC 2231 encoded, so decode it, and it better end up as ascii.
! charset = unicode(charset[2], charset[0]).encode('us-ascii')
# RFC 2046, $4.1.2 says charsets are not case sensitive
return charset.lower()
--- 797,802 ----
if isinstance(charset, TupleType):
# RFC 2231 encoded, so decode it, and it better end up as ascii.
! pcharset = charset[0] or 'us-ascii'
! charset = unicode(charset[2], pcharset).encode('us-ascii')
# RFC 2046, $4.1.2 says charsets are not case sensitive
return charset.lower()
More information about the Python-checkins
mailing list