Python pathlib2.PurePath() Examples

The following are 4 code examples of pathlib2.PurePath(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pathlib2 , or try the search function .
Example #1
Source File: base.py    From streamalert with Apache License 2.0 6 votes vote down vote up
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) 
Example #2
Source File: files.py    From floyd-cli with Apache License 2.0 5 votes vote down vote up
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 
Example #3
Source File: upload.py    From blobxfer with MIT License 5 votes vote down vote up
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)) 
Example #4
Source File: splitter.py    From flatten-dict with MIT License 5 votes vote down vote up
def path_splitter(flat_key):
    keys = PurePath(flat_key).parts
    return keys