
    \jA                       d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 ddl
mZmZmZmZmZmZmZmZ  edd      Z	 dd	lmZ dd
lmZmZmZ ddlmZ ddlmZ ddlmZ ddl m!Z!m"Z" ddl#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+  G d dee'         Z,y)zn
This module provides :class:`.PathSpec` which is an object-oriented interface
for pattern matching of files.
    )annotations)
CollectionIterableIteratorSequence)zip_longest)CallableGenericLiteralOptionalTypeVarUnioncastoverloadSelfPathSpec)bound)util)BackendNamesHint_Backend_TestBackendFactoryHintmake_pathspec_backend)Pattern)GitIgnoreBasicPattern)AnyStr
deprecated)CheckResultStrPathTPatternTPattern_coTStrPath	TreeEntry_is_iterablenormalize_filec                     e Zd ZdZddd	 	 	 	 	 	 	 ddZddZddZddZddZdd	Z		 d 	 	 	 	 	 d!d
Z
	 d 	 	 	 	 	 d"dZ	 	 d#	 	 	 	 	 	 	 d$dZeeddd	 	 	 	 	 	 	 	 	 	 	 d%d              Zeeddd	 	 	 	 	 	 	 	 	 	 	 d&d              Zeeddd	 	 	 	 	 	 	 	 	 	 	 d'd              Zeeddd	 	 	 	 	 	 	 	 	 	 	 d(d              Zeddd	 	 	 	 	 	 	 	 	 	 	 d)d       Ze	 	 	 	 	 	 d*d       Z	 d dd	 	 	 	 	 	 	 d+dZ	 d 	 	 	 	 	 d,dZ	 d dd	 	 	 	 	 	 	 d-dZ	 	 d#dd	 	 	 	 	 	 	 	 	 d.dZ ed      d/d       Z	 	 d#dd	 	 	 	 	 	 	 	 	 d0dZy)1r   zd
	The :class:`PathSpec` class is a wrapper around a list of compiled
	:class:`.Pattern` instances.
	Nbackend_test_backend_factoryc                   t        |t              r|}nt        |      }|d}t        t        |      }|	 ||      }n| j                  ||      }|| _        	 || _        	 || _        y)a  
		Initializes the :class:`.PathSpec` instance.

		*patterns* (:class:`~collections.abc.Sequence` or :class:`~collections.abc.Iterable`)
		contains each compiled pattern (:class:`.Pattern`). If not a sequence, it
		will be converted to a :class:`list`.

		*backend* (:class:`str` or :data:`None`) is the pattern (regular expression)
		matching backend to use. Default is :data:`None` for "best" to use the best
		available backend. Priority of backends is: "re2", "hyperscan", "simple".
		The "simple" backend is always available.
		Nbest)	
isinstancer   listr   r   _make_backend_backend_backend_namepatterns)selfr1   r(   r)   use_patternsbackend_nameuse_backends          ;/root/env/lib/python3.12/site-packages/pathspec/pathspec.py__init__zPathSpec.__init__=   s~    & (#<x.<_7&0,&&|4;##L,?;'$-
 *6$ *6$-    c                h    | j                   j                   d| j                  d| j                  dS )z7
		Returns a debug representation of this path-spec.
		z
(patterns=z
, backend=))	__class____name__r1   r0   r2   s    r6   __repr__zPathSpec.__repr__o   s5     NN##$Jt}}.?z$J\J\I__`	aar8   c                    t        |t              r5| j                  g | j                  |j                  | j                        S t
        S )zn
		Combines the :attr:`self.patterns <.PathSpec.patterns>` patterns from two
		:class:`PathSpec` instances.
		)r(   )r,   r   r;   r1   r0   NotImplementedr2   others     r6   __add__zPathSpec.__add__u   s@    
 x 
..:4==:5>>:DDVDV.
WW
r8   c                    t        |t              r2t        | j                  |j                        }t	        d |D              S t
        S )z
		Tests the equality of this path-spec with *other* (:class:`PathSpec`) by
		comparing their :attr:`self.patterns <.PathSpec.patterns>` attributes.
		c              3  ,   K   | ]  \  }}||k(    y wN ).0abs      r6   	<genexpr>z"PathSpec.__eq__.<locals>.<genexpr>   s     1Aa1f1s   )r,   r   r   r1   allr@   )r2   rB   paired_patternss      r6   __eq__zPathSpec.__eq__   s9    
 x  ??
11
11
r8   c                    t        |t              rLg | j                  |j                  | _        | j                  | j                  | j                        | _        | S t        S )zn
		Adds the :attr:`self.patterns <.PathSpec.patterns>` from *other*
		(:class:`PathSpec`) to this instance.
		)r,   r   r1   r.   r0   r/   r@   rA   s     r6   __iadd__zPathSpec.__iadd__   sP    
 x 4T]]4U^^44=%%d&8&8$--H4=
