
    W-Ph3                         d Z ddl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mZ ddlmZ ddlmZ ddlmZmZmZmZmZmZmZ  ed	d
          Z	  G d d
e          ZdS )zR
This module provides an object oriented interface for pattern matching of files.
    )
Collection)zip_longest)	AnyStrCallabler   IterableIteratorOptionalTypeTypeVarUnion   )util)Pattern)CheckResultStrPathTStrPath	TreeEntry_filter_check_patterns_is_iterablenormalize_fileSelfPathSpec)boundc                      e Zd ZdZdee         ddfdZdedefdZ	de
fdZd	edd defd
Zd	edd defdZ	 d!dedeee                  dee         fdZ	 d!dee         deee                  deee                  fdZ	 	 d"dedeeegdf                  dee         deee                  fdZedee         deeeegef         f         dee         defd            Z	 d!dddee          deee                  dee         dee          fdZ! e"e#j$                  Z%	 	 d!dedeee                  defdZ&	 d!dddee         deee                  dee         dee         fdZ'	 	 d"dddedeeegdf                  dee         dee         dee          f
dZ(	 	 d"dddedeeegdf                  dee         dee         dee         f
d Z)e)Z*dS )#r   zd
	The :class:`PathSpec` class is a wrapper around a list of compiled
	:class:`.Pattern` instances.
	patternsreturnNc                 \    t          |t                    st          |          }|| _        dS )z
		Initializes the :class:`PathSpec` instance.

		*patterns* (:class:`~collections.abc.Collection` or :class:`~collections.abc.Iterable`)
		yields each compiled pattern (:class:`.Pattern`).
		N)
isinstanceCollectionTypelistr   )selfr   s     Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pathspec/pathspec.py__init__zPathSpec.__init__-   s2     
Hn	-	- 8nn8'/$-     otherc                     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:`~PathSpec.patterns` attributes.
		c              3   (   K   | ]\  }}||k    V  d S N ).0abs      r"   	<genexpr>z"PathSpec.__eq__.<locals>.<genexpr>D   s*      11Aa1f111111r$   )r   r   r   r   allNotImplemented)r!   r%   paired_patternss      r"   __eq__zPathSpec.__eq__=   sL    
 x    ???
11111
1
11
r$   c                 *    t          | j                  S )zW
		Returns the number of compiled patterns this path-spec contains
		(:class:`int`).
		)lenr   )r!   s    r"   __len__zPathSpec.__len__H   s    
 
T]		r$   r!   c                 ~    t          |t                    r"|                     | j        |j        z             S t          S )z]
		Combines the :attr:`Pathspec.patterns` patterns from two
		:class:`PathSpec` instances.
		)r   r   	__class__r   r/   r!   r%   s     r"   __add__zPathSpec.__add__O   s7    
 x   
..7
8
88
r$   c                 h    t          |t                    r| xj        |j        z  c_        | S t          S )zi
		Adds the :attr:`Pathspec.patterns` patterns from one :class:`PathSpec`
		instance to this instance.
		)r   r   r   r/   r7   s     r"   __iadd__zPathSpec.__iadd__Y   s3    
 x   ==EN"==
;
r$   file
separatorsc                     t          ||          }|                     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:`~pathspec.util.normalize_file` for more information.

		Returns the file check result (:class:`~pathspec.util.CheckResult`).
		)r   _match_file	enumerater   r   )r!   r;   r<   	norm_fileincludeindexs         r"   
check_filezPathSpec.check_filed   sH    " T:..)##Idm$<$<iHH.'5	T7E	*	**r$   filesc              #      K   t          |          st          d|d          t          | j                  }|D ]>}t	          ||          }|                     ||          \  }}t          |||          V  ?d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:`~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   	TypeErrorr   r   r   r>   r   )r!   rD   r<   use_patterns	orig_filer@   rA   rB   s           r"   check_fileszPathSpec.check_filesy   s      & 
e		 ;	9E999	:	::'66, 0 0ii449$$\9==>7E	Y	/	/////0 0r$   rooton_errorfollow_linksc              #   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:`~pathspec.util.CheckResult`).
		rM   rN   N)r   iter_tree_filesrK   )r!   rL   rM   rN   rD   s        r"   check_tree_fileszPathSpec.check_tree_files   sK      < 
