本文整理汇总了Python中pathlib2.PurePath方法的典型用法代码示例。如果您正苦于以下问题:Python pathlib2.PurePath方法的具体用法?Python pathlib2.PurePath怎么用?Python pathlib2.PurePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pathlib2
的用法示例。
在下文中一共展示了pathlib2.PurePath方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: path_matches_any
# 需要导入模块: import pathlib2 [as 别名]
# 或者: from pathlib2 import PurePath [as 别名]
def path_matches_any(text, patterns):
"""Check if the text matches any of the given wildcard patterns.
NOTE: Intended for filepaths with wildcards where fnmatch is too greedy.
Especially useful in cases where a username in a filepath may need to be wildcarded.
For example;
path_matches_any('/Users/foobar/path/to/file', {'/Users/*/path/*/file'}) == True
Args:
text (str): Text to examine
patterns (iterable): Collection of string patterns, compatible with fnmatch (* wildcards)
Returns:
bool: True if the text matches at least one of the patterns, False otherwise.
"""
if not isinstance(text, str):
return False
return any(pathlib2.PurePath(text).match(pattern) for pattern in patterns)
示例2: matches_glob_list
# 需要导入模块: import pathlib2 [as 别名]
# 或者: from pathlib2 import PurePath [as 别名]
def matches_glob_list(path, glob_list):
"""
Given a list of glob patterns, returns a boolean
indicating if a path matches any glob in the list
"""
for glob in glob_list:
try:
if PurePath(path).match(glob):
return True
except TypeError:
pass
return False
示例3: create_destination_id
# 需要导入模块: import pathlib2 [as 别名]
# 或者: from pathlib2 import PurePath [as 别名]
def create_destination_id(client, container, name):
# type: (azure.storage.StorageClient, str, str) -> str
"""Create a unique destination id
:param azure.storage.StorageClient client: storage client
:param str container: container name
:param str name: entity name
:rtype: str
:return: unique id for the destination
"""
path = str(pathlib.PurePath(name))
return ';'.join((client.primary_endpoint, container, path))
示例4: path_splitter
# 需要导入模块: import pathlib2 [as 别名]
# 或者: from pathlib2 import PurePath [as 别名]
def path_splitter(flat_key):
keys = PurePath(flat_key).parts
return keys