Parses a database URL.
966050
def parse(url):
    """"""

    config = {}

    url = urlparse.urlparse(url)

    # Remove query strings.
    path = url.path[1:]
    path = path.split('?', 2)[0]

    # Update with environment configuration.
    config.update({
        "DB": int(path or 0),
        "PASSWORD": url.password or None,
        "HOST": url.hostname or "localhost",
        "PORT": int(url.port or 6379),
    })

    return config
504479
def parse_url(url):
    
    try:
        url = unicode(url)
    except UnicodeDecodeError:
        pass

    if py3k:
        make_utf8 = lambda x: x
    else:
        make_utf8 = lambda x: isinstance(x, unicode) and x.encode('utf-8') or x

    if '://' in url:
        scheme, url = url.split('://', 1)
    else:
        scheme = 'http'
    url = 'http://' + url
    parsed = urlparse.urlsplit(url)
    r = ObjectDict()
    r['scheme'] = make_utf8(scheme)
    r['netloc'] = make_utf8(parsed.netloc)
    r['path'] = make_utf8(parsed.path)
    r['query'] = make_utf8(parsed.query)
    r['fragment'] = make_utf8(parsed.fragment)
    r['uri'] = make_utf8(parsed.path)
    if parsed.query:
        r['uri'] += '?' + make_utf8(parsed.query)
    r['username'] = make_utf8(parsed.username)
    r['password'] = make_utf8(parsed.password)
    host = make_utf8(parsed.hostname.encode('idna').decode('utf-8'))
    r['host'] = r['hostname'] = host
    try:
        r['port'] = parsed.port
    except ValueError:
        r['port'] = None
    if r['port']:
        r['http_host'] = '%s:%d' % (r['host'], r['port'])
    else:
        r['http_host'] = r['host']

    return r
221674
public static String extractDatabaseName(String url) {
        int leftIndex = url.lastIndexOf("/");
        if (leftIndex == -1) {
            leftIndex = url.lastIndexOf(":");
        }
        leftIndex++;

        int rightIndex = url.length();
        if (url.contains("?")) {
            rightIndex = url.indexOf("?");
        } else if (url.contains(";")) {
            rightIndex = url.indexOf(";");
        }
        return url.substring(leftIndex, rightIndex);
    }
1118133
def parse_url(url):
        
        parsed = url

        if not url.startswith("http://") and not url.startswith(
                "https://"):  # if url is like www.yahoo.com
            parsed = "http://" + parsed
        elif url.startswith("https://"):
            parsed = parsed[8:]
            parsed = "http://" + parsed

        index_hash = parsed.rfind("#")  # remove trailing #
        index_slash = parsed.rfind("/")
        if index_hash > index_slash:
            parsed = parsed[0: index_hash]

        return parsed
385780
function parseURL(s) {
  var url = null;
  try {
    url = new URL(s);
  } catch (error) {
    console.error(error);
  }
  return url;
}
1101025
def parse(url_str):
    
    url_str = to_unicode(url_str)
    result = urlparse(url_str)
    netloc_parts = result.netloc.rsplit('@', 1)
    if len(netloc_parts) == 1:
        username = password = None
        host = netloc_parts[0]
    else:
        user_and_pass = netloc_parts[0].split(':')
        if len(user_and_pass) == 2:
            username, password = user_and_pass
        elif len(user_and_pass) == 1:
            username = user_and_pass[0]
            password = None
        host = netloc_parts[1]

    if host and ':' in host:
        host = host.split(':')[0]

    return {'host': host,
            'username': username,
            'password': password,
            'scheme': result.scheme,
            'port': result.port,
            'path': result.path,
            'query': result.query,
            'fragment': result.fragment}
1325384
def from_url(cls, url):
        
        parsed = urlparse(url)
        return cls(
            username=parsed.username,
            password=parsed.password,
            hostname=parsed.hostname,
            port=parsed.port,
            database=parsed.path.lstrip('/'),
            # Like parse_qs, but produces a scalar per key, instead of a list:
            query_params=dict(param.split('=')
                              for param in parsed.query.split('&'))
            if parsed.query else {},
        )
