]> git.phdru.name Git - mimedecode.git/blob - formatparam_27.py
Cleanup: Fix flake8 E128 continuation line under-indented for visual indent
[mimedecode.git] / formatparam_27.py
1 from email import message
2 from email import utils
3
4
5 def _formatparam(param, value=None, quote=True):
6     """This is _formatparam from Python 2.7"""
7     if value is not None and len(value) > 0:
8         # A tuple is used for RFC 2231 encoded parameter values where items
9         # are (charset, language, value).  charset is a string, not a Charset
10         # instance.
11         if isinstance(value, tuple):
12             # Encode as per RFC 2231
13             param += '*'
14             value = utils.encode_rfc2231(value[2], value[0], value[1])
15         # BAW: Please check this.  I think that if quote is set it should
16         # force quoting even if not necessary.
17         if quote or message.tspecials.search(value):
18             return '%s="%s"' % (param, utils.quote(value))
19         else:
20             return '%s=%s' % (param, value)
21     else:
22         return param
23
24
25 # Replace with this _formatparam to avoid re-encoding non-ascii params
26 message._formatparam = _formatparam