
    [d                          d Z ddl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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  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)PathLike)	AnyStrCallabler   IterableIteratorOptionalTypeTypeVarUnion   )util)Pattern)	TreeEntry_filter_patterns_is_iterable
match_file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edee         deeeegef         f         dee         defd            Z	 ddee         deee                  dee         fdZ ee          Z	 ddeeef         deee                  defdZ	 ddeeeef                  deee                  deeeef                  fdZ	 	 ddeeef         dee         dee         dee         fdZ 	 	 ddeee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                    r|n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     1lib/python3.11/site-packages/pathspec/pathspec.py__init__zPathSpec.__init__.   s.     )>BBV((X$-     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>C   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__G   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__N   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.   r6   s     r!   __iadd__zPathSpec.__iadd__X   s3    
 x   ==EN"==
;
r#   clspattern_factorylinesc                    t          t                    rt          j                  t	                    st          dd          t          |          st          d|d          fd|D             } | |          S )ad  
		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 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: is not an iterable.c                 *    g | ]}| |          S r(   r(   )r)   liner;   s     r!   
<listcomp>z'PathSpec.from_lines.<locals>.<listcomp>   s(    >>>>ood##>>>r#   )r   strr   lookup_patterncallable	TypeErrorr   )r:   r;   r<   r   s    `  r!   
from_lineszPathSpec.from_linesc   s    * %% :(99?	/	"	" L	JoJJJ	K	KK	e		 ;	9E999	:	::>>>>>>>(	Xr#   entries
separatorsc              #      K   t          |          st          d|d          t          | j                  }|D ]1}t	          |j        |          }|                     ||          r|V  2dS )a	  
		Matches the entries to this path-spec.

		*entries* (:class:`~collections.abc.Iterable` of :class:`~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.

		Returns the matched entries (:class:`~collections.abc.Iterator` of
		:class:`~util.TreeEntry`).
		zentries:r>   N)r   rE   r   r   r   path_match_file)r    rG   rH   use_patternsentry	norm_files         r!   match_entrieszPathSpec.match_entries   s      & 
g		 ?	=g===	>	>>!$-00,  eej*559
|Y// 
KKK r#   filec                 d    t          j        ||          }|                     | j        |          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`.
		)rH   )r   r   rK   r   )r    rP   rH   rN   s       r!   r   zPathSpec.match_file   s1    " !$:>>>)			$-	3	33r#   filesc              #      K   t          |          st          d|d          t          | j                  }|D ],}t	          ||          }|                     ||          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:`~pathspec.util.normalize_file` for more
		information.

		Returns the matched files (:class:`~collections.abc.Iterator` of
		:class:`str` or :class:`os.PathLike`).
		zfiles:r>   N)r   rE   r   r   r   rK   )r    rR   rH   rL   	orig_filerN   s         r!   match_fileszPathSpec.match_files   s      ( 
e		 ;	9E999	:	::!$-00,  ii449
|Y// 
OOO r#   rooton_errorfollow_linksc              #   n   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. See
		:func:`~pathspec.util.iter_tree_entries` for more information.

		*follow_links* (:class:`bool` or :data:`None`) optionally is whether
		to walk symbolic links that resolve to directories. See
		:func:`~pathspec.util.iter_tree_files` for more information.

		Returns the matched files (:class:`~collections.abc.Iterator` of
		:class:`.TreeEntry`).
		rW   rX   N)r   iter_tree_entriesrO   )r    rV   rW   rX   rG   s        r!   match_tree_entrieszPathSpec.match_tree_entries   sK      0 "4(VVV'(((((((((((r#   c              #   n   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. See
		:func:`~pathspec.util.iter_tree_files` for more information.

		*follow_links* (:class:`bool` or :data:`None`) optionally is whether
		to walk symbolic links that resolve to directories. See
		:func:`~pathspec.util.iter_tree_files` for more information.

		Returns the matched files (:class:`~collections.abc.Iterable` of
		:class:`str`).
		rZ   N)r   iter_tree_filesrU   )r    rV   rW   rX   rR   s        r!   match_tree_fileszPathSpec.match_tree_files   sK      0 
th\
R
R
R%e$$$$$$$$$$$r#   r'   )NN)#__name__
__module____qualname____doc__r   r   r"   objectboolr0   intr3   r   r7   r9   classmethodr   r   rB   r   r   rF   r   r
   r   r	   rO   staticmethodr   rK   r   rU   r\   r_   
match_treer(   r#   r!   r   r   (   s        
hw/ D    	 	D 	 	 	 	c    4 
 t    	D 	 	 	 	 	 	 Dzhx'899: 
&	 	   +F +/ I z#' y	   > |J''
 +/4 4c8m4 z#'4 	4 4 4 4. +/ 	%X&	' z#' uS(]#$	   @ "&!%	) )c8m) X) 	)
 y) ) ) )< "&!%	% %c8m% X% 	%
 sm% % % %: r#   N)rc   collections.abcr   r   	itertoolsr   osr   typingr   r   r   r	   r
   r   r   r    r   patternr   r   r   r   r   r   r   rd   r   r(   r#   r!   <module>rp      s   
               	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	      
 
 
 
 
 
              wvZ(((f f f f fv f f f f fr#   