Encode a URL path element according to RFC3986.
12204
def encodePathElement(element):
    """"""
    return urllib.parse.quote(
        (
            element.encode('utf-8')
            if isinstance(element, str)
            else str(element)
            if isinstance(element, int)
            else element
        ),
        safe=d1_common.const.URL_PATHELEMENT_SAFE_CHARS,
    )
404923
private String urlEncode(String str) {
        try {
            return URLEncoder.encode(str, LettuceCharsets.UTF8.name()).replaceAll("%2F", "/");
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException(e);
        }
    }
843928
public static String decodeUrlPath(String href, String encoding) throws UnsupportedEncodingException {
		if(href.startsWith("tel:")) return href;
		int len = href.length();
		int pos = 0;
		StringBuilder SB = new StringBuilder(href.length()*2); // Leave a little room for encoding
		while(pos<len) {
			int nextPos = StringUtility.indexOf(href, noEncodeCharacters, pos);
			if(nextPos==-1) {
				SB.append(URLDecoder.decode(href.substring(pos, len), encoding));
				pos = len;
			} else {
				SB.append(URLDecoder.decode(href.substring(pos, nextPos), encoding));
				char nextChar = href.charAt(nextPos);
				if(nextChar=='?') {
					// End decoding
					SB.append(href, nextPos, len);
					pos = len;
				} else {
					SB.append(nextChar);
					pos = nextPos+1;
				}
			}
		}
		return SB.toString();
	}
1192959
function encodeRFC5987 (str) {
  return encodeURIComponent(str)
    // Note that although RFC3986 reserves "!", RFC5987 does not,
    // so we do not need to escape it
    .replace(/['()]/g, escape) // i.e., %27 %28 %29
    .replace(/\*/g, '%2A')
    // The following are not required for percent-encoding per RFC5987,
    // so we can allow for a little better readability over the wire: |`^
    .replace(/%(?:7C|60|5E)/g, unescape)
}
559937
def _encoded_routing_key(self):
        """"""
        topic = self.topic
        if config.conf["topic_prefix"]:
            topic = ".".join((config.conf["topic_prefix"].rstrip("."), topic))
        return topic.encode("utf-8")
1370052
private static function encodeAttachment($boundary, FsPath $path, $fileName, $charset, $encoding, $eol = "\n") {
		$file = new FsPath($fileName);
		$string = "--{$boundary}{$eol}"
			. "Content-Type: " . self::getMimeType($file->getExtension()) . "; name=\"" . mb_encode_mimeheader($file->getName(), $charset, 'Q', $eol) . "\"" . $eol
			. "Content-Disposition: attachment; filename=\"" . mb_encode_mimeheader($file->getName(), $charset, 'Q', $eol) . "\"" . $eol
			. "Content-Transfer-Encoding: " . self::ENCODING_BASE64 . $eol . $eol;
		$string .= self::encodeString(IoUtils::getContents($path), 'base64', $eol);
		return $string;
	}
498563
def encodeQueryElement(element):
    """"""
    return urllib.parse.quote(
        (
            element.encode('utf-8')
            if isinstance(element, str)
            else str(element)
            if isinstance(element, int)
            else element
        ),
        safe=d1_common.const.URL_QUERYELEMENT_SAFE_CHARS,
    )
1108919
public static String encodeURIPathComponent(String s) {
    StringBuilder result = new StringBuilder();
    for (int i = 0; i < s.length(); i++) {
      result.append(Char.encodeURIPathComponent(s.charAt(i)));
    }
    return (result.toString());
  }
894311
public static String pathEncode(String path, Charset charset) {
    return encodeReserved(path, FragmentType.PATH_SEGMENT, charset);

    /*
     * path encoding is not equivalent to query encoding, there are few differences, namely dealing
     * with spaces, !, ', (, ), and ~ characters. we will need to manually process those values.
     */
    // return encoded.replaceAll("\\+", "%20");
  }
641769
def with_path(self, path, *, encoded=False):
        """"""
        if not encoded:
            path = self._PATH_QUOTER(path)
            if self.is_absolute():
                path = self._normalize_path(path)
        if len(path) > 0 and path[0] != "/":
            path = "/" + path
        return URL(self._val._replace(path=path, query="", fragment=""), encoded=True)
580710
def valid_path(value):
    ""
    # Generate UnicodeDecodeError if path can't store as ASCII.
    value.encode("ascii")
    # Cookies without leading slash will likely be ignored, raise ASAP.
    if not (value and value[0] == "/"):
        return False
    if not Definitions.PATH_RE.match(value):
        return False
    return True
773039
function encode(uri) {
    
    var prefix,
        protocolCode,
        encoded;

    // check each protocol, unless we've found a match
    // "urn:" is the one exception where we need to keep checking
    // slice so we don't check ""
    protocols.slice(1).forEach(function(protocol) {                        
        if ((!prefix || prefix === "urn:") && uri.indexOf(protocol) === 0) { 
            prefix = protocol;
        }
    });

    if (!prefix) {
        prefix = "";
    }
    
    encoded = util.stringToBytes(uri.slice(prefix.length));
    protocolCode = protocols.indexOf(prefix);    
    // prepend protocol code
    encoded.unshift(protocolCode);
    
    return encoded; 
}
508137
function uriEncodeString( text ){
    return encodeURIComponent(text).replace( /[\!\*\'\(\)]/g, function( chr ){
        chr = chr.charCodeAt(0).toString(16);
        while( chr.length < 2 ){
            chr = '0'+hex;
        }
        return '%'+chr;
    } )
}
1045351
private static String encodePath(final String path) {
        // Accept ':' if it is part of a scheme prefix
        int validColonPrefixLen = 0;
        for (final String scheme : SCHEME_PREFIXES) {
            if (path.startsWith(scheme)) {
                validColonPrefixLen = scheme.length();
                break;
            }
        }
        final byte[] pathBytes = path.getBytes(StandardCharsets.UTF_8);
        final StringBuilder encodedPath = new StringBuilder(pathBytes.length * 3);
        for (int i = 0; i < pathBytes.length; i++) {
            final byte pathByte = pathBytes[i];
            final int b = pathByte & 0xff;
            if (safe[b] || (b == ':' && i < validColonPrefixLen)) {
                encodedPath.append((char) b);
            } else {
                encodedPath.append('%');
                encodedPath.append(HEXADECIMAL[(b & 0xf0) >> 4]);
                encodedPath.append(HEXADECIMAL[b & 0x0f]);
            }
        }
        return encodedPath.toString();
    }
1360419
public static String encodePath(String path) {
        if (path != null) {
            path = encodeUrl(path);
            path = path.replaceAll("/jcr:", "/_jcr_");
            path = path.replaceAll("\\?", "%3F");
            path = path.replaceAll("=", "%3D");
            path = path.replaceAll(";", "%3B");
            path = path.replaceAll(":", "%3A");
            path = path.replaceAll("\\+", "%2B");
            path = path.replaceAll("&", "%26");
            path = path.replaceAll("#", "%23");
        }
        return path;
    }
460896
def url_encode(url):
    
    if isinstance(url, text_type):
        url = url.encode('utf8')
    return quote(url, ':/%?&=')
939837
def request_path(request):
    """"""
    url = request.get_full_url()
    parts = urlsplit(url)
    path = escape_path(parts.path)
    if not path.startswith("/"):
        # fix bad RFC 2396 absoluteURI
        path = "/" + path
    return path