
    0yi'                     t    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
 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. 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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         b/var/www/html/content_weaver/venv/lib/python3.12/site-packages/pathspec/patterns/gitignore/spec.py__normalize_segmentsz)GitIgnoreSpecPattern.__normalize_segments6   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}	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_segmentsjoinr   encode)clsr&   pattern_strreturn_typeoriginal_patternincluder   r   override_regexeregexregex_parts	out_regexs                r#   pattern_to_regexz%GitIgnoreSpecPattern.pattern_to_regex   s   * ;;'5!0;;	hg\!BC	DD %   ##%;
 
 c" c C  7QR;7 ""3', $B''."%":":L#< 5**><HK 77;5 ~*\O+@A ;%/||O,9 W	 9
W	A 
 	,/0
  
-01s0   E %E$ 	E!EE!$	F-E<<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	                  |             ||k(  r|j                  t
               d} |S )aK  
		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.

		Returns the regular expression parts (:class:`list` of :class:`str`).
		Fr   r   r   z	^(?:.+/)?z(?:/.+)?Tr   ^r   z[^/]+)r   	enumerateappendr   _translate_segment_glob_DIR_MARK_OPT)r8   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#67Cx m$J[-^ 
r%   N)__name__
__module____qualname____doc__	__slots__staticmethodboollistr,   tupler   r4   r   classmethodr   rB   r5   r   r%   r#   r   r   )   s     ]]S	] HT#Y#./] ]~ qq HVhtn,-q  qf CC S	C 3i	C Cr%   r   N)rP   typingr   pathspec._typingr   r   r   baser   r	   r
   	_DIR_MARKr   rH   r   r   r%   r#   <module>r[      sh    
 
 	
 i[$ l^3'
f0 fr%   