def EncodeUrl(base, params, escape_url, use_html_entities):
 real_params = []
 for (key, value) in params.iteritems():
  if escape_url:
   value = urllib.quote(value)
  if value:
   real_params.append(('%s=%s' % (key, value)))
 if real_params:
  url = ('%s?%s' % (base, '&'.join(real_params)))
 else:
  url = base
 if use_html_entities:
  url = cgi.escape(url, quote=True)
 return url

def EncodeUrl ( base , params , escape_url , use_html_entities ) : real_params = [ ] for ( key , value ) in params . iteritems ( ) : if escape_url : value = urllib . quote ( value ) if value : real_params . append ( ( '%s=%s' % ( key , value ) ) ) if real_params : url = ( '%s?%s' % ( base , '&' . join ( real_params ) ) ) else : url = base if use_html_entities : url = cgi . escape ( url , quote = True ) return url
escape params .