B
    Khh7                 @   s   d Z ddl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 ddlmZ edd	d
ZG dd	 d	e
ZdS )zV
This module provides :class:`.GitIgnoreSpec` which replicates
*.gitignore* behavior.
    )AnyStrCallable
CollectionIterableTypeTypeVarUnion   )PathSpec)Pattern)GitWildMatchPatternGitWildMatchPatternError	_DIR_MARK)_is_iterableSelfGitIgnoreSpec)Zboundc            	       s|   e Zd ZdZeed fddZedee	 e
e eeeegef df e	d fddZeee eed	d
dZ  ZS )r   zc
	The :class:`GitIgnoreSpec` class extends :class:`PathSpec` to
	replicate *.gitignore* behavior.
	)otherreturnc                s,   t |trt |S t |tr$dS tS dS )z
		Tests the equality of this gitignore-spec with *other*
		(:class:`GitIgnoreSpec`) by comparing their :attr:`~PathSpec.patterns`
		attributes. A non-:class:`GitIgnoreSpec` will not compare equal.
		FN)
isinstancer   super__eq__r
   NotImplemented)selfr   )	__class__ 8/tmp/pip-install-vv81h98y/pathspec/pathspec/gitignore.pyr   '   s
    

zGitIgnoreSpec.__eq__N)clslinespattern_factoryr   c                sD   |dkrt }n$t|ts t|r2t|r2|| }}t ||}|S )a  
		Compiles the pattern lines.

		*lines* (:class:`~collections.abc.Iterable`) yields each uncompiled
		pattern (:class:`str`). This simply has to yield each line so it can
		be a :class:`io.TextIOBase` (e.g., from :func:`open` or
		:class:`io.StringIO`) or the result from :meth:`str.splitlines`.

		*pattern_factory* can be :data:`None`, the name of a registered
		pattern factory (:class:`str`), or a :class:`~collections.abc.Callable`
		used to compile patterns. The callable must accept an uncompiled
		pattern (:class:`str`) and return the compiled pattern (:class:`.Pattern`).
		Default is :data:`None` for :class:`.GitWildMatchPattern`).

		Returns the :class:`GitIgnoreSpec` instance.
		N)r   r   strcallabler   r   
from_lines)r   r   r   r   )r   r   r   r!   4   s    
zGitIgnoreSpec.from_lines)patternsfiler   c       	      C   s   d}d}x| D ]}|j dk	r||}|dk	ry|jt}W nJ tk
r } z,td|d|jdtd|jd	|W dd}~X Y nX |rd	}nd
}|j r|r|j }|}q||kr|j }|}qW |S )a  
		Matches the file to the patterns.

		.. NOTE:: Subclasses of :class:`.PathSpec` may override this
		   method as an instance method. It does not have to be a static
		   method.

		*patterns* (:class:`~collections.abc.Iterable` of :class:`~pathspec.pattern.Pattern`)
		contains the patterns to use.

		*file* (:class:`str`) is the normalized file path to be matched
		against *patterns*.

		Returns :data:`True` if *file* matched; otherwise, :data:`False`.
		Fr   NzJInvalid git pattern: directory marker regex group is missing. Debug: file=z regex=z group=z match=.r	      )includeZ
match_filematchgroupr   
IndexErrorr   regex)	r"   r#   Zout_matchedZout_prioritypatternr'   Zdir_markepriorityr   r   r   _match_fileT   s,    


"
zGitIgnoreSpec._match_file)N)__name__
__module____qualname____doc__objectboolr   classmethodr   r   r   r   r   r   r   r   r!   staticmethodr   r   r.   __classcell__r   r   )r   r   r   !   s   $N)r2   typingr   r   r   r   r   r   r   Zpathspecr
   r+   r   Zpatterns.gitwildmatchr   r   r   utilr   r   r   r   r   r   r   <module>   s   $	