
    \ju                        d Z ddlmZ ddlmZmZmZ 	 ddlZddl	m
Z
 ddlmZmZmZmZ ddlmZ dd	lmZmZ dd
lmZ  G d de      Zy# e$ r dZY ;w xY w)z
This module provides the :module:`re2` backend for :class:`~pathspec.gitignore.GitIgnoreSpec`.

WARNING: The *pathspec._backends.re2* package is not part of the public API. Its
contents and structure are likely to change.
    )annotations)CallableOptionalUnionN)RegexPattern)GitIgnoreSpecPattern_BYTES_ENCODING_DIR_MARK_CG_DIR_MARK_OPT)override   )Re2RegexDatRe2RegexDebug)Re2PsBackendc                  R    e Zd ZdZee	 	 	 	 	 	 	 	 	 	 dd              Zedd       Zy)Re2GiBackendz
	The :class:`Re2GiBackend` class is the :module:`re2` implementation used by
	:class:`~pathspec.gitignore.GitIgnoreSpec` for matching files.
	c           
        t        |j                               }| ||       g }|D ]  }||   }|j                  |j                  J |       t	        |t
              sJ |       |j                  j                  }g }	t	        |t              rt	        |t              r|}
n,t	        |t              sJ |       |j                  t              }
t        |
v r~|
j                  t              r@|
dt        t                }|	j!                  | ddf       |	j!                  | ddf       n)|
j#                  t        d      }|	j!                  |df       |	s|	j!                  |df       |	D ]h  \  }}| r)|j!                  t%        |j                  |||             n'|j!                  t'        |j                  ||             |j)                  |       j  |j+                          |S )aV  
		Create the re2 regex set.

		*debug* (:class:`bool`) is whether to include additional debugging
		information for the regular expressions.

		*patterns* (:class:`dict`) maps pattern index (:class:`int`) to pattern
		(:class:`.RegexPattern`).

		*regex_set* (:class:`re2.Set`) is the regex set.

		*sort_indices* (:class:`callable` or :data:`None`) is a function used to
		sort the patterns by index. This is used during testing to ensure the order
		of patterns is not accidentally relied on.

		Returns a :class:`list` indexed by regex id (:class:`int`) to its data
		(:class:`Re2RegexDat`).
		N/T$F)includeindexis_dir_patternregex)r   r   r   )listkeysr   r   
isinstancer   patternr   strbytesdecoder	   r
   endswithr   lenappendreplacer   r   AddCompile)debugpatterns	regex_setsort_indicesindices
regex_datapattern_indexr   r   use_regexes	regex_str
base_regexr   s                J/root/env/lib/python3.12/site-packages/pathspec/_backends/re2/gitignore.py	_init_setzRe2GiBackend._init_set*   s   6 !' #%* 5mm$7oo
--
#,W,
#
Wl
+4W4
+==  579;./
 %Yue$+e+$o.Yy =) 1s=112jZL*D12ZL*E23 $$\37j*d+,
u~& + un}oo#	  {oo#  MM%M5p 	    c                4   | j                   j                  |      }|syd}d}d}| j                  }|D ]Q  }||   }|j                  }	|	rd}
nd}
|j                  }|j
                  }|r|	r||kD  s|
|k(  r||kD  s|
|kD  sL|}|}|
}S |dk7  s
J |||f       ||fS )a  
		Check the file against the patterns.

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

		Returns a :class:`tuple` containing whether to include *file* (:class:`bool`
		or :data:`None`), and the index of the last matched pattern (:class:`int` or
		:data:`None`).
		)NNNr      )_setMatch_regex_datar   r   r   )selffile	match_idsout_include	out_indexout_priorityr,   regex_id	regex_datr   priorityr   r   s                r1   
match_filezRe2GiBackend.match_file   s     $(99??4#8)	
 $+),* h(#9,,>H H 7??5EI$5L UY%6,KIL-0 
b@9k<@@
y	!!r3   N)
r'   boolr(   zdict[int, RegexPattern]r)   zre2.Setr*   z%Optional[Callable[[list[int]], None]]returnzlist[Re2RegexDat])r;   r   rE   z$tuple[Optional[bool], Optional[int]])__name__
__module____qualname____doc__r   staticmethodr2   rC    r3   r1   r   r   $   sm    
 X	X#X X 6	X
 X  Xt -" -"r3   r   )rI   
__future__r   typingr   r   r   re2ModuleNotFoundErrorpathspec.patternr    pathspec.patterns.gitignore.specr   r	   r
   r   pathspec._typingr   _baser   r   pathspecr   r   rK   r3   r1   <module>rU      sc    # 
 
P"< P")  s   A
 
AA