
    0yi                        d Z ddlmZ ddlmZ ddlmZmZ 	 ddlZddl
mZ ddlmZ ddlmZ d	d
lmZ ddlmZ ddlmZmZ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.pathspec.PathSpec`.

WARNING: The *pathspec._backends.re2* package is not part of the public API. Its
contents and structure are likely to change.
    )annotations)Sequence)CallableOptionalN)_Backend)RegexPattern)override   )enumerate_patterns   )	re2_error)RE2_OPTIONSRe2RegexDatRe2RegexDebugc                  x    e Zd ZdZddd	 	 	 	 	 	 	 ddZe	 	 	 	 	 	 	 	 	 	 d	d       Zed
d       Zedd       Z	y)Re2PsBackendz
	The :class:`Re2PsBackend` class is the :module:`re2` implementation used by
	:class:`~pathspec.pathspec.PathSpec` for matching files.
	N)_debug_regex
_test_sortc               B   t         t         |r%t        |d   t              st        d|d   d      t	        t        |dd            }| j                         }t        |      | _        	 || _	        	 | j                  | j                  |||      | _        	 || _        y)	z
		Initialize the :class:`Re2PsBackend` instance.

		*patterns* (:class:`Sequence` of :class:`.RegexPattern`) contains the
		compiled patterns.
		Nr   zpatterns[0]=z must be a RegexPattern.TF)filterreverse)debugpatterns	regex_setsort_indices)r   
isinstancer   	TypeErrordictr   	_make_setboolr   	_patterns	_init_set_regex_data_set)selfr   r   r   use_patternsr   s         a/var/www/html/content_weaver/venv/lib/python3.12/site-packages/pathspec/_backends/re2/pathspec.py__init__zRe2PsBackend.__init__,   s     	?j!l;	lhqk%%=>	??(D% , nn)<($
 -9$.
 )-				 )7 )$
 !$)    c           	        t        |j                               }| ||       g }|D ]  }||   }|j                  t        |t              sJ |       |j
                  j                  }| r)|j                  t        |j                  |d|             n'|j                  t        |j                  |d             |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`).
		F)includeindexis_dir_patternregex)r+   r,   r-   )listkeysr+   r   r   r.   patternappendr   r   AddCompile)	r   r   r   r   indices
regex_datapattern_indexr1   r.   s	            r'   r"   zRe2PsBackend._init_set`   s    4 !' #%* mm$7oo
Wl
+4W4
+==  5m__	  k__  ==-2 	r)   c                 H    t         j                  j                  t              S )zF
		Create the re2 regex set.

		Returns the set (:class:`re2.Set`).
		)re2Set	SearchSetr    r)   r'   r   zRe2PsBackend._make_set   s     
		;	''r)   c                    | j                   j                  |      }|sy| j                  t        fd|D              }| j                  |   }|j
                  |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`).
		)NNc              3  <   K   | ]  }|   j                     y w)N)r,   ).0_Re2PsBackend__idr6   s     r'   	<genexpr>z*Re2PsBackend.match_file.<locals>.<genexpr>   s     Cj&,,Cs   )r$   Matchr#   maxr!   r+   )r%   file	match_idsr7   r1   r6   s        @r'   
match_filezRe2PsBackend.match_file   sU     $(99??4#8)	
*CCC-NN=)'
//=	))r)   )r   zSequence[RegexPattern]r   zOptional[bool]r   z Optional[Callable[[list], None]]returnNone)
r   r    r   zdict[int, RegexPattern]r   re2.Setr   z%Optional[Callable[[list[int]], None]]rG   zlist[Re2RegexDat])rG   rI   )rD   strrG   z$tuple[Optional[bool], Optional[int]])
__name__
__module____qualname____doc__r(   staticmethodr"   r   r	   rF   r<   r)   r'   r   r   &   s     "&152"2 	2
 /2 2h 9	9#9 9 6	9
 9 9v ( ( * *r)   r   )rN   
__future__r   collections.abcr   typingr   r   r9   ModuleNotFoundErrorpathspec.backendr   pathspec.patternr   pathspec._typingr	   _utilsr   baser   _baser   r   r   r   r<   r)   r'   <module>rZ      sh    # U*8 U*+  s   A AA