当前位置: 首页>>代码示例>>Python>>正文


Python posixpath.dirname方法代码示例

本文整理汇总了Python中posixpath.dirname方法的典型用法代码示例。如果您正苦于以下问题:Python posixpath.dirname方法的具体用法?Python posixpath.dirname怎么用?Python posixpath.dirname使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在posixpath的用法示例。


在下文中一共展示了posixpath.dirname方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: resolveEntity

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def resolveEntity(self, publicId, systemId):
        assert systemId is not None
        source = DOMInputSource()
        source.publicId = publicId
        source.systemId = systemId
        source.byteStream = self._get_opener().open(systemId)

        # determine the encoding if the transport provided it
        source.encoding = self._guess_media_encoding(source)

        # determine the base URI is we can
        import posixpath, urllib.parse
        parts = urllib.parse.urlparse(systemId)
        scheme, netloc, path, params, query, fragment = parts
        # XXX should we check the scheme here as well?
        if path and not path.endswith("/"):
            path = posixpath.dirname(path) + "/"
            parts = scheme, netloc, path, params, query, fragment
            source.baseURI = urllib.parse.urlunparse(parts)

        return source 
开发者ID:war-and-code,项目名称:jawfish,代码行数:23,代码来源:xmlbuilder.py

示例2: adjust_uri

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def adjust_uri(self, uri, relativeto):
        """Adjust the given ``uri`` based on the given relative URI."""

        key = (uri, relativeto)
        if key in self._uri_cache:
            return self._uri_cache[key]

        if uri[0] != "/":
            if relativeto is not None:
                v = self._uri_cache[key] = posixpath.join(
                    posixpath.dirname(relativeto), uri
                )
            else:
                v = self._uri_cache[key] = "/" + uri
        else:
            v = self._uri_cache[key] = uri
        return v 
开发者ID:remg427,项目名称:misp42splunk,代码行数:19,代码来源:lookup.py

示例3: _refuri2http

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def _refuri2http(self, node):
        # Replace 'refuri' in reference with HTTP address, if possible
        # None for no possible address
        url = node.get('refuri')
        if not node.get('internal'):
            return url
        # If HTTP page build URL known, make link relative to that.
        if not self.markdown_http_base:
            return None
        this_doc = self.builder.current_docname
        if url in (None, ''):  # Reference to this doc
            url = self.builder.get_target_uri(this_doc)
        else:  # URL is relative to the current docname.
            this_dir = posixpath.dirname(this_doc)
            if this_dir:
                url = posixpath.normpath('{}/{}'.format(this_dir, url))
        url = '{}/{}'.format(self.markdown_http_base, url)
        if 'refid' in node:
            url += '#' + node['refid']
        return url 
开发者ID:codejamninja,项目名称:sphinx-markdown-builder,代码行数:22,代码来源:doctree2md.py

示例4: adjust_uri

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def adjust_uri(self, uri, relativeto):
        """Adjust the given ``uri`` based on the given relative URI."""

        key = (uri, relativeto)
        if key in self._uri_cache:
            return self._uri_cache[key]

        if uri[0] != '/':
            if relativeto is not None:
                v = self._uri_cache[key] = posixpath.join(
                    posixpath.dirname(relativeto), uri)
            else:
                v = self._uri_cache[key] = '/' + uri
        else:
            v = self._uri_cache[key] = uri
        return v 
开发者ID:jpush,项目名称:jbox,代码行数:18,代码来源:lookup.py

示例5: resolveEntity

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def resolveEntity(self, publicId, systemId):
        assert systemId is not None
        source = DOMInputSource()
        source.publicId = publicId
        source.systemId = systemId
        source.byteStream = self._get_opener().open(systemId)

        # determine the encoding if the transport provided it
        source.encoding = self._guess_media_encoding(source)

        # determine the base URI is we can
        import posixpath, urlparse
        parts = urlparse.urlparse(systemId)
        scheme, netloc, path, params, query, fragment = parts
        # XXX should we check the scheme here as well?
        if path and not path.endswith("/"):
            path = posixpath.dirname(path) + "/"
            parts = scheme, netloc, path, params, query, fragment
            source.baseURI = urlparse.urlunparse(parts)

        return source 
开发者ID:glmcdona,项目名称:meddle,代码行数:23,代码来源:xmlbuilder.py

示例6: test_realpath_resolve_first

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def test_realpath_resolve_first(self):
            # Bug #1213894: The first component of the path, if not absolute,
            # must be resolved too.

            try:
                os.mkdir(ABSTFN)
                os.mkdir(ABSTFN + "/k")
                os.symlink(ABSTFN, ABSTFN + "link")
                with support.change_cwd(dirname(ABSTFN)):
                    base = basename(ABSTFN)
                    self.assertEqual(realpath(base + "link"), ABSTFN)
                    self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k")
            finally:
                test_support.unlink(ABSTFN + "link")
                safe_rmdir(ABSTFN + "/k")
                safe_rmdir(ABSTFN) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_posixpath.py

示例7: get_dependents

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def get_dependents(archive, filename):
    """
    Normalise dependency file paths to absolute ones

    Relative paths are relative to parent object
    """
    src = archive.read(filename)
    node = fromstring(src)
    rels = RelationshipList.from_tree(node)
    folder = posixpath.dirname(filename)
    parent = posixpath.split(folder)[0]
    for r in rels.Relationship:
        if r.TargetMode == "External":
            continue
        elif r.target.startswith("/"):
            r.target = r.target[1:]
        else:
            pth = posixpath.join(parent, r.target)
            r.target = posixpath.normpath(pth)
    return rels 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:relationship.py

