![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /usr/local/lib/python3.8/dist-packages/watchdog/utils/ |
Upload File : |
# patterns.py: Common wildcard searching/filtering functionality for files. # # Copyright (C) 2010 Yesudeep Mangalapilly <yesudeep@gmail.com> # # Written by Boris Staletic <boris.staletic@gmail.com> from __future__ import annotations # Non-pure path objects are only allowed on their respective OS's. # Thus, these utilities require "pure" path objects that don't access the filesystem. # Since pathlib doesn't have a `case_sensitive` parameter, we have to approximate it # by converting input paths to `PureWindowsPath` and `PurePosixPath` where: # - `PureWindowsPath` is always case-insensitive. # - `PurePosixPath` is always case-sensitive. # Reference: https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.match from pathlib import PurePosixPath, PureWindowsPath def _match_path(path, included_patterns, excluded_patterns, case_sensitive): """Internal function same as :func:`match_path` but does not check arguments.""" if case_sensitive: path = PurePosixPath(path) else: included_patterns = {pattern.lower() for pattern in included_patterns} excluded_patterns = {pattern.lower() for pattern in excluded_patterns} path = PureWindowsPath(path) common_patterns = included_patterns & excluded_patterns if common_patterns: raise ValueError(f"conflicting patterns `{common_patterns}` included and excluded") return any(path.match(p) for p in included_patterns) and not any(path.match(p) for p in excluded_patterns) def filter_paths(paths, included_patterns=None, excluded_patterns=None, case_sensitive=True): """Filters from a set of paths based on acceptable patterns and ignorable patterns. :param paths: A list of path names that will be filtered based on matching and ignored patterns. :param included_patterns: Allow filenames matching wildcard patterns specified in this list. If no pattern list is specified, ["*"] is used as the default pattern, which matches all files. :param excluded_patterns: Ignores filenames matching wildcard patterns specified in this list. If no pattern list is specified, no files are ignored. :param case_sensitive: ``True`` if matching should be case-sensitive; ``False`` otherwise. :returns: A list of pathnames that matched the allowable patterns and passed through the ignored patterns. """ included = set(["*"] if included_patterns is None else included_patterns) excluded = set([] if excluded_patterns is None else excluded_patterns) for path in paths: if _match_path(path, included, excluded, case_sensitive): yield path def match_any_paths(paths, included_patterns=None, excluded_patterns=None, case_sensitive=True): """Matches from a set of paths based on acceptable patterns and ignorable patterns. See ``filter_paths()`` for signature details. """ return any( filter_paths( paths, included_patterns=included_patterns, excluded_patterns=excluded_patterns, case_sensitive=case_sensitive, ) )