K i3dZddlmZddlmZddlmZmZmZm Z m Z m Z m Z m Z mZddlmZddlmZddlmZmZmZmZmZmZmZe d d Z Gd d eZy )zR This module provides an object oriented interface for pattern matching of files. ) Collection) zip_longest) AnyStrCallablerIterableIteratorOptionalTypeTypeVarUnion)util)Pattern) CheckResultStrPathTStrPath TreeEntry_filter_check_patterns _is_iterablenormalize_fileSelfPathSpec)boundc eZdZdZdeeddfdZdedefdZ de fdZ d e ddde fd Z d e ddde fd Z d!d ed eeedeefdZ d!deed eeedeeefdZ d"dedeeegdfdeedeeefdZedee deeeegeffdeede fdZ d!dddee d eeedeedee fdZ!e"e#jHZ% d!d ed eeedefdZ& d!dddeed eeedeedeefdZ' d"dddedeeegdfdeedeedee f dZ( d"dddedeeegdfdeedeedeef d Z)e)Z*y)#rzd The :class:`PathSpec` class is a wrapper around a list of compiled :class:`.Pattern` instances. patternsreturnNcHt|ts t|}||_y)z Initializes the :class:`PathSpec` instance. *patterns* (:class:`~collections.abc.Collection` or :class:`~collections.abc.Iterable`) yields each compiled pattern (:class:`.Pattern`). N) isinstanceCollectionTypelistr)selfrs W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pathspec/pathspec.py__init__zPathSpec.__init__-s# Hn -8n8'/$-otherct|tr2t|j|j}t d|DSt S)z Tests the equality of this path-spec with *other* (:class:`PathSpec`) by comparing their :attr:`~PathSpec.patterns` attributes. c3,K|] \}}||k(ywN).0abs r" z"PathSpec.__eq__..Ds 1Aa1f 1s)rrrrallNotImplemented)r!r%paired_patternss r"__eq__zPathSpec.__eq__=s9 x  ?? 1 1 11 r$c,t|jS)zW Returns the number of compiled patterns this path-spec contains (:class:`int`). )lenr)r!s r"__len__zPathSpec.__len__Hs T]] r$r!c~t|tr(|j|j|jzStS)z] Combines the :attr:`Pathspec.patterns` patterns from two :class:`PathSpec` instances. )rr __class__rr/r!r%s r"__add__zPathSpec.__add__Os0 x ..7 88 r$cpt|tr!|xj|jz c_|StS)zi Adds the :attr:`Pathspec.patterns` patterns from one :class:`PathSpec` instance to this instance. )rrrr/r7s r"__iadd__zPathSpec.__iadd__Ys+ x ==ENN"= ; r$file separatorsct||}|jt|j|\}}t |||S)a Check the files against this path-spec. *file* (:class:`str` or :class:`os.PathLike`) is the file path to be matched against :attr:`self.patterns `. *separators* (:class:`~collections.abc.Collection` of :class:`str`; or :data:`None`) optionally contains the path separators to normalize. See :func:`~pathspec.util.normalize_file` for more information. Returns the file check result (:class:`~pathspec.util.CheckResult`). )r _match_file enumeraterr)r!r;r< norm_fileincludeindexs r" check_filezPathSpec.check_fileds>"T:.)##Idmm$`. *separators* (:class:`~collections.abc.Collection` of :class:`str`; or :data:`None`) optionally contains the path separators to normalize. See :func:`~pathspec.util.normalize_file` for more information. Returns an :class:`~collections.abc.Iterator` yielding each file check result (:class:`~pathspec.util.CheckResult`). files: is not an iterable.N)r TypeErrorrrrr>r)r!rDr< use_patterns orig_filer@rArBs r" check_fileszPathSpec.check_filesyss& e  VE9$89 ::' 6,0ii49$$\9=>7E Y //0sA(A*rooton_error follow_linksc#rKtj|||}|j|Ed{y7w)a Walks the specified root path for all files and checks them against this path-spec. *root* (:class:`str` or :class:`os.PathLike`) is the root directory to search for files. *on_error* (:class:`~collections.abc.Callable` or :data:`None`) optionally is the error handler for file-system exceptions. It will be called with the exception (:exc:`OSError`). Reraise the exception to abort the walk. Default is :data:`None` to ignore file-system exceptions. *follow_links* (:class:`bool` or :data:`None`) optionally is whether to walk symbolic links that resolve to directories. Default is :data:`None` for :data:`True`. *negate* (:class:`bool` or :data:`None`) is whether to negate the match results of the patterns. If :data:`True`, a pattern matching a file will exclude the file rather than include it. Default is :data:`None` for :data:`False`. Returns an :class:`~collections.abc.Iterator` yielding each file check result (:class:`~pathspec.util.CheckResult`). rMrNN)riter_tree_filesrK)r!rLrMrNrDs r"check_tree_fileszPathSpec.check_tree_filess0<   th\ R%   e $$$s -757clspattern_factorylinesct|trtj|}t |st d|dt |st d|d|Dcgc] }|s||}}||Scc}w)ai Compiles the pattern lines. *pattern_factory* can be either the name of a registered pattern factory (:class:`str`), or a :class:`~collections.abc.Callable` used to compile patterns. It must accept an uncompiled pattern (:class:`str`) and return the compiled pattern (:class:`.Pattern`). *lines* (:class:`~collections.abc.Iterable`) yields each uncompiled pattern (:class:`str`). This simply has to yield each line so that it can be a :class:`io.TextIOBase` (e.g., from :func:`open` or :class:`io.StringIO`) or the result from :meth:`str.splitlines`. Returns the :class:`PathSpec` instance. zpattern_factory:z is not callable.zlines:rG)rstrrlookup_patterncallablerHr)rSrTrUliners r" from_lineszPathSpec.from_liness*%((9? / " %o%88IJ KK e  VE9$89 ::05 >od# >( > X?s A:& A:negateentriesr]c#Kt|std|dt|j}|D]9}t |j |}|j ||\}}|r| }|s6|;yw)a Matches the entries to this path-spec. *entries* (:class:`~collections.abc.Iterable` of :class:`~pathspec.util.TreeEntry`) contains the entries to be matched against :attr:`self.patterns `. *separators* (:class:`~collections.abc.Collection` of :class:`str`; or :data:`None`) optionally contains the path separators to normalize. See :func:`~pathspec.util.normalize_file` for more information. *negate* (:class:`bool` or :data:`None`) is whether to negate the match results of the patterns. If :data:`True`, a pattern matching a file will exclude the file rather than include it. Default is :data:`None` for :data:`False`. Returns the matched entries (:class:`~collections.abc.Iterator` of :class:`~pathspec.util.TreeEntry`). zentries:rGN)rrHrrrpathr>) r!r^r<r]rIentryr@rA_indexs r" match_entrieszPathSpec.match_entriessz2 g  Xg[(<= >>' 6,eejj*59%%lI>?7F kG Ks A'A1*A1ct||}|jt|j|\}}t |S)a Matches the file to this path-spec. *file* (:class:`str` or :class:`os.PathLike`) is the file path to be matched against :attr:`self.patterns `. *separators* (:class:`~collections.abc.Collection` of :class:`str`) optionally contains the path separators to normalize. See :func:`~pathspec.util.normalize_file` for more information. Returns :data:`True` if *file* matched; otherwise, :data:`False`. )rr>r?rbool)r!r;r<r@rArbs r" match_filezPathSpec.match_files9"T:.)$$Yt}}%=yI/'6 gr$c#Kt|std|dt|j}|D]/}t ||}|j ||\}}|r| }|s,|1yw)a  Matches the files to this path-spec. *files* (:class:`~collections.abc.Iterable` of :class:`str` or :class:`os.PathLike`) contains the file paths to be matched against :attr:`self.patterns `. *separators* (:class:`~collections.abc.Collection` of :class:`str`; or :data:`None`) optionally contains the path separators to normalize. See :func:`~pathspec.util.normalize_file` for more information. *negate* (:class:`bool` or :data:`None`) is whether to negate the match results of the patterns. If :data:`True`, a pattern matching a file will exclude the file rather than include it. Default is :data:`None` for :data:`False`. Returns the matched files (:class:`~collections.abc.Iterator` of :class:`str` or :class:`os.PathLike`). rFrGN)rrHrrrr>) r!rDr<r]rIrJr@rArbs r" match_fileszPathSpec.match_filessv4 e  VE9$89 ::' 6,ii49%%lI>?7F kG Os AA' A'c#vKtj|||}|j||Ed{y7w)a Walks the specified root path for all files and matches them to this path-spec. *root* (:class:`str` or :class:`os.PathLike`) is the root directory to search. *on_error* (:class:`~collections.abc.Callable` or :data:`None`) optionally is the error handler for file-system exceptions. It will be called with the exception (:exc:`OSError`). Reraise the exception to abort the walk. Default is :data:`None` to ignore file-system exceptions. *follow_links* (:class:`bool` or :data:`None`) optionally is whether to walk symbolic links that resolve to directories. Default is :data:`None` for :data:`True`. *negate* (:class:`bool` or :data:`None`) is whether to negate the match results of the patterns. If :data:`True`, a pattern matching a file will exclude the file rather than include it. Default is :data:`None` for :data:`False`. Returns the matched files (:class:`~collections.abc.Iterator` of :class:`.TreeEntry`). rPr\N)riter_tree_entriesrc)r!rLrMrNr]r^s r"match_tree_entrieszPathSpec.match_tree_entriesBs6@  " "4( V'     777 /979c#vKtj|||}|j||Ed{y7w)a Walks the specified root path for all files and matches them to this path-spec. *root* (:class:`str` or :class:`os.PathLike`) is the root directory to search for files. *on_error* (:class:`~collections.abc.Callable` or :data:`None`) optionally is the error handler for file-system exceptions. It will be called with the exception (:exc:`OSError`). Reraise the exception to abort the walk. Default is :data:`None` to ignore file-system exceptions. *follow_links* (:class:`bool` or :data:`None`) optionally is whether to walk symbolic links that resolve to directories. Default is :data:`None` for :data:`True`. *negate* (:class:`bool` or :data:`None`) is whether to negate the match results of the patterns. If :data:`True`, a pattern matching a file will exclude the file rather than include it. Default is :data:`None` for :data:`False`. Returns the matched files (:class:`~collections.abc.Iterable` of :class:`str`). rPr\N)rrQrh)r!rLrMrNr]rDs r"match_tree_fileszPathSpec.match_tree_fileses6@   th\ R%   eF  333rlr()NN)+__name__ __module__ __qualname____doc__rrr#objectrer1intr4rr8r:rr rrWrrCrrKrrOSErrorrR classmethodr r rr[rrc staticmethodrcheck_match_filer>rfrhrkrn match_treer)r$r"rr'sH hw/D  D c4 t D   +/++z#'+( +0+/0 ( 0z#'0{8$% 0>37!% %% Xwio. /% % {3 %B Dzhx'899: &  F+/%  % I %z#'% 4. % y %ND112+/z#' 0+/&  & ' &z#'& 4. & w &V37!% !8  !8!8 Xwio. /!8 !8 4. !8y!8L37!% !4  !4!4 Xwio. /!4 !4 4. !4sm!4Jr$N)rrcollections.abcrr itertoolsrtypingrrrrr r r r rpatternrrrrrrrrrrsrr)r$r"rs]    vZ( cvcr$