
    [d^/                         d Z ddlZddlZddlmZmZmZ ddlmZ ddl	m
Z
 dZ	 dZ	  G d	 d
e          Z G d de
          Z ej        de            G d de          Z ej        de           dS )z
This module implements Git's wildmatch pattern matching which itself is
derived from Rsync's wildmatch. Git uses wildmatch for its ".gitignore"
files.
    N)AnyStrOptionalTuple   )util)RegexPatternlatin1ps_dc                       e Zd ZdZdS )GitWildMatchPatternErrorzW
	The :class:`GitWildMatchPatternError` indicates an invalid git wild match
	pattern.
	N)__name__
__module____qualname____doc__     >lib/python3.11/site-packages/pathspec/patterns/gitwildmatch.pyr   r      s          r   r   c                       e Zd ZdZdZededeee         ee	         f         fd            Z
ededefd            Zededefd            Zd	S )
GitWildMatchPatternzX
	The :class:`GitWildMatchPattern` class represents a compiled Git
	wildmatch pattern.
	r   patternreturnc                    t          |t                    rt          }nJt          |t                    r"t          }|                    t                    }nt          d|d          |}|                                }|                    d          rd}d}n(|dk    rd}d}n|r|                    d          rd}|dd         }nd	}d}|                    d          }t          t          |          dz
  d
d          D ]$}||dz
           }	||         }
|	dk    r	|
dk    r||= %t          |          dk    r|d
         dk    r|d         sdt           d}|d
         s|d
= nRt          |          dk    st          |          dk    r+|d         s#|d
         dk    r|                    d
d           n	 |st          d|          |d         st          |          dk    rd|d<   |dg}d}t          |          dz
  }t          |          D ]w\  }}
|
dk    r|d
k    r%||k    r|                    dt           d           7|d
k    r|                    d           d}U||k    r|                    dt           d           z|                    d           d	}|
dk    rS|r|                    d           |                    d           ||k    r|                    dt           d           d	}|r|                    d           	 |                    |                     |
                     n%# t"          $ r}t          d|          |d}~ww xY w||k    r|                    dt           d           d	}y|                    d           d                    |          }n|}nd}d}|#|t          u r|                    t                    }||fS )a  
		Convert the pattern into a regular expression.

		*pattern* (:class:`str` or :class:`bytes`) is the pattern to convert
		into a regular expression.

		Returns the uncompiled regular expression (:class:`str`, :class:`bytes`,
		or :data:`None`); and whether matched files should be included
		(:data:`True`), excluded (:data:`False`), or if it is a
		null-operation (:data:`None`).
		zpattern:! is not a unicode or byte string.#N/!F   Tr   z**r   z^.+(?P<z>/).*$zInvalid git pattern: ^z[^/]+(?:(?P<z>/).*)?z(?:.+/)?z(?P<z>/).*z(?:/.+)?*z[^/]+z(?:(?P<$ )
isinstancestrbytesdecode_BYTES_ENCODING	TypeErrorstrip
startswithsplitrangelen	_DIR_MARKinsertr   	enumerateappend_translate_segment_glob
ValueErrorjoinencode)clsr   return_typeoriginal_patternregexincludeoverride_regexpattern_segsiprevsegoutput
need_slashendes                  r   pattern_to_regexz$GitWildMatchPattern.pattern_to_regex.   s      L;;'5!! L;^^O,,77	JgJJJ	K	KKMMOO' \ 577#~ U 577 O 	
 GabbkGGG > --$$< #l##a'B//  q!D
q/Ct| t 	a	,1 1aD!8 1a 1 1y000N
q/ 	
 	QLQ 	3|#4#4#9 	,q/ 	 A$ "D!!! 	
 Q ##O;K#O#O
P
PP
r
 s<0014 
 L @UFJ
l

