
    mi'                     |    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dS )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d
S )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= nRt          |          dk    st          |          dk    r+|d         s#|d         dk    r|                    dd           n	 |st          d          |d         s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| r	dt          fS dS |dk    r|d         dk    r|d         d	k    rdS |d
k    r1|d         dk    r%|d         d	k    r|d         dk    r| r	dt          fS dS |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         x/var/www/html/bestrading.cuttalo.com/scripts/kaggle-env/lib/python3.11/site-packages/pathspec/patterns/gitignore/spec.py__normalize_segmentsz)GitIgnoreSpecPattern.__normalize_segments6   s   ( 
a  A
<A#l"3"3q"8"8a"8 1o4    	 6 
4	5	55	b	 
 <
 \""Q&2..  a
qs
4	a3
dllsd{{Q,)!^^Q4//  , ; >>A$A# + >>A$A#A$
  ,; 	    patternc                    t          |t                    r
|}t          }nJt          |t                    r"|                    t                    }t          }nt          d|d          |}~|                    d          rn|                                }|sdS |                    d          rdS |dk    rdS |                    d          rd}|d	d
         }nd}|	                    d          }|d          }	 | 
                    ||          \  }}n%# t          $ r}	t          d|          |	d
}	~	ww xY w||}
nk|S	 |                     ||          }n%# t          $ r}	t          d|          |	d
}	~	ww xY wd                    |          }
nt          d|d|d           |
$|t          u r|
                    t                    }n|
}||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 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   *  E;;;'5!! E00;;;	CgCCC	D	DD %   &  ##%%;
 
  ,c"" 	 ,c ,C    7QRR;;7 ""3'', $B''."%":":L# #< 
   	0,00
 

 55**><HHKK
   
1-11 
 77;55 A~AA\AAA   ;%//||O,,999
W	s0   =D 
D9!D44D9E 
E=%E88E=c                    g }d}t          |          dz
  }t          |          D ]#\  }}|dk    r|dk    r|                    d           (||k     r|                    d           d}F||k    sJ ||f            |r|                    t                     u|                    d           |dk    r|                    d	           |r|                    d           |d
k    r|                    d           n(|                    |                     |                     ||k    r|                    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	TkkAvv k""""	
S j!!!ZZ HHHq#hHHH 	 |$$$$s 	Avvc c
czzg c11#66777Cxx m$$$JJ	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 q + (qf CC S	C 3i	C C C +C C Cr%   r   N)rP   typingr   pathspec._typingr   r   r   baser   r	   r
   	_DIR_MARKr   rH   r   r   r%   r#   <module>r[      s
                 
         
 	
 %i$$$ (l'''
f f f f f0 f f f f fr%   