當前位置: 首頁>>代碼示例>>Python>>正文


Python posixpath.isabs方法代碼示例

本文整理匯總了Python中posixpath.isabs方法的典型用法代碼示例。如果您正苦於以下問題:Python posixpath.isabs方法的具體用法?Python posixpath.isabs怎麽用?Python posixpath.isabs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在posixpath的用法示例。


在下文中一共展示了posixpath.isabs方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: open

# 需要導入模塊: import posixpath [as 別名]
# 或者: from posixpath import isabs [as 別名]
def open(self, h5_rel_path):
        """
        Create an HDF5 group and enter this specific group. If the group exists in the HDF5 path only the h5_path is
        set correspondingly otherwise the group is created first.

        Args:
            h5_rel_path (str): relative path from the current HDF5 path - h5_path - to the new group

        Returns:
            FileHDFio: FileHDFio object pointing to the new group
        """
        new_h5_path = self.copy()
        if os.path.isabs(h5_rel_path):
            raise ValueError(
                "Absolute paths are not supported -> replace by relative path name!"
            )

        if h5_rel_path.strip() == ".":
            h5_rel_path = ""
        if h5_rel_path.strip() != "":
            new_h5_path.h5_path = posixpath.join(new_h5_path.h5_path, h5_rel_path)
        new_h5_path.history.append(h5_rel_path)

        return new_h5_path 
開發者ID:pyiron,項目名稱:pyiron,代碼行數:26,代碼來源:hdfio.py

示例2: canonical_filename

# 需要導入模塊: import posixpath [as 別名]
# 或者: from posixpath 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

示例3: canonical_filename

# 需要導入模塊: import posixpath [as 別名]
# 或者: from posixpath 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

示例4: __init__

# 需要導入模塊: import posixpath [as 別名]
# 或者: from posixpath 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

示例5: read_file

# 需要導入模塊: import posixpath [as 別名]
# 或者: from posixpath import isabs [as 別名]
def read_file(filename: str, binary: bool = False) -> typing.Any:
    """Get the contents of a file contained with qutebrowser.

    Args:
        filename: The filename to open as string.
        binary: Whether to return a binary string.
                If False, the data is UTF-8-decoded.

    Return:
        The file contents as string.
    """
    assert not posixpath.isabs(filename), filename
    assert os.path.pardir not in filename.split(posixpath.sep), filename

    if not binary and filename in _resource_cache:
        return _resource_cache[filename]

    if hasattr(sys, 'frozen'):
        # PyInstaller doesn't support pkg_resources :(
        # https://github.com/pyinstaller/pyinstaller/wiki/FAQ#misc
        fn = os.path.join(os.path.dirname(sys.executable), filename)
        if binary:
            with open(fn, 'rb') as f:  # type: typing.IO
                return f.read()
        else:
            with open(fn, 'r', encoding='utf-8') as f:
                return f.read()
    else:
        data = pkg_resources.resource_string(
            qutebrowser.__name__, filename)

        if binary:
            return data

        return data.decode('UTF-8') 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:37,代碼來源:utils.py

示例6: test_isabs

# 需要導入模塊: import posixpath [as 別名]
# 或者: from posixpath import isabs [as 別名]
def test_isabs(self):
        self.assertIs(posixpath.isabs(""), False)
        self.assertIs(posixpath.isabs("/"), True)
        self.assertIs(posixpath.isabs("/foo"), True)
        self.assertIs(posixpath.isabs("/foo/bar"), True)
        self.assertIs(posixpath.isabs("foo/bar"), False) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_posixpath.py

示例7: __init__

# 需要導入模塊: import posixpath [as 別名]
# 或者: from posixpath import isabs [as 別名]
def __init__(self, file_name, h5_path="/", mode="a"):
        if not os.path.isabs(file_name):
            raise ValueError("file_name must be given as absolute path name")
        self._file_name = None
        self.file_name = file_name
        self.history = []
        self.h5_path = h5_path
        self._filter = ["groups", "nodes", "objects"] 
