
    mid                        d Z ddlmZ ddlmZ ddlmZ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:`hyperscan` backend for :class:`~pathspec.pathspec.PathSpec`.

WARNING: The *pathspec._backends.hyperscan* package is not part of the public
API. Its contents and structure are likely to change.
    )annotations)Sequence)AnyCallableOptionalN)_Backend)RegexPattern)override   )enumerate_patterns   )hyperscan_error)HS_FLAGSHyperscanExprDatHyperscanExprDebugc                  r    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'd"Z
dS )(HyperscanPsBackendz
	The :class:`HyperscanPsBackend` class is the :module:`hyperscan`
	implementation used by :class:`~pathspec.pathspec.PathSpec` for matching
	files. The Hyperscan database uses block mode for matching files.
	N)_debug_exprs
_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          |dd          }t          |          }|r.|                                 }|                     ||||          }nd}g }|| _	        	 || _
        	 || _        	 d	| _        	 t          |          | _        dS )
z
		Initialize the :class:`HyperscanPsBackend` instance.

		*patterns* (:class:`Sequence` of :class:`.RegexPattern`) contains the
		compiled patterns.
		Nr   zpatterns[0]=z must be a RegexPattern.TF)filterreverse)dbdebugr   sort_idsN)	hyperscanr   
isinstancer	   	TypeErrorr   bool_make_db_init_db_dbr   
_expr_data_outdict	_patterns)selfr   r   r   use_patternsdebug_exprsr   	expr_datas           }/var/www/html/bestrading.cuttalo.com/scripts/kaggle-env/lib/python3.11/site-packages/pathspec/_backends/hyperscan/pathspec.py__init__zHyperscanPsBackend.__init__.   s    	 @j!l;; @	>hqk>>>	?	??#D%  , \""+ 2}}	
	   99 	29+-$( "$
 -6$/
 +5$) -1,>,>$.     r   hyperscan.Databaser    r'   list[tuple[int, RegexPattern]]r!   %Optional[Callable[[list[int]], None]]list[HyperscanExprDat]c           	       
 |s
J |            g }g 
|D ]\  }}|j         J ||f            t          |t                    s
J |            |j        j        }t          |t
                    r|}n4t          |t                    s
J |            |                    d          }|r,|                    t          |j         |d|                     n*|                    t          |j         |d                     
                    |           t          t          t          
                              }	| ||	           
fd|	D             
|                     
|	t          
          t                     |S )a  
		Initialize the Hyperscan database from the given patterns.

		*db* (:class:`hyperscan.Hyperscan`) is the Hyperscan database.

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

		*patterns* (:class:`~collections.abc.Sequence` of :class:`.RegexPattern`)
		contains the patterns.

		*sort_ids* (:class:`callable` or :data:`None`) is a function used to sort
		the compiled expression ids. This is used during testing to ensure the order
		of expressions is not accidentally relied on.

		Returns a :class:`list` indexed by expression id (:class:`int`) to its data
		(:class:`HyperscanExprDat`).
		Nutf8F)includeindexis_dir_patternregex)r<   r=   r>   c                     g | ]
}|         S  rA   ).0_HyperscanPsBackend__idexprss     r3   
<listcomp>z/HyperscanPsBackend._init_db.<locals>.<listcomp>   s    (((DE$K(((r5   )expressionsidselementsflags)r<   r%   r	   r?   patternbytesstrencodeappendr   r   listrangelencompiler   )r   r    r   r!   r2   pattern_indexrJ   r?   regex_bytesrG   rD   s             @r3   r)   zHyperscanPsBackend._init_dbt   s   6 
8 '))% (  mW
/
%
%w'?
%
%
% Wl
+
+44W444= 5 'KKeS!!((5(((,,v&&K '_	       %_      	<< 	U3u::#8C===((((C(((5 **
JJ		     
r5   filerL   $tuple[Optional[bool], Optional[int]]c                    | j         }| j         dS d| _        |                    |                    d          | j                   | j        \  }}|dk    rd}||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`).
		N)NNr"   r;   )match_event_handlerr#   )r*   r,   scanrM   _HyperscanPsBackend__on_match)r/   rU   r   out_include	out_indexs        r3   
match_filezHyperscanPsBackend.match_file   sj     x"	X ,$)''$++f

4?'CCC9+y"__9
y	!!r5   c                 @    t          j        t           j                  S )z[
		Create the Hyperscan database.

		Returns the database (:class:`hyperscan.Database`).
		)mode)r$   DatabaseHS_MODE_BLOCKrA   r5   r3   r(   zHyperscanPsBackend._make_db   s     
	!8	9	9	99r5   expr_idint_from_to_flags_contextr   c                t    | j         |         }|j        }| j        d         }||k    r|j        |f| _        dS dS )zn
		Called on each match.

		*expr_id* (:class:`int`) is the expression id (index) of the matched
		pattern.
		r   N)r+   r=   r,   r<   )	r/   rb   rd   re   rf   rg   expr_datr=   
prev_indexs	            r3   
__on_matchzHyperscanPsBackend.__on_match   sH    " _W%(
.%y|*
Z %(4999 r5   )r   r   r   r   r   r   r   r   )
r   r6   r    r'   r   r7   r!   r8   r   r9   )rU   rL   r   rV   )r   r6   )rb   rc   rd   rc   re   rc   rf   rc   rg   r   r   r   )__name__
__module____qualname____doc__r4   staticmethodr)   r
   r]   r(   rZ   rA   r5   r3   r   r   '   s          "&15D D D D D DL J J J ,JX " " " ("6 : : : ,:) ) ) ) ) )r5   r   )ro   
__future__r   collections.abcr   typingr   r   r   r$   ModuleNotFoundErrorpathspec.backendr   pathspec.patternr	   pathspec._typingr
   _utilsr   baser   _baser   r   r   r   rA   r5   r3   <module>r{      s    # " " " " "              
                                     T) T) T) T) T) T) T) T) T) T)s    ))