
    ni/;                        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%dS )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dDdZdEdZdFdZdEdZdGdZ	 dHdIdZ		 dHdJd Z
	 	 dKdLd(ZeddddMd/            ZedNd4            Z	 dHdd5dOd:Z	 dHdPd;Z	 dHdd5dQd>Z	 	 dKdd5dRd?Z ed@          dSdB            Z	 	 dKdd5dTdCZdS )Ur   zd
	The :class:`PathSpec` class is a wrapper around a list of compiled
	:class:`.Pattern` instances.
	Nbackend_test_backend_factorypatterns+Union[Sequence[Pattern], Iterable[Pattern]]r!   "Union[BackendNamesHint, str, None]r"   1Optional[Callable[[Sequence[Pattern]], _Backend]]returnNonec                   t          |t                    st          |          }|d}t          t          |          }| ||          }n|                     ||          }|| _        	 || _        	 || _        dS )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_namer#   )selfr#   r!   r"   use_backends        N/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/pathspec/pathspec.py__init__zPathSpec.__init__5   s    & 
Hh	'	' 8nn8_7!7++'&&&x00;;##GX66;'$-
 *1$ &.$-     r0   r   otherc                    t          |t                    r)|                     | 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r0   r5   s     r2   __add__zPathSpec.__add__e   s>    
 x   
..7AS.
T
TT
r4   objectboolc                    t          |t                    r3t          | 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    V  d S N ).0abs      r2   	<genexpr>z"PathSpec.__eq__.<locals>.<genexpr>v   s*      11Aa1f111111r4   )r+   r   r   r#   allr8   )r0   r5   paired_patternss      r2   __eq__zPathSpec.__eq__o   sL    
 x    ???
11111
1
11
r4   c                    t          |t                    r<| xj        |j        z  c_        |                     | 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.   r8   r9   s     r2   __iadd__zPathSpec.__iadd__z   sO    
 x   ==EN"==%%d&8$-HH4=
;
r4   intc                *    t          | j                  S )zp
		Returns the number of :attr:`self.patterns <.PathSpec.patterns>` this
		path-spec contains (:class:`int`).
		)lenr#   )r0   s    r2   __len__zPathSpec.__len__   s    
 
