a
    ¯M^5  ã                   @   s<   d Z ddlZddlmZ G dd„ deƒZG dd„ deƒZdS )	z8
This module provides the base definition for patterns.
é    Né   )Úunicodec                   @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )ÚPatternzG
	The :class:`Pattern` class is the abstract definition of a pattern.
	©Úincludec                 C   s
   || _ dS )zâ
		Initializes the :class:`Pattern` instance.

		*include* (:class:`bool` or :data:`None`) is whether the matched
		files should be included (:data:`True`), excluded (:data:`False`),
		or is a null-operation (:data:`None`).
		Nr   )Úselfr   © r   ú/lib/python3.9/site-packages/pathspec/pattern.pyÚ__init__   s    	zPattern.__init__c                 C   s   t d | jj| jj¡ƒ‚dS )a3  
		Matches this pattern against the specified files.

		*files* (:class:`~collections.abc.Iterable` of :class:`str`) contains
		each file relative to the root directory (e.g., ``"relative/path/to/file"``).

		Returns an :class:`~collections.abc.Iterable` yielding each matched
		file path (:class:`str`).
		z{}.{} must override match().N)ÚNotImplementedErrorÚformatÚ	__class__Ú
__module__Ú__name__)r   Úfilesr   r   r	   Úmatch#   s    
zPattern.matchN)r   r   Ú__qualname__Ú__doc__Ú	__slots__r
   r   r   r   r   r	   r      s   r   c                       sB   e Zd ZdZdZd‡ fdd„	Zdd„ Zdd	„ Zed
d„ ƒZ	‡  Z
S )ÚRegexPatternza
	The :class:`RegexPattern` class is an implementation of a pattern
	using regular expressions.
	)ÚregexNc                    s°   d| _ t|ttfƒrN|du s,J d ||¡ƒ‚|  |¡\}}|dur–t |¡}nH|durft|dƒrf|}n0|du rˆ|du s–J d ||¡ƒ‚nt	d |¡ƒ‚t
t| ƒ |¡ || _ dS )a>  
		Initializes the :class:`RegexPattern` instance.

		*pattern* (:class:`unicode`, :class:`bytes`, :class:`re.RegexObject`,
		or :data:`None`) is the pattern to compile into a regular
		expression.

		*include* (:class:`bool` or :data:`None`) must be :data:`None`
		unless *pattern* is a precompiled regular expression (:class:`re.RegexObject`)
		in which case it is whether matched files should be included
		(:data:`True`), excluded (:data:`False`), or is a null operation
		(:data:`None`).

			.. NOTE:: Subclasses do not need to support the *include*
			   parameter.
		Nz8include:{!r} must be null when pattern:{!r} is a string.r   z4include:{!r} must be null when pattern:{!r} is null.z3pattern:{!r} is not a string, RegexObject, or None.)r   Ú
isinstancer   Úbytesr   Úpattern_to_regexÚreÚcompileÚhasattrÚ	TypeErrorÚsuperr   r
   )r   Úpatternr   r   ©r   r   r	   r
   9   s    zRegexPattern.__init__c                 C   s*   t |tƒr"| j|jko | j|jkS tS dS )z¯
		Tests the equality of this regex pattern with *other* (:class:`RegexPattern`)
		by comparing their :attr:`~Pattern.include` and :attr:`~RegexPattern.regex`
		attributes.
		N)r   r   r   r   ÚNotImplemented)r   Úotherr   r   r	   Ú__eq__i   s    
zRegexPattern.__eq__c                 c   s.   | j dur*|D ]}| j |¡dur|V  qdS )a/  
		Matches this pattern against the specified files.

		*files* (:class:`~collections.abc.Iterable` of :class:`str`)
		contains each file relative to the root directory (e.g., "relative/path/to/file").

		Returns an :class:`~collections.abc.Iterable` yielding each matched
		file path (:class:`str`).
		N)r   r   r   )r   r   Úpathr   r   r	   r   t   s    

zRegexPattern.matchc                 C   s   |dfS )a¼  
		Convert the pattern into an uncompiled regular expression.

		*pattern* (:class:`str`) is the pattern to convert into a regular
		expression.

		Returns the uncompiled regular expression (:class:`str` or :data:`None`),
		and whether matched files should be included (:data:`True`),
		excluded (:data:`False`), or is a null-operation (:data:`None`).

			.. NOTE:: The default implementation simply returns *pattern* and
			   :data:`True`.
		Tr   )Úclsr   r   r   r	   r   ƒ   s    zRegexPattern.pattern_to_regex)N)r   r   r   r   r   r
   r#   r   Úclassmethodr   Ú__classcell__r   r   r    r	   r   0   s   0r   )r   r   Úcompatr   Úobjectr   r   r   r   r   r	   Ú<module>   s   %