Break url parameters and turn into sort arguments
322195
def build_sort(self, **kwargs):
        '''  '''
        sort = []
        order = kwargs.get('order_by', None)
        if order:
            if type(order) is list:
                order = order[0]
            if order[:1] == '-':
                sort.append((order[1:], -1))
            else:
                sort.append((order, 1))
        return sort
1259727
def url_to_parts(url):
    

    if not url:
        return None

    scheme, netloc, path, query, fragment = _urlsplit(url)

    if not path or path == '/':
        path = []
    else:
        path = path.strip('/').split('/')

    if not query:
        query = {}
    else:
        query = _parse_qs(query)

    return _urllib_parse.SplitResult(scheme, netloc, path, query, fragment)
139838
def parseUrl(url):
    
    scheme, netloc, url, params, query, fragment = urllib.parse.urlparse(url)
    query_dict = {
        k: sorted(v) if len(v) > 1 else v[0]
        for k, v in list(urllib.parse.parse_qs(query).items())
    }
    return {
        'scheme': scheme,
        'netloc': netloc,
        'url': url,
        'params': params,
        'query': query_dict,
        'fragment': fragment,
    }
624643
def _parse_parameters(self, resource, params):
        '''
        '''
        # remove params from resource URI (needed for paginated stuff)
        parsed_uri = urlparse(resource)
        qs = parsed_uri.query
        resource = urlunparse(parsed_uri._replace(query=''))
        prms = {}
        for tup in parse_qsl(qs):
            prms[tup[0]] = tup[1]

        # params supplied to self.get() override parsed params
        for key in params:
            prms[key] = params[key]
        return resource, prms
569043
function replaceUrlParameters (url, urlParameters) {
  var replacedUrl = url;
  for (var urlParameter in urlParameters) {
    var regex = (urlParameter === '*'
      ? new RegExp('\\*') // The first occurrence of the literal character '*'.
      : new RegExp(':' + urlParameter, 'g')); // All occurrences of `:param`.
    var urlValue = urlParameters[urlParameter];
    replacedUrl = replacedUrl.replace(regex, urlValue);
  }
  return replacedUrl;
}
856635
def normalize_url(url):
    """"""
    if url.endswith('.json'):
        url = url[:-5]
    if url.endswith('/'):
        url = url[:-1]
    return url
403372
function paramsParser(url, rule) {
    var matches = rule.regexp.exec(url).slice(1);
    var keys = rule.keys;
    var params = {};

    for (var i = 0; i < keys.length; i++) {
      params[keys[i]] = matches[i];
    }

    return params;
  }
1105015
function appendQueryParameters(url, parameters){
    
    var hash = "", indexOf = url.indexOf("#");
    if (indexOf !== -1) {
        hash = url.substring(indexOf);
        url = url.substring(0, indexOf);
    }
    var q = [];
    for (var key in parameters) {
        if (parameters.hasOwnProperty(key)) {
            q.push(key + "=" + encodeURIComponent(parameters[key]));
        }
    }
    return url + (useHash ? "#" : (url.indexOf("?") == -1 ? "?" : "&")) + q.join("&") + hash;
}
1340225
function customNormalizeUrl (url) {
  const [urlWithoutFragment, fragment] = url.split('#')
  return [normalizeUrl(urlWithoutFragment) + '/', fragment].filter(Boolean).join('#')
}
469829
def convert_parameters(self, request, *args, **kwargs):
        '''
        
        '''
        args = list(args)
        urlparam_i = 0

        parameters = self.view_parameters.get(request.method.lower()) or self.view_parameters.get(None)
        if parameters is not None:
            # add urlparams into the arguments and convert the values
            for parameter_i, parameter in enumerate(parameters):
                # skip request object, *args, **kwargs
                if parameter_i == 0 or parameter.kind is inspect.Parameter.VAR_POSITIONAL or parameter.kind is inspect.Parameter.VAR_KEYWORD:
                    pass
                # value in kwargs?
                elif parameter.name in kwargs:
                    kwargs[parameter.name] = self.convert_value(kwargs[parameter.name], parameter, request)
                # value in args?
                elif parameter_i - 1 < len(args):
                    args[parameter_i - 1] = self.convert_value(args[parameter_i - 1], parameter, request)
                # urlparam value?
                elif urlparam_i < len(request.dmp.urlparams):
                    kwargs[parameter.name] = self.convert_value(request.dmp.urlparams[urlparam_i], parameter, request)
                    urlparam_i += 1
                # can we assign a default value?
                elif parameter.default is not inspect.Parameter.empty:
                    kwargs[parameter.name] = self.convert_value(parameter.default, parameter, request)
                # fallback is None
                else:
                    kwargs[parameter.name] = self.convert_value(None, parameter, request)

        return args, kwargs
