def match_path_against(pathname, patterns, case_sensitive=True): """ Determines whether the pathname matches any of the given wildcard patterns, optionally ignoring the case of the pathname and patterns. :param pathname: A path name that will be matched against a wildcard pattern. :param patterns: A list of wildcard patterns to match_path the filename against. :param case_sensitive: ``True`` if the matching should be case-sensitive; ``False`` otherwise. :returns: ``True`` if the pattern matches; ``False`` otherwise. """ if case_sensitive: match_func = partial(fnmatchcase, pathname) transform = identity else: match_func = partial(fnmatch, pathname.lower()) transform = _string_lower return some(match_func, map(transform, set(patterns)))
def match_path_against(pathname, patterns, case_sensitive=True): """ Determines whether the pathname matches any of the given wildcard patterns, optionally ignoring the case of the pathname and patterns. :param pathname: A path name that will be matched against a wildcard pattern. :param patterns: A list of wildcard patterns to match_path the filename against. :param case_sensitive: ``True`` if the matching should be case-sensitive; ``False`` otherwise. :returns: ``True`` if the pattern matches; ``False`` otherwise. """ if case_sensitive: match_func = functools.partial(fnmatch.fnmatchcase, pathname) transform = functional.identity else: match_func = functools.partial(fnmatch.fnmatch, pathname.lower()) transform = _string_lower return functional.some(match_func, map(transform, set(patterns)))
def test_valid(self): self.assertTrue(some(lambda w: w > 0, [0, -1, 4, 6])) self.assertFalse(some(lambda w: w > 0, [0, -1, -4, 0]))
def test_valid(self): self.assertTrue(functional.some(lambda w: w > 0, [0, -1, 4, 6])) self.assertFalse(functional.some(lambda w: w > 0, [0, -1, -4, 0]))