
    Ae                          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y)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"y)r   zd
	The :class:`PathSpec` class is a wrapper around a list of compiled
	:class:`.Pattern` instances.
	patternsreturnNc                 T    t        |t              r|| _        yt        |      | _        y)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.12/site-packages/pathspec/pathspec.py__init__zPathSpec.__init__.   s-     )>B($- IMX$-    otherc                     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:`~PathSpec.patterns` attributes.
		c              3   ,   K   | ]  \  }}||k(    y wN ).0abs      r!   	<genexpr>z"PathSpec.__eq__.<locals>.<genexpr>C   s     1Aa1f1s   )r   r   r   r   allNotImplemented)r    r$   paired_patternss      r!   __eq__zPathSpec.__eq__<   s9    
 x  ??
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                  |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   s0    
 x 
..7
88
r#   c                 p    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   s+    
 x ==ENN"=
;
r#   clspattern_factorylinesc                     t        |t              rt        j                  |      }t	        |      st        d|d      t        |      st        d|d      |D cg c]  }|s ||       }} | |      S c c}w )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.)r   strr   lookup_patterncallable	TypeErrorr   )r:   r;   r<   liner   s        r!   
from_lineszPathSpec.from_linesc   s    * %((9?	/	"	%o%88IJ	KK	e		VE9$89	::05>od#>(>	X ?s   A:&
A:entries
separatorsc              #      K   t        |      st        d|d      t        | j                        }|D ]/  }t	        |j
                  |      }| j                  ||      s,| 1 yw)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   rB   r   r   r   path_match_file)r    rE   rF   use_patternsentry	norm_files         r!   match_entrieszPathSpec.match_entries   sg     & 
g		Xg[(<=	>>!$--0, eejj*59
|Y/
Ks   AA' A'filec                 h    t        j                  ||      }| 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`.
		)rF   )r   r   rI   r   )r    rN   rF   rL   s       r!   r   zPathSpec.match_file   s-    " !!$:>)			$--	33r#   filesc              #      K   t        |      st        d|d      t        | j                        }|D ]%  }t	        ||      }| j                  ||      s"| ' 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:`~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   rB   r   r   r   rI   )r    rP   rF   rJ   	orig_filerL   s         r!   match_fileszPathSpec.match_files   sc     ( 
e		VE9$89	::!$--0, ii49
|Y/
Os   AAArooton_errorfollow_linksc              #   r   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. 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`).
		rU   rV   N)r   iter_tree_entriesrM   )r    rT   rU   rV   rE   s        r!   match_tree_entrieszPathSpec.match_tree_entries   s0     0 ""4(V'(((   -757c              #   r   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. 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`).
		rX   N)r   iter_tree_filesrS   )r    rT   rU   rV   rP   s        r!   match_tree_fileszPathSpec.match_tree_files   s0     0 

th\
R%e$$$r[   r'   )NN)#__name__
__module____qualname____doc__r   r   r"   objectboolr0   intr3   r   r7   r9   classmethodr   r   r?   r   r   rD   r   r
   r   r	   rM   staticmethodr   rI   r   rS   rZ   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c8m4 z#'4 	4. +/	%X&	' z#' uS(]#$	@ "&!%	)c8m) X) 	)
 y)< "&!%	%c8m% X% 	%
 sm%: r#   N)rb   collections.abcr   r   	itertoolsr   osr   typingr   r   r   r	   r
   r   r   r    r   patternr   r   r   r   r   r   r   rc   r   r(   r#   r!   <module>ro      s]   
	 	 	 
  vZ(fv fr#   