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


Python ntpath.isabs方法代码示例

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


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

示例1: canonical_filename

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import isabs [as 别名]
def canonical_filename(filename):
    """Return a canonical file name for `filename`.

    An absolute path with no redundant components and normalized case.

    """
    if filename not in CANONICAL_FILENAME_CACHE:
        if not os.path.isabs(filename):
            for path in [os.curdir] + sys.path:
                if path is None:
                    continue
                f = os.path.join(path, filename)
                try:
                    exists = os.path.exists(f)
                except UnicodeError:
                    exists = False
                if exists:
                    filename = f
                    break
        cf = abs_file(filename)
        CANONICAL_FILENAME_CACHE[filename] = cf
    return CANONICAL_FILENAME_CACHE[filename] 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:24,代码来源:files.py

示例2: canonical_filename

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import isabs [as 别名]
def canonical_filename(filename):
    """Return a canonical file name for `filename`.

    An absolute path with no redundant components and normalized case.

    """
    if filename not in CANONICAL_FILENAME_CACHE:
        cf = filename
        if not os.path.isabs(filename):
            for path in [os.curdir] + sys.path:
                if path is None:
                    continue
                f = os.path.join(path, filename)
                try:
                    exists = os.path.exists(f)
                except UnicodeError:
                    exists = False
                if exists:
                    cf = f
                    break
        cf = abs_file(cf)
        CANONICAL_FILENAME_CACHE[filename] = cf
    return CANONICAL_FILENAME_CACHE[filename] 
开发者ID:nedbat,项目名称:coveragepy,代码行数:25,代码来源:files.py

示例3: __init__

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import isabs [as 别名]
def __init__(self, path, root=Root.builddir, destdir=False):
        if destdir and isinstance(root, Root):
            raise ValueError('destdir only applies to install paths')
        drive, path = self.__normalize(path, expand_user=True)

        if posixpath.isabs(path):
            root = Root.absolute
            destdir = False
        elif root == Root.absolute:
            raise ValueError("'{}' is not absolute".format(path))
        elif isinstance(root, BasePath):
            path = self.__join(root.suffix, path)
            destdir = root.destdir
            root = root.root

        if ( path == posixpath.pardir or
             path.startswith(posixpath.pardir + posixpath.sep) ):
            raise ValueError("too many '..': path cannot escape root")

        self.suffix = drive + path
        self.root = root
        self.destdir = destdir 
开发者ID:jimporter,项目名称:bfg9000,代码行数:24,代码来源:basepath.py

示例4: test_isabs

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import isabs [as 别名]
def test_isabs(self):
        tester('ntpath.isabs("c:\\")', 1)
        tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1)
        tester('ntpath.isabs("\\foo")', 1)
        tester('ntpath.isabs("\\foo\\bar")', 1) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_ntpath.py

示例5: validate_abspath

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import isabs [as 别名]
def validate_abspath(self, value: PathType) -> None:
        value = str(value)
        is_posix_abs = posixpath.isabs(value)
        is_nt_abs = ntpath.isabs(value)
        err_object = ValidationError(
            description=(
                "an invalid absolute file path ({}) for the platform ({}).".format(
                    value, self.platform.value
                )
                + " to avoid the error, specify an appropriate platform correspond"
                + " with the path format, or 'auto'."
            ),
            platform=self.platform,
            reason=ErrorReason.MALFORMED_ABS_PATH,
        )

        if any([self._is_windows() and is_nt_abs, self._is_linux() and is_posix_abs]):
            return

        if self._is_universal() and any([is_posix_abs, is_nt_abs]):
            ValidationError(
                description=(
                    "{}. expected a platform independent file path".format(
                        "POSIX absolute file path found"
                        if is_posix_abs
                        else "NT absolute file path found"
                    )
                ),
                platform=self.platform,
                reason=ErrorReason.MALFORMED_ABS_PATH,
            )

        if any([self._is_windows(), self._is_universal()]) and is_posix_abs:
            raise err_object

        drive, _tail = ntpath.splitdrive(value)
        if not self._is_windows() and drive and is_nt_abs:
            raise err_object 
