[Python-checkins] python/dist/src/Lib/email Message.py,1.13,1.14

bwarsaw@users.sourceforge.net bwarsaw@users.sourceforge.net
2002年6月28日 22:56:17 -0700


Update of /cvsroot/python/python/dist/src/Lib/email
In directory usw-pr-cvs1:/tmp/cvs-serv3560/email
Modified Files:
	Message.py 
Log Message:
Oleg Broytmann's support for RFC 2231 encoded parameters, SF patch #549133
Specifically,
_formatparam(): Teach this about encoded `param' arguments, which are
a 3-tuple of items (charset, language, value). language is ignored.
_unquotevalue(): Handle both 3-tuple RFC 2231 values and unencoded
values.
_get_params_preserve(): Decode the parameters before returning them.
get_params(), get_param(): Use _unquotevalue().
get_filename(), get_boundary(): Teach these about encoded (3-tuple)
parameters.
Index: Message.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/Message.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** Message.py	2 Jun 2002 19:05:51 -0000	1.13
--- Message.py	29 Jun 2002 05:56:15 -0000	1.14
***************
*** 8,12 ****
 import warnings
 from cStringIO import StringIO
! from types import ListType, StringType
 
 # Intrapackage imports
--- 8,12 ----
 import warnings
 from cStringIO import StringIO
! from types import ListType, TupleType, StringType
 
 # Intrapackage imports
***************
*** 28,38 ****
 
 
! # Helper function
 def _formatparam(param, value=None, quote=1):
 """Convenience function to format and return a key=value pair.
 
! Will quote the value if needed or if quote is true.
 """
 if value is not None and len(value) > 0:
 # BAW: Please check this. I think that if quote is set it should
 # force quoting even if not necessary.
--- 28,44 ----
 
 
! # Helper functions
 def _formatparam(param, value=None, quote=1):
 """Convenience function to format and return a key=value pair.
 
! This will quote the value if needed or if quote is true.
 """
 if value is not None and len(value) > 0:
+ # TupleType is used for RFC 2231 encoded parameter values where items
+ # are (charset, language, value). charset is a string, not a Charset
+ # instance.
+ if isinstance(value, TupleType):
+ # Convert to ascii, ignore language
+ value = unicode(value[2], value[0]).encode("ascii")
 # BAW: Please check this. I think that if quote is set it should
 # force quoting even if not necessary.
***************
*** 45,48 ****
--- 51,61 ----
 
 
+ def _unquotevalue(value):
+ if isinstance(value, TupleType):
+ return (value[0], value[1], Utils.unquote(value[2]))
+ else:
+ return Utils.unquote(value)
+ 
+ 
 
 class Message:
***************
*** 401,404 ****
--- 414,418 ----
 val = ''
 params.append((name, val))
+ params = Utils.decode_params(params)
 return params
 
***************
*** 421,425 ****
 return failobj
 if unquote:
! return [(k, Utils.unquote(v)) for k, v in params]
 else:
 return params
--- 435,439 ----
 return failobj
 if unquote:
! return [(k, _unquotevalue(v)) for k, v in params]
 else:
 return params
***************
*** 440,444 ****
 if k.lower() == param.lower():
 if unquote:
! return Utils.unquote(v)
 else:
 return v
--- 454,458 ----
 if k.lower() == param.lower():
 if unquote:
! return _unquotevalue(v)
 else:
 return v
***************
*** 549,553 ****
 if filename is missing:
 return failobj
! return Utils.unquote(filename.strip())
 
 def get_boundary(self, failobj=None):
--- 563,573 ----
 if filename is missing:
 return failobj
! if isinstance(filename, TupleType):
! # It's an RFC 2231 encoded parameter
! newvalue = _unquotevalue(filename)
! return unicode(newvalue[2], newvalue[0])
! else:
! newvalue = _unquotevalue(filename.strip())
! return newvalue
 
 def get_boundary(self, failobj=None):
***************
*** 561,565 ****
 if boundary is missing:
 return failobj
! return Utils.unquote(boundary.strip())
 
 def set_boundary(self, boundary):
--- 581,585 ----
 if boundary is missing:
 return failobj
! return _unquotevalue(boundary.strip())
 
 def set_boundary(self, boundary):

AltStyle によって変換されたページ (->オリジナル) /