
    hO1                         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       y)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y)GitWildMatchPatternErrorzW
	The :class:`GitWildMatchPatternError` indicates an invalid git wild match
	pattern.
	N)__name__
__module____qualname____doc__     Q/var/www/html/immo/lib/python3.12/site-packages/pathspec/patterns/gitwildmatch.pyr   r      s     r   r   c                   x    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y	)
GitWildMatchPatternzX
	The :class:`GitWildMatchPattern` class represents a compiled Git wildmatch
	pattern.
	r   patternreturnc                    t        |t              rt        }n;t        |t              rt        }|j                  t              }nt        d|d      |}|j                  d      r|j                         }n|j                         }|j                  d      rd}d}n|dk(  rd}d}nx|rq|j                  d      rd}|d	d }nd
}d}|j                  d      }|d    }t        t        |      d	z
  dd      D ]  }	||	d	z
     }
||	   }|
dk(  s|dk(  s||	=   t        |      dk(  r|d   dk(  r|d	   s
dt         d}|d   s|d= n=t        |      d	k(  st        |      dk(  r |d	   s|d   dk7  r|j                  dd       n	 |st        d|      |d   st        |      d	kD  rd|d<   |jdg}d}t        |      d	z
  }t!        |      D ]%  \  }	}|dk(  r||	dk(  r|	|k(  r|j#                  d       (|	dk(  r|j#                  d       d}A|	|k(  r.|r|j#                  dt         d       b|j#                  d       t|j#                  d       d
}|dk(  rE|r|j#                  d       |j#                  d       |	|k(  r|j#                  dt         d       d
}|r|j#                  d       	 |j#                  | j%                  |             |	|k(  r|j#                  dt         d       d
}( |j#                  d       dj)                  |      }n|}nd}d}||t        u r|j+                  t              }||fS # t&        $ r}t        d|      |d}~ww xY w)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    ;'5!;^^O,7	Xg[(IJ	KKe ^^7]]_7 57#~ 57 GabkGG > --$< %R((> #l#a'B/ q!D
q/Ct|t	a	 
,1aD!8a yk0N
q/ 	QLQ3|#4#9,q/ A$D! 	
 #%:;K:N#O
PP
r
s<014
 LUFJ
l
a
CL) :3t	
aAH }}}&6 }}Z z8 YKu-.
 }}Z z
*	}}SmmG	
c }}wyk12j 
}}S[}}S0056 
c }}wyk12ju:x MM#GGFOE E
 57
;%/<<(5	7  [%(=>N=Q&RSYZZ[s   4 M	M!MM!c                 p   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k7  r|dz  }||k  r	| |   dk7  r||k  rL|dz  }d}| |   dk(  r|dz  }|dz  }n| |   dk(  r
|dz  }|dz  }|| || j                  dd      z  }||z  }|}n|dz  }n|t        j                  |      z  }||k  r|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'lS!	C
!*461F	RYYt_EF 
WE 
VOE 	
A 	3wGAJ#%s):!VQ 	3w71:$!VQ c'gajC'!VQ c'gajC' 	3w !VQT
c
ckd1fa
!*
 ckd1fa 
WQq\!!$//T d]U 
Q
 e^U 
RYYt_Eo 	
Cr 	OPW{[	\\	,r   sc                 "   t        | t              r	t        }| }n;t        | t              rt        }| j                  t              }nt        d| d      ddj                  fd|D              }|t        u r|j                  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   4   K   | ]  }|v rd |z   n|  yw)rI   Nr   ).0xmeta_characterss     r   	<genexpr>z-GitWildMatchPattern.escape.<locals>.<genexpr>z  s!     O11#7taxQ>Os   )r#   r$   r%   r&   r'   r(   r6   r7   )rS   r9   string
out_stringrX   s       @r   rN   zGitWildMatchPattern.escaped  s     3;6!U;HH_%6	Ru=>	?? /ww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N lc lc l l\ v &  r   r   gitwildmatchc                   J     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.
	c                 L    | j                          t        t        |   |i | y)
		Warn about deprecation.
		N)_deprecatedsuperrb   __init__)selfargskw	__class__s      r   rg   zGitIgnorePattern.__init__  s&     $($5"5r   c                  <    t        j                  dt        d       y)rd   z_GitIgnorePattern ('gitignore') is deprecated. Use GitWildMatchPattern ('gitwildmatch') instead.   )
stacklevelN)warningswarnDeprecationWarningr   r   r   re   zGitIgnorePattern._deprecated  s    
 --A'r   c                 J    | j                          t        t        |   |i |S )rd   )re   rf   rb   rG   )r8   ri   rj   rk   s      r   rG   z!GitIgnorePattern.pattern_to_regex  s'    
 //		6	C	CCr   )r   N)
r   r   r   r   rg   r_   re   r]   rG   __classcell__)rk   s   @r   rb   rb     s7    
6 ' ' 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      s   
 
  
  " 	z [, [z
   n&9 :D* DB   k#3 4r   