o
    b{.                     @   s   d Z ddlmZ ddlZddlZzddlmZmZmZm	Z	 W n	 e
y'   Y nw ddlmZ ddlmZ ddlm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.
    )unicode_literalsN)AnyStrOptionalTextTuple   )util)unicode)RegexPatternlatin1c                   @   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   ]/var/www/secure340b-portal/env/lib/python3.10/site-packages/pathspec/patterns/gitwildmatch.pyr      s    r   c                   @   s8   e Zd ZdZdZedd Zedd Zedd Z	d	S )
GitWildMatchPatternzX
	The :class:`GitWildMatchPattern` class represents a compiled Git
	wildmatch pattern.
	r   c                 C   s  t |trt}nt |trt}|t}ntd||}| }|dr-d}d}n4|dkr7d}d}n*|r]|drHd}|dd }nd}|d	rU|dd }d}|	d}t
t|d d
dD ]}||d  }	|| }
|	dkr}|
dkr}||= qft|dkr|d
 dkr|d sd}|d
 s|d
= nt|dkst|dkr|d s|d
 dkr|d
d n	 |std|f |d st|dkrd|d< |du rZdg}d}t|d }t|D ]m\}}
|
dkr|d
kr||kr|d q|d
kr|d d}q||kr|d q|d d}q|
dkr-|r%|d |d d}q|r5|d || |
 ||krL|du rL|d d}q|d d|}n|}nd}d}|durp|tu rp|t}||fS )a  
		Convert the pattern into a regular expression.

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

		Returns the uncompiled regular expression (:class:`unicode`, :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:{!r} is not a unicode or byte string.#N/!F   T\r   z**r   z^.+/.*$zInvalid git pattern: %r^z.+z(?:.+/)?z/.*z(?:/.+)?*z[^/]+z(?:/.*)?$ )
isinstancer	   bytesdecode_BYTES_ENCODING	TypeErrorformatstrip
startswithsplitrangeleninsertr   	enumerateappend_translate_segment_globjoinencode)clspatternreturn_typeZoriginal_patternregexincludeZoverride_regexZpattern_segsiprevsegoutputZ
need_slashendr   r   r   pattern_to_regex-   s   





  












z$GitWildMatchPattern.pattern_to_regexc                 C   s  d}d}dt | }}||k r| | }|d7 }|r#d}|t|7 }n|dkr*d}n|dkr3|d7 }n|d	kr<|d
7 }n|dkr|}||k rP| | dkrP|d7 }||k r^| | dkr^|d7 }||k rv| | dkrv|d7 }||k rv| | dksh||k r|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 }n|t|7 }||k s|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   r   Tr   z[^/]*?z[^/][r   ]r   z\^z\\z\[)r(   reescapereplace)r0   r>   r2   r4   r8   charjexprr   r   r   r,      sP   



Wz+GitWildMatchPattern._translate_segment_globc                    sn   t | tr
t}| }nt | trt}| t}ntd| d d fdd|D }|tu r5|tS |S )a   
		Escape special characters in the given string.

		*s* (:class:`unicode` 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:`unicode` or :class:`bytes`)
		z's:{!r} is not a unicode or byte string.z[]!*#?r   c                 3   s$    | ]}| v rd | n|V  qdS )r   Nr   ).0xZmeta_charactersr   r   	<genexpr>h  s   " z-GitWildMatchPattern.escape.<locals>.<genexpr>)	r   r	   r   r    r!   r"   r#   r-   r.   )sr1   stringZ
out_stringr   rE   r   r>   Q  s   


zGitWildMatchPattern.escapeN)
r   r   r   r   	__slots__classmethodr9   staticmethodr,   r>   r   r   r   r   r   $   s    
 9
jr   Zgitwildmatchc                       s<   e Zd ZdZ fddZe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.
	c                    s"   |    tt| j|i | dS )
		Warn about deprecation.
		N)_deprecatedsuperrL   __init__)selfargskw	__class__r   r   rP   x  s   zGitIgnorePattern.__init__c                   C   s   t jdtdd dS )rM   z_GitIgnorePattern ('gitignore') is deprecated. Use GitWildMatchPattern ('gitwildmatch') instead.   )
stacklevelN)warningswarnDeprecationWarningr   r   r   r   rN     s   zGitIgnorePattern._deprecatedc                    s   |    tt| j|i |S )rM   )rN   rO   rL   r9   )r/   rR   rS   rT   r   r   r9     s   z!GitIgnorePattern.pattern_to_regex)
r   r   r   r   rP   rK   rN   rJ   r9   __classcell__r   r   rT   r   rL   r  s    
rL   Z	gitignore)r   
__future__r   r=   rX   typingr   r   r   r   ImportErrorr   r   compatr	   r0   r
   r!   
ValueErrorr   r   Zregister_patternrL   r   r   r   r   <module>   s(     M