def percent_encode(input_str, safe=SAFE_CHARS):
 if (not isinstance(input_str, string_types)):
  input_str = text_type(input_str)
 return quote(text_type(input_str).encode('utf-8'), safe=safe)

def percent_encode ( input_str , safe = SAFE_CHARS ) : if ( not isinstance ( input_str , string_types ) ) : input_str = text_type ( input_str ) return quote ( text_type ( input_str ) . encode ( 'utf-8' ) , safe = safe )
urlencodes a string .