
    mi                        d Z ddlmZ ddlmZ ddlmZmZ 	 ddlZn# e	$ r dZY nw xY w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dS )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                  j    e Zd ZdZdddddZedd            Zedd            Zedd            Z	dS )Re2PsBackendz
	The :class:`Re2PsBackend` class is the :module:`re2` implementation used by
	:class:`~pathspec.pathspec.PathSpec` for matching files.
	N)_debug_regex
_test_sortpatternsSequence[RegexPattern]r   Optional[bool]r    Optional[Callable[[list], None]]returnNonec                  t           t           |r4t          |d         t                    st          d|d         d          t	          t          |dd                    }|                                 }t          |          | _        	 || _	        	 | 
                    | j        |||          | _        	 || _        dS )	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)debugr   	regex_setsort_indices)r   
isinstancer   	TypeErrordictr   	_make_setboolr   	_patterns	_init_set_regex_data_set)selfr   r   r   use_patternsr   s         w/var/www/html/bestrading.cuttalo.com/scripts/kaggle-env/lib/python3.11/site-packages/pathspec/_backends/re2/pathspec.py__init__zRe2PsBackend.__init__,   s     	? @j!l;; @	>hqk>>>	?	??(D%    , nn)<(($
 -9$.
 )-			 )7 ) )$
 !$)     r   r%   dict[int, RegexPattern]r   re2.Setr    %Optional[Callable[[list[int]], None]]list[Re2RegexDat]c           	        t          |                                          }| ||           g }|D ]}||         }|j        t          |t                    s
J |            |j        j        }| r,|                    t          |j        |d|                     n*|                    t          |j        |d                     |
                    |           |                                 |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`).
		NF)includeindexis_dir_patternregex)r4   r5   r6   )listkeysr4   r!   r   r7   patternappendr   r   AddCompile)	r   r   r   r    indices
regex_datapattern_indexr:   r7   s	            r,   r'   zRe2PsBackend._init_set`   s-   4 !!'< #%*  mm$7o
Wl
+
+44W444= 5 m_	       k_      == 	r.   c                 J    t           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.   filestr$tuple[Optional[bool], Optional[int]]c                    | j                             |          }|sdS | 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  2   K   | ]}|         j         V  d S )N)r5   ).0_Re2PsBackend__idr?   s     r,   	<genexpr>z*Re2PsBackend.match_file.<locals>.<genexpr>   s+      CCj&,CCCCCCr.   )r)   Matchr(   maxr&   r4   )r*   rF   	match_idsr@   r:   r?   s        @r,   
match_filezRe2PsBackend.match_file   sh     $(9??4#8#8)	 
,*CCCCCCCCC-N=)'
/=	))r.   )r   r   r   r   r   r   r   r   )
r   r%   r   r/   r   r0   r    r1   r   r2   )r   r0   )rF   rG   r   rH   )
__name__
__module____qualname____doc__r-   staticmethodr'   r$   r	   rQ   rE   r.   r,   r   r   &   s          "&152 2 2 2 2 2h 9 9 9 ,9v ( ( ( ,( * * * (* * *r.   r   )rU   
__future__r   collections.abcr   typingr   r   rB   ModuleNotFoundErrorpathspec.backendr   pathspec.patternr   pathspec._typingr	   _utilsr   baser   _baser   r   r   r   rE   r.   r,   <module>ra      s    # " " " " "                                                 U* U* U* U* U*8 U* U* U* U* U*s    ''