def create_return_url(base, query, **kwargs):
 part = urlsplit(base)
 if part.fragment:
  raise ValueError("Base URL contained parts it shouldn't")
 for (key, values) in parse_qs(query).items():
  if (key in kwargs):
   if isinstance(kwargs[key], basestring):
    kwargs[key] = [kwargs[key]]
   kwargs[key].extend(values)
  else:
   kwargs[key] = values
 if part.query:
  for (key, values) in parse_qs(part.query).items():
   if (key in kwargs):
    if isinstance(kwargs[key], basestring):
     kwargs[key] = [kwargs[key]]
    kwargs[key].extend(values)
   else:
    kwargs[key] = values
  _pre = base.split('?')[0]
 else:
  _pre = base
 logger.debug(('kwargs: %s' % kwargs))
 return ('%s?%s' % (_pre, url_encode_params(kwargs)))

def create_return_url ( base , query , ** kwargs ) : part = urlsplit ( base ) if part . fragment : raise ValueError ( "Base URL contained parts it shouldn't" ) for ( key , values ) in parse_qs ( query ) . items ( ) : if ( key in kwargs ) : if isinstance ( kwargs [ key ] , basestring ) : kwargs [ key ] = [ kwargs [ key ] ] kwargs [ key ] . extend ( values ) else : kwargs [ key ] = values if part . query : for ( key , values ) in parse_qs ( part . query ) . items ( ) : if ( key in kwargs ) : if isinstance ( kwargs [ key ] , basestring ) : kwargs [ key ] = [ kwargs [ key ] ] kwargs [ key ] . extend ( values ) else : kwargs [ key ] = values _pre = base . split ( '?' ) [ 0 ] else : _pre = base logger . debug ( ( 'kwargs: %s' % kwargs ) ) return ( '%s?%s' % ( _pre , url_encode_params ( kwargs ) ) )
add a query string plus extra parameters to a base url which may contain a query part already .