K iX dZddlZddlZddlZddlZddlZddlZddlZddlm Z m Z ddl mZddlmZddlmZmZmZm Z mZmZm Z mZmZmZmZmZmZmZmZddlmZej@d k\r ee!ee!fZ"nee!efZ"ed e" Z# ejHejJfDcgc]}|r|ejHk7r|c}Z& iZ' d ejPd e!fdZ)de ee*efde!d eee+ee*ffdZ, d8de ede e!dee+d ee!dffdZ-de ed eee*effdZ.ded e+fdZ/ d9de"deee0gdfdee+d edfdZ1de!de!d ee!e!fdee0gdfde+d edf d!Z2 d9de"deee0gdfdee+d ee!fd"Z3d9d#Z4d$e!d eegeffd%Z5de ede!d e+fd&Z6de ede e!d ee!fd'Z7 d8de"d(ee e!d e!fd)Z8 d8de e"d(ee e!d ee!ee"ffd*Z9 d8d$e!d+eegefd,ee+d dfd-Z:Gd.d/e;Z<Gd0d1e;Z=ed23Gd4d5ee#Z>Gd6de?Z@Gd7de?ZAycc}w):zC This module provides utility methods for dealing with path-specs. N) CollectionIterable) dataclass)PathLike)AnyAnyStrCallablerDictGenericrIteratorListOptionalSequenceSetTupleTypeVarUnion)Pattern) TStrPath)boundpathreturncbt|}|jr|tjz }|S)a5 Appends the path separator to the path if the path is a directory. This can be used to aid in distinguishing between directories and files on the file-system by relying on the presence of a trailing path separator. *path* (:class:`pathlib.Path`) is the path to use. Returns the path (:class:`str`). )stris_dirossep)rstr_paths S/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pathspec/util.pyappend_dir_sepr#Ds) IKKM bff(patternsfilecd}d}|D]2\}}|j|j|%|j}|}4||fS)a Check the file against the patterns. *patterns* (:class:`~collections.abc.Iterable`) yields each indexed pattern (:class:`tuple`) which contains the pattern index (:class:`int`) and actual pattern (:class:`~pathspec.pattern.Pattern`). *file* (:class:`str`) is the normalized file path to be matched against *patterns*. Returns a :class:`tuple` containing whether to include *file* (:class:`bool` or :data:`None`), and the index of the last matched pattern (:class:`int` or :data:`None`). Ninclude match_file)r%r& out_include out_indexindexpatterns r"check_match_filer/VsV$ $ ^UG __ W%7%7%=%I;9 Yr$files all_matches MatchDetailcXt|tr|n t|}i}|D]}|j|j |}|jrO|D]I}||vr4|r||j j |(|||j d<;t|g||<K||D]}||=|S)a Matches the files to the patterns, and returns which patterns matched the files. *patterns* (:class:`~collections.abc.Iterable` of :class:`~pathspec.pattern.Pattern`) contains the patterns to use. *files* (:class:`~collections.abc.Iterable` of :class:`str`) contains the normalized file paths to be matched against *patterns*. *all_matches* (:class:`bool` or :data:`None`) is whether to return all matches patterns (:data:`True`), or only the last matched pattern (:data:`False`). Default is :data:`None` for :data:`False`. Returns the matched files (:class:`dict`) which maps each matched file (:class:`str`) to the patterns that matched in order (:class:`.MatchDetail`). r) isinstanceCollectionTypelistr)matchr%appendr2) r%r0r1 all_files return_filesr. result_files result_filer&s r"detailed_match_filesr=rs,!7UT%[W __ -- *< oo#9 |# K ))009/6|K ))!,"-wi"8l;9 d !& r$cft|Dcgc]\}}|j||fc}}Scc}}w)a& Filters out null-patterns. *patterns* (:class:`Iterable` of :class:`.Pattern`) contains the patterns. Returns a :class:`list` containing each indexed pattern (:class:`tuple`) which contains the pattern index (:class:`int`) and the actual pattern (:class:`~pathspec.pattern.Pattern`). ) enumerater))r%__index__pats r"_filter_check_patternsrBs<"(+ gu ]] E  s-valuecTt|txrt|ttf S)z Check whether the value is an iterable (excludes strings). *value* is the value to check, Returns whether *value* is a iterable (:class:`bool`). )r4 IterableTyperbytes)rCs r" _is_iterablerGs$ 5,'O 53,0O,OOr$rooton_error follow_links TreeEntryc#K|t|std|d|d}ttjj |di||Ed{y7w)a Walks the specified directory for all files and directories. *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`. Raises :exc:`RecursionError` if recursion is detected. Returns an :class:`~collections.abc.Iterator` yielding each file or directory entry (:class:`.TreeEntry`) relative to *root*. Nz on_error: is not callable.T)callable TypeError_iter_tree_entries_nextrrabspathrHrIrJs r"iter_tree_entriesrTsX4 (!3Ih\):;<<, #BGGOOD$92r8\ ZZZsAAAA root_fulldir_relmemoc #xKtjj||}tjj|}||vr|||<nt ||||tj |5}|D]}tjj||j } |jd} |jr |j} n| } |j|r2t|j | | | t|| |||Ed{|js|jst|j | | |  ddd||=y#t$r} ||| Yd} ~  d} ~ wwxYw#t$r} ||| Yd} ~ ,d} ~ wwxYw7#1swY||=yxYww)aq Scan the directory for all descendant files. *root_full* (:class:`str`) the absolute path to the root directory. *dir_rel* (:class:`str`) the path to the directory to scan relative to *root_full*. *memo* (:class:`dict`) keeps track of ancestor directories encountered. Maps each ancestor real path (:class:`str`) to relative path (:class:`str`). *on_error* (:class:`~collections.abc.Callable` or :data:`None`) optionally is the error handler for file-system exceptions. *follow_links* (:class:`bool`) is whether to walk symbolic links that resolve to directories. Yields each entry (:class:`.TreeEntry`). ) real_path first_path second_pathF)follow_symlinksN)rrjoinrealpathRecursionErrorscandirnamestatOSError is_symlinkrrKrQis_file) rUrVrWrIrJdir_fulldir_real scan_iternode_entnode_rel node_lstate node_stats r"rQrQs6 GGLLG , GG  X &  D$x.d8nRYZZjj!DiDhggll7HMM28 u5J Y Ioolo3 HMM8Z CC&y(D(LYYYh113 HMM8Z CC?D!DP (^A   a[   qk Z;!DP (^sA0F:20F+#E'5F+FAF+F)%F+>F+ F:' F0 F:F+FF+ F& F!F+!F&&F++F70 F:c#rKt|||D]"}|j|r|j$yw)a Walks the specified directory for all files. *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`. Raises :exc:`RecursionError` if recursion is detected. Returns an :class:`~collections.abc.Iterator` yielding the path to each file (:class:`str`) relative to *root*. rIrJN)rTrr)rHrIrJentrys r"iter_tree_filesrq3s64 xlSU l # s#77cVtjdtdt|||S)zg DEPRECATED: The :func:`.iter_tree` function is an alias for the :func:`.iter_tree_files` function. zCutil.iter_tree() is deprecated. Use util.iter_tree_files() instead. stacklevelro)warningswarnDeprecationWarningrqrSs r" iter_treeryRs)  G1& xlKKr$ract|S)z Lookups a registered pattern factory by name. *name* (:class:`str`) is the name of the pattern factory. Returns the registered pattern factory (:class:`~collections.abc.Callable`). If no pattern factory is registered, raises :exc:`KeyError`. )_registered_patterns)ras r"lookup_patternr|]s T""r$cnd}|D]-}|j|j|"|j}/|S)a7 Matches the file to the patterns. *patterns* (:class:`~collections.abc.Iterable` of :class:`~pathspec.pattern.Pattern`) contains the patterns to use. *file* (:class:`str`) is the normalized file path to be matched against *patterns*. Returns :data:`True` if *file* matched; otherwise, :data:`False`. Fr()r%r&matchedr.s r"r*r*isB W __ W%7%7%=%I __7 r$ctjtdtdtd|Dcgc]}|j|}}t }|D] }t ||s|j|"|Scc}w)a DEPRECATED: This is an old function no longer used. Use the :func:`~pathspec.util.match_file` function with a loop for better results. Matches the files to the patterns. *patterns* (:class:`~collections.abc.Iterable` of :class:`~pathspec.pattern.Pattern`) contains the patterns to use. *files* (:class:`~collections.abc.Iterable` of :class:`str`) contains the normalized file paths to be matched against *patterns*. Returns the matched files (:class:`set` of :class:`str`). z".match_files() is deprecated. Use z-.match_file() with a loop for better results.rsrt)rvrw__name__rxr)setr*add)r%r0rA use_patternsr:r&s r" match_filesr}s$  J0 ; 1& %-J5 0IJJ T d#D Ks A8A8 separatorsc|t}tj|}|D]"}|j|tj }$|j dr|dd}|S|j dr|dd}|S)ay Normalizes the file path to use the POSIX path separator (i.e., ``"/"``), and make the paths relative (remove leading ``"/"``). *file* (:class:`str` or :class:`os.PathLike`) is the file path. *separators* (:class:`~collections.abc.Collection` of :class:`str`; or ``None``) optionally contains the path separators to normalize. This does not need to include the POSIX path separator (``"/"``), but including it will not affect the results. Default is ``None`` for ``NORMALIZE_PATH_SEPS``. To prevent normalization, pass an empty container (e.g., an empty tuple ``()``). Returns the normalized file path (:class:`str`). N/rz./rs)NORMALIZE_PATH_SEPSrfspathreplace posixpathr startswith)r&r norm_filer s r"normalize_filers("*))D/ 4SY]]3)4m)  4 m)r$ctjdtdi}|D].}t||}||vr||j |)|g||<0|S)a DEPRECATED: This function is no longer used. Use the :func:`.normalize_file` function with a loop for better results. Normalizes the file paths to use the POSIX path separator. *files* (:class:`~collections.abc.Iterable` of :class:`str` or :class:`os.PathLike`) contains the file paths to be normalized. *separators* (:class:`~collections.abc.Collection` of :class:`str`; or :data:`None`) optionally contains the path separators to normalize. See :func:`normalize_file` for more information. Returns a :class:`dict` mapping each normalized file path (:class:`str`) to the original file paths (:class:`list` of :class:`str` or :class:`os.PathLike`). z_util.normalize_files() is deprecated. Use util.normalize_file() with a loop for better results.rsrt)r)rvrwrxrr8)r0r norm_filesrrs r"normalize_filesrsk* $1&  "TTj9)* i% 6:i " r$pattern_factoryoverridect|tstd|dt|std|d|tvr|st |t||t|<y)aE Registers the specified pattern factory. *name* (:class:`str`) is the name to register the pattern factory under. *pattern_factory* (:class:`~collections.abc.Callable`) is used to compile patterns. It must accept an uncompiled pattern (:class:`str`) and return the compiled pattern (:class:`.Pattern`). *override* (:class:`bool` or :data:`None`) optionally is whether to allow overriding an already registered pattern under the same name (:data:`True`), instead of raising an :exc:`AlreadyRegisteredError` (:data:`False`). Default is :data:`None` for :data:`False`. zname:z is not a string.zpattern_factory:rMN)r4rrPrOr{AlreadyRegisteredError)rarrs r"register_patternrsk( 4E$!2344!$_$77HIJJ  t%9$%?@@-dr$ceZdZdZdedeegefddffd Ze defdZ e defdZ e deegeffd Z xZ S) rz| The :exc:`AlreadyRegisteredError` exception is raised when a pattern factory is registered under a name already in use. rarrNc.tt| ||y)z Initializes the :exc:`AlreadyRegisteredError` instance. *name* (:class:`str`) is the name of the registered pattern. *pattern_factory* (:class:`~collections.abc.Callable`) is the registered pattern factory. N)superr__init__)selfrar __class__s r"rzAlreadyRegisteredError.__init__s.t_Er$cPdj|j|jS)4 *message* (:class:`str`) is the error message. zG{name!r} is already registered for pattern factory:{pattern_factory!r}.)rar)formatrarrs r"messagezAlreadyRegisteredError.message s. S Y Y '' Z r$c |jdS)zB *name* (:class:`str`) is the name of the registered pattern. rargsrs r"razAlreadyRegisteredError.name*s 1r$c |jdS)za *pattern_factory* (:class:`~collections.abc.Callable`) is the registered pattern factory. rrrs r"rz&AlreadyRegisteredError.pattern_factory1 1r$)r __module__ __qualname____doc__rr rrrpropertyrrar __classcell__rs@r"rr s F  FVHg-. F F c  3   hx'89 r$rceZdZdZdedededdffd ZedefdZedefd Zedefd Z edefd Z xZ S) r_zN The :exc:`RecursionError` exception is raised when recursion is detected. rYrZr[rNc0tt| |||y)a+ Initializes the :exc:`RecursionError` instance. *real_path* (:class:`str`) is the real path that recursion was encountered on. *first_path* (:class:`str`) is the first path encountered for *real_path*. *second_path* (:class:`str`) is the second path encountered for *real_path*. N)rr_r)rrYrZr[rs r"rzRecursionError.__init__@s$&y*kJr$c |jdS)zx *first_path* (:class:`str`) is the first path encountered for :attr:`self.real_path `. rrrs r"rZzRecursionError.first_pathTrr$cfdj|j|j|jS)rzDReal path {real!r} was encountered at {first!r} and then {second!r}.)realfirstsecond)rrYrZr[rs r"rzRecursionError.message\s5 P V V      W r$c |jdS)zV *real_path* (:class:`str`) is the real path that recursion was encountered on. rrrs r"rYzRecursionError.real_pathgrr$c |jdS)zz *second_path* (:class:`str`) is the second path encountered for :attr:`self.real_path `. rsrrs r"r[zRecursionError.second_pathorr$) rrrrrrrrZrrYr[rrs@r"r_r_:s K KK K  K(   c    # r$r_T)frozencDeZdZUdZdZeed< eeed< ee ed<y) CheckResultze The :class:`CheckResult` class contains information about the file and which pattern matched it. )r&r)r-r&r)r-N) rrrr __slots__r__annotations__rboolintr$r"rrxs<   4.  r$rc*eZdZdZdZdeeddfdZy)r2z> The :class:`.MatchDetail` class contains information about r%r%rNc||_y)z Initialize the :class:`.MatchDetail` instance. *patterns* (:class:`~collections.abc.Sequence` of :class:`~pathspec.pattern.Pattern`) contains the patterns that matched the file in the order they were encountered. Nr)rr%s r"rzMatchDetail.__init__s$-r$)rrrrrrrrrr$r"r2r2s& hw/Dr$c eZdZdZdZdededejdejddf d Zdd e e de fd Z dd e e de fd Z de fd Z dd e e dejfdZy)rKzR The :class:`.TreeEntry` class contains information about a file-system entry. _lstatrar_statrarlstatrbrNcB||_ ||_ ||_ ||_y)aP Initialize the :class:`.TreeEntry` instance. *name* (:class:`str`) is the base name of the entry. *path* (:class:`str`) is the relative path of the entry. *lstat* (:class:`os.stat_result`) is the stat result of the direct entry. *stat* (:class:`os.stat_result`) is the stat result of the entry, potentially linked. Nr)rrarrrbs r"rzTreeEntry.__init__s:*!&$+ $)$) $$*r$rJc||d}|r |jn |j}tj|jS)a< Get whether the entry is a directory. *follow_links* (:class:`bool` or :data:`None`) is whether to follow symbolic links. If this is :data:`True`, a symlink to a directory will result in :data:`True`. Default is :data:`None` for :data:`True`. Returns whether the entry is a directory (:class:`bool`). T)rrrbS_ISDIRst_moderrJrms r"rzTreeEntry.is_dir5<(djjdkk) i'' ((r$c||d}|r |jn |j}tj|jS)aE Get whether the entry is a regular file. *follow_links* (:class:`bool` or :data:`None`) is whether to follow symbolic links. If this is :data:`True`, a symlink to a regular file will result in :data:`True`. Default is :data:`None` for :data:`True`. Returns whether the entry is a regular file (:class:`bool`). T)rrrbS_ISREGrrs r"rezTreeEntry.is_filerr$cTtj|jjS)zC Returns whether the entry is a symbolic link (:class:`bool`). )rbS_ISLNKrrrs r"rdzTreeEntry.is_symlinks dkk)) **r$c>|d}|r |jS|jS)a9 Get the cached stat result for the entry. *follow_links* (:class:`bool` or :data:`None`) is whether to follow symbolic links. If this is :data:`True`, the stat result of the linked file will be returned. Default is :data:`None` for :data:`True`. Returns that stat result (:class:`os.stat_result`). T)rr)rrJs r"rbzTreeEntry.stat s$<#44r$N)rrrrrrr stat_resultrrrrrerdrbrr$r"rKrKs 1) ) )  )  )  )V))$) )$)4) ++ 5htn 5 5r$r)NN)Brros.pathpathlibrrbsysrvcollections.abcrr5rrE dataclassesrrtypingrrr r r r r rrrrrrr.r version_inforStrPathrr altseprr{Pathr#rrr/r=rBrGrcrTrQrqryr|r*rrrr Exceptionrr_robjectr2rK)__seps0r"rs&    " v hsm# $ h  :W - vvryy!  ey}}$  #$ E#w,' (  8D>8C= ()> $+ G + +tn+ #}  +\ G  %W (PPP26 $ [ [ HgY_- . [~ [k [FN N N CH~N WItO $ N  N k Nf26 $ HgY_- .~c] >L # #6(G*;!< #'*#$( G   XF*.%% jo &% %T*."" jo &" #tG} "P!. .F8W,-. D>. .@,Y,^;Y;| $'(#>&2g5g5As!I