def format_header_param(name, value):
 if (not any(((ch in value) for ch in '"\\\r\n'))):
  result = ('%s="%s"' % (name, value))
  try:
   result.encode('ascii')
  except (UnicodeEncodeError, UnicodeDecodeError):
   pass
  else:
   return result
 if ((not six.PY3) and isinstance(value, six.text_type)):
  value = value.encode('utf-8')
 value = email.utils.encode_rfc2231(value, 'utf-8')
 value = ('%s*=%s' % (name, value))
 return value

def format_header_param ( name , value ) : if ( not any ( ( ( ch in value ) for ch in '"\\\r\n' ) ) ) : result = ( '%s="%s"' % ( name , value ) ) try : result . encode ( 'ascii' ) except ( UnicodeEncodeError , UnicodeDecodeError ) : pass else : return result if ( ( not six . PY3 ) and isinstance ( value , six . text_type ) ) : value = value . encode ( 'utf-8' ) value = email . utils . encode_rfc2231 ( value , 'utf-8' ) value = ( '%s*=%s' % ( name , value ) ) return value
helper function to format and quote a single header parameter .