
    Vi*                    J   S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSK	J
r
JrJrJrJr  \R                  \" \SS5      -  r\R$                  \R
                  1\R&                  :*  =(       a    \R(                  \R*                  ;   r\R.                  " S\R0                  5      \R.                  " S	\R0                  5      4r\R.                  " S
5      \R.                  " S5      4r " S S\\   5      r " S S\R8                  \\   5      rS r\R>                  " \\5        g)zHandle path matching.    )annotationsN   )util)PatternAnyStrGenericAnycastO_DIRECTORYz\\|[a-z]:(?:\\|$)s   \\|[a-z]:(?:\\|$)/   /c                      \ rS rSrSr              S	S jr                  S
S jr        SS jrSSS jjrSr	g)_Match   zMatch the given pattern.c                    Xl         X l        X0l        X@l        XPl        X`l        [        U R                   [        5      (       a  [        R                  U l        g[        R                  U l        g)zInitialize.N)filenameincludeexcluderealpathfollow
isinstancebytesr   BYTESUNICODEptype)selfr   r   r   r   r   r   s          c/home/james-whalen/.local/share/pipx/venvs/semgrep/lib/python3.13/site-packages/wcmatch/_wcmatch.py__init___Match.__init__   sG     !		#-dmmU#C#CTZZ

    c	           	        Sn	[        U5      n
SnUR                  U5      nU(       Ga  Sn	U(       Gd  [        UR                  5       5      n [        UR                  5       S5       GHH  u  pU(       Ga0  UR	                  U5      U
:H  nUR                  U5      R                  U5      nUc1  [        R                  R                  XrSUR                  U5       5      nU H  n[        R                  R                  UU5      nX4nU(       d  X:w  d	  U(       a  M;  UR                  US5      nUcb  Uc%  [        R                  R                  U5      nUUU'   O: [        R                  " XS9n[        R                  " UR                   5      nUUU'   U(       + n	U	(       a  M    O   U	(       a  GMH    U	$     U	$ U	$ ! ["        [$        4 a    Sn NAf = f! ["         a    Sn	 U	$ f = f)aX  
Match path against the pattern.

Since `globstar` doesn't match symlinks (unless `FOLLOW` is enabled), we must look for symlinks.
If we identify a symlink in a `globstar` match, we know this result should not actually match.

We only check for the symlink if we know we are looking at a directory.
And we only call `lstat` if we can't find it in the cache.

We know it's a directory if:

1. If the base is a directory, all parts are directories.
2. If we are not the last part of the `globstar`, the part is a directory.
3. If the base is a file, but the part is not at the end, it is a directory.

FNTr   dir_fd)len	fullmatchgroups	enumerateendstripsplitosr   joinstartgetislinklstatstatS_ISLNKst_modeOSError
ValueError)r   patternr   is_dirsepr   symlinksrootr$   matchedr)   basemlastistarat_endpartspartkeyis_linksts                         r   	_fs_match_Match._fs_match0   s   8 (mh'G 188:$#,QXXZ#;%&UU1X_F$(JJsO$9$9#$>E#|')ww||D;AGGAJ:O'P(-')ww||D$'?'-n#)QYff.6ll3.EG'.+1>68ggnnT6JG<CHSM-S57XXd5R ;?,,rzz:R<CHSM29kG+27(-' ).(  'w! = $<< w 5<Z3H -@:?-@  $#G$sO   C	G =G F9,1G !	G /G 2G 9GG GG G! G!c                   [         R                  " 5       S:X  a  SOSn[        U R                  [        5      (       a  [
        R                  " U5      nOUnU R                  R                  U5      n UcG  [
        R                  R                  [
        R                  R                  X R                  5      5      nO] [
        R                  " [
        R                  R                  X R                  5      US9n[        R                  " UR                  5      nU(       d  U(       a  SnU R                  U-   n	OU R                  n	Sn
U R                    H+  nU R#                  XXeU R$                  XU5      (       d  M)  Sn
  O   U
(       aC  U R&                  (       a2  U R&                   H"  nU R#                  XXeSXU5      (       d  M  Sn
  U
$    U
$ ! [        [        4 a    Sn Nf = f! [         a     gf = f)z*Match real filename includes and excludes.windows\r   r#   FT)r   platformr   r   r   r,   fsencodeendswithr   isdirr-   r2   S_ISDIRr4   r5   r6   r   rH   r   r   )r   r:   r;   r$   tempr9   r8   is_file_dirrG   r   r<   r7   s               r   _match_real_Match._match_realx   s    }})3tdmmU++++d#CC'',	~ ggmmBGGLL}},MN;dMM!B6RB #',,rzz":K +F}}s*H}}H||G~~gdkk8[abb $
 ||#||G~~gdH\bcc"'  ,
 5  , ("'K(  		s7   2A	G& =<G 9 G& G# G& "G##G& &
G32G3Nc           	     J   U R                   (       Gam  [        U R                  [        5      (       a  Ub  UOSnOUb  UOSnUb  [        (       d  Sn[        U R                  [        U5      5      (       d7  [        SR                  [        U R                  5      [        U5      5      5      eU R                  (       a  [        U R                  S   R                  [        U R                  5      5      (       dN  [        SR                  [        U R                  5      [        U R                  S   R                  5      5      5      e[        [        [           [        R                  " 5       S:X  a  [        O[         U R"                     5      nUR%                  U R                  5      SLnU(       a*  [&        R(                  R+                  U R                  5      nOUcG  [&        R(                  R+                  [&        R(                  R-                  X0R                  5      5      nO? [&        R.                  " [&        R(                  R-                  X0R                  5      US9  S	nU(       a  0 nU R5                  XsU5      $ g
S
nU R                   H'  n	U	R7                  U R                  5      (       d  M%  S	n  O   U(       aK  S	nU R8                  (       a8  U R8                   H(  n	U	R7                  U R                  5      (       d  M%  S
n  U$    U$ ! [0        [2        4 a    S
n Nf = f)zMatch.N   ..zIThe filename and root directory should be of the same type, not {} and {}r   zBThe filename and pattern should be of the same type, not {} and {}rK   r#   TF)r   r   r   r   SUPPORT_DIR_FDtype	TypeErrorformatr   r7   r
   r   r   r   rM   RE_WIN_MOUNTRE_MOUNTr   matchr,   r   lexistsr-   r1   r5   r6   rT   r&   r   )
r   root_dirr$   r;   re_mountis_absexistsr:   r<   r7   s
             r   r_   _Match.match   sR    999$--//#+#7xT#+#7xS!..dmmT$Z88_ffT]]+T(^  ||Jt||A/F/FT]]H[$\$\X__T]]+T$,,q/2I2I-J  GFOdmmoQZ>Zl`hjnjtjt-uvH^^DMM2$>F7dMM)JK"HHRWW\\$>vN "F''??||G  // $
 G||#||G((77"'	  , 1  , #"F#s   &<L L"!L")r   r   r   r   r   r   r   )r   r   r   tuple[Pattern[AnyStr], ...]r   "tuple[Pattern[AnyStr], ...] | Noner   boolr   rh   r   rh   returnNone)r7   zPattern[AnyStr]r   r   r8   rh   r9   r   r   rh   r:   %dict[tuple[int | None, AnyStr], bool]r;   r   r$   
