def _safe_quote(val):
 SAFE_QUOTE_CHARS = '/.?&=,'
 try:
  ret = urllib.parse.quote(val, safe=SAFE_QUOTE_CHARS)
 except KeyError:
  ret = urllib.parse.quote(val.encode('utf-8'), safe=SAFE_QUOTE_CHARS)
 return ret

def _safe_quote ( val ) : SAFE_QUOTE_CHARS = '/.?&=,' try : ret = urllib . parse . quote ( val , safe = SAFE_QUOTE_CHARS ) except KeyError : ret = urllib . parse . quote ( val . encode ( 'utf-8' ) , safe = SAFE_QUOTE_CHARS ) return ret
unicode values will raise a keyerror .