
    0yi/;                        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  edd      Z	 dd	lmZ dd
lmZ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#  G d d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OptionalTypeVarUnioncastSelfPathSpec)bound)util)_BackendBackendNamesHintmake_pathspec_backend)Pattern)AnyStr
deprecated)CheckResultStrPath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d	Z		 d	 	 	 	 	 dd
Z
	 	 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	 	 	 	 	 	 	 	 	 d&dZy)'r   zd
	The :class:`PathSpec` class is a wrapper around a list of compiled
	:class:`.Pattern` instances.
	Nbackend_test_backend_factoryc                   t        |t              s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)selfr*   r!   r"   use_backends        S/var/www/html/content_weaver/venv/lib/python3.12/site-packages/pathspec/pathspec.py__init__zPathSpec.__init__5   sy    & 
Hh	'8n8_7!7+'&&x0;##GX6;'$-
 *1$ &.$-    c                    t        |t              r4| j                  | j                  |j                  z   | j                        S t
        S )zn
		Combines the :attr:`self.patterns <.PathSpec.patterns>` patterns from two
		:class:`PathSpec` instances.
		)r!   )r%   r   	__class__r*   r)   NotImplementedr+   others     r-   __add__zPathSpec.__add__e   s:    
 x 
..7ASAS.
TT
r/   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      r-   	<genexpr>z"PathSpec.__eq__.<locals>.<genexpr>v   s     1Aa1f1s   )r%   r   r   r*   allr2   )r+   r4   paired_patternss      r-   __eq__zPathSpec.__eq__o   s9    
 x  ??
11
11
r/   c                    t        |t              rL| xj                  |j                  z  c_        | j                  | j                  | j                        | _        | S t        S )zn
		Adds the :attr:`self.patterns <.PathSpec.patterns>` from *other*
		(:class:`PathSpec`) to this instance.
		)r%   r   r*   r'   r)   r(   r2   r3   s     r-   __iadd__zPathSpec.__iadd__z   sI    
 x ==ENN"=%%d&8&8$--H4=
;
r/   c                ,    t        | j                        S )zp
		Returns the number of :attr:`self.patterns <.PathSpec.patterns>` this
		path-spec contains (:class:`int`).
		)lenr*   )r+   s    r-   __len__zPathSpec.__len__   s    
 
T]]	r/   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   )r+   file
separators	norm_fileincludeindexs         r-   
check_filezPathSpec.check_file   s7    " T:.)==++I6.'5	T7E	**r/   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(   rG   r   )r+   filesrI   	orig_filerJ   rK   rL   s          r-   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_filesrT   )r+   rootrW   rX   rR   s        r-   check_tree_fileszPathSpec.check_tree_files   s0     < 

th\
R%e$$$s   -757c                  t        |t              rt        j                  |      }t	        |      s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:rP   r    )r%   strr   lookup_patterncallablerQ   r   )clspattern_factorylinesr!   r"   liner*   s          r-   
from_lineszPathSpec.from_lines   s    : %((9?	/	"	%o%88IJ	KK	e		VE9$89	::05>od#>(>	Xw>S	TT ?s   A=&
A=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   )namer*   s     r-   r'   zPathSpec._make_backend  s    $ 
tX	..r/   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:rP   N)r   rQ   r   pathr(   rG   )r+   entriesrI   rh   entryrJ   rK   _indexs           r-   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(   rG   bool)r+   rH   rI   rJ   rK   rm   s         r-   rG   zPathSpec.match_fileA  s2    " T:.)MM,,Y7/'6	gr/   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`).
		rO   rP   N)r   rQ   r   r(   rG   )r+   rR   rI   rh   rS   rJ   rK   rm   s           r-   match_fileszPathSpec.match_filesV  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`).
		rV   rg   N)r   iter_tree_entriesrn   )r+   rZ   rW   rX   rh   rk   s         r-   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)r+   argskws      r-   
match_treezPathSpec.match_tree  s     
			+	++r/   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`).
		rV   rg   N)r   rY   rr   )r+   rZ   rW   rX   rh   rR   s         r-   rx   zPathSpec.match_tree_files  s5     > 

th\
R%eF333rv   )r*   z+Union[Sequence[Pattern], Iterable[Pattern]]r!   "Union[BackendNamesHint, str, None]r"   1Optional[Callable[[Sequence[Pattern]], _Backend]]returnNone)r+   r   r4   r   r   r   )r4   objectr   rp   )r   intr8   )rH   r   rI   Optional[Collection[str]]r   zCheckResult[TStrPath])rR   zIterable[TStrPath]rI   r   r   zIterator[CheckResult[TStrPath]])NN)rZ   r   rW   #Optional[Callable[[OSError], None]]rX   Optional[bool]r   zIterator[CheckResult[str]])r`   z
type[Self]ra   z'Union[str, Callable[[AnyStr], Pattern]]rb   zIterable[AnyStr]r!   r}   r"   r~   r   r   )rf   r   r*   zSequence[Pattern]r   r   )rk   zIterable[TreeEntry]rI   r   rh   r   r   Iterator[TreeEntry])rH   r   rI   r   r   rp   )rR   zIterable[StrPath]rI   r   rh   r   r   zIterator[StrPath])
rZ   r   rW   r   rX   r   rh   r   r   r   )r   Iterator[str])
rZ   r   rW   r   rX   r   rh   r   r   r   )__name__
__module____qualname____doc__r.   r5   r@   rB   rE   rM   rT   r[   classmethodrd   staticmethodr'   rn   rG   rr   ru   r   r{   rx   r9   r/   r-   r   r   /   s    15MQ.7. .	.
 K. .`	
 +/++ (+ 	+0 +/0	0 (0 &	0< 37!%	%% 0% 	%
 !%B  15MQ&U&U:&U 
&U
 .&U K&U &U &UP /// / /, +/$
  $$ ($
 $ $R +/ ( 	0 +/%
  %	% (%
 % %T 37!%	!8  !8!8 0!8 	!8 !8 !8H I,, 37!%	 4   4 4 0 4 	 4  4  4r/   N)&r   
__future__r   collections.abcr   r   r   r   	itertoolsr   typingr	   r
   r   r   r   r   pathspecr   pathspec.backendr   r   pathspec._backends.aggr   pathspec.patternr   pathspec._typingr   r   pathspec.utilr   r   r   r   r   r   r   r   r9   r/   r-   <module>r      sl    # 
  vZ(
 
 ]4v ]4r/   