int | Noneri   rh   )r:   rk   r;   r   r$   rl   ri   rh   NN)ra   AnyStr | Noner$   rl   ri   rh   )
__name__
__module____qualname____firstlineno____doc__r   rH   rT   r_   __static_attributes__ r!   r   r   r      s    "VV -V 4	V
 V V V 
V&F F F 	F
 F F 8F F F 
FP/7/ / 	/
 
/b< <r!   r   c                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'   S\S
'   S\S'   Sr    S         SU 4S jjjrSS jrSS jr	SS jr
SS jrSSS jjrSrU =r$ )WcRegexp   zFile name match object.rf   _includerg   _excluderh   _real_path_followint_hashry   rz   r{   r|   r}   r   c                   > [         TU ]  UUUUU[        [        U 5      [        U5      U[        U5      U[        U5      U[        U5      U[        U5      U45      S9  g)zInitialization.r   N)superr   hashrZ   )r   r   r   r   r   r   	__class__s         r   r   WcRegexp.__init__   sg     	JM7M7JJL&	 	 	
r!   c                    U R                   $ )zHash.)r   r   s    r   __hash__WcRegexp.__hash__  s     zzr!   c                z    [        U R                  5      U R                  b  [        U R                  5      -   $ S-   $ )zLength.r   )r%   ry   rz   r   s    r   __len__WcRegexp.__len__  s3     4==!4==;TS%7\\Z[\\r!   c                b   [        U[        5      =(       a    U R                  UR                  :H  =(       ay    U R                  UR                  :H  =(       aY    U R                  UR                  :H  =(       a9    U R
                  UR
                  :H  =(       a    U R                  UR                  :H  $ zEqual.r   rw   ry   rz   r{   r|   r}   r   others     r   __eq__WcRegexp.__eq__  s     uh' *MMU^^+*MMU^^+* JJ%++%* JJ%++%	*
 LLEMM)	
r!   c                l   [        U[        5      (       + =(       d    U R                  UR                  :g  =(       dy    U R                  UR                  :g  =(       dY    U R                  UR                  :g  =(       d9    U R
                  UR
                  :g  =(       d    U R                  UR                  :g  $ r   r   r   s     r   __ne__WcRegexp.__ne__&  s     5(++ *MMU^^+*MMU^^+* JJ%++%* JJ%++%	*
 LLEMM)	
r!   c                    [        UU R                  U R                  U R                  U R                  U R
                  5      R                  UUS9$ )zMatch filename.)ra   r$   )r   ry   rz   r{   r|   r}   r_   )r   r   ra   r$   s       r   r_   WcRegexp.match2  sN     MMMMJJJJLL
 %  

	
r!   ru   )NFFF)
r   rf   r   rg   r   rh   r   rh   r   rh   )ri   r~   )r   r	   ri   rh   rm   )r   r   ra   rn   r$   rl   ri   rh   )ro   rp   rq   rr   rs   __annotations__	__slots__r   r   r   r   r   r_   rt   __classcell__)r   s   @r   rw   rw      s    !))00KKMJNI
 7;
,
 4
 	

 
 
 
8
]





 
r!   rw   c                    [         U R                  U R                  U R                  U R                  U R
                  44$ )N)rw   ry   rz   r{   r|   r}   )ps    r   _pickler   B  s,    ajj!**aggqww		JJJr!   ) rs   
__future__r   rer,   r2   copyreg r   typingr   r   r   r	   r
   O_RDONLYgetattr	DIR_FLAGSopensupports_dir_fdscandirsupports_fdrY   compileIr]   r^   r   	Immutablerw   r   pickleru   r!   r   <module>r      s     " 	 	    6 6 KK'"mQ77	''277#r'9'99ZbjjBNN>Z JJ#RTT*JJ$bdd+
 JJtJJuKWV_ K\W
t~~wv W
tK x !r!   