B
    Khh                 @   s   d Z ddlZddlZddlZddlmZmZmZmZm	Z
mZmZmZmZ G dd deZG dd deZe G dd	 d	eZdS )
z8
This module provides the base definition for patterns.
    N)	AnyAnyStrIterableIteratorMatchOptionalPatternTupleUnionc               @   sT   e Zd ZdZdZee ddddZee	 e
e	 ddd	Ze	ee d
ddZdS )r   zG
	The :class:`Pattern` class is the abstract definition of a pattern.
	)includeN)r   returnc             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`).
		N)r   )selfr    r   6/tmp/pip-install-vv81h98y/pathspec/pathspec/pattern.py__init__   s    	zPattern.__init__)filesr   c             c   s>   t jd| jtdd x |D ]}| |dk	r|V  qW dS )a  
		DEPRECATED: This method is no longer used and has been replaced by
		:meth:`.match_file`. Use the :meth:`.match_file` method with a loop
		for similar results.

		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.,
		:data:`"relative/path/to/file"`).

		Returns an :class:`~collections.abc.Iterable` yielding each matched
		file path (:class:`str`).
		z{0.__module__}.{0.__qualname__}.match() is deprecated. Use {0.__module__}.{0.__qualname__}.match_file() with a loop for similar results.   )
stacklevelN)warningswarnformat	__class__DeprecationWarning
match_file)r   r   filer   r   r   match,   s    
zPattern.match)r   r   c             C   s   t d| jdS )z
		Matches this pattern against the specified file.

		*file* (:class:`str`) is the normalized file path to match against.

		Returns the match result if *file* matched; otherwise, :data:`None`.
		z;{0.__module__}.{0.__qualname__} must override match_file().N)NotImplementedErrorr   r   )r   r   r   r   r   r   E   s    zPattern.match_file)__name__
__module____qualname____doc__	__slots__r   boolr   r   strr   r   r   r   r   r   r   r   r      s
   r   c                   s|   e Zd ZdZdZdeeef ee	 dd fddZ
d e	ddd	Zeed
 dddZeeeee	f dddZ  ZS )RegexPatternza
	The :class:`RegexPattern` class is an implementation of a pattern
	using regular expressions.
	)regexN)patternr   r   c                s   t |ttfrH|dks&td||| |\}}|dk	rt|}nH|dk	r`t|dr`|}n0|dkr|dkstd||nt	d|t
t| | || _dS )a0  
		Initializes the :class:`RegexPattern` instance.

		*pattern* (:class:`str`, :class:`bytes`, :class:`re.Pattern`, 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.Pattern`)
		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.z2pattern:{!r} is not a string, re.Pattern, or None.)
isinstancer#   bytesAssertionErrorr   pattern_to_regexrecompilehasattr	TypeErrorsuperr$   r   r%   )r   r&   r   r%   )r   r   r   r   [   s"    


zRegexPattern.__init__)otherr   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   r0   r   r   r   __eq__   s    
zRegexPattern.__eq__RegexMatchResult)r   r   c             C   s*   | j dk	r&| j|}|dk	r&t|S dS )a
  
		Matches this pattern against the specified file.

		*file* (:class:`str`)
		contains each file relative to the root directory (e.g., "relative/path/to/file").

		Returns the match result (:class:`RegexMatchResult`) if *file*
		matched; otherwise, :data:`None`.
		N)r   r%   r   r3   )r   r   r   r   r   r   r      s
    

zRegexPattern.match_file)r&   r   c             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   PatternHintr   r"   r   r2   r#   r   classmethodr	   r*   __classcell__r   r   )r   r   r$   R   s   2r$   c               @   s   e Zd ZU dZdZeed< dS )r3   zq
	The :class:`RegexMatchResult` data class is used to return information
	about the matched regular expression.
	)r   r   N)r   r   r   r    r!   	MatchHint__annotations__r   r   r   r   r3      s   
r3   )r    Zdataclassesr+   r   typingr   r   r   r   r   r8   r   r   r5   r	   r
   objectr$   Z	dataclassr3   r   r   r   r   <module>   s   ,>m