示例8: test_realpath_resolve_first

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def test_realpath_resolve_first(self):
            # Bug #1213894: The first component of the path, if not absolute,
            # must be resolved too.

            try:
                old_path = abspath('.')
                os.mkdir(ABSTFN)
                os.mkdir(ABSTFN + "/k")
                os.symlink(ABSTFN, ABSTFN + "link")
                os.chdir(dirname(ABSTFN))

                base = basename(ABSTFN)
                self.assertEqual(realpath(base + "link"), ABSTFN)
                self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k")
            finally:
                os.chdir(old_path)
                test_support.unlink(ABSTFN + "link")
                safe_rmdir(ABSTFN + "/k")
                safe_rmdir(ABSTFN) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:21,代码来源:test_posixpath.py

示例9: run

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def run(self):
        self.env = env = self.state.document.settings.env
        self.genopt = Options()
        self.warnings = []
        self.result = ViewList()

        names = [x.strip().split()[0] for x in self.content
                 if x.strip() and re.search(r'^[~a-zA-Z_]', x.strip()[0])]
        #print "DEBUG: running for ",names
        items = self.get_items(names)
        nodes = self.get_table(items)

        if 'toctree' in self.options:
            dirname = posixpath.dirname(env.docname)

            tree_prefix = self.options['toctree'].strip()
            docnames = []
            for name, sig, summary, real_name in items:
                docname = posixpath.join(tree_prefix, real_name)
                docname = posixpath.normpath(posixpath.join(dirname, docname))
                if docname not in env.found_docs:
                    self.warn('toctree references unknown document %r'
                              % docname)
                docnames.append(docname)

            tocnode = addnodes.toctree()
            tocnode['includefiles'] = docnames
            tocnode['entries'] = [(None, docn) for docn in docnames]
            tocnode['maxdepth'] = -1
            tocnode['glob'] = None

            tocnode = autosummary_toc('', '', tocnode)
            #print "DEBUG: appending toc node:",tocnode
            nodes.append(tocnode)

        return self.warnings + nodes 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:38,代码来源:autosummary__init__.py

示例10: autohandler

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def autohandler(template, context, name="autohandler"):
    lookup = context.lookup
    _template_uri = template.module._template_uri
    if not lookup.filesystem_checks:
        try:
            return lookup._uri_cache[(autohandler, _template_uri, name)]
        except KeyError:
            pass

    tokens = re.findall(r"([^/]+)", posixpath.dirname(_template_uri)) + [name]
    while len(tokens):
        path = "/" + "/".join(tokens)
        if path != _template_uri and _file_exists(lookup, path):
            if not lookup.filesystem_checks:
                return lookup._uri_cache.setdefault(
                    (autohandler, _template_uri, name), path
                )
            else:
                return path
        if len(tokens) == 1:
            break
        tokens[-2:] = [name]

    if not lookup.filesystem_checks:
        return lookup._uri_cache.setdefault(
            (autohandler, _template_uri, name), None
        )
    else:
        return None 
开发者ID:remg427,项目名称:misp42splunk,代码行数:31,代码来源:autohandler.py

示例11: resolve_path

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def resolve_path(self, name, parent_path=None):
        if parent_path and not parent_path.startswith("<") and \
            not parent_path.startswith("/") and \
                not name.startswith("/"):
            current_path = os.path.join(self.root, parent_path)
            file_dir = os.path.dirname(os.path.abspath(current_path))
            relative_path = os.path.abspath(os.path.join(file_dir, name))
            if relative_path.startswith(self.root):
                name = relative_path[len(self.root) + 1:]
        return name 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:12,代码来源:template.py

示例12: autohandler

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def autohandler(template, context, name='autohandler'):
    lookup = context.lookup
    _template_uri = template.module._template_uri
    if not lookup.filesystem_checks:
        try:
            return lookup._uri_cache[(autohandler, _template_uri, name)]
        except KeyError:
            pass

    tokens = re.findall(r'([^/]+)', posixpath.dirname(_template_uri)) + [name]
    while len(tokens):
        path = '/' + '/'.join(tokens)
        if path != _template_uri and _file_exists(lookup, path):
            if not lookup.filesystem_checks:
                return lookup._uri_cache.setdefault(
                    (autohandler, _template_uri, name), path)
            else:
                return path
        if len(tokens) == 1:
            break
        tokens[-2:] = [name]

    if not lookup.filesystem_checks:
        return lookup._uri_cache.setdefault(
            (autohandler, _template_uri, name), None)
    else:
        return None 
开发者ID:jpush,项目名称:jbox,代码行数:29,代码来源:autohandler.py

示例13: _is_child

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def _is_child(self, path):
        return posixpath.dirname(path.at.rstrip("/")) == self.at.rstrip("/") 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:4,代码来源:zipp.py

示例14: _add_implied_dirs

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def _add_implied_dirs(names):
        return names + [
            name + "/"
            for name in map(posixpath.dirname, names)
            if name and name + "/" not in names
        ] 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:8,代码来源:zipp.py

示例15: parent

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def parent(self):
        parent_at = posixpath.dirname(self.at.rstrip('/'))
        if parent_at:
            parent_at += '/'
        return self._next(parent_at) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:7,代码来源:zipp.py


注:本文中的posixpath.dirname方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。