Cheap URI relativize for current directory and /.
963183
def add_annotation(self, about, content, motivated_by="oa:describing"):
        # type: (str, List[str], str) -> str
        """"""
        self.self_check()
        curr = self.base_uri + METADATA + "/"
        content = [c.replace(curr, "").replace(self.base_uri, "../")
                   for c in content]
        uri = uuid.uuid4().urn
        ann = {
            "uri": uri,
            "about": about,
            "content": content,
            "oa:motivatedBy": {"@id": motivated_by}
        }
        self.annotations.append(ann)
        return uri
36323
def uri(self):
        """"""
        CheckParent(self)

        val = _fitz.Link_uri(self)

        if not val:
            val = ""
        else:
            nval = "".join([c for c in val if 32 <= ord(c) <= 127])
            val = nval


        return val
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
766614
def clean_base_uri(url):
        
        if url is None:
            return url
        if not '//' in url:
            url = 'https://' + url

        ret = url[:url.find('/', url.find('//') + 2) + 1] or url
        assert '.' in url, "<%s> is not a proper base_uri" % ret

        if not ret.endswith('/'):
            ret += '/'
        return ret
1218637
def include_dir(self, root):
        """"""
        parts = [root]
        parts.extend(self.pathname.split(os.path.sep))
        return "/".join(parts)
293061
def uri(self, value, strip_iri=True):
        

        return self.convert_to_uri(value, strip_iri=strip_iri)
421245
def get_root_uri(uri):
    """"""
    chunks = urlsplit(uri)
    return urlunsplit((chunks.scheme, chunks.netloc, chunks.path, '', ''))
1240893
def directory(self, value):
        """"""
        # Normalize the value of `directory'.
        set_property(self, "directory", parse_path(value))
        # Clear the computed values of `context' and `entries'.
        clear_property(self, "context")
        clear_property(self, "entries")
1230720
def _url(self, uri):
        """"""
        prefix = "{}://{}{}".format(
            self._protocol,
            self.real_connection.host,
            self._port_postfix(),
        )
        return uri.replace(prefix, '', 1)
1286076
def _uri_split(uri):
    """"""
    scheme, netloc, path, query, fragment = _safe_urlsplit(uri)

    auth = None
    port = None

    if '@' in netloc:
        auth, netloc = netloc.split('@', 1)

    if netloc.startswith('['):
        host, port_part = netloc[1:].split(']', 1)
        if port_part.startswith(':'):
            port = port_part[1:]
    elif ':' in netloc:
        host, port = netloc.split(':', 1)
    else:
        host = netloc
    return scheme, auth, host, port, path, query, fragment
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
731706
def normalize(url, strip=False):
    ""
    if strip:
        p = _urltools.parse(url)
        url = p.scheme + '://' + p.subdomain + p.domain + p.path
    return _urltools.normalize(url)
1294870
def select_directory(self):
        """"""
        self.__redirect_stdio_emit(False)
        directory = getexistingdirectory(
                self, _(""), self.path)
        if directory:
            directory = to_unicode_from_fs(osp.abspath(directory))
        self.__redirect_stdio_emit(True)
        return directory
443483
def pretty_relpath(path, start):
    '''
    
    '''
    relpath = os.path.relpath(path, start)
    if relpath.startswith('..'):
        return path
    return relpath
146327
def FindPotentialURIs(self, file_obj):
    """"""
    rfc822_format = ""  # will contain all lines not in legacy format
    uris_to_parse = []

    for line in utils.ReadFileBytesAsUnicode(file_obj).splitlines(True):
      # check if legacy style line - if it is then extract URL
      m = re.search(r"^\s*deb(?:-\S+)?(?:\s+\[[^\]]*\])*\s+(\S+)(?:\s|$)", line)
      if m:
        uris_to_parse.append(m.group(1))
      else:
        rfc822_format += line

    uris_to_parse.extend(self.ParseURIFromKeyValues(rfc822_format, ":", "uri"))
    return uris_to_parse
1116535
def get_uri(self):
        """"""
        if self.source_file and os.path.exists(self.source_file.path):
            return self.source_file.path
        elif self.source_url:
            return self.source_url
        return None
708407
@SuppressWarnings("WeakerAccess")
    @NonNull
    public static Uri getUriForFile(@NonNull Context context, @NonNull Directory directory, @NonNull String relativePath) {
        final Uri.Builder builder = new Uri.Builder()
                .scheme(ContentResolver.SCHEME_CONTENT)
                .authority(getAuthority(context))
                .appendPath(directory.name().toLowerCase());
        for (String segment : relativePath.split(Pattern.quote(File.separator))) {
            if (segment.length() > 0) {
                builder.appendPath(segment);
            }
        }
        return builder.build();
    }