
    W-PhO1                         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__     ^/var/www/html/test/jupyter/venv/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                 X   t          |t                    rt          }nJt          |t                    r"t          }|                    t                    }nt          d|d          |}|                    d          r|                                }n|                                }|	                    d          rd}d}n@|dk    rd}d}n4|r-|	                    d          rd}|d	d         }nd
}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 ]\  }	}|dk    r|	dk    r|	|k    r|                    d           .|	dk    r|                    d           d}L|	|k    r7|r|                    dt           d           s|                    d           |                    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
}|                    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.z\ #N/!F   Tr   z**r   z^.+(?P<z>/).*$zInvalid git pattern: ^z[^/]+(?:/.*)?z(?:.+/)?z(?P<z>/).*z/.*z(?:/.+)?*z[^/]+z(?:(?P<z>/).*)?$ )
isinstancestrbytesdecode_BYTES_ENCODING	TypeErrorendswithlstrip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is_dir_pattern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e  ^^77]]__7 a 577#~~ 577 T  GabbkGGG > --$$< %R((> #l##a'B//  q!D
q/Ct||t	a	,1aD!8!8a!8 1y000N
q/ 	 	QLQ3|#4#4#9#9,q/#9 A$D!!! 	
 Q ##O;K#O#O
P
PP
r
 s<00144
 LUFJ
l

a
CL)) : :3t	
aAHH }}%&&&&66 }}Z   zz88  -Y---....f
 }}Z   zz
**	 }}SmmG	
c }}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 }}1y111222jj
MM#GGFOOEE EE
 57
;%//<<((5	s   (N
N&N!!N&c                    d}d}dt          |           }}||k     r>| |         }|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    s| |         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     >|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\[z9Escape character found with no next character to escape: )r/   reescapereplacer5   )r   rN   r;   r@   rE   charjexprs           r   r4   z+GitWildMatchPattern._translate_segment_glob   s#    &
%c'llS!	C
!*461 RF	RYt__EEFF 
WEE 
VOEE 	
A 	3wwGAJ#%%s):):!VQ 	3ww71:$$!VQ c''gajC''!VQ c''gajC'' 	3ww !VQT
c
ckd1faa
!*

 ckd1fa 
WQqS\!!$///T d]U 
QQ
 e^UU 
RYt__Eo 	
Cr  ]	[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 )rI   Nr   ).0xmeta_characterss     r   	<genexpr>z-GitWildMatchPattern.escape.<locals>.<genexpr>z  s5      OO11#7#7taxxQOOOOOOr   )r#   r$   r%   r&   r'   r(   r6   r7   )rS   r9   string
out_stringrX   s       @r   rN   zGitWildMatchPattern.escaped  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   boolrG   staticmethodr$   r4   rN   r   r   r   r   r   $   s          EE HVhtn,-E E E +EN lc lc l l l ,l\ 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superrb   __init__)selfargskw	__class__s      r   rg   zGitIgnorePattern.__init__  s@     (%$($5"55555r   c                  >    t          j        dt          d           dS )rd   z_GitIgnorePattern ('gitignore') is deprecated. Use GitWildMatchPattern ('gitwildmatch') instead.   )
stacklevelN)warningswarnDeprecationWarningr   r   r   re   zGitIgnorePattern._deprecated  s1    
 -A' ' ' ' ' 'r   c                 l    |                                    t          t          |           j        |i |S )rd   )re   rf   rb   rG   )r8   ri   rj   rk   s      r   rG   z!GitIgnorePattern.pattern_to_regex  s8    
 //	6	%	%	6	C	C	CCr   )r   N)
r   r   r   r   rg   r_   re   r]   rG   __classcell__)rk   s   @r   rb   rb     s         
6 6 6 6 6 6 ' ' ' ,' D D D D +D D D D Dr   rb   	gitignore)r   rM   ro   typingr   r   r   r"   r   r   r   r'   r0   r5   r   r   register_patternrb   r   r   r   <module>rw      sX   
 
			          
       " " " " " " 	    z   [ [ [ [ [, [ [ [z
  n&9 : : :D D D D D* D D DB  k#3 4 4 4 4 4r   