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


Python posixpath.sep方法代码示例

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


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

示例1: relto

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import sep [as 别名]
def relto(self, relpath):
        """ return a string which is the relative part of the path
        to the given 'relpath'.
        """
        if not isinstance(relpath, (str, PathBase)):
            raise TypeError("%r: not a string or path object" %(relpath,))
        strrelpath = str(relpath)
        if strrelpath and strrelpath[-1] != self.sep:
            strrelpath += self.sep
        #assert strrelpath[-1] == self.sep
        #assert strrelpath[-2] != self.sep
        strself = self.strpath
        if sys.platform == "win32" or getattr(os, '_name', None) == 'nt':
            if os.path.normcase(strself).startswith(
               os.path.normcase(strrelpath)):
                return strself[len(strrelpath):]
        elif strself.startswith(strrelpath):
            return strself[len(strrelpath):]
        return "" 
开发者ID:pytest-dev,项目名称:py,代码行数:21,代码来源:common.py

示例2: bestrelpath

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import sep [as 别名]
def bestrelpath(self, dest):
        """ return a string which is a relative path from self
            (assumed to be a directory) to dest such that
            self.join(bestrelpath) == dest and if not such
            path can be determined return dest.
        """
        try:
            if self == dest:
                return os.curdir
            base = self.common(dest)
            if not base:  # can be the case on windows
                return str(dest)
            self2base = self.relto(base)
            reldest = dest.relto(base)
            if self2base:
                n = self2base.count(self.sep) + 1
            else:
                n = 0
            l = [os.pardir] * n
            if reldest:
                l.append(reldest)
            target = dest.sep.join(l)
            return target
        except AttributeError:
            return str(dest) 
开发者ID:pytest-dev,项目名称:py,代码行数:27,代码来源:common.py

示例3: __call__

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import sep [as 别名]
def __call__(self, path):
        pattern = self.pattern

        if (pattern.find(path.sep) == -1 and
        iswin32 and
        pattern.find(posixpath.sep) != -1):
            # Running on Windows, the pattern has no Windows path separators,
            # and the pattern has one or more Posix path separators. Replace
            # the Posix path separators with the Windows path separator.
            pattern = pattern.replace(posixpath.sep, path.sep)

        if pattern.find(path.sep) == -1:
            name = path.basename
        else:
            name = str(path) # path.strpath # XXX svn?
            if not os.path.isabs(pattern):
                pattern = '*' + path.sep + pattern
        return fnmatch.fnmatch(name, pattern) 
开发者ID:pytest-dev,项目名称:py,代码行数:20,代码来源:common.py

示例4: make_webrelpath

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import sep [as 别名]
def make_webrelpath(path):
	"""
	Forcefully make *path* into a web-suitable relative path. This will strip
	off leading and trailing directory separators.

	.. versionadded:: 1.14.0

	:param str path: The path to convert into a web-suitable relative path.
	:return: The converted path.
	:rtype: str
	"""
	if not path.startswith(webpath.sep):
		path = webpath.sep + path
	path = webpath.relpath(path, webpath.sep)
	if path == webpath.curdir:
		path = ''
	return path 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:19,代码来源:utilities.py

示例5: build

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import sep [as 别名]
def build(cls, path):
        """
        Build a dictionary similar to the zipimport directory
        caches, except instead of tuples, store ZipInfo objects.

        Use a platform-specific path separator (os.sep) for the path keys
        for compatibility with pypy on Windows.
        """
        with zipfile.ZipFile(path) as zfile:
            items = (
                (
                    name.replace('/', os.sep),
                    zfile.getinfo(name),
                )
                for name in zfile.namelist()
            )
            return dict(items) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:__init__.py

示例6: _index

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import sep [as 别名]
def _index(self):
        try:
            return self._dirindex
        except AttributeError:
            ind = {}
            for path in self.zipinfo:
                parts = path.split(os.sep)
                while parts:
                    parent = os.sep.join(parts[:-1])
                    if parent in ind:
                        ind[parent].append(parts[-1])
                        break
                    else:
                        ind[parent] = [parts.pop()]
            self._dirindex = ind
            return ind 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:__init__.py

