a
    e	gO1                     @   s   d Z ddlZddlZddlmZmZmZ ddlmZ ddl	m
Z
 dZdZG d	d
 d
eZG dd de
Zede G dd deZede dS )z
This module implements Git's wildmatch pattern matching which itself is derived
from Rsync's wildmatch. Git uses wildmatch for its ".gitignore" files.
    N)AnyStrOptionalTuple   )util)RegexPatternlatin1Zps_dc                   @   s   e Zd ZdZdS )GitWildMatchPatternErrorzW
	The :class:`GitWildMatchPatternError` indicates an invalid git wild match
	pattern.
	N)__name__
__module____qualname____doc__ r   r   a/var/www/html/llm_bihealth/app/venv/lib/python3.9/site-packages/pathspec/patterns/gitwildmatch.pyr	      s   r	   c                   @   s`   e Zd ZdZdZeeeee ee	 f dddZ
eeedddZeeedd	d
ZdS )GitWildMatchPatternzX
	The :class:`GitWildMatchPattern` class represents a compiled Git wildmatch
	pattern.
	r   )patternreturnc                 C   s  t |trt}n*t |tr*t}|t}ntd|d|}|drR| }n| }|	drpd}d}n|dkrd}d}n|rX|	drd}|d	d }nd
}d}|
d}|d  }tt|d	 ddD ].}	||	d	  }
||	 }|
dkr|dkr||	= qt|dkr8|d dkr8|d	 s8dt d}|d sJ|d= nBt|d	kspt|dkr|d	 s|d dkr|dd n |std||d st|d	krd|d< |du rRdg}d}t|d	 }t|D ]P\}	}|dkrv|	dkr|	|kr|d nX|	dkr6|d d}n>|	|krf|rZ|dt d n
|d n|d d
}n|dkr|r|d |d |	|kr|dt d d
}n||r|d z|| | W n6 ty } ztd||W Y d}~n
d}~0 0 |	|kr4|dt d d
}q|d d|}n|}nd}d}|dur~|tu r~|t}||fS )a  
		Convert the pattern into a regular expression.

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

		Returns the uncompiled regular expression (:class:`str`, :class:`bytes`, or
		:data:`None`); and whether matched files should be included (:data:`True`),
		excluded (:data:`False`), or if it is a null-operation (:data:`None`).
		zpattern:! is not a unicode or byte string.z\ #N/!F   Tr   z**r   z^.+(?P<z>/).*$zInvalid git pattern: ^z[^/]+(?:/.*)?z(?:.+/)?z(?P<z>/).*z/.*z(?:/.+)?*z[^/]+z(?:(?P<z>/).*)?$ )
isinstancestrbytesdecode_BYTES_ENCODING	TypeErrorendswithlstripstrip
startswithsplitrangelen	_DIR_MARKinsertr	   	enumerateappend_translate_segment_glob
ValueErrorjoinencode)clsr   return_typeZoriginal_patternregexincludeZoverride_regexZpattern_segsZis_dir_patterniprevsegoutputZ
need_slashender   r   r   pattern_to_regex-   s    







&
&










&


z$GitWildMatchPattern.pattern_to_regexc                 C   s  d}d}dt |  }}||k r~| | }|d7 }|rHd}|t|7 }q|dkrVd}q|dkrh|d7 }q|d	krz|d
7 }q|dkrn|}||k r| | dks| | dkr|d7 }||k r| | dkr|d7 }||k r| | dkr|d7 }q||k rd|d7 }d}| | dkr |d7 }|d7 }n| | dkr>|d7 }|d7 }|| || dd7 }||7 }|}n|d7 }q|t|7 }q|rtd| |S )a  
		Translates the glob pattern to a regular expression. This is used in the
		constructor to translate a path segment glob pattern to its corresponding
		regular expression.

		*pattern* (:class:`str`) is the glob pattern.

		Returns the regular expression (:class:`str`).
		Fr   r   r   \Tr   z[^/]*?z[^/][r   r   ]z\\z\[z9Escape character found with no next character to escape: )r)   reescapereplacer/   )r   rB   r4   r6   r:   charjexprr   r   r   r.      sP    



 



z+GitWildMatchPattern._translate_segment_glob)sr   c                    st   t | trt}| }n*t | tr.t}| t}ntd| dd d fdd|D }|tu rl|tS |S dS )z
		Escape special characters in the given string.

		*s* (:class:`str` or :class:`bytes`) a filename or a string that you want to
		escape, usually before adding it to a ".gitignore".

		Returns the escaped string (:class:`str` or :class:`bytes`).
		zs:r   z[]!*#?r   c                 3   s"   | ]}| v rd | n|V  qdS )r=   Nr   ).0xZmeta_charactersr   r   	<genexpr>z      z-GitWildMatchPattern.escape.<locals>.<genexpr>N)r   r   r   r    r!   r"   r0   r1   )rG   r3   stringZ
out_stringr   rJ   r   rB   d  s    



zGitWildMatchPattern.escapeN)r
   r   r   r   	__slots__classmethodr   r   r   boolr<   staticmethodr   r.   rB   r   r   r   r   r   $   s    Hnr   Zgitwildmatchc                       sH   e Zd ZdZdd fddZeddddZe fdd	Z  Z	S )
GitIgnorePatternz
	The :class:`GitIgnorePattern` class is deprecated by :class:`GitWildMatchPattern`.
	This class only exists to maintain compatibility with v0.4.
	N)r   c                    s"   |    tt| j|i | dS )
		Warn about deprecation.
		N)_deprecatedsuperrR   __init__)selfargskw	__class__r   r   rV     s    zGitIgnorePattern.__init__c                   C   s   t jdtdd dS )rS   z_GitIgnorePattern ('gitignore') is deprecated. Use GitWildMatchPattern ('gitwildmatch') instead.   )
stacklevelN)warningswarnDeprecationWarningr   r   r   r   rT     s    zGitIgnorePattern._deprecatedc                    s   |    tt| j|i |S )rS   )rT   rU   rR   r<   )r2   rX   rY   rZ   r   r   r<     s    z!GitIgnorePattern.pattern_to_regex)
r
   r   r   r   rV   rQ   rT   rO   r<   __classcell__r   r   rZ   r   rR     s   	rR   Z	gitignore)r   rA   r^   typingr   r   r   r   r   r   r   r!   r*   r/   r	   r   Zregister_patternrR   r   r   r   r   <module>   s     _!