def do_urlencode(value):
 itemiter = None
 if isinstance(value, dict):
  itemiter = iteritems(value)
 elif (not isinstance(value, string_types)):
  try:
   itemiter = iter(value)
  except TypeError:
   pass
 if (itemiter is None):
  return unicode_urlencode(value)
 return u'&'.join((((unicode_urlencode(k) + '=') + unicode_urlencode(v, for_qs=True)) for (k, v) in itemiter))

def do_urlencode ( value ) : itemiter = None if isinstance ( value , dict ) : itemiter = iteritems ( value ) elif ( not isinstance ( value , string_types ) ) : try : itemiter = iter ( value ) except TypeError : pass if ( itemiter is None ) : return unicode_urlencode ( value ) return u'&' . join ( ( ( ( unicode_urlencode ( k ) + '=' ) + unicode_urlencode ( v , for_qs = True ) ) for ( k , v ) in itemiter ) )
escape strings for use in urls .