def percent_encode_sequence(mapping, safe=SAFE_CHARS):
 encoded_pairs = []
 if hasattr(mapping, 'items'):
  pairs = mapping.items()
 else:
  pairs = mapping
 for (key, value) in pairs:
  if isinstance(value, list):
   for element in value:
    encoded_pairs.append(('%s=%s' % (percent_encode(key), percent_encode(element))))
  else:
   encoded_pairs.append(('%s=%s' % (percent_encode(key), percent_encode(value))))
 return '&'.join(encoded_pairs)

def percent_encode_sequence ( mapping , safe = SAFE_CHARS ) : encoded_pairs = [ ] if hasattr ( mapping , 'items' ) : pairs = mapping . items ( ) else : pairs = mapping for ( key , value ) in pairs : if isinstance ( value , list ) : for element in value : encoded_pairs . append ( ( '%s=%s' % ( percent_encode ( key ) , percent_encode ( element ) ) ) ) else : encoded_pairs . append ( ( '%s=%s' % ( percent_encode ( key ) , percent_encode ( value ) ) ) ) return '&' . join ( encoded_pairs )
urlencode a dict or list into a string .