开发者ID:thombashi,项目名称:pathvalidate,代码行数:40,代码来源:_filepath.py

示例6: validate_abspath

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import isabs [as 别名]
def validate_abspath(self, value: str) -> None:
        if any([ntpath.isabs(value), posixpath.isabs(value)]):
            raise ValidationError(
                description="found an absolute path ({}), expected a filename".format(value),
                platform=self.platform,
                reason=ErrorReason.FOUND_ABS_PATH,
            ) 
开发者ID:thombashi,项目名称:pathvalidate,代码行数:9,代码来源:_filename.py

示例7: isabs_anywhere

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import isabs [as 别名]
def isabs_anywhere(filename):
    """Is `filename` an absolute path on any OS?"""
    return ntpath.isabs(filename) or posixpath.isabs(filename) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:5,代码来源:files.py

示例8: __normalize

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import isabs [as 别名]
def __normalize(path, expand_user=False):
        if expand_user:
            path = os.path.expanduser(path)
        drive, path = ntpath.splitdrive(path)
        if drive and not ntpath.isabs(path):
            raise ValueError('relative paths with drives not supported')

        drive = drive.replace('\\', '/')
        path = posixpath.normpath(path.replace('\\', '/'))
        if path == posixpath.curdir:
            path = ''
        return drive, path 
开发者ID:jimporter,项目名称:bfg9000,代码行数:14,代码来源:basepath.py

示例9: append

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import isabs [as 别名]
def append(self, path):
        drive, path = self.__normalize(path, expand_user=True)
        if not posixpath.isabs(path):
            path = self.__join(self.suffix, path)
        return type(self)(drive + path, self.root, self.destdir) 
开发者ID:jimporter,项目名称:bfg9000,代码行数:7,代码来源:basepath.py

示例10: test_path_isabs

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import isabs [as 别名]
def test_path_isabs(self):
        self.assertPathEqual(self.path.isabs) 
开发者ID:bkerler,项目名称:android_universal,代码行数:4,代码来源:test_ntpath.py

示例11: _validate_resource_path

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import isabs [as 别名]
def _validate_resource_path(path):
        """
        Validate the resource paths according to the docs.
        https://setuptools.readthedocs.io/en/latest/pkg_resources.html#basic-resource-access

        >>> warned = getfixture('recwarn')
        >>> warnings.simplefilter('always')
        >>> vrp = NullProvider._validate_resource_path
        >>> vrp('foo/bar.txt')
        >>> bool(warned)
        False
        >>> vrp('../foo/bar.txt')
        >>> bool(warned)
        True
        >>> warned.clear()
        >>> vrp('/foo/bar.txt')
        >>> bool(warned)
        True
        >>> vrp('foo/../../bar.txt')
        >>> bool(warned)
        True
        >>> warned.clear()
        >>> vrp('foo/f../bar.txt')
        >>> bool(warned)
        False

        Windows path separators are straight-up disallowed.
        >>> vrp(r'\\foo/bar.txt')
        Traceback (most recent call last):
        ...
        ValueError: Use of .. or absolute path in a resource path \
is not allowed.

        >>> vrp(r'C:\\foo/bar.txt')
        Traceback (most recent call last):
        ...
        ValueError: Use of .. or absolute path in a resource path \
is not allowed.
        """
        invalid = (
            os.path.pardir in path.split(posixpath.sep) or
            posixpath.isabs(path) or
            ntpath.isabs(path)
        )
        if not invalid:
            return

        msg = "Use of .. or absolute path in a resource path is not allowed."

        # Aggressively disallow Windows absolute paths
        if ntpath.isabs(path) and not posixpath.isabs(path):
            raise ValueError(msg)

        # for compatibility, warn; in future
        # raise ValueError(msg)
        warnings.warn(
            msg[:-1] + " and will raise exceptions in a future release.",
            DeprecationWarning,
            stacklevel=4,
        ) 
开发者ID:bkerler,项目名称:android_universal,代码行数:62,代码来源:__init__.py


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