
    mi&                         d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
mZmZ  G d de          Z ej        d	e           d
S )z
This module provides :class:`GitIgnoreBasicPattern` which implements Git's
`gitignore`_ patterns as documented. This differs from how Git actually behaves
when including files in excluded directories.

.. _`gitignore`: https://git-scm.com/docs/gitignore
    )Optional)util)AnyStrassert_unreachableoverride   )GitIgnorePatternError_BYTES_ENCODING_GitIgnoreBasePatternc            
       
   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e         dee         fd	            Zd
S )GitIgnoreBasicPatternz
	The :class:`GitIgnoreBasicPattern` class represents a compiled gitignore
	pattern as documented. This is registered as "gitignore".
	 is_dir_patternpattern_segsreturnc                 t   |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S dS |dk    r|d         dk    r|d         d	k    rdS |d
k    r&|d         dk    r|d         d	k    r|d         dk    r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)r   r   iprevseg	seg_counts         y/var/www/html/bestrading.cuttalo.com/scripts/kaggle-env/lib/python3.11/site-packages/pathspec/patterns/gitignore/basic.py__normalize_segmentsz*GitIgnoreBasicPattern.__normalize_segments!   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          rd}|dd	         }nd
}|	                    d          }|d          }|dk    rd}	 | 
                    ||          \  }}n%# t          $ r}	t          d|          |	d	}	~	ww xY w||}
nj|R	 |                     |          }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#!Fr   NTr   r   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*_GitIgnoreBasicPattern__normalize_segmentsr   r	   *_GitIgnoreBasicPattern__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&GitIgnoreBasicPattern.pattern_to_regex~   s   *  E;;;'5!! E00;;;	CgCCC	D	DD %   &  ##%%;
 
 	 ,c""  ,C    7QRR;;7 ""3'', $B''.C >"%":":L# #< 
   	0,00
 

 55**<88KK
   
1-11 
 77;55 A~AA\AAA   ;%//||O,,999
W	s0   =D 
D9!D44D9E 
E<$E77E<c                    g }d}t          |          dz
  }t          |          D ]\  }}|dk    rb|dk    r|                    d           (||k     r|                    d           d}F||k    sJ ||f            |                    d           n|dk    r|                    d	           |r|                    d           |d
k    r|                    d           n(|                    |                     |                     ||k    r1|d
k    r|                    d           n|                    d           d}|S )z
		Translate the pattern segments to regular expressions.

		*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[^/]+z/?$z(?:/|$))r   	enumerateappend_translate_segment_glob)r7   r   	out_parts
need_slashendr   r    s          r"   __translate_segmentsz*GitIgnoreBasicPattern.__translate_segments   s    )*LA#,'' 3 3fa	TkkAvv
 k""""	
S j!!!ZZ HHHq#hHHH c 	Avvc c
czzg c11#66777Cxxs

 u y!!!JJ	r$   N)__name__
__module____qualname____doc__	__slots__staticmethodboollistr+   tupler   r3   r   classmethodr   rA   r4   r   r$   r"   r   r      s         ZZS	Z HT#Y#./Z Z Z ,Zx tt HVhtn,-t t t + (tl BT#Y B49 B B B +B B Br$   r   	gitignoreN)rN   typingr   pathspecr   pathspec._typingr   r   r   baser	   r
   r   r   register_patternr   r$   r"   <module>r[      s                        
         a a a a a1 a a aJ	  k#8 9 9 9 9 9r$   