
    nii                        d Z ddlmZ ddlmZ ddlmZ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mZmZmZ ddlmZ d	d
lmZmZmZ d	dlmZ  G d de          ZdS )z
This module provides the :module:`hyperscan` backend for :class:`~pathspec.gitignore.GitIgnoreSpec`.

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OptionalUnionN)RegexPattern)GitIgnoreSpecPattern_BYTES_ENCODING_DIR_MARK_CG_DIR_MARK_OPT)override   )HS_FLAGSHyperscanExprDatHyperscanExprDebug)HyperscanPsBackendc                       e Zd ZU dZded<   dddd$ fdZeed%d                        Zed&d            Z	ed'd#            Z
 xZS )(HyperscanGiBackendz
	The :class:`HyperscanGiBackend` class is the :module:`hyperscan`
	implementation used by :class:`~pathspec.gitignore.GitIgnoreSpec`. The
	Hyperscan database uses block mode for matching files.
	ztuple[Optional[bool], int, int]_outN_debug_exprs
_test_sortpatternsSequence[RegexPattern]r   Optional[bool]r    Optional[Callable[[list], None]]returnNonec               ^    t                                          |||           d| _        dS )z
		Initialize the :class:`HyperscanMatcher` instance.

		*patterns* (:class:`Sequence` of :class:`.RegexPattern`) contains the
		compiled patterns.
		r   Nr   N)super__init__r   )selfr   r   r   	__class__s       c/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/pathspec/_backends/hyperscan/gitignore.pyr$   zHyperscanGiBackend.__init__2   s5     ''8,:NNN$)     dbhyperscan.Databasedebugboollist[tuple[int, RegexPattern]]sort_ids%Optional[Callable[[list[int]], None]]list[HyperscanExprDat]c           
     h   |s
J |            g }g |D ]-\  }}|j         J ||f            t          |t                    s
J |            |j        j        }g }t          |t
                    rt          |t                    r|}	n9t          |t                    s
J |            |                    t                    }	t          |	v r|	                    t                    rR|	dt          t                              }
|                    |
 ddf           |                    |
 ddf           n2|	                    t          d          }
|                    |
df           |s|                    |df           |D ]\  }}t          |t                    r|}n4t          |t                    s
J |            |                    d          }|r,|                    t#          |j         |||                     n*|                    t%          |j         ||                                         |           /t'          t)          t                                        }| ||           fd	|D             |                     |t                    t,          
           |S )a  
		Create 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/T$Futf8)includeindexis_dir_patternregex)r5   r6   r7   c                     g | ]
}|         S  r:   ).0_HyperscanGiBackend__idexprss     r'   
<listcomp>z/HyperscanGiBackend._init_db.<locals>.<listcomp>   s    (((DE$K(((r(   )expressionsidselementsflags)r5   
isinstancer	   r8   patternr
   strbytesdecoder   r   endswithr   lenappendreplaceencoder   r   listrangecompiler   )r)   r+   r   r.   	expr_datapattern_indexrD   r8   use_regexes	regex_str
base_regexr7   regex_bytesr@   r=   s                 @r'   _init_dbzHyperscanGiBackend._init_dbL   s)   8 
8 '))% ( 8 8mW
/
%
%w'?
%
%
% Wl
+
+44W444= 579;.// - % /YYue$$++e+++o..Yy  =)) 	- 1s=11112jZ***D1222Z***E23333 $$\377j*d+,,,
 'u~&&& +  un% ([[uc""))E)))<<''[ (o#	       &o#      
LL+0 	U3u::#8C===((((C(((5 **
JJ		     
r(   filerE   $tuple[Optional[bool], Optional[int]]c                    | j         }| j         dS d| _        |                    |                    d          | j                   | j        dd         \  }}|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!   r4   )match_event_handler   r"   )_dbr   scanrL   _HyperscanGiBackend__on_match)r%   rW   r)   out_include	out_indexs        r'   
match_filezHyperscanGiBackend.match_file   sr     x"	X ,$)''$++f

4?'CCC9RaR=+y"__9
y	!!r(   expr_idint_from_to_flags_contextr   c                    | j         |         }|j        }|rd}nd}|j        }	|j        }
| j        d         }| j        d         }|	r|r|
|k    s||k    r|
|k    s||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   r[   N)
_expr_datar7   r5   r6   r   )r%   rb   rd   re   rf   rg   expr_datr7   priorityr5   r6   
prev_indexprev_prioritys                r'   
__on_matchzHyperscanGiBackend.__on_match   s     _W%(*. 88 8 '
.%y|*)A,-33#(:#5#5=  UZ%7%724999 r(   )r   r   r   r   r   r   r   r   )
r)   r*   r+   r,   r   r-   r.   r/   r   r0   )rW   rE   r   rX   )rb   rc   rd   rc   re   rc   rf   rc   rg   r   r   r   )__name__
__module____qualname____doc____annotations__r$   r   staticmethodrV   ra   r^   __classcell__)r&   s   @r'   r   r   (   s           '&&& "&15       4 f f f , (fP " " " ("6 "3 "3 "3 ("3 "3 "3 "3 "3r(   r   )rr   
__future__r   collections.abcr   typingr   r   r   r   	hyperscanModuleNotFoundErrorpathspec.patternr	    pathspec.patterns.gitignore.specr
   r   r   r   pathspec._typingr   _baser   r   r   pathspecr   r   r:   r(   r'   <module>r      s    # " " " " "                                   
                   M3 M3 M3 M3 M3+ M3 M3 M3 M3 M3s   ! ++