;
r8   c                ,    t        | j                        S )zp
		Returns the number of :attr:`self.patterns <.PathSpec.patterns>` this
		path-spec contains (:class:`int`).
		)lenr1   r=   s    r6   __len__zPathSpec.__len__   s    
 
T]]	r8   c                p    t        ||      }| j                  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 <.PathSpec.patterns>`.

		*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 the file check result (:class:`.CheckResult`).
		)r%   r/   
match_filer   )r2   file
separators	norm_fileincludeindexs         r6   
check_filezPathSpec.check_file   s7    " T:.)==++I6.'5	T7E	**r8   c              #     K   t        |      st        d|d      |D ];  }t        ||      }| j                  j	                  |      \  }}t        |||       = yw)a  
		Check the files against this path-spec.

		*files* (:class:`~collections.abc.Iterable` of :class:`str` or
		:class:`os.PathLike`) contains the file paths to be checked against
		:attr:`self.patterns <.PathSpec.patterns>`.

		*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 an :class:`~collections.abc.Iterator` yielding each file check
		result (:class:`.CheckResult`).
		files: is not an iterable.N)r$   	TypeErrorr%   r/   rU   r   )r2   filesrW   	orig_filerX   rY   rZ   s          r6   check_fileszPathSpec.check_files   sg     & 
e		VE9$89	:: 0ii49MM,,Y7>7E	Y	//0s   AAc              #  r   K   t        j                  |||      }| j                  |      E d{    y7 w)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:`.CheckResult`).
		on_errorfollow_linksN)r   iter_tree_filesrb   )r2   rootre   rf   r`   s        r6   check_tree_fileszPathSpec.check_tree_files   s0     < 

th\
R%e$$$s   -757c                    y rF   rG   clspattern_factorylinesr(   r)   s        r6   
from_lineszPathSpec.from_lines        r8   c                    y rF   rG   rk   s        r6   ro   zPathSpec.from_lines   rp   r8   c                    y rF   rG   rk   s        r6   ro   zPathSpec.from_lines  rp   r8   c                    y rF   rG   rk   s        r6   ro   zPathSpec.from_lines  rp   r8   c                  t        |t              rt        j                  |      }nt	        |      r|}nt        d|d      t        |      st        d|d      |D cg c]  }|s ||       }} | |||      }|S c c}w )a  
		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`.

		*backend* (:class:`str` or :data:`None`) is the pattern (or regular
		expression) matching backend to use. Default is :data:`None` for "best" to
		use the best available backend. Priority of backends is: "re2", "hyperscan",
		"simple". The "simple" backend is always available.

		Returns the :class:`PathSpec` instance.
		zpattern_factory:z is not callable.zlines:r^   r'   )r,   strr   lookup_patterncallabler_   r$   )	rl   rm   rn   r(   r)   use_factory_PathSpec__liner1   r2   s	            r6   ro   zPathSpec.from_lines  s    < %$$_5;  ;	%o%88IJ	KK	e		VE9$89	::05@fk&!@(@	Xw>S	T$	+ As   "B*
Bc                    t        | |      S )aM  
		.. warning:: This method is not part of the public API. It is subject to
			change.

		Create the backend for the patterns.

		*name* (:class:`str`) is the name of the backend.

		*patterns* (:class:`~collections.abc.Sequence` of :class:`.Pattern`)
		contains the compiled patterns.

		Returns the matcher (:class:`._Backend`).
		r   )namer1   s     r6   r.   zPathSpec._make_backendJ  s    $ 
tX	..r8   negatec             #     K   t        |      st        d|d      |D ]B  }t        |j                  |      }| j                  j                  |      \  }}|r| }|s?| D yw)a  
		Matches the entries to this path-spec.

		*entries* (:class:`~collections.abc.Iterable` of :class:`.TreeEntry`)
		contains the entries to be matched against :attr:`self.patterns <.PathSpec.patterns>`.

		*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.

		*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:`.TreeEntry`).
		zentries:r^   N)r$   r_   r%   pathr/   rU   )r2   entriesrW   r}   entryrX   rY   _indexs           r6   match_entrieszPathSpec.match_entries^  sn     2 
g		Xg[(<=	>> eejj*59]]--i8?7FkG
Ks   AA%A%c                l    t        ||      }| j                  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 <.PathSpec.patterns>`.

		*separators* (:class:`~collections.abc.Collection` of :class:`str`)
		optionally contains the path separators to normalize. See
		:func:`.normalize_file` for more information.

		Returns :data:`True` if *file* matched; otherwise, :data:`False`.
		)r%   r/   rU   bool)r2   rV   rW   rX   rY   r   s         r6   rU   zPathSpec.match_file  s2    " T:.)MM,,Y7/'6	gr8   c             #     K   t        |      st        d|d      |D ]8  }t        ||      }| j                  j	                  |      \  }}|r| }|s5| : yw)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 <.PathSpec.patterns>`.

		*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.

		*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`).
		r]   r^   N)r$   r_   r%   r/   rU   )r2   r`   rW   r}   ra   rX   rY   r   s           r6   match_fileszPathSpec.match_files  sj     4 
