
    \jf)                     x    d Z ddlmZ ddlmZmZmZ ddlmZm	Z	m
Z
mZ dZ	 de dZ	 d	e d
Z	  G d de
      Zy)a  
This module provides :class:`GitIgnoreSpecPattern` which implements Git's
`gitignore`_ patterns, and handles edge-cases where Git's behavior differs from
what's documented. Git allows including files from excluded directories which
appears to contradict the documentation. Git discards patterns with invalid
range notation. This is used by :class:`~pathspec.gitignore.GitIgnoreSpec` to
fully replicate Git's handling.

.. _`gitignore`: https://git-scm.com/docs/gitignore
    )Optional)AnyStrassert_unreachableoverride   )GitIgnorePatternError_BYTES_ENCODING_GitIgnoreBasePattern_RangeErrorps_dz(?P<z>/)z(?:z|$)c            
           e Zd ZdZdZededee   de	e
ee      e
e   f   fd       Zeedede	e
e   e
e   f   fd              Zededee   dee   fd	       Zy
)GitIgnoreSpecPatterna6  
	The :class:`GitIgnoreSpecPattern` class represents a compiled gitignore
	pattern with special handling for edge-cases to replicate Git's behavior.

	This is registered under the deprecated name "gitwildmatch" for backward
	compatibility with v0.12. The registered name will be removed in a future
	version.
	 is_dir_patternpattern_segsreturnc                    |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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| rdt        fS y|dk(  r|d   dk(  r	|d   d	k(  ry|d
k(  r#|d   dk(  r|d   d	k(  r|d   dk(  r| rdt        fS y|dfS )a  
		Normalize the pattern segments to make processing easier.

		*is_dir_pattern* (:class:`bool`) is whether the pattern is a directory
		pattern (i.e., ends with a slash '/').

		*pattern_segs* (:class:`list` of :class:`str`) contains the pattern
		segments. This may be modified in place.

		Returns a :class:`tuple` containing either:

		- The normalized segments (:class:`list` of :class:`str`; or :data:`None`).

		- The regular expression override (:class:`str` or :data:`None`).
		r   r      **zPattern normalized to nothing.N)N.*   )N/)leninsert
ValueErrorrange_DIR_MARK_CG)r   r   iprevseg	seg_counts         J/root/env/lib/python3.12/site-packages/pathspec/patterns/gitignore/spec.py__normalize_segmentsz)GitIgnoreSpecPattern.__normalize_segments8   sp   ( 
a A
<A#l"3q"8a 1o4  	 
4	55	b	
 <
 \"Q&2. a
qs
4	a3
dlsd{Q	 ,)!^Q4/ ,  >A$A#  >A$A#A$
 , 	    patternc                     t        |t              r	|}t        }n;t        |t              r|j                  t              }t        }nt        d|d      |}~|j                  d      rn|j                         }|sy|j                  d      ry|dk(  ry|j                  d      rd}|d	d
 }nd}|j                  d      }|d    }	 | j                  ||      \  }}	|	|	}n9|%	 | j                  ||      }dj                  |      }nt!        d|	d|d       #|t        u r|j#                  t              }|}||fS |}||fS # t        $ r}
t        d|      |
d
}
~
ww xY w# t        $ r Y y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 a :class:`tuple` containing:

			-	*pattern* (:class:`str`, :class:`bytes` or :data:`None`) is the
				uncompiled regular expression.

			-	*include* (:class:`bool` or :data:`None`) is whether matched files
				should be included (:data:`True`), excluded (:data:`False`), or is a
				null-operation (:data:`None`).
		zpattern=z! is not a unicode or byte string.z\ )NN#r   !Fr   NTr   zInvalid git pattern:  zoverride_regex=z and pattern_segs=z cannot both be null.)
isinstancestrbytesdecoder	   	TypeErrorendswithrstrip
startswithsplit)_GitIgnoreSpecPattern__normalize_segmentsr   r   )_GitIgnoreSpecPattern__translate_segmentsr   joinr   encode)clsr'   pattern_strreturn_typeoriginal_patterninclude	orig_segsr   r   override_regexeregexregex_partsregex_bytes	out_regexs                  r$   pattern_to_regexz%GitIgnoreSpecPattern.pattern_to_regex   s   * ;;'5!0;;	hg\!BC	DD %   ##%;
 
 c" c C  7QR;7 $) !}$."%":":I#< 5**><HK 77;5 ~*\O+@A ;%/o.;9 W	 9
W	I 
 	,/0
  
 
-01s6   E %E& 	E#EE#&	F1F9FFc                 $   g }d}t        |      dz
  }t        |      D ]  \  }}|dk(  rh|dk(  r|j                  d       "||k  r|j                  d       d};||k(  s	J ||f       |r|j                  t               a|j                  d       s|dk(  r|j                  d	       |r|j                  d       |d
k(  r|j                  d       n!|j                  | j	                  |d             ||k(  r|j                  t
               d} |S )a  
		Translate the pattern segments to regular expressions.

		*is_dir_pattern* (:class:`bool`) is whether the pattern is a directory
		pattern (i.e., ends with a slash '/').

		*pattern_segs* (:class:`list` of :class:`str`) contains the pattern
		segments.

		Raises :class:`_RangeError` if invalid range notation is found.

		Returns the regular expression parts (:class:`list` of :class:`str`).
		Fr   r   r   z	^(?:.+/)?z(?:/.+)?Tr   ^r   z[^/]+raise)r   	enumerateappendr   _translate_segment_glob_DIR_MARK_OPT)r9   r   r   	out_parts
need_slashendr    r"   s           r$   __translate_segmentsz)GitIgnoreSpecPattern.__translate_segments  s'   ( )*LA#,' .fa	TkAv k"	
S j!Z Hq#hH 	|$s 	Avcc
czg
 c11#w?@Cx m$J].` 
r&   N)__name__
__module____qualname____doc__	__slots__staticmethodboollistr-   tupler   r5   r   classmethodr   rE   r6   r   r&   r$   r   r   +   s     ]]S	] HT#Y#./] ]~ uu HVhtn,-u  un FF S	F 3i	F Fr&   r   N)rT   typingr   pathspec._typingr   r   r   baser   r	   r
   r   	_DIR_MARKr   rL   r   r   r&   r$   <module>r_      sh   	 
  	
 i[$ l^3'
m0 mr&   