T]		r4   filer   
separatorsOptional[Collection[str]]CheckResult[TStrPath]c                ~    t          ||          }| 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   )r0   rN   rO   	norm_fileincludeindexs         r2   
check_filezPathSpec.check_file   s>    " T:..)=++I66.'5	T7E	*	**r4   filesIterable[TStrPath]Iterator[CheckResult[TStrPath]]c              #     K   t          |          st          d|d          |D ]B}t          ||          }| j                            |          \  }}t          |||          V  CdS )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.   rS   r   )r0   rX   rO   	orig_filerT   rU   rV   s          r2   check_fileszPathSpec.check_files   s      & 
e		 ;	9E999	:	:: 0 0ii449M,,Y77>7E	Y	/	/////0 0r4   rootr   on_error#Optional[Callable[[OSError], None]]follow_linksOptional[bool]Iterator[CheckResult[str]]c              #  n   K   t          j        |||          }|                     |          E d{V  dS )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`).
		rb   rd   N)r   iter_tree_filesr`   )r0   ra   rb   rd   rX   s        r2   check_tree_fileszPathSpec.check_tree_files   sK      < 
th\
R
R
R%e$$$$$$$$$$$r4   cls
type[Self]pattern_factory'Union[str, Callable[[AnyStr], Pattern]]linesIterable[AnyStr]c                  t          t                    rt          j                  t	                    st          dd          t          |          st          d|d          fd|D             } | |||          S )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]   c                *    g | ]}| |          S r@   r@   )rA   linerm   s     r2   
<listcomp>z'PathSpec.from_lines.<locals>.<listcomp>  s(    >>>>ood##>>>r4   r    )r+   strr   lookup_patterncallabler^   r   )rk   rm   ro   r!   r"   r#   s    `    r2   
from_lineszPathSpec.from_lines   s    : %% :(99?	/	"	" L	JoJJJ	K	KK	e		 ;	9E999	:	::>>>>>>>(	Xw>S	T	T	TTr4   namer   Sequence[Pattern]r   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   )ry   r#   s     r2   r-   zPathSpec._make_backend  s    $ 
tX	.	..r4   negateentriesIterable[TreeEntry]r}   Iterator[TreeEntry]c             #     K   t          |          st          d|d          |D ]?}t          |j        |          }| j                            |          \  }}|r| }|r|V  @dS )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.   rS   )r0   r~   rO   r}   entryrT   rU   _indexs           r2   match_entrieszPathSpec.match_entries  s      2 
g		 ?	=g===	>	>>  eej*559]--i88?7F kG 
KKK r4   c                z    t          ||          }| 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.   rS   r<   )r0   rN   rO   rT   rU   r   s         r2   rS   zPathSpec.match_fileA  s8    " T:..)M,,Y77/'6	gr4   Iterable[StrPath]Iterator[StrPath]c             #     K   t          |          st          d|d          |D ]:}t          ||          }| j                            |          \  }}|r| }|r|V  ;dS )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.   rS   )r0   rX   rO   r}   r_   rT   rU   r   s           r2   match_fileszPathSpec.match_filesV  s      4 
e		 ;	9E999	:	::  ii449]--i88?7F kG 
OOO r4   c             #  r   K   t          j        |||          }|                     ||          E d{V  dS )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`).
		rh   r|   N)r   iter_tree_entriesr   )r0   ra   rb   rd   r}   r~   s         r2   match_tree_entrieszPathSpec.match_tree_entries}  sQ      @ "4(VVV'77777777777r4   zEPathSpec.match_tree() is deprecated. Use .match_tree_files() instead.Iterator[str]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)r0   argskws      r2   
match_treezPathSpec.match_tree  s     
		+	+	++r4   c             #  r   K   t          j        |||          }|                     ||          E d{V  dS )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`).
		rh   r|   N)r   ri   r   )r0   ra   rb   rd   r}   rX   s         r2   r   zPathSpec.match_tree_files  sP      > 
th\
R
R
R%eF33333333333r4   )r#   r$   r!   r%   r"   r&   r'   r(   )r0   r   r5   r   r'   r   )r5   r;   r'   r<   )r'   rJ   r?   )rN   r   rO   rP   r'   rQ   )rX   rY   rO   rP   r'   rZ   )NN)ra   r   rb   rc   rd   re   r'   rf   )rk   rl   rm   rn   ro   rp   r!   r%   r"   r&   r'   r   )ry   r   r#   rz   r'   r   )r~   r   rO   rP   r}   re   r'   r   )rN   r   rO   rP   r'   r<   )rX   r   rO   rP   r}   re   r'   r   )
ra   r   rb   rc   rd   re   r}   re   r'   r   )r'   r   )
ra   r   rb   rc   rd   re   r}   re   r'   r   )__name__
__module____qualname____doc__r3   r:   rG   rI   rM   rW   r`   rj   classmethodrx   staticmethodr-   r   rS   r   r   r   r   r   r@   r4   r2   r   r   /   sY         15MQ. . . . . .`   	 	 	 	
 
 
 
    +/+ + + + +0 +/0 0 0 0 0< 37!%	% % % % %B  15MQ&U &U &U &U &U +&UP / / / ,/, +/$
  $ $ $ $ $ $R +/    0 +/%
  % % % % % %T 37!%	!8  !8 !8 !8 !8 !8 !8H *I , , , , 37!%	 4   4  4  4  4  4  4  4  4r4   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   r@   r4   r2   <module>r      s    # " " " " "           
                   wvZ(((
                  
 
 
 
 
 
                      ]4 ]4 ]4 ]4 ]4v ]4 ]4 ]4 ]4 ]4r4   