th\
R
R
R%e$$$$$$$$$$$r$   clspattern_factorylinesc                    t          t                    rt          j                  t	                    st          dd          t          |          st          d|d          fd|D             } | |          S )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.
		zpattern_factory:z is not callable.zlines:rG   c                 *    g | ]}| |          S r)   r)   )r*   linerT   s     r"   
<listcomp>z'PathSpec.from_lines.<locals>.<listcomp>   s(    >>>>ood##>>>r$   )r   strr   lookup_patterncallablerH   r   )rS   rT   rU   r   s    `  r"   
from_lineszPathSpec.from_lines   s    * %% :(99?	/	"	" L	JoJJJ	K	KK	e		 ;	9E999	:	::>>>>>>>(	Xr$   negateentriesr_   c             #      K   t          |          st          d|d          t          | j                  }|D ];}t	          |j        |          }|                     ||          \  }}|r| }|r|V  <dS )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 <PathSpec.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`).
		zentries:rG   N)r   rH   r   r   r   pathr>   )	r!   r`   r<   r_   rI   entryr@   rA   _indexs	            r"   match_entrieszPathSpec.match_entries   s      2 
g		 ?	=g===	>	>>'66,  eej*559%%lI>>?7F kG 
KKK r$   c                     t          ||          }|                     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:`~pathspec.util.normalize_file` for more information.

		Returns :data:`True` if *file* matched; otherwise, :data:`False`.
		)r   r>   r?   r   bool)r!   r;   r<   r@   rA   rd   s         r"   
match_filezPathSpec.match_file  sB    " T:..)$$Yt}%=%=yII/'6	gr$   c             #      K   t          |          st          d|d          t          | j                  }|D ]6}t	          ||          }|                     ||          \  }}|r| }|r|V  7d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:`~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`).
		rF   rG   N)r   rH   r   r   r   r>   )	r!   rD   r<   r_   rI   rJ   r@   rA   rd   s	            r"   match_fileszPathSpec.match_files  s      4 
e		 ;	9E999	:	::'66,  ii449%%lI>>?7F kG 
OOO r$   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`).
		rP   r^   N)r   iter_tree_entriesre   )r!   rL   rM   rN   r_   r`   s         r"   match_tree_entrieszPathSpec.match_tree_entriesB  sQ      @ "4(VVV'77777777777r$   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`).
		rP   r^   N)r   rQ   rj   )r!   rL   rM   rN   r_   rD   s         r"   match_tree_fileszPathSpec.match_tree_filese  sQ      @ 
th\
R
R
R%eF33333333333r$   r(   )NN)+__name__
__module____qualname____doc__r   r   r#   objectrg   r1   intr4   r   r8   r:   r   r	   r   rZ   r   rC   r   rK   r   r   OSErrorrR   classmethodr
   r   r   r]   r   re   staticmethodr   check_match_filer>   rh   rj   rm   ro   
match_treer)   r$   r"   r   r   '   sf        
hw/ D     	 	D 	 	 	 	c    4 
 t    	D 	 	 	 	 	 	 +/+ ++ z#'+ (	+ + + +0 +/0 0	(	0 z#'0 {8$%	0 0 0 0> 37!%	% %% Xwio./% 	%
 {3 % % % %B Dzhx'899: 
&	 	   +F +/%
  % % %I% z#'%
 4.% y% % % %N |D122 +/  z#' 	   0 +/&
  & & &	'	& z#'&
 4.& w& & & &V 37!%	!8  !8 !8 !8!8 Xwio./!8 	!8 4.!8 y!8 !8 !8 !8L 37!%	!4  !4 !4 !4!4 Xwio./!4 	!4 4.!4 sm!4 !4 !4 !4J r$   N)rs   collections.abcr   r   	itertoolsr   typingr   r   r   r   r	   r
   r   r    r   patternr   r   r   r   r   r   r   r   r   rt   r   r)   r$   r"   <module>r      s             	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	      
 
 
 
 
 
                  wvZ(((c c c c cv c c c c cr$   