o
    bp                     @   s   d Z zddlmZmZmZmZmZmZmZm	Z	 W n	 e
y!   Y nw zddlmZ ddlmZ W n	 e
y9   Y nw 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 G d
d deZdS )zR
This module provides an object oriented interface for pattern matching
of files.
    )AnyAnyStrCallableIterableIteratorOptionalTextUnion)PathLike)
Collection   )util)CollectionTypeiterkeysizip_longeststring_types)Pattern)	TreeEntryc                   @   sz   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Ze	dd Z
dddZdddZdddZdddZdddZeZdS )PathSpeczd
	The :class:`PathSpec` class is a wrapper around a list of compiled
	:class:`.Pattern` instances.
	c                 C   s"   t |tr
|| _d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)
isinstancer   listpatterns)selfr    r   P/var/www/secure340b-portal/env/lib/python3.10/site-packages/pathspec/pathspec.py__init__+   s   	
zPathSpec.__init__c                 C   s.   t |trt| j|j}td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                 s   s    | ]	\}}||kV  qd S Nr   ).0abr   r   r   	<genexpr>B   s    z"PathSpec.__eq__.<locals>.<genexpr>)r   r   r   r   allNotImplemented)r   otherZpaired_patternsr   r   r   __eq__:   s   
zPathSpec.__eq__c                 C   s
   t | jS )zW
		Returns the number of compiled patterns this path-spec contains
		(:class:`int`).
		)lenr   )r   r   r   r   __len__F   s   
zPathSpec.__len__c                 C   s   t |trt| j|j S tS )z]
		Combines the :attr:`Pathspec.patterns` patterns from two
		:class:`PathSpec` instances.
		r   r   r   r"   r   r#   r   r   r   __add__M   s   
zPathSpec.__add__c                 C   s"   t |tr|  j|j7  _| S tS )zi
		Adds the :attr:`Pathspec.patterns` patterns from one :class:`PathSpec`
		instance to this instance.
		r'   r(   r   r   r   __iadd__X   s   
zPathSpec.__iadd__c                    s\   t  tr
t  t std t|s!td| fd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 it can
		be a :class:`file` (e.g., from :func:`open` or :class:`io.StringIO`)
		or the result from :meth:`str.splitlines`.

		Returns the :class:`PathSpec` instance.
		z%pattern_factory:{!r} is not callable.zlines:{!r} is not an iterable.c                    s   g | ]}|r |qS r   r   )r   linepattern_factoryr   r   
<listcomp>~   s    z'PathSpec.from_lines.<locals>.<listcomp>)r   r   r   Zlookup_patterncallable	TypeErrorformat_is_iterable)clsr-   linesr   r   r,   r   
from_linesd   s   


zPathSpec.from_linesNc                 C   s   t j||d}t | j|S )a  
		Matches the file to this path-spec.

		*file* (:class:`str` or :class:`~pathlib.PurePath`) 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`.
		
separators)r   Znormalize_file
match_filer   )r   filer7   	norm_filer   r   r   r8      s   zPathSpec.match_filec                 c   sR    t |std|t j||d}t | jt|}|D ]}|| V  qd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} is not an iterable.r6   N)r   r2   r0   r1   Z_normalize_entriesmatch_filesr   r   )r   entriesr7   Z	entry_mapZmatch_pathspathr   r   r   match_entries   s   
zPathSpec.match_entriesc                 c   s\    t |std|t j||d}t | jt|}|D ]}|| D ]}|V  q%qdS )a*  
		Matches the files to this path-spec.

		*files* (:class:`~collections.abc.Iterable` of :class:`str; or
		:class:`pathlib.PurePath`) 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:`pathlib.PurePath`).
		zfiles:{!r} is not an iterable.r6   N)r   r2   r0   r1   Znormalize_filesr;   r   r   )r   filesr7   Zfile_mapZmatched_filesr:   Z	orig_filer   r   r   r;      s   
zPathSpec.match_filesc                 C      t j|||d}| |S )a  
		Walks the specified root path for all files and matches them to this
		path-spec.

		*root* (:class:`str`; or :class:`pathlib.PurePath`) 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`).
		on_errorfollow_links)r   Ziter_tree_entriesr>   )r   rootrB   rC   r<   r   r   r   match_tree_entries      
zPathSpec.match_tree_entriesc                 C   r@   )a  
		Walks the specified root path for all files and matches them to this
		path-spec.

		*root* (:class:`str`; or :class:`pathlib.PurePath`) 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`).
		rA   )r   Ziter_tree_filesr;   )r   rD   rB   rC   r?   r   r   r   match_tree_files   rF   zPathSpec.match_tree_filesr   )NN)__name__
__module____qualname____doc__r   r$   r&   r)   r*   classmethodr5   r8   r>   r;   rE   rG   Z
match_treer   r   r   r   r   %   s    





r   N)rK   typingr   r   r   r   r   r   r   r	   ImportErrorosr
   r    r   compatr   r   r   r   patternr   r   objectr   r   r   r   r   <module>   s"   ,	