a
    e	g3                     @   s   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
dZG d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                   @   s
  e Zd ZdZee ddddZeedddZ	e
d	d
dZed edddZed edddZd+eeee  ee dddZd,ee eee  eee  dddZd-eeeegdf  ee eee  dddZeee eeeegef f ee edddZd.ddee  eee  ee ee  ddd Z!e"e#j$Z%d/eeee  edd!d"Z&d0ddee eee  ee ee d#d$d%Z'd1ddeeeegdf  ee ee ee  d&d'd(Z(d2ddeeeegdf  ee ee ee d&d)d*Z)e)Z*dS )3r   zd
	The :class:`PathSpec` class is a wrapper around a list of compiled
	:class:`.Pattern` instances.
	N)patternsreturnc                 C   s   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    r   T/var/www/html/llm_bihealth/app/venv/lib/python3.9/site-packages/pathspec/pathspec.py__init__-   s    
zPathSpec.__init__)otherr   c                 C   s2   t |tr*t| j|j}tdd |D S tS d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>D       z"PathSpec.__eq__.<locals>.<genexpr>N)r   r   r   r   allNotImplemented)r   r"   Zpaired_patternsr   r   r    __eq__=   s    
zPathSpec.__eq__)r   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__H   s    zPathSpec.__len__)r   r"   r   c                 C   s$   t |tr| | j|j S tS dS )z]
		Combines the :attr:`Pathspec.patterns` patterns from two
		:class:`PathSpec` instances.
		N)r   r   	__class__r   r)   r   r"   r   r   r    __add__O   s    
zPathSpec.__add__c                 C   s&   t |tr|  j|j7  _| S tS dS )zi
		Adds the :attr:`Pathspec.patterns` patterns from one :class:`PathSpec`
		instance to this instance.
		N)r   r   r   r)   r.   r   r   r    __iadd__Y   s    
zPathSpec.__iadd__)file
separatorsr   c                 C   s,   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   r1   r2   	norm_fileincludeindexr   r   r    
check_filed   s    
zPathSpec.check_file)filesr2   r   c                 c   sX   t |std|dt| j}|D ],}t||}| ||\}}t|||V  q&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   r3   r   )r   r9   r2   use_patterns	orig_filer5   r6   r7   r   r   r    check_filesy   s    

zPathSpec.check_files)rooton_errorfollow_linksr   c                 c   s$   t j|||d}| |E dH  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`).
		rA   rB   N)r   iter_tree_filesr?   )r   r@   rA   rB   r9   r   r   r    check_tree_files   s    zPathSpec.check_tree_files)clspattern_factorylinesr   c                    s^   t  trt  t s,td dt|sDtd|d fd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:r;   c                    s   g | ]}|r |qS r   r   )r#   linerG   r   r    
<listcomp>   r'   z'PathSpec.from_lines.<locals>.<listcomp>)r   strr   Zlookup_patterncallabler<   r   )rF   rG   rH   r   r   rJ   r    
from_lines   s    

zPathSpec.from_linesnegate)entriesr2   rP   r   c          	      c   s`   t |std|dt| j}|D ]4}t|j|}| ||\}}|rP| }|r&|V  q&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:r;   N)r   r<   r   r   r   pathr3   )	r   rQ   r2   rP   r=   entryr5   r6   _indexr   r   r    match_entries   s    
zPathSpec.match_entriesc                 C   s(   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   r3   r4   r   bool)r   r1   r2   r5   r6   rT   r   r   r    
match_file  s    
zPathSpec.match_file)r9   r2   rP   r   c          	      c   s^   t |std|dt| j}|D ]2}t||}| ||\}}|rN| }|r&|V  q&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.

		*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`).
		r:   r;   N)r   r<   r   r   r   r3   )	r   r9   r2   rP   r=   r>   r5   r6   rT   r   r   r    match_files  s    

zPathSpec.match_files)r@   rA   rB   rP   r   c                c   s(   t j|||d}| j||dE dH  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`).
		rC   rO   N)r   Ziter_tree_entriesrU   )r   r@   rA   rB   rP   rQ   r   r   r    match_tree_entriesB  s     zPathSpec.match_tree_entriesc                c   s(   t j|||d}| j||dE dH  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`).
		rC   rO   N)r   rD   rX   )r   r@   rA   rB   rP   r9   r   r   r    match_tree_filese  s     zPathSpec.match_tree_files)N)N)NN)N)N)N)NN)NN)+__name__
__module____qualname____doc__r   r   r!   objectrV   r*   intr,   r   r/   r0   r   r   r   rL   r   r8   r   r?   r   r   OSErrorrE   classmethodr	   r   r   rN   r   rU   staticmethodr   Zcheck_match_filer3   rW   rX   rY   rZ   Z
match_treer   r   r   r    r   '   s   
 
 

  
!# 
'

 
 
+  &  %N)r^   collections.abcr   r   	itertoolsr   typingr   r   r   r   r   r	   r
   r    r   patternr   r   r   r   r   r   r   r   r   r_   r   r   r   r   r    <module>   s   ,$	