446452
def unwrap(url):
    """"""
    url = str(url).strip()
    if url[:1] == '<' and url[-1:] == '>':
        url = url[1:-1].strip()
    if url[:4] == 'URL:': url = url[4:].strip()
    return url
260370
def _transform_list_args(self, args):
        # type: (dict) -> None
        

        if '_limit' in args:
            args['limit'] = int(args['_limit'])
            del args['_limit']

        if '_page' in args:
            page = int(args['_page'])
            if page < 0:
                page = 1

            args['page'] = page
            del args['_page']

            if 'limit' not in args:
                args['limit'] = 10

        if '_end' in args:
            end = int(args['_end'])
            args['limit'] = end - int(args.get('_start', 0))

        if '_start' in args:
            args['offset'] = args['_start']
            del args['_start']

        if '_sort' in args:
            args['order_by'] = args['_sort'].replace('__', '.')
            del args['_sort']

            if args.get('_order', 'ASC') == 'DESC':
                args['order_by'] = '-' + args['order_by']

        if '_order' in args:
            del args['_order']

        filter_by = self._create_filter_by()
        if filter_by:
            args['filter_by'] = filter_by
760178
function splitURL(url) {
    var method, path, match = /^([A-Z]+)(?:\s+|$)/.exec(url);
    if (match) {
        method = match[1];
        path = /^[A-Z]+\s+(.*)$/.exec(url);
        url = path ? path[1]: '';
    }
    return {url: url, method: method};
}
843628
def clean_url(url, base_url=None):
    """"""
    parsed_url = urlparse(url)

    fragment = '{url.fragment}'.format(url=parsed_url)
    if fragment:
        url = url.split(fragment)[0]

    # Identify internal URLs and fix their format
    netloc = '{url.netloc}'.format(url=parsed_url)
    if base_url is not None and not netloc:
        parsed_base = urlparse(base_url)
        split_base = '{url.scheme}://{url.netloc}{url.path}/'.format(url=parsed_base)
        url = urljoin(split_base, url)
        netloc = '{url.netloc}'.format(url=urlparse(url))

    if 'www.' in netloc:
        url = url.replace(netloc, netloc.replace('www.', ''))
    return url.rstrip(string.punctuation)
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
71670
function getUrlParameter(sPageURL) {
    var url = sPageURL.split('?');
    var obj = {};
    if (url.length == 2) {
      var sURLVariables = url[1].split('&'),
          sParameterName,
          i;
      for (i = 0; i < sURLVariables.length; i++) {
          sParameterName = sURLVariables[i].split('=');
          obj[sParameterName[0]] = sParameterName[1];
      }
      return obj;
    } else {
      return undefined;
    }
}
911951
function parseUrlSearch(search) {
  if (search[0] === '?') search = search.slice(1);

  function splitParam(param) {
    var [key, value = ''] = param.split('=');
    return [key, decodeURIComponent(value)];
  }

  return objectFromPairs(search . split('&') . map(splitParam));
}