532038
def parse_search_url(url):
    """"""

    config = {}

    url = urlparse.urlparse(url)

    # Remove query strings.
    path = url.path[1:]
    path = path.split('?', 2)[0]

    if url.scheme in SEARCH_SCHEMES:
        config["ENGINE"] = SEARCH_SCHEMES[url.scheme]

    if url.scheme in USES_URL:
        config["URL"] = urlparse.urlunparse(("http",) + url[1:])

    if url.scheme in USES_INDEX:
        if path.endswith("/"):
            path = path[:-1]

        split = path.rsplit("/", 1)

        if len(split) > 1:
            path = split[:-1]
            index = split[-1]
        else:
            path = ""
            index = split[0]

        config.update({
            "URL": urlparse.urlunparse(("http",) + url[1:2] + (path,) + url[3:]),
            "INDEX_NAME": index,
        })

    if url.scheme in USES_PATH:
        config.update({
            "PATH": path,
        })

    return config
1179396
def parse(url):
    
    parts = split(url)
    if parts.scheme:
        username, password, host, port = split_netloc(parts.netloc)
        subdomain, domain, tld = split_host(host)
    else:
        username = password = subdomain = domain = tld = port = ''
    return URL(parts.scheme, username, password, subdomain, domain, tld,
               port, parts.path, parts.query, parts.fragment, url)
103688
def _parse_uri(cls, server, sanitize_username=False):
        
        parsed = pymongo.uri_parser.parse_uri(server)

        username = parsed.get('username')
        password = parsed.get('password')
        db_name = parsed.get('database')
        nodelist = parsed.get('nodelist')
        auth_source = parsed.get('options', {}).get('authsource')

        # Remove password (and optionally username) from sanitized server URI.
        # To ensure that the `replace` works well, we first need to url-decode the raw server string
        # since the password parsed by pymongo is url-decoded
        decoded_server = unquote_plus(server)
        clean_server_name = decoded_server.replace(password, "*" * 5) if password else decoded_server

        if sanitize_username and username:
            username_pattern = u"{}[@:]".format(re.escape(username))
            clean_server_name = re.sub(username_pattern, "", clean_server_name)

        return username, password, db_name, nodelist, clean_server_name, auth_source
1072081
def parse_pgurl(self, url):
        
        parsed = urlsplit(url)

        return {
            'user': parsed.username,
            'password': parsed.password,
            'database': parsed.path.lstrip('/'),
            'host': parsed.hostname,
            'port': parsed.port or 5432,
        }
809790
def parse_url(url):
    
    if url.startswith(('http', 'https', '//')):
        if url.startswith('//'):
            return urlparse.urlparse(url, scheme='http')
        else:
            return urlparse.urlparse(url)
    else:
        return urlparse.urlparse(urlparse.urljoin('http://', url))
241765
def safeDbUrl(db_url):
    """"""
    url = urlparse(db_url)
    return db_url.replace(url.password, "****") if url.password else db_url
969449
public static HttpUrl parse(String url) {
        Builder builder = new Builder();
        Builder.ParseResult result = builder.parse(null, url);
        return result == Builder.ParseResult.SUCCESS ? builder.build() : null;
    }
525169
def _get_url(url):
        
        if isinstance(url, urlparse.ParseResult):
            return urlparse.urlunparse(url)
        else:
            return url
390474
function parse(uri) {
  var result = { baseUri: '', fragment: '#' };

  if (uri.slice(0, 4).toLowerCase() === 'urn:') {
    result.kind = 'urn';
    var parts = uri.match(URN_REGEX);
    if (parts) {
        result.baseUri = parts[1] + (parts[2] || '');
      result.host = parts[1];
      if (parts[2]) { result.pathname = parts[2]; }
      if (parts[3]) { result.fragment = parts[3]; }
    }
  } else {
    result.kind = 'url';
    var parsed = url.parse(uri);
    if (parsed.hash) {
      result.fragment = parsed.hash;
      delete parsed.hash;
    }
    result.absolute =
      (parsed.host && parsed.pathname && parsed.pathname[0] === '/') ?
      true : false;
    result.baseUri = url.format(parsed);
  }

  return result;
}
752285
def _split_url_string(param_str):
        """"""
        if not PY3:
            # If passed unicode with quoted UTF8, Python2's parse_qs leaves
            # mojibake'd uniocde after unquoting, so encode first.
            param_str = b(param_str, 'utf-8')
        parameters = parse_qs(param_str, keep_blank_values=True)
        for k, v in parameters.items():
            if len(v) == 1:
                parameters[k] = unquote(v[0])
            else:
                parameters[k] = sorted([unquote(s) for s in v])
        return parameters