Normalize a URI (And return a URIResult)
328060
def normalize_uri_result(uri):
    
    ref = uri_reference(uri).normalize()

    return ref._replace(
        authority=normalize_uri_authority(ref),
        query=normalize_uri_query(ref),
        path=normalize_uri_path(ref),
    )
1211163
def normalize_url(href) #:nodoc:
      uri = URI.parse(href)
      normalized_url = []
      normalized_url << "#{uri.scheme}://" if uri.scheme
      normalized_url << uri.host if uri.host
      normalized_url << ":#{uri.port}" if uri.port && ![80,443].include?(uri.port)
      normalized_url << uri.path if uri.path
      normalized_url << "?#{uri.query}" if uri.query
      normalized_url.join
    end
1040910
public function standardizeUri(string $uri): string {
        if ($uri == '') {
            throw new BadMethodCallException('URI is empty');
        }
        if (substr($uri, 0, 1) === '/') {
            $uri = substr($uri, 1);
        }
        $uri = preg_replace('|^https?://[^/]+/rest/(tx:[-0-9a-zA-Z]+/)?|', '', $uri);
        $uri = $this->apiUrl . '/' . $uri;
        return $uri;
    }
470418
def normalized(url)
      Addressable::URI.parse(url).normalize.to_s
    rescue Addressable::URI::InvalidURIError => e
      raise MetaInspector::ParserError.new(e)
    end
901070
def normalize(url):
    
    url = url.strip()
    if url == '':
        return ''
    parts = split(url)
    if parts.scheme:
        netloc = parts.netloc
        if parts.scheme in SCHEMES:
            path = normalize_path(parts.path)
        else:
            path = parts.path
    # url is relative, netloc (if present) is part of path
    else:
        netloc = parts.path
        path = ''
        if '/' in netloc:
            netloc, path_raw = netloc.split('/', 1)
            path = normalize_path('/' + path_raw)
    username, password, host, port = split_netloc(netloc)
    host = normalize_host(host)
    port = _normalize_port(parts.scheme, port)
    query = normalize_query(parts.query)
    fragment = normalize_fragment(parts.fragment)
    return construct(URL(parts.scheme, username, password, None, host, None,
                         port, path, query, fragment, None))
421245
def get_root_uri(uri):
    """"""
    chunks = urlsplit(uri)
    return urlunsplit((chunks.scheme, chunks.netloc, chunks.path, '', ''))
69005
def clean_iri(uri_string):
    ''''''
    uri_string = str(uri_string).strip()
    if uri_string[:1] == "<" and uri_string[len(uri_string)-1:] == ">":
        uri_string = uri_string[1:len(uri_string)-1]
    return uri_string
242733
public static function NormalizeUrlRewrite()
	{
		$uri = array();
		if (isset($_SERVER["REQUEST_URI"]))
		{
			$uri = parse_url($_SERVER["REQUEST_URI"]);
		}
		elseif (isset($_SERVER["QUERY_STRING"]))
		{
			$uri['query'] = $_SERVER["QUERY_STRING"];
		}

		if (isset($uri['query']))
		{
			$parts = explode("&",$uri['query']);
			foreach ($parts as $part)
			{
				$keyval = explode("=",$part,2);
				$_REQUEST[$keyval[0]] = isset($keyval[1]) ? urldecode($keyval[1]) : "";
			}
		}
	}
883754
private static function normalize($uri)
    {
        $uri = self::filterUri($uri);
        $null = $uri instanceof Psr7UriInterface ? '' : null;

        $path = $uri->getPath();
        if ('/' === ($path[0] ?? '') || '' !== $uri->getScheme().$uri->getAuthority()) {
            $path = UriResolver::resolve($uri, $uri->withPath('')->withQuery($null))->getPath();
        }

        $query = $uri->getQuery();
        $fragment = $uri->getFragment();
        $fragmentOrig = $fragment;
        $pairs = null === $query ? [] : explode('&', $query);
        sort($pairs, SORT_REGULAR);

        $replace = static function (array $matches): string {
            return rawurldecode($matches[0]);
        };

        $retval = preg_replace_callback(self::REGEXP_ENCODED_CHARS, $replace, [$path, implode('&', $pairs), $fragment]);
        if (null !== $retval) {
            [$path, $query, $fragment] = $retval + ['', $null, $null];
        }

        if ($null !== $uri->getAuthority() && '' === $path) {
            $path = '/';
        }

        return $uri
            ->withHost(Uri::createFromComponents(['host' => $uri->getHost()])->getHost())
            ->withPath($path)
            ->withQuery([] === $pairs ? $null : $query)
            ->withFragment($null === $fragmentOrig ? $fragmentOrig : $fragment);
    }
1366878
def parse(cls, uri):
        """"""
        match = _URI_FORMAT.search(uri)
        return cls(match.group(1), match.group(2), match.group(3), match.group(4))
524785
def uriunsplit(uri):
    
    (scheme, authority, path, query, fragment) = uri
    result = ''
    if scheme:
        result += scheme + ':'
    if authority:
        result += '//' + authority
    if path:
        result += path
    if query:
        result += '?' + query
    if fragment:
        result += '#' + fragment
    return result
386627
def iri2uri(uri):
	""""""

	assert uri != None, 'iri2uri must be passed a non-none string!'

	original = uri
	if isinstance(uri ,str):
		(scheme, authority, path, query, fragment) = urllib.parse.urlsplit(uri)
		authority = authority.encode('idna').decode('utf-8')
		# For each character in 'ucschar' or 'iprivate'
		#  1. encode as utf-8
		#  2. then %-encode each octet of that utf-8
		# path = urllib.parse.quote(path)
		uri = urllib.parse.urlunsplit((scheme, authority, path, query, fragment))
		uri = "".join([encode(c) for c in uri])

	# urllib.parse.urlunsplit(urllib.parse.urlsplit({something})
	# strips any trailing "?" chars. While this may be legal according to the
	# spec, it breaks some services. Therefore, we patch
	# the "?" back in if it has been removed.
	if original.endswith("?") and not uri.endswith("?"):
		uri = uri+"?"
	return uri
708210
def urlparse(uri):
    """"""
    scheme, netloc, path, params, query, fragment = parse.urlparse(uri)
    return (
        parse.unquote(scheme),
        parse.unquote(netloc),
        parse.unquote(path),
        parse.unquote(params),
        parse.unquote(query),
        parse.unquote(fragment)
    )
856635
def normalize_url(url):
    """"""
    if url.endswith('.json'):
        url = url[:-5]
    if url.endswith('/'):
        url = url[:-1]
    return url
169244
def normalize_uriparm(p: URIPARM) -> List[URIRef]:
    
    return normalize_urilist(p) if isinstance(p, List) else \
        normalize_urilist([p]) if isinstance(p, (str, URIRef)) else p
710417
@Override
	public UriComponents normalize() {
		String normalizedPath = StringUtils.cleanPath(getPath());
		return new HierarchicalUriComponents(getScheme(), this.userInfo, this.host,
				this.port, new FullPathComponent(normalizedPath), this.queryParams,
				getFragment(), this.encoded, false);
	}
928044
def resolveURI(self, URI):
        
        ret = libxml2mod.xmlACatalogResolveURI(self._o, URI)
        return ret