Unparse and encode parts of a URI.
323999
def urlunparse(parts):
    """"""
    scheme, netloc, path, params, query, fragment = parts

    # Avoid encoding the windows drive letter colon
    if RE_DRIVE_LETTER_PATH.match(path):
        quoted_path = path[:3] + parse.quote(path[3:])
    else:
        quoted_path = parse.quote(path)

    return parse.urlunparse((
        parse.quote(scheme),
        parse.quote(netloc),
        quoted_path,
        parse.quote(params),
        parse.quote(query),
        parse.quote(fragment)
    ))
972808
private static List<String> splitAndEncodeParams(URL url) {
		if (url.getQuery() == null) {
			return new ArrayList<>();
		}
		String[] params = url.getQuery().split("&");
		List<String> result = new ArrayList<>(params.length);
		for (String p : params) {
			String[] kv = p.split("=");
			kv[0] = PercentEncoding.decode(kv[0]);
			kv[1] = PercentEncoding.decode(kv[1]);
			kv[0] = PercentEncoding.encode(kv[0]);
			kv[1] = PercentEncoding.encode(kv[1]);
			String np = kv[0] + "=" + kv[1];
			result.add(np);
		}
		return result;
	}
293415
function encodeUriSegment(s) {
    return encodeUriString(s).replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/%26/gi, '&');
}
1194934
def url_unparse(components):
    
    scheme, netloc, path, query, fragment = \
        normalize_string_tuple(components)
    s = make_literal_wrapper(scheme)
    url = s('')

    # We generally treat file:///x and file:/x the same which is also
    # what browsers seem to do.  This also allows us to ignore a schema
    # register for netloc utilization or having to differenciate between
    # empty and missing netloc.
    if netloc or (scheme and path.startswith(s('/'))):
        if path and path[:1] != s('/'):
            path = s('/') + path
        url = s('//') + (netloc or s('')) + path
    elif path:
        url += path
    if scheme:
        url = scheme + s(':') + url
    if query:
        url = url + s('?') + query
    if fragment:
        url = url + s('#') + fragment
    return url
1026248
def parse_url(url, encoding=None):
    
    return url if isinstance(url, urlparse.ParseResult) else \
        urlparse.urlparse(unicode_to_str(url, encoding))
851673
def urisplit(uristring):
    
    if isinstance(uristring, bytes):
        result = SplitResultBytes
    else:
        result = SplitResultUnicode
    return result(*result.RE.match(uristring).groups())
94982
def uriencode(uristring, safe='', encoding='utf-8', errors='strict'):
    """"""
    if not isinstance(uristring, bytes):
        uristring = uristring.encode(encoding, errors)
    if not isinstance(safe, bytes):
        safe = safe.encode('ascii')
    try:
        encoded = _encoded[safe]
    except KeyError:
        encoded = _encoded[b''][:]
        for i in _tointseq(safe):
            encoded[i] = _fromint(i)
        _encoded[safe] = encoded
    return b''.join(map(encoded.__getitem__, _tointseq(uristring)))
1213033
def encode_params(uri, params)
      params_str = String.new('?')
      params.each do |k, v|
        params_str << "#{k}=#{CGI.escape(v.to_s)}&" if v
      end
      params_str.chop!
      uri + params_str
    end
609053
def parse(cls, uri):
		
		uri_components = urlsplit(uri)
		adapter_fn = lambda x: x if x is not None and (isinstance(x, str) is False or len(x)) > 0 else None

		return cls(
			scheme=adapter_fn(uri_components.scheme),
			username=adapter_fn(uri_components.username),
			password=adapter_fn(uri_components.password),
			hostname=adapter_fn(uri_components.hostname),
			port=adapter_fn(uri_components.port),
			path=adapter_fn(uri_components.path),
			query=adapter_fn(uri_components.query),
			fragment=adapter_fn(uri_components.fragment),
		)
1271125
def filter_url(url, **kwargs):
    """"""

    d = parse_url_to_dict(url)

    d.update(kwargs)

    return unparse_url_dict({k: v for k, v in list(d.items()) if v})
609820
def escape_uri(str)
      str = str.dup
      binary_encode(str)
      str.gsub(UNESCAPED) { "%%%02X" % $1[0].ord }
    end
672489
def parseURI(str):
    
    ret = libxml2mod.xmlParseURI(str)
    if ret is None:raise uriError('xmlParseURI() failed')
    return URI(_obj=ret)
141323
def uri_from_fields(prefix, *fields):
        """"""
        string = '_'.join(AlignmentHelper.alpha_numeric(f.strip().lower(), '') for f in fields)

        if len(string) == len(fields) - 1:
            return ''

        return prefix + string
555573
public static String normalizeURI( String uri )
    {
        //
        // If it's a relative URI, normalize it.  Note that we don't want to create a URI
        // (very expensive) unless we think we'll need to.  "./" catches "../" and "./".
        //
        if ( uri.indexOf( "./" ) != -1 )
        {
            try
            {
                uri = new URI( uri ).normalize().toString();
            }
            catch ( URISyntaxException e )
            {
                logger.error( "Could not parse relative URI " + uri );
            }
        }
        
        return uri;
    }
1274586
def unescape(s):
    
    """
    if re.search(r'(?<!\\)\\(\\\\)*[uU]', s) or isinstance(s, unicode):
        return unescapeUnicode(s)
    else:
        return unescapeAscii(s)
64467
function full_uri_encode(string) {
  string = encodeURIComponent(string);
  string = string.replace(/\./g, '%2E');
  return(string);
}
154086
def _unparse_attr(self, attr_type, attr_value):
        """"""
        if self._needs_base64_encoding(attr_type, attr_value):
            if not isinstance(attr_value, bytes):
                attr_value = attr_value.encode(self._encoding)
            encoded = base64.encodestring(attr_value)\
                .replace(b'\n', b'')\
                .decode('ascii')
            line = ':: '.join([attr_type, encoded])
        else:
            line = ': '.join([attr_type, attr_value])
        self._fold_line(line.encode('ascii'))