Turn a dictionary into a query string in a URL, with keys
    in alphabetical order.
433836
def _quote_query(query):
    """"""
    return "&".join("%s=%s" % (
        k, urllib_quote(
            unicode(query[k]).encode('utf-8'), safe='~'))
            for k in sorted(query))
142228
def get_query(path, force_unicode=True):
    
    u = urlparse(path)
    if not u.query:
        return {}
    p = parse_qs(u.query)

    if force_unicode:
        p = _unicode(p)
    return p
64380
def make_series_url(key):
    """"""

    url = urlparse.urljoin(endpoint.SERIES_ENDPOINT, 'key/')
    url = urlparse.urljoin(url, urllib.quote(key))
    return url
516201
def __build_url(self, api_call, **kwargs):
        """"""
        kwargs['key'] = self.api_key
        if 'language' not in kwargs:
            kwargs['language'] = self.language
        if 'format' not in kwargs:
            kwargs['format'] = self.__format
        api_query = urlencode(kwargs)

        return "{0}{1}?{2}".format(urls.BASE_URL,
                                   api_call,
                                   api_query)
992183
def reverse_lazy_with_query(named_url,**kwargs):
    ""
    q = QueryDict('',mutable=True)
    q.update(kwargs)
    return '{}?{}'.format(reverse_lazy(named_url),q.urlencode())
962529
function queryStringToJSON(url) {
  if (url === '') {
    return '';
  }
  var pairs = (url).slice(0).split('&'), result = {};
  for (var idx in pairs) {
    var pair = pairs[idx].split('=');
    if (!!pair[0]) {
      result[pair[0].toLowerCase()] = decodeURIComponent(pair[1] || '');
    }
  }
  return result;
}
88532
def add_params_to_qs(query, params):
    """"""
    if isinstance(params, dict):
        params = params.items()
    queryparams = urlparse.parse_qsl(query, keep_blank_values=True)
    queryparams.extend(params)
    return urlencode(queryparams)
1273387
def parse_url_to_dict(url):
    
    p = urlparse(url)

    return {
        'scheme': p.scheme,
        'netloc': p.netloc,
        'path': p.path,
        'params': p.params,
        'query': p.query,
        'fragment': p.fragment,
        'username': p.username,
        'password': p.password,
        'hostname': p.hostname,
        'port': p.port
    }
1090394
def clean_query_Dict(cls, query_Dict):
    
    return {k: v for k, v in query_Dict.items() if v}
1991
def _build_query_string(q, default_field=None, default_operator='AND'):
    
    def _is_phrase_search(query_string):
        clean_query = query_string.strip()
        return clean_query and clean_query.startswith('"') and clean_query.endswith('"')

    def _get_phrase(query_string):
        return query_string.strip().strip('"')

    if _is_phrase_search(q):
        query = {'match_phrase': {'_all': _get_phrase(q)}}
    else:
        query = {'query_string': {'query': q, 'default_operator': default_operator}}
        query['query_string'].update({'lenient': False} if default_field else {'default_field': default_field})

    return query
312609
def splitkeyurl(url):
    '''
       
    '''
    key = url[-22:]
    urlid = url[-34:-24]
    service = url[:-43]
    return service, urlid, key
819235
def from_urlencode(self, data, options=None):
        
        qs = dict((k, v if len(v) > 1 else v[0])
                  for k, v in urlparse.parse_qs(data).iteritems())
        return qs
1282212
def replace_urls(status):
    '''
    
    '''
    text = status.text

    if not has_url(status):
        return text

    urls = [(e['indices'], e['expanded_url']) for e in status.entities['urls']]
    urls.sort(key=lambda x: x[0][0], reverse=True)

    for (start, end), url in urls:
        text = text[:start] + url + text[end:]

    return text
735244
def reverse_with_query(named_url,**kwargs):
    ""
    q = QueryDict('',mutable=True)
    q.update(kwargs)
    return '{}?{}'.format(reverse(named_url),q.urlencode())
667470
def urlencode(params):
    """"""

    # Not doing duck typing here. Will make debugging easier.
    if not isinstance(params, dict):
        raise TypeError("Only dicts are supported.")

    params = flatten(params)

    url_params = OrderedDict()
    for param in params:
        value = param.pop()

        name = parametrize(param)
        if isinstance(value, (list, tuple)):
            name += "[]"

        url_params[name] = value

    return urllib_urlencode(url_params, doseq=True)
46404
def _querystring(self):
        """"""
        kw = {}
        if self.status:
            kw["status"] = "all"

        if self.links:
            kw["links"] = "all"

        if self.include is not None:
            kw["include"] = self.include
        if self.subject_key_type != "SubjectName":
            kw["subjectKeyType"] = self.subject_key_type
        return kw
47032
def url_to_query(url):
        
        q = {}

        # pylint: disable=unpacking-non-sequence
        (ignore, ignore, path,
         ignore, query, ignore) = urlparse(url)

        base = os.path.basename(path)
        if base not in ('buglist.cgi', 'query.cgi'):
            return {}

        for (k, v) in parse_qsl(query):
            if k not in q:
                q[k] = v
            elif isinstance(q[k], list):
                q[k].append(v)
            else:
                oldv = q[k]
                q[k] = [oldv, v]

        # Handle saved searches
        if base == "buglist.cgi" and "namedcmd" in q and "sharer_id" in q:
            q = {
                "sharer_id": q["sharer_id"],
                "savedsearch": q["namedcmd"],
            }

        return q