def url_quote(string, charset='utf-8', errors='strict', safe='/:', unsafe=''):
 if (not isinstance(string, (text_type, bytes, bytearray))):
  string = text_type(string)
 if isinstance(string, text_type):
  string = string.encode(charset, errors)
 if isinstance(safe, text_type):
  safe = safe.encode(charset, errors)
 if isinstance(unsafe, text_type):
  unsafe = unsafe.encode(charset, errors)
 safe = (frozenset((bytearray(safe) + _always_safe)) - frozenset(bytearray(unsafe)))
 rv = bytearray()
 for char in bytearray(string):
  if (char in safe):
   rv.append(char)
  else:
   rv.extend(('%%%02X' % char).encode('ascii'))
 return to_native(bytes(rv))

def url_quote ( string , charset = 'utf-8' , errors = 'strict' , safe = '/:' , unsafe = '' ) : if ( not isinstance ( string , ( text_type , bytes , bytearray ) ) ) : string = text_type ( string ) if isinstance ( string , text_type ) : string = string . encode ( charset , errors ) if isinstance ( safe , text_type ) : safe = safe . encode ( charset , errors ) if isinstance ( unsafe , text_type ) : unsafe = unsafe . encode ( charset , errors ) safe = ( frozenset ( ( bytearray ( safe ) + _always_safe ) ) - frozenset ( bytearray ( unsafe ) ) ) rv = bytearray ( ) for char in bytearray ( string ) : if ( char in safe ) : rv . append ( char ) else : rv . extend ( ( '%%%02X' % char ) . encode ( 'ascii' ) ) return to_native ( bytes ( rv ) )
url encode a single string with a given encoding .