
    \j                         d Z ddlZddlmZ ddlmZ ddlmZmZ dZ		  G d de      Z
 G d	 d
e      Z G d de      Zy)zA
This module provides common classes for the gitignore patterns.
    N)Literal)RegexPattern)AnyStrassert_unreachablelatin1c                   R    e Zd ZdZdZededefd       Zedede	d   defd	       Z
y
)_GitIgnoreBasePatternz
	.. warning:: This class is not part of the public API. It is subject to
		change.

	The :class:`_GitIgnoreBasePattern` class is the base implementation for a
	compiled gitignore pattern.
	 sreturnc                    t        | t              r	t        }| }n;t        | t              rt        }| j                  t              }nt        d| d      dj                  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:z! is not a unicode or byte string. c              3   2   K   | ]  }|d v rd| n|  yw)z\[]!*#?\Nr
   ).0xs     J/root/env/lib/python3.12/site-packages/pathspec/patterns/gitignore/base.py	<genexpr>z/_GitIgnoreBasePattern.escape.<locals>.<genexpr>6   s!     LAO"QC:Ls   )
isinstancestrbytesdecode_BYTES_ENCODING	TypeErrorjoinencode)r   return_typestring
out_string	out_bytess        r   escapez_GitIgnoreBasePattern.escape"   s     3;6!U;HH_%6	Ru=>	?? wwLVLL*E  19

    patternrange_error)literalraisec                    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  }|}nM|dk(  r|dz  }nB|dk(  rt	        d| || d| d      t        d|d       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.

		*range_error* (:class:`int`) is how to handle invalid range notation in the
		pattern:

		-	:data:`"literal"`: Invalid notation will be treated as a literal string.

		-	:data:`"raise"`: Invalid notation will cause a :class:`_RangeError` to be
			raised.

		Returns the regular expression (:class:`str`).
		Fr   r      r   T*z[^/]*?z[^/][!^]z\\r%   z\[r&   zInvalid range notation=z found in pattern=.zrange_error=z is invalid.z9Escape character found with no next character to escape: )lenrer!   replace_RangeErrorr   
ValueError)	r#   r$   r!   regexiendcharjexprs	            r   _translate_segment_globz-_GitIgnoreBasePattern._translate_segment_glob>   s(   2 &
%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 	y  une

 	 1 00B
A	 	
 LK+<89 
RYYt_EC 	
CF 	?{K
  
,r"   N)__name__
__module____qualname____doc__	__slots__staticmethodr   r!   r   r   r;   r
   r"   r   r	   r	      sg     v &  6 CC)*C 
C Cr"   r	   c                       e Zd ZdZy)GitIgnorePatternErrorzU
	The :class:`GitIgnorePatternError` class indicates an invalid gitignore
	pattern.
	Nr<   r=   r>   r?   r
   r"   r   rC   rC           r"   rC   c                       e Zd ZdZy)r3   zi
	The :class:`_RangeError` class indicates an invalid range notation was found
	in a gitignore pattern.
	NrD   r
   r"   r   r3   r3      rE   r"   r3   )r?   r1   typingr   pathspec.patternr   pathspec._typingr   r   r   r	   r4   rC   r3   r
   r"   r   <module>rJ      sR    

 
lL l^J ' r"   