本文整理汇总了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
示例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]
示例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]
示例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
示例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')
示例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)
示例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"]
示例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 += "."
示例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
示例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,
)
示例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)
示例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))
示例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)
示例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)
示例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)