Parse the URL in a Python2/3 independent fashion.

    :param str url: The URL to parse
    :rtype: Parsed
963323
def urlparse(url):
    
    value = 'http%s' % url[5:] if url[:5] == 'postgresql' else url
    parsed = _urlparse.urlparse(value)
    path, query = parsed.path, parsed.query
    hostname = parsed.hostname if parsed.hostname else ''
    return PARSED(parsed.scheme.replace('http', 'postgresql'),
                  parsed.netloc,
                  path,
                  parsed.params,
                  query,
                  parsed.fragment,
                  parsed.username,
                  parsed.password,
                  hostname.replace('%2f', '/'),
                  parsed.port)
361138
def parseURIRaw(str, raw):
    
    ret = libxml2mod.xmlParseURIRaw(str, raw)
    if ret is None:raise uriError('xmlParseURIRaw() failed')
    return URI(_obj=ret)
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
408480
def extract(url):
    
    parts = split(url)
    if parts.scheme:
        netloc = parts.netloc
        path = parts.path
    else:
        netloc = parts.path
        path = ''
        if '/' in netloc:
            netloc, path_raw = netloc.split('/', 1)
            path = '/' + path_raw
    username, password, host, port = split_netloc(netloc)
    subdomain, domain, tld = split_host(host)
    return URL(parts.scheme, username, password, subdomain, domain, tld,
               port, path, parts.query, parts.fragment, url)
904431
def urlread(url, encoding='utf8'):
    
    try:
        from urllib.request import urlopen
    except ImportError:
        from urllib2 import urlopen
    response = urlopen(url)
    content = response.read()
    content = content.decode(encoding)
    return content
305521
def parse_url(url):
    
    split_url = url.split('/', 3)
    if len(split_url) == 3:
        # http://foo.com
        path = '/'
    elif len(split_url) == 4:
        path = '/' + split_url[3]
    else:
        raise ValueError('Invalid URL: %s' % url)

    try:
        parse_result = urlparse(url)
    except Exception:
        raise ValueError('Invalid URL: %s' % url)

    protocol = parse_result.scheme
    protocol = protocol.lower()
    if protocol not in ('http', 'https'):
        raise ValueError('Invalid URL protocol "%s"' % protocol)

    split_netloc = parse_result.netloc.split(':')
    domain = split_netloc[0]
    domain = domain.lower()

    if len(split_netloc) == 2:
        try:
            port = int(split_netloc[1])
        except:
            raise ValueError('Invalid port: "%s"' % split_netloc[1])
    elif protocol == 'https':
        port = 443
    elif protocol == 'http':
        port = 80
    else:
        raise ValueError('Invalid scheme: "%s"' % protocol)

    return protocol, domain, port, path
875989
def url_normolize(url: str):
    
    u = parse.urljoin('///{}/'.format(url), '.')
    u = re.sub(r'/+', '/', u)
    return u if url.endswith('/') else u[:-1]
1051111
def parse_url_or_log(url, encoding='utf-8'):
    '''
    '''
    try:
        url_info = URLInfo.parse(url, encoding=encoding)
    except ValueError as error:
        _logger.warning(__(
            _('Unable to parse URL ‘{url}’: {error}.'),
            url=wpull.string.printable_str(url), error=error))
    else:
        return url_info
1287256
def _parse_request(self, url=None, handle=None):
        '''
        '''
        # To accomdate self.redirect, we need to be able to parse a full url as
        # well
        if url is None:
            url = sys.argv[0]
            if len(sys.argv) == 3:
                url += sys.argv[2]
        if handle is None:
            handle = sys.argv[1]
        return Request(url, handle)
754933
def _parse_url_and_validate(cls, url):
        
        parsed_url = urlparse(url)
        if parsed_url.scheme and parsed_url.netloc:
            final_url = parsed_url.geturl()
        else:
            raise BadURLException
        return final_url
681994
def parse_url(url, warning=True):
    
    parsed = urllib_parse.urlparse(url)
    query = urllib_parse.parse_qs(parsed.query)
    is_gdrive = parsed.hostname == 'drive.google.com'
    is_download_link = parsed.path.endswith('/uc')

    file_id = None
    if is_gdrive and 'id' in query:
        file_ids = query['id']
        if len(file_ids) == 1:
            file_id = file_ids[0]
    match = re.match(r'^/file/d/(.*?)/view$', parsed.path)
    if match:
        file_id = match.groups()[0]

    if is_gdrive and not is_download_link:
        warnings.warn(
            'You specified Google Drive Link but it is not the correct link '
            "to download the file. Maybe you should try: {url}"
            .format(url='https://drive.google.com/uc?id={}'.format(file_id))
        )

    return file_id, is_download_link
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)
1151144
def url_parse(name):
    """"""
    position = name.find("github.com")
    if position >= 0:
        if position != 0:
            position_1 = name.find("www.github.com")
            position_2 = name.find("http://github.com")
            position_3 = name.find("https://github.com")
            if position_1*position_2*position_3 != 0:
                exception()
                sys.exit(0)
        name = name[position+11:]
        if name.endswith('/'):
            name = name[:-1]
        return name
    else:
        if name.endswith('/'):
            name = name[:-1]
        return name
787772
def parse_code(url):
    
    result = urlparse(url)
    query = parse_qs(result.query)
    return query['code']
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
353536
def parse_uri(uri_string):
    
    parts = urlparse.urlparse(uri_string)
    uri = Uri()
    if parts[0]:
      uri.scheme = parts[0]
    if parts[1]:
      host_parts = parts[1].split(':')
      if host_parts[0]:
        uri.host = host_parts[0]
      if len(host_parts) > 1:
        uri.port = int(host_parts[1])
    if parts[2]:
      uri.path = parts[2]
    if parts[4]:
      param_pairs = parts[4].split('&')
      for pair in param_pairs:
        pair_parts = pair.split('=')
        if len(pair_parts) > 1:
          uri.query[urllib.unquote_plus(pair_parts[0])] = (
              urllib.unquote_plus(pair_parts[1]))
        elif len(pair_parts) == 1:
          uri.query[urllib.unquote_plus(pair_parts[0])] = None
    return uri
301116
def url_join(url, path):
    
    p = six.moves.urllib.parse.urlparse(url)

    t = None
    if p.path and p.path[-1] == '/':
        if path and path[0] == '/':
            path = path[1:]
        t = ''.join([p.path, path])
    else:
        t = ('' if path and path[0] == '/' else '/').join([p.path, path])

    return six.moves.urllib.parse.urlunparse(
        p[:2]+
        (t,)+ # os.sep is different on windows, don't use it here.
        p[3:]
    )