o
    bi&                     @   s   d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
 d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   )util)unicode)RegexPatternlatin1c                   @   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.
	 c                 C   sB  t |trt}nt |trt}|t}ntd|| }|dr*d}d}n|dkr3d}d}n|r
|drDd}|dd }nd}|d	rQ|dd }|	d}|d
 s^|d
= nt
|dksnt
|dkr{|d s{|d
 dkrz|d
d n	 |d st
|dkrd|d< dg}d}t
|d }t|D ]e\}	}
|
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|r|d || |
 |	|kr|du r|d d}q|d d|}nd}d}|dur|tu r|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   r   z**^z.+z(?:.+/)?z/.*z(?:/.+)?*z[^/]+z(?:/.*)?$ )
isinstancer   bytesdecode_BYTES_ENCODING	TypeErrorformatstrip
startswithsplitleninsert	enumerateappend_translate_segment_globjoinencode)clspatternreturn_typeregexincludepattern_segsoutput
need_slashendisegr	   r	   j/home/ubuntu/.local/lib/python3.10/site-packages/ray/_private/thirdparty/pathspec/patterns/gitwildmatch.py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)r%   r5   r'   r-   r,   charjexprr	   r	   r/   r!      sP   



Wz+GitWildMatchPattern._translate_segment_globc                    s   d d  fdd| D S )z
		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`, :class:`bytes`)
		z[]!*#?r   c                 3   s$    | ]}| v rd | n|V  qdS )r   Nr	   ).0xmeta_charactersr	   r/   	<genexpr>'  s   " z-GitWildMatchPattern.escape.<locals>.<genexpr>)r"   )sr	   r<   r/   r5     s   zGitWildMatchPattern.escapeN)
__name__
__module____qualname____doc__	__slots__classmethodr0   staticmethodr!   r5   r	   r	   r	   r/   r      s    
 
ir   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                       |    tt| j|i |S 
		Warn about deprecation.
		)_deprecatedsuperrH   __init__)selfargskw	__class__r	   r/   rN   2  s   zGitIgnorePattern.__init__c                   C   s   t jdtdd dS )rK   z_GitIgnorePattern ('gitignore') is deprecated. Use GitWildMatchPattern ('gitwildmatch') instead.   )
stacklevelN)warningswarnDeprecationWarningr	   r	   r	   r/   rL   9  s   zGitIgnorePattern._deprecatedc                    rI   rJ   )rL   rM   rH   r0   )r$   rP   rQ   rR   r	   r/   r0   @  s   z!GitIgnorePattern.pattern_to_regex)
r@   rA   rB   rC   rN   rF   rL   rE   r0   __classcell__r	   r	   rR   r/   rH   ,  s    
rH   	gitignore)rC   
__future__r   r4   rV   r   r   compatr   r%   r   r   r   register_patternrH   r	   r	   r	   r/   <module>   s     