def _formatparam(param, value=None, quote=True): if value is not None and len(value) > 0: if isinstance(value, tuple): param += '*' value = Utils.encode_rfc2231(value[2], value[0], value[1]) if quote or tspecials.search(value): return '%s="%s"' % (param, Utils.quote(value)) else: return '%s=%s' % (param, value) else: return param
def _formatparam(param, value = None, quote = True): if value is not None and len(value) > 0: if isinstance(value, tuple): param += '*' value = Utils.encode_rfc2231(value[2], value[0], value[1]) if quote or tspecials.search(value): return '%s="%s"' % (param, Utils.quote(value)) else: return '%s=%s' % (param, value) else: return param return
def _formatparam(param, value=None, quote=True): """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): # Encode as per RFC 2231 param += '*' value = Utils.encode_rfc2231(value[2], value[0], value[1]) # BAW: Please check this. I think that if quote is set it should # force quoting even if not necessary. if quote or tspecials.search(value): return '%s="%s"' % (param, Utils.quote(value)) else: return '%s=%s' % (param, value) else: return param