開發者ID:pyiron,項目名稱:pyiron,代碼行數:10,代碼來源:hdfio.py

示例8: h5_path

# 需要導入模塊: import posixpath [as 別名]
# 或者: from posixpath import isabs [as 別名]
def h5_path(self, path):
        """
        Set the path in the HDF5 file starting from the root group

        Args:
            path (str): HDF5 path
        """
        if (path is None) or (path == ""):
            path = "/"
        self._h5_path = posixpath.normpath(path)
        if not posixpath.isabs(self._h5_path):
            self._h5_path = "/" + self._h5_path
        self._h5_group = "store.root" + self._h5_path.replace("/", ".")
        if self._h5_group[-1] != ".":
            self._h5_group += "." 
開發者ID:pyiron,項目名稱:pyiron,代碼行數:17,代碼來源:hdfio.py

示例9: validate_abspath

# 需要導入模塊: import posixpath [as 別名]
# 或者: from posixpath 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

示例10: validate_abspath

# 需要導入模塊: import posixpath [as 別名]
# 或者: from posixpath 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

示例11: isabs_anywhere

# 需要導入模塊: import posixpath [as 別名]
# 或者: from posixpath 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

示例12: testShell_externalStorageDefined

# 需要導入模塊: import posixpath [as 別名]
# 或者: from posixpath import isabs [as 別名]
def testShell_externalStorageDefined(self):
    under_test = self.getTestInstance()
    external_storage = under_test.Shell('echo $EXTERNAL_STORAGE')
    self.assertIsInstance(external_storage, str)
    self.assertTrue(posixpath.isabs(external_storage)) 
開發者ID:FSecureLABS,項目名稱:Jandroid,代碼行數:7,代碼來源:adb_compatibility_devicetest.py

示例13: test_isabs

# 需要導入模塊: import posixpath [as 別名]
# 或者: from posixpath import isabs [as 別名]
def test_isabs(self):
        self.assertIs(posixpath.isabs(""), False)
        self.assertIs(posixpath.isabs("/"), True)
        self.assertIs(posixpath.isabs("/foo"), True)
        self.assertIs(posixpath.isabs("/foo/bar"), True)
        self.assertIs(posixpath.isabs("foo/bar"), False)

        self.assertIs(posixpath.isabs(b""), False)
        self.assertIs(posixpath.isabs(b"/"), True)
        self.assertIs(posixpath.isabs(b"/foo"), True)
        self.assertIs(posixpath.isabs(b"/foo/bar"), True)
        self.assertIs(posixpath.isabs(b"foo/bar"), False) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:14,代碼來源:test_posixpath.py

示例14: validate_path

# 需要導入模塊: import posixpath [as 別名]
# 或者: from posixpath import isabs [as 別名]
def validate_path(path, ctx=None):
  ctx = ctx or validation.Context.raise_on_error(prefix='Invalid path: ')
  if not path:
    ctx.error('not specified')
    return
  if posixpath.isabs(path):
    ctx.error('must not be absolute: %s', path)
  if any(p in ('.', '..') for p in path.split(posixpath.sep)):
    ctx.error('must not contain ".." or "." components: %s', path) 
開發者ID:luci,項目名稱:luci-py,代碼行數:11,代碼來源:validation.py

示例15: test_isabs

# 需要導入模塊: import posixpath [as 別名]
# 或者: from posixpath import isabs [as 別名]
def test_isabs(self):
        self.assertIs(posixpath.isabs(""), False)
        self.assertIs(posixpath.isabs("/"), True)
        self.assertIs(posixpath.isabs("/foo"), True)
        self.assertIs(posixpath.isabs("/foo/bar"), True)
        self.assertIs(posixpath.isabs("foo/bar"), False)

        self.assertRaises(TypeError, posixpath.isabs) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:10,代碼來源:test_posixpath.py


注:本文中的posixpath.isabs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。