o
    $is                     @   s@   d Z ddlmZ ddlmZmZmZmZmZ G dd de	Z
dS )zR
This module provides an object oriented interface for pattern matching
of files.
   )util)
Collectioniterkeysizip_longeststring_typesunicodec                   @   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   f/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/ray/_private/thirdparty/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>&   s    z"PathSpec.__eq__.<locals>.<genexpr>)r	   r   r   r   allNotImplemented)r   other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__*   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__1   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__;   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   lookup_patterncallable	TypeErrorformat_is_iterable)clsr"   linesr   r!   r   
from_linesF   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   normalize_file
match_filer   )r   filer-   	norm_filer   r   r   r/   b   s   zPathSpec.match_filec                 c   R    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.Iterable` of
		:class:`~util.TreeEntry`).
		z entries:{!r} is not an iterable.r,   N)r   r(   r&   r'   _normalize_entriesmatch_filesr   r   )r   entriesr-   	entry_mapmatch_pathspathr   r   r   match_entriesr   s   
zPathSpec.match_entriesc                 c   r2   )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.Iterable` of
		:class:`str`).
		zfiles:{!r} is not an iterable.r,   N)r   r(   r&   r'   normalize_filesr4   r   r   )r   filesr-   file_mapmatched_filesr8   r   r   r   r4      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.Iterable` of
		:class:`str`).
		on_errorfollow_links)r   iter_tree_entriesr9   )r   rootr@   rA   r5   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`).
		r?   )r   iter_tree_filesr4   )r   rC   r@   rA   r;   r   r   r   match_tree_files   rE   zPathSpec.match_tree_filesr   )NN)__name__
__module____qualname____doc__r   r   r   r   r   classmethodr+   r/   r9   r4   rD   rG   
match_treer   r   r   r   r      s    






r   N)rK    r   compatr   r   r   r   r   objectr   r   r   r   r   <module>   s   