Ë
    ù\j3  ã                  óÂ   — 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
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y# e$ r dZ
Y Œ=w xY w)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_sortc               ó8   •— t         ‰|   |||¬«       d| _        y)z–
		Initialize the :class:`HyperscanMatcher` instance.

		*patterns* (:class:`Sequence` of :class:`.RegexPattern`) contains the
		compiled patterns.
		r   ©Néÿÿÿÿr   N)ÚsuperÚ__init__r   )ÚselfÚpatternsr   r   Ú	__class__s       €úP/root/env/lib/python3.12/site-packages/pathspec/_backends/hyperscan/gitignore.pyr   zHyperscanGiBackend.__init__2   s%   ø€ ô 'Ñ8¨,À:ÐÔNà€$„)ðó    c           
     óÎ  — |sJ |«       ‚g }g }|D ]ñ  \  }}|j                   €	J ||f«       ‚|j                  €	J ||f«       ‚t        |t        «      sJ |«       ‚|j                  j                  }g }	t        |t
        «      rÅt        |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 ]£  \  }}t        |t        «      r|}n(t        |t        «      sJ |«       ‚|j!                  d«      }|r)|j                  t#        |j                   |||¬«      «       n'|j                  t%        |j                   ||¬«      «       |j                  |«       Œ¥ Œô t'        t)        t        |«      «      «      }| ||«       |D cg c]  }||   ‘Œ	 }}| j+                  ||t        |«      t,        ¬	«       |S c c}w )
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)r(   r)   r*   )ÚexpressionsÚidsÚelementsÚflags)r(   r+   Ú
isinstancer	   Úpatternr
   ÚstrÚbytesÚdecoder   r   Úendswithr   ÚlenÚappendÚreplaceÚencoder   r   ÚlistÚrangeÚcompiler   )ÚdbÚdebugr    Úsort_idsÚ	expr_dataÚexprsÚpattern_indexr1   r+   Úuse_regexesÚ	regex_strÚ
base_regexr*   Úregex_bytesr-   Ú_HyperscanGiBackend__ids                   r"   Ú_init_dbzHyperscanGiBackend._init_dbL   sy  € ñ8 
Ð8Óˆð ')€)Ø€%Ø (ó 9Ñ€mWØ
/‰/Ð
%Ð?¨°wÐ'?Ó?Ð
%Ø
-‰-Ð
#Ð= m°WÐ%=Ó=Ð
#ô WœlÔ
+Ð4¨WÓ4Ð
+Ø=‰=× Ñ €5à79€;ÜÔ.Ô/ô %œÔØYäuœeÔ$Ð+ eÓ+Ð$Ø—‘œoÓ.€YäyÑ à×Ñœ=Ô)ð Ð1œs¤=Ó1Ð1Ð2€jØ×Ñ˜Z˜L¨Ð*¨DÐ1Ô2Ø×Ñ˜Z˜L¨Ð*¨EÐ2Õ3ð ×$Ñ$¤\°3Ó7€jØ×Ñ˜* dÐ+Ô,á
à×Ñ˜˜u~Ô&à +ò Ñ€uˆnÜ%œÔØ[äuœcÔ"Ð) EÓ)Ð"Ø—<‘< Ó'€[áØ×ÑÔ(Øo‰oØØ#Øô	õ ð ×ÑÔ&Øo‰oØØ#ôô ð 
‡LLÕò+ðI9ôx 	ŒU”3u“:ÓÓ€#ØÐÙˆC„=Ø$'Ö(˜DˆE$‹KÐ(€5Ð(ð ‡**ØØ
Ü‹JÜ	ð	 ô ð 
Ðùò )s   È0I"c                óÀ   — | j                   }|€yd| _        |j                  |j                  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   r'   )Úmatch_event_handleré   r   )Ú_dbr   Úscanr9   Ú_HyperscanGiBackend__on_match)r   Úfiler=   Úout_includeÚ	out_indexs        r"   Ú
match_filezHyperscanGiBackend.match_file·   sh   € ð ‡xx€"Ø€Zð à€$„)Ø‡''ˆ$+‰+fÓ
°4·?±?€'ÔCð  Ÿ9™9 R a˜=Ñ€+ˆyØ"‚_Ø€9à
yÐ	!Ð!r#   c                ó  — | j                   |   }|j                  }|rd}nd}|j                  }	|j                  }
| j                  d   }| j                  d   }|	r|r|
|kD  s||k(  r|
|kD  s||kD  r|	|j                  |f}|| _        y)zn
		Called on each match.

		*expr_id* (:class:`int`) is the expression id (index) of the matched
		pattern.
		r   rK   N)Ú
_expr_datar*   r(   r)   r   )r   Úexpr_idÚ_fromÚ_toÚ_flagsÚ_contextÚexpr_datr*   Úpriorityr(   r)   Ú
prev_indexÚprev_priorityÚout_tups                 r"   Ú
__on_matchzHyperscanGiBackend.__on_matchÔ   s™   € ð _‰_˜WÑ%€(à×*Ñ*€.Ùà8ð €8ð ×Ñ€'Ø
.‰.€%Øy‰y˜‰|€*Ø—)‘)˜A‘,€-á‘ 5¨:Ò#5Ø=Ò  U¨ZÒ%7ØÒàx—~‘~ xÐ0€7Ø€4„9à	r#   )r    zSequence[RegexPattern]r   úOptional[bool]r   z Optional[Callable[[list], None]]ÚreturnÚNone)
r=   zhyperscan.Databaser>   Úboolr    zlist[tuple[int, RegexPattern]]r?   z%Optional[Callable[[list[int]], None]]ra   zlist[HyperscanExprDat])rO   r2   ra   z$tuple[Optional[bool], Optional[int]])rU   ÚintrV   rd   rW   rd   rX   rd   rY   r   ra   r`   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   ÚstaticmethodrH   rR   rN   Ú__classcell__)r!   s   @r"   r   r   (   s÷   ø… ñð 'Ó&ð "&Ø15ñà"ðð ð	ð
 /ðð õð4 ØðgØðgà	ðgð +ðgð 2ð	gð
 ògó ó ðgðR ò"ó ð"ð8 ð%àð%ð 
ð%ð ð	%ð
 ð%ð ð%ð ò%ó ô%r#   r   )rh   Ú
__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"   ú<module>rw      sn   ðñõ #õ÷ó ðÛõ÷ó õ
÷ñ õôRÐ+õ Røð+ ò Ø‚ðús   œA ÁAÁA