a
CL)) 4 43t 3	
a AH  }}6I66677776  }}Z   zz8  }},I,,,---- }}Z   zz
* 	 }}SmmG	
c 3 }}1y111222jj 
 }}S[}}S00556666 [ [ [%&R>N&R&RSSYZZ[ 
c 3 }}1y111222jj
MM#GGFOOEE EE
 57
 );%/ )<<((5	s   (M
M$MM$c                    d}d}dt          |           }}||k     r1| |         }|dz  }|rd}|t          j        |          z  }n |dk    rd}n|dk    r|dz  }n|d	k    r|d
z  }n|dk    r|}||k     r| |         dk    r|dz  }||k     r| |         dk    r|dz  }||k     r#| |         dk    r|dz  }||k     r| |         dk    ||k     r]|dz  }d}| |         dk    r|dz  }|dz  }n| |         dk    r
|dz  }|dz  }|| ||                             dd          z  }||z  }|}n|dz  }n|t          j        |          z  }||k     1|rt	          d|           |S )a  
		Translates the glob pattern to a regular expression. This is used in
		the constructor to translate a path segment glob pattern to its
		corresponding regular expression.

		*pattern* (:class:`str`) is the glob pattern.

		Returns the regular expression (:class:`str`).
		Fr"   r   r   \Tr    z[^/]*?z[^/][r   ]r   z\^z\\z\[z9Escape character found with no next character to escape: )r-   reescapereplacer3   )r   rK   r9   r=   rB   charjexprs           r   r2   z+GitWildMatchPattern._translate_segment_glob   sC    &
%c'llS!	C U
!*461 PF	RYt__EE KFF G 
WEE B 
VOEE = 	
A3w 71:$ !VQ 	3w 71:$ !VQ
c' gajC' !VQ c' gajC'  	3w % !VQT
c 
ckd1faa
!*
  emd1fa 
WQqS\!!$///T d]U 
QQ
 e^UU 
RYt__Ek 	
C Un  ]	[PW[[	\	\\	,r   sc                 f   t          | t                    r
t          }| }nJt          | t                    r"t          }|                     t                    }nt          d| d          dd                    fd|D                       }|t          u r|                    t                    S |S )z
		Escape special characters in the given string.

		*s* (:class:`str` or :class:`bytes`) a filename or a string that you
		want to escape, usually before adding it to a ".gitignore".

		Returns the escaped string (:class:`str` or :class:`bytes`).
		zs:r   z[]!*#?r"   c              3   .   K   | ]}|v rd |z   n|V  dS )rF   Nr   ).0xmeta_characterss     r   	<genexpr>z-GitWildMatchPattern.escape.<locals>.<genexpr>o  s5      OO11#7>taxxQOOOOOOr   )r#   r$   r%   r&   r'   r(   r4   r5   )rP   r7   string
out_stringrU   s       @r   rK   zGitWildMatchPattern.escapeY  s     3 @;66!U @;HH_%%66	>>>>	?	?? /wwOOOOOOOOO*E 


O
,
,,
r   N)r   r   r   r   	__slots__classmethodr   r   r   boolrD   staticmethodr$   r2   rK   r   r   r   r   r   %   s          {{ HVhtn,-{ { { +{z jc jc j j j ,jX v &    ,  r   r   gitwildmatchc                   V     e Zd ZdZd fdZedd            Ze fd            Z xZ	S )GitIgnorePatternz
	The :class:`GitIgnorePattern` class is deprecated by :class:`GitWildMatchPattern`.
	This class only exists to maintain compatibility with v0.4.
	r   Nc                 p    |                                    t          t          |           j        |i | dS )
		Warn about deprecation.
		N)_deprecatedsuperr_   __init__)selfargskw	__class__s      r   rd   zGitIgnorePattern.__init__  s@     (%$($5"55555r   c                  >    t          j        dt          d           dS )ra   z_GitIgnorePattern ('gitignore') is deprecated. Use GitWildMatchPattern ('gitwildmatch') instead.   )
stacklevelN)warningswarnDeprecationWarningr   r   r   rb   zGitIgnorePattern._deprecated  s1    
 -3A' ' ' ' ' 'r   c                 l    |                                    t          t          |           j        |i |S )ra   )rb   rc   r_   rD   )r6   rf   rg   rh   s      r   rD   z!GitIgnorePattern.pattern_to_regex  s8    
 //	6	%	%	6	C	C	CCr   )r   N)
r   r   r   r   rd   r\   rb   rZ   rD   __classcell__)rh   s   @r   r_   r_   y  s         
6 6 6 6 6 6 ' ' ' ,' D D D D +D D D D Dr   r_   	gitignore)r   rJ   rl   typingr   r   r   r"   r   r   r   r'   r.   r3   r   r   register_patternr_   r   r   r   <module>rt      sX    
			          
       " " " " " " 	    z   O O O O O, O O Ob
  n&9 : : :D D D D D* D D DB  k#3 4 4 4 4 4r   