e		VE9$89	:: ii49]]--i8?7FkG
Os   AAAc             #  v   K   t        j                  |||      }| j                  ||      E d{    y7 w)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`).
		rd   r|   N)r   iter_tree_entriesr   )r2   rh   re   rf   r}   r   s         r6   match_tree_entrieszPathSpec.match_tree_entries  s6     @ ""4(V'777   /979zEPathSpec.match_tree() is deprecated. Use .match_tree_files() instead.c                &     | j                   |i |S )z
		.. version-deprecated:: 0.3.2
			This is an alias for the :meth:`self.match_tree_files <.PathSpec.match_tree_files>`
			method.
		)match_tree_files)r2   argskws      r6   
match_treezPathSpec.match_tree  s     
			+	++r8   c             #  v   K   t        j                  |||      }| j                  ||      E d{    y7 w)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`).
		rd   r|   N)r   rg   r   )r2   rh   re   rf   r}   r`   s         r6   r   zPathSpec.match_tree_files  s5     > 

th\
R%eF333r   )r1   z3Union[Sequence[TPattern_co], Iterable[TPattern_co]]r(   "Union[BackendNamesHint, str, None]r)   r   returnNone)r   ru   )r2   r   rB   r   r   r   )rB   objectr   r   )r   intrF   )rV   r"   rW   Optional[Collection[str]]r   zCheckResult[TStrPath])r`   Iterable[TStrPath]rW   r   r   zIterator[CheckResult[TStrPath]])NN)rh   r   re   #Optional[Callable[[OSError], None]]rf   Optional[bool]r   zIterator[CheckResult[str]])rl   type[PathSpec]rm   zLiteral['gitignore']rn   Iterable[AnyStr]r(   r   r)   r   r   zPathSpec[GitIgnoreBasicPattern])rl   r   rm   ru   rn   r   r(   r   r)   r   r   zPathSpec[Pattern])rl   r   rm   ztype[TPattern]rn   r   r(   r   r)   r   r   PathSpec[TPattern])rl   r   rm   zCallable[[AnyStr], TPattern]rn   r   r(   r   r)   r   r   r   )rl   z
type[Self]rm   z6Union[str, type[Pattern], Callable[[AnyStr], Pattern]]rn   r   r(   r   r)   r   r   r   )r{   r   r1   zSequence[Pattern]r   r   )r   zIterable[TreeEntry]rW   r   r}   r   r   Iterator[TreeEntry])rV   r   rW   r   r   r   )r`   r   rW   r   r}   r   r   zIterator[TStrPath])
rh   r   re   r   rf   r   r}   r   r   r   )r   Iterator[str])
rh   r   re   r   rf   r   r}   r   r   r   )r<   
__module____qualname____doc__r7   r>   rC   rN   rP   rS   r[   rb   ri   r   classmethodro   staticmethodr.   r   rU   r   r   r   r   r   rG   r8   r6   r   r   7   s    15370?0 .	0
 10 0db	
 +/++ (+ 	+0 +/0	0 (0 &	0< 37!%	%% 0% 	%
 !%B  1537' 

 . 1 &    1537 

 . 1     1537! 

 . 1     1537/ 

 . 1     1537))I) 
)
 .) 1) ) )V /// / /, +/$
  $$ ($
 $ $R +/ ( 	0 +/%
  %	% (%
 % %T 37!%	!8  !8!8 0!8 	!8 !8 !8H I,, 37!%	 4   4 4 0 4 	 4  4  4r8   N)-r   
__future__r   collections.abcr   r   r   r   	itertoolsr   typingr	   r
   r   r   r   r   r   r   r   pathspecr   pathspec.backendr   r   r   pathspec._backends.aggr   pathspec.patternr   !pathspec.patterns.gitignore.basicr   pathspec._typingr   r   pathspec.utilr   r   r    r!   r"   r#   r$   r%   r   rG   r8   r6   <module>r      s    # 
   vZ(
  
  X4w{# X4r8   