示例7: _parents

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import sep [as 别名]
def _parents(path):
    """
    Given a path with elements separated by
    posixpath.sep, generate all parents of that path.

    >>> list(_parents('b/d'))
    ['b']
    >>> list(_parents('/b/d/'))
    ['/b']
    >>> list(_parents('b/d/f/'))
    ['b/d', 'b']
    >>> list(_parents('b'))
    []
    >>> list(_parents(''))
    []
    """
    return itertools.islice(_ancestry(path), 1, None) 
开发者ID:jaraco,项目名称:zipp,代码行数:19,代码来源:zipp.py

示例8: _ancestry

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import sep [as 别名]
def _ancestry(path):
    """
    Given a path with elements separated by
    posixpath.sep, generate all elements of that path

    >>> list(_ancestry('b/d'))
    ['b/d', 'b']
    >>> list(_ancestry('/b/d/'))
    ['/b/d', '/b']
    >>> list(_ancestry('b/d/f/'))
    ['b/d/f', 'b/d', 'b']
    >>> list(_ancestry('b'))
    ['b']
    >>> list(_ancestry(''))
    []
    """
    path = path.rstrip(posixpath.sep)
    while path and path != posixpath.sep:
        yield path
        path, tail = posixpath.split(path) 
开发者ID:jaraco,项目名称:zipp,代码行数:22,代码来源:zipp.py

示例9: mkdir

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import sep [as 别名]
def mkdir(self, path, mode, recursive=False, overwrite=False, zone=None):
        """Create a directory at a (zone-root-relative) path with the given (integer) mode."""
        real_path = self._zone_real_path(path, zone=zone or self.default_zone)
        if posixpath.sep not in real_path.strip(posixpath.sep):
            # The first component of real_path is actually a RAN namespace.
            # In this case, there is only one component: ifs.
            # The ifs namespace cannot be modified,
            # but calling create_directory on any namespace will fail.
            raise OneFSValueError('Calling mkdir on the ifs namespace will fail.')
        self._sdk.NamespaceApi(self._api_client).create_directory(
            directory_path=real_path.lstrip(posixpath.sep),
            x_isi_ifs_target_type='container',
            x_isi_ifs_access_control='{:o}'.format(mode),
            recursive=recursive,
            overwrite=overwrite,
        ) 
开发者ID:Isilon,项目名称:isilon_hadoop_tools,代码行数:18,代码来源:onefs.py

示例10: _convert_egg_info_reqs_to_simple_reqs

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import sep [as 别名]
def _convert_egg_info_reqs_to_simple_reqs(sections):
        """
        Historically, setuptools would solicit and store 'extra'
        requirements, including those with environment markers,
        in separate sections. More modern tools expect each
        dependency to be defined separately, with any relevant
        extras and environment markers attached directly to that
        requirement. This method converts the former to the
        latter. See _test_deps_from_requires_text for an example.
        """
        def make_condition(name):
            return name and 'extra == "{name}"'.format(name=name)

        def parse_condition(section):
            section = section or ''
            extra, sep, markers = section.partition(':')
            if extra and markers:
                markers = '({markers})'.format(markers=markers)
            conditions = list(filter(None, [markers, make_condition(extra)]))
            return '; ' + ' and '.join(conditions) if conditions else ''

        for section, deps in sections.items():
            for dep in deps:
                yield dep + parse_condition(section) 
开发者ID:pypa,项目名称:pipenv,代码行数:26,代码来源:__init__.py

示例11: get_template

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import sep [as 别名]
def get_template(self, uri):
        """Return a :class:`.Template` object corresponding to the given
        ``uri``.

        .. note:: The ``relativeto`` argument is not supported here at
           the moment.

        """

        try:
            if self.filesystem_checks:
                return self._check(uri, self._collection[uri])
            else:
                return self._collection[uri]
        except KeyError:
            u = re.sub(r"^\/+", "", uri)
            for dir_ in self.directories:
                # make sure the path seperators are posix - os.altsep is empty
                # on POSIX and cannot be used.
                dir_ = dir_.replace(os.path.sep, posixpath.sep)
                srcfile = posixpath.normpath(posixpath.join(dir_, u))
                if os.path.isfile(srcfile):
                    return self._load(srcfile, uri)
            else:
                raise exceptions.TopLevelLookupException(
                    "Cant locate template for uri %r" % uri
                ) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:29,代码来源:lookup.py


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