Transform an IRI to a URI by escaping unicode.
777663
def iriToURI(iri):
    """"""
    # According to RFC 3987, section 3.1, "Mapping of IRIs to URIs"
    if isinstance(iri, bytes):
        iri = str(iri, encoding="utf-8")
    return iri.encode('ascii', errors='oid_percent_escape').decode()
1087187
def iri_to_uri(value, normalize=False):
    

    if not isinstance(value, str_cls):
        raise TypeError(unwrap(
            '''
            value must be a unicode string, not %s
            ''',
            type_name(value)
        ))

    scheme = None
    # Python 2.6 doesn't split properly is the URL doesn't start with http:// or https://
    if sys.version_info < (2, 7) and not value.startswith('http://') and not value.startswith('https://'):
        real_prefix = None
        prefix_match = re.match('^[^:]*://', value)
        if prefix_match:
            real_prefix = prefix_match.group(0)
            value = 'http://' + value[len(real_prefix):]
        parsed = urlsplit(value)
        if real_prefix:
            value = real_prefix + value[7:]
            scheme = _urlquote(real_prefix[:-3])
    else:
        parsed = urlsplit(value)

    if scheme is None:
        scheme = _urlquote(parsed.scheme)
    hostname = parsed.hostname
    if hostname is not None:
        hostname = hostname.encode('idna')
    # RFC 3986 allows userinfo to contain sub-delims
    username = _urlquote(parsed.username, safe='!$&\'()*+,;=')
    password = _urlquote(parsed.password, safe='!$&\'()*+,;=')
    port = parsed.port
    if port is not None:
        port = str_cls(port).encode('ascii')

    netloc = b''
    if username is not None:
        netloc += username
        if password:
            netloc += b':' + password
        netloc += b'@'
    if hostname is not None:
        netloc += hostname
    if port is not None:
        default_http = scheme == b'http' and port == b'80'
        default_https = scheme == b'https' and port == b'443'
        if not normalize or (not default_http and not default_https):
            netloc += b':' + port

    # RFC 3986 allows a path to contain sub-delims, plus "@" and ":"
    path = _urlquote(parsed.path, safe='/!$&\'()*+,;=@:')
    # RFC 3986 allows the query to contain sub-delims, plus "@", ":" , "/" and "?"
    query = _urlquote(parsed.query, safe='/?!$&\'()*+,;=@:')
    # RFC 3986 allows the fragment to contain sub-delims, plus "@", ":" , "/" and "?"
    fragment = _urlquote(parsed.fragment, safe='/?!$&\'()*+,;=@:')

    if normalize and query is None and fragment is None and path == b'/':
        path = None

    # Python 2.7 compat
    if path is None:
        path = ''

    output = urlunsplit((scheme, netloc, path, query, fragment))
    if isinstance(output, str_cls):
        output = output.encode('latin1')
    return output
65745
def _native_to_unicode(s):
  """"""
  if six.PY2:
    return s if isinstance(s, unicode) else s.decode("utf-8")
  else:
    return s
1157945
def normalize_uri(cls, uri):
		
		uri = WWebRoute.multiple_slashes_re.sub("/", uri)

		# remove last slash
		if len(uri) > 1:
			if uri[-1] == '/':
				uri = uri[:-1]

		return uri
273667
def doi_uri_to_doi(value):
    ""
    if value is None:
        return value
    replace_values = ['http://dx.doi.org/', 'https://dx.doi.org/',
                      'http://doi.org/', 'https://doi.org/']
    for replace_value in replace_values:
        value = value.replace(replace_value, '')
    return value
352393
function baseStringUri(uri) {
    var parsed = url.parse(uri);

    //  The port MUST be included if it is not the default port for the
    //  scheme, and MUST be excluded if it is the default.
    if (parsed.protocol === 'https:/') {
        parsed.host = parsed.host.replace(/:443$/, '');
    } else if (parsed.protocol === 'http:/') {
        parsed.host = parsed.host.replace(/:80$/, '');
    }

    return url.format({
        protocol: parsed.protocol,
        host: parsed.host,
        auth: parsed.auth,
        pathname: parsed.pathname
    });
}
423917
def extract_fragment(self, iri: str) -> str:
        ''' 
        '''
        fragment = str(iri).rsplit('/')[-1].split(':', 1)[-1].split('#', 1)[-1].split('_', 1)[-1]
        return fragment
1018558
def parse_uri(value):
        
        value = RdfNsManager.clean_iri(value)
        lookup = None
        end = None

        try:
            lookup = value[:value.rindex('#')+1]
            end = value[value.rindex('#')+1:]
        except ValueError:
            try:
                lookup = value[:value.rindex('/')+1]
                end = value[value.rindex('/')+1:]
            except ValueError:
                try:
                    lookup = value[:value.index(':')]
                    end = value[value.rindex(':')+1:]
                except ValueError:
                    try:
                        lookup = value[:value.index('_')]
                        end = value[value.index('_')+1:]
                    except ValueError:
                        lookup = value
                        end = ""

        return (lookup, end)
403658
private String encodeUri( String uri )
    {
        String newUri = "";
        StringTokenizer st = new StringTokenizer( uri, "/ ", true );
        while ( st.hasMoreTokens())
        {
            String tok = st.nextToken();
            if ( tok.equals( "/" ))
                newUri += "/";
            else if ( tok.equals( " " ))
                newUri += "%20";
            else
            {
                newUri += URLEncoder.encode( tok );
                // For Java 1.4 you'll want to use this instead:
                // try { newUri += URLEncoder.encode( tok, "UTF-8" ); } catch ( java.io.UnsupportedEncodingException uee ) {}
            }
        }
        return newUri;
    }
859742
function fullEncodeURIComponent (str) {
    var rv = encodeURIComponent(str).replace(/[!'()*~]/g, function(c) {
      return '%' + c.charCodeAt(0).toString(16).toUpperCase();
    });
    return rv.replace(/\%20/g,'+');
}
703445
def to_uri(url)
      uri = URI.parse(url)
      uri.host.nil? ? false : uri
    rescue URI::BadURIError
      false
    rescue URI::InvalidURIError
      false
    end
1015682
def safe_unicode(string):
    """"""
    if not PY3:
        uni = string.replace(u'\u2019', "'")
        return uni.encode('utf-8')
        
    return string
708317
def _relativize_uris(text)
      return text unless _relativize?
      path_to_root= _path_to_root
      text.force_encoding("UTF-8") if text.respond_to? :force_encoding
      text.gsub HTML_MUNGABLE_RE do |match|
        if $5 == '/'
          "#{ $1 }#{ $2 }=#{ $3 }#{ $4 }/"
        else
          "#{ $1 }#{ $2 }=#{ $3 }#{ $4 }#{ path_to_root }"
        end
      end
    end
557199
def iri_to_str(self, iri_: ShExDocParser.IriContext) -> str:
        
        if iri_.IRIREF():
            return self.iriref_to_str(iri_.IRIREF())
        else:
            return self.prefixedname_to_str(iri_.prefixedName())
672489
def parseURI(str):
    
    ret = libxml2mod.xmlParseURI(str)
    if ret is None:raise uriError('xmlParseURI() failed')
    return URI(_obj=ret)
535387
def geturi(self):
        """"""
        fragment = self.fragment
        if fragment is None:
            return self.uri
        elif isinstance(fragment, bytes):
            return self.uri + b'#' + fragment
        else:
            return self.uri + u'#' + fragment
999385
def unescape_uri(str)
      str = str.dup
      binary_encode(str)
      str.gsub(ESCAPED) { $1.hex.chr }
    end