
    mi`                        d Z ddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
 ddlmZ ddlmZmZmZmZmZmZ ddlmZ ddlmZmZ eeej        e         f         Z ed	e
          Z	 d ej        ej        fD             Z	 i Z 	 dej!        defdZ"	 d=dee#e$ef                  dedee%         de#ee%         ee$         f         fdZ&	 d=dee         dee         dee%         de'edf         fdZ(dee         de)e#e$ef                  fdZ*dede%fdZ+ ed          d>d            Z,	 	 d>dedeee-gdf                  dee%         de	d         fd Z.d!ed"ed#e'eef         dee-gdf         de%de	d         fd$Z/	 	 d>dedeee-gdf                  dee%         de	e         fd%Z0d!ed"ed#e'eef         dee-gdf         de%de	e         fd&Z1d'edeegef         fd(Z2dee         dede%fd)Z3 ed*          dee         dee         de4e         fd+            Z5	 d=ded,eee                  defd-Z6 ed.          	 d=dee         d,eee                  de'ee)e         f         fd/            Z7	 d=d'ed0eegef         d1ee%         ddfd2Z8 G d3 d4e9          Z: G d5 d6e9          Z; ed78           G d9 d:ee                               Z< G d; de=          Z> G d< de=          Z?dS )?zC
This module provides utility methods for dealing with path-specs.
    N)
CollectionIterableIteratorSequence)	dataclass)AnyCallableGenericOptionalTypeVarUnion   )Pattern)AnyStr
deprecatedTStrPath)boundc                 6    g | ]}|r|t           j        k    |S  )	posixpathsep).0__seps     e/var/www/html/bestrading.cuttalo.com/scripts/kaggle-env/lib/python3.11/site-packages/pathspec/util.py
<listcomp>r   &   s9       
	 y}$$ $$$    pathreturnc                 j    t          |           }|                                 r|t          j        z  }|S )a4  
	Appends the path separator to the path if the path is a directory. This can be
	used to aid in distinguishing between directories and files on the file-system
	by relying on the presence of a trailing path separator.

	*path* (:class:`pathlib.Path`) is the path to use.

	Returns the path (:class:`str`).
	)stris_dirosr   )r   str_paths     r   append_dir_sepr$   9   s0     IIKKMM 
bf(r   patternsfileis_reversedc                     |r1| D ],\  }}|j          |                    |          |j         |fc S -dS d}d}| D ]*\  }}|j         |                    |          	|j         }|}+||fS )a  
	Check the file against the patterns.

	*patterns* (:class:`~collections.abc.Iterable`) yields each indexed pattern
	(:class:`tuple`) which contains the pattern index (:class:`int`) and actua
	pattern (:class:`.Pattern`).

	*file* (:class:`str`) is the normalized file path to be matched against
	*patterns*.

	*is_reversed* (:class:`bool` or :data:`None`) is whether the order of the
	patterns has been reversed. Default is :data:`None` for :data:`False`.
	Reversing the order of the patterns is an optimization.

	Returns a :class:`tuple` containing whether to include *file* (:class:`bool`
	or :data:`None`), and the index of the last matched pattern (:class:`int` or
	:data:`None`).
	NNNinclude
match_file)r%   r&   r'   indexpatternout_include	out_indexs          r   check_match_filer1   J   s    .    ! " "neWo!g&8&8&>&>&J?E!!!!	 !%+!)   neWo!g&8&8&>&>&J/KI	i	r   filesall_matchesMatchDetailc                 X   t          |t                    r|nt          |          }i }| D ]~}|j        u|                    |          }|j        rQ|D ]M}||v r4|r!||         j                            |           )|||         j        d<   :t          |g          ||<   Nv|D ]}||= |S )a  
	Matches the files to the patterns, and returns which patterns matched the
	files.

	*patterns* (:class:`~collections.abc.Iterable` of :class:`.Pattern`) contains
	the patterns to use.

	*files* (:class:`~collections.abc.Iterable` of :class:`str`) contains the
	normalized file paths to be matched against *patterns*.

	*all_matches* (:class:`bool` or :data:`None`) is whether to return all matches
	patterns (:data:`True`), or only the last matched pattern (:data:`False`).
	Default is :data:`None` for :data:`False`.

	Returns the matched files (:class:`dict`) which maps each matched file
	(:class:`str`) to the patterns that matched in order (:class:`.MatchDetail`).
	Nr   )
isinstancer   listr+   matchr%   appendr4   )	r%   r2   r3   	all_filesreturn_filesr.   result_filesresult_filer&   s	            r   detailed_match_filesr>   v   s    , !
33DUUe  W_ --	**<o # 9 9|##	 7K )009999/6|K )!,,"-wi"8"8l;9   	d		r   c                 4    d t          |           D             S )a&  
	Filters out null-patterns.

	*patterns* (:class:`~collections.abc.Iterable` of :class:`.Pattern`) contains
	the patterns.

	Returns a :class:`list` containing each indexed pattern (:class:`tuple`) which
	contains the pattern index (:class:`int`) and the actual pattern
	(:class:`.Pattern`).
	c                 *    g | ]\  }}|j         ||fS Nr+   )r   __index__pats      r   r   z*_filter_check_patterns.<locals>.<listcomp>   s3     	 	 	gu
] Er   )	enumerater%   s    r   _filter_check_patternsrG      s+    	 	!(++	 	 	 r   valuec                 f    t          | t                    ot          | t          t          f           S )z
	Check whether the value is an iterable (excludes strings).

	*value* is the value to check,

	Returns whether *value* is an iterable (:class:`bool`).
	)r6   r   r    bytes)rH   s    r   _is_iterablerK      s*     	5(##KJusEl,K,K(KKr   zGpathspec.util.iter_tree() is deprecated. Use iter_tree_files() instead.c                 &    t          | ||          S )z`
	.. version-deprecated:: 0.10.0
		This is an alias for the :func:`.iter_tree_files` function.
	)on_errorfollow_links)iter_tree_filesrootrM   rN   s      r   	iter_treerR      s     	xlKKKKr   rQ   rM   rN   	TreeEntryc              #      K   |"t          |          st          d|d          |d}t          t          j                            |           di ||          E d{V  dS )a  
	Walks the specified directory for all files and directories.

	*root* (:class:`str` or :class:`os.PathLike`) is the root directory to search.

	*on_error* (:class:`~collections.abc.Callable` or :data:`None`) optionally is
	the error handler for file-system exceptions. It will be called with the
	exception (:exc:`OSError`). Reraise the exception to abort the walk. Default
	is :data:`None` to ignore file-system exceptions.

	*follow_links* (:class:`bool` or :data:`None`) optionally is whether to walk
	symbolic links that resolve to directories. Default is :data:`None` for
	:data:`True`.

	Raises :exc:`.RecursionError` if recursion is detected.

	Returns an :class:`~collections.abc.Iterator` yielding each file or directory
	entry (:class:`.TreeEntry`) relative to *root*.
	N	on_error: is not callable.T )callable	TypeError_iter_tree_entries_nextr"   r   abspathrP   s      r   iter_tree_entriesr\      s|      0 (!3!3;h;;;<<<,#BGOOD$9$92r8\ZZZZZZZZZZZr   	root_fulldir_relmemoc           	   #     K   t           j                            | |          }t           j                            |          }||vr|||<   nt	          |||         |          t          j        |          5 }|D ]>}t           j                            ||j                  }		 |                    d          }
n$# t          $ r}| ||           Y d}~\d}~ww xY w|	                                r:	 |                                }n&# t          $ r}| ||           Y d}~d}~ww xY w|
}|
                    |          r3t          |j        |	|
|          V  t          | |	|||          E d{V  |                                s|	                                rt          |j        |	|
|          V  @	 ddd           n# 1 swxY w Y   ||= dS )ap  
	Scan the directory for all descendant files.

	*root_full* (:class:`str`) the absolute path to the root directory.

	*dir_rel* (:class:`str`) the path to the directory to scan relative to
	*root_full*.

	*memo* (:class:`dict`) keeps track of ancestor directories encountered. Maps
	each ancestor real path (:class:`str`) to relative path (:class:`str`).

	*on_error* (:class:`~collections.abc.Callable` or :data:`None`) optionally is
	the error handler for file-system exceptions.

	*follow_links* (:class:`bool`) is whether to walk symbolic links that resolve
	to directories.

	Yields each entry (:class:`.TreeEntry`).
		real_path
first_pathsecond_pathFfollow_symlinksN)r"   r   joinrealpathRecursionErrorscandirnamestatOSError
is_symlinkr!   rS   rZ   is_file)r]   r^   r_   rM   rN   dir_fulldir_real	scan_iternode_entnode_rel
node_lstate	node_stats                r   rZ   rZ      s}     4 GLLG,,GX&& D$x..d8nRYZZZZj !Di D Dhgll7HM228u55JJ
   Xa[[[HHHH
  	YY   hqkkkXXXX
 Ioolo33 	D HM8Z
C
CCCC&y(D(LYYYYYYYYYY Dh1133 D
HM8Z
C
CCCC?D!D !D !D !D !D !D !D !D !D !D !D !D !D !D !DP 
(^^^sg   8+G$B;:G;
CCGCG4D	G	
D*D% G%D**BGGGc              #      K   |"t          |          st          d|d          |d}t          t          j                            |           di ||          E d{V  dS )a  
	Walks the specified directory for all files.

	*root* (:class:`str` or :class:`os.PathLike`) is the root directory to search
	for files.

	*on_error* (:class:`~collections.abc.Callable` or :data:`None`) optionally is
	the error handler for file-system exceptions. It will be called with the
	exception (:exc:`OSError`). Reraise the exception to abort the walk. Default
	is :data:`None` to ignore file-system exceptions.

	*follow_links* (:class:`bool` or :data:`None`) optionally is whether to walk
	symbolic links that resolve to directories. Default is :data:`None` for
	:data:`True`.

	Raises :exc:`.RecursionError` if recursion is detected.

	Returns an :class:`~collections.abc.Iterator` yielding the path to each file
	(:class:`str`) relative to *root*.
	NrU   rV   TrW   )rX   rY   _iter_tree_files_nextr"   r   r[   rP   s      r   rO   rO   >  s|      2 (!3!3;h;;;<<<,!"'//$"7"7R<XXXXXXXXXXXr   c           	   #   F  K   t           j                            | |          }t           j                            |          }||vr|||<   nt	          |||         |          t          j        |          5 }|D ]}t           j                            ||j                  }	|                    |          rt          | |	|||          E d{V  W|	                                r|	V  p|s|
                                r|	V  	 ddd           n# 1 swxY w Y   ||= dS )am  
	Scan the directory for all descendant files.

	*root_full* (:class:`str`) the absolute path to the root directory.

	*dir_rel* (:class:`str`) the path to the directory to scan relative to
	*root_full*.

	*memo* (:class:`dict`) keeps track of ancestor directories encountered. Maps
	each ancestor real path (:class:`str`) to relative path (:class:`str`).

	*on_error* (:class:`~collections.abc.Callable` or :data:`None`) optionally is
	the error handler for file-system exceptions.

	*follow_links* (:class:`bool`) is whether to walk symbolic links that resolve
	to directories.

	Yields each file path (:class:`str`).
	ra   re   N)r"   r   rg   rh   ri   rj   rk   r!   ry   ro   rn   )
r]   r^   r_   rM   rN   rp   rq   rr   rs   rt   s
             r   ry   ry   `  s     4 GLLG,,GX&& D$x..d8nRYZZZZj i  hgll7HM228oolo33  %Y$,WWWWWWWWWW 
NNNN X0022 
NNN              . 
(^^^s   8BDDDrk   c                     t           |          S )z
	Lookups a registered pattern factory by name.

	*name* (:class:`str`) is the name of the pattern factory.

	Returns the registered pattern factory (:class:`~collections.abc.Callable`).
	If no pattern factory is registered, raises :exc:`KeyError`.
	)_registered_patterns)rk   s    r   lookup_patternr}     s     	T""r   c                 Z    d}| D ]%}|j         |                    |          |j         }&|S )a&  
	Matches the file to the patterns.

	*patterns* (:class:`~collections.abc.Iterable` of :class:`.Pattern`) contains
	the patterns to use.

	*file* (:class:`str`) is the normalized file path to be matched against
	*patterns*.

	Returns :data:`True` if *file* matched; otherwise, :data:`False`.
	Fr*   )r%   r&   matchedr.   s       r   r,   r,     s@       W_ W%7%7%=%=%I_7r   z[pathspec.util.match_files() is deprecated. Use match_file() with a loop for better results.c                     d | D             }t                      }|D ]'}t          ||          r|                    |           (|S )a  
	.. version-deprecated:: 0.10.0
		This function is no longer used. Use the :func:`.match_file` function with a
		loop for better results.

	Matches the files to the patterns.

	*patterns* (:class:`~collections.abc.Iterable` of :class:`.Pattern`) contains
	the patterns to use.

	*files* (:class:`~collections.abc.Iterable` of :class:`str`) contains the
	normalized file paths to be matched against *patterns*.

	Returns the matched files (:class:`set` of :class:`str`).
	c                      g | ]}|j         	|S rA   rB   )r   rD   s     r   r   zmatch_files.<locals>.<listcomp>  s    JJJ50I0I0I0Ir   )setr,   add)r%   r2   use_patternsr;   r&   s        r   match_filesr     s]    . KJHJJJ  Td## Dr   
separatorsc                    |t           }t          j        |           }|D ]"}|                    |t          j                  }#|                    d          r|dd         }n|                    d          r
|dd         }|S )a  
	Normalizes the file path to use the POSIX path separator (i.e., ``"/"``), and
	make the paths relative (remove leading ``"/"``).

	*file* (:class:`str` or :class:`os.PathLike`) is the file path.

	*separators* (:class:`~collections.abc.Collection` of :class:`str`; or
	:data:`None`) optionally contains the path separators to normalize. This does
	not need to include the POSIX path separator (``"/"``), but including it will
	not affect the results. Default is ``None`` for :data:`.NORMALIZE_PATH_SEPS`.
	To prevent normalization, pass an empty container (e.g., an empty tuple
	``()``).

	Returns the normalized file path (:class:`str`).
	N/r   z./   )NORMALIZE_PATH_SEPSr"   fspathreplacer   r   
startswith)r&   r   	norm_filer   s       r   normalize_filer     s    ( "* )D// 4 4SY]33)) m))4   m)r   zcpathspec.util.normalize_files() is deprecated. Use normalize_file() with a loop for better results.c                     i }| D ]9}t          ||          }||v r||                             |           3|g||<   :|S )a  
	.. version-deprecated:: 0.10.0
		This function is no longer used. Use the :func:`.normalize_file` function
		with a loop for better results.

	Normalizes the file paths to use the POSIX path separator.

	*files* (:class:`~collections.abc.Iterable` of :class:`str` or
	:class:`os.PathLike`) contains the file paths to be normalized.

	*separators* (:class:`~collections.abc.Collection` of :class:`str`; or
	:data:`None`) optionally contains the path separators to normalize. See
	:func:`.normalize_file` for more information.

	Returns a :class:`dict` mapping each normalized file path (:class:`str`) to
	the original file paths (:class:`list` of :class:`str` or
	:class:`os.PathLike`).
	)r   )r   r9   )r2   r   
norm_filesr   r   s        r   normalize_filesr     sf    4  " "TTj999)*i%%%% 6:ir   pattern_factoryoverridec                     t          | t                    st          d| d          t          |          st          d|d          | t          v r|st          | t          |                    |t          | <   dS )aE  
	Registers the specified pattern factory.

	*name* (:class:`str`) is the name to register the pattern factory under.

	*pattern_factory* (:class:`~collections.abc.Callable`) is used to compile
	patterns. It must accept an uncompiled pattern (:class:`str`) and return the
	compiled pattern (:class:`.Pattern`).

	*override* (:class:`bool` or :data:`None`) optionally is whether to allow
	overriding an already registered pattern under the same name (:data:`True`),
	instead of raising an :exc:`.AlreadyRegisteredError` (:data:`False`). Default
	is :data:`None` for :data:`False`.
	zname:z is not a string.zpattern_factory:rV   N)r6   r    rY   rX   r|   AlreadyRegisteredError)rk   r   r   s      r   register_patternr   ,  s    & 	4 53$333444!! KI_IIIJJJ    t%9$%?@@@-dr   c                        e Zd ZdZdedeegef         ddf fdZe	defd            Z
e	defd            Ze	deegef         fd	            Z xZS )
r   z|
	The :exc:`AlreadyRegisteredError` exception is raised when a pattern factory
	is registered under a name already in use.
	rk   r   r   Nc                 L    t                                          ||           dS )z
		Initializes the :exc:`AlreadyRegisteredError` instance.

		*name* (:class:`str`) is the name of the registered pattern.

		*pattern_factory* (:class:`~collections.abc.Callable`) is the registered
		pattern factory.
		Nsuper__init__)selfrk   r   	__class__s      r   r   zAlreadyRegisteredError.__init__Q  s%     ''4)))))r   c                 &    | j         d| j        dS )4
		*message* (:class:`str`) is the error message.
		z+ is already registered for pattern factory=.)rk   r   r   s    r   messagezAlreadyRegisteredError.message`  s-     i    
     r   c                     | j         d         S )zB
		*name* (:class:`str`) is the name of the registered pattern.
		r   argsr   s    r   rk   zAlreadyRegisteredError.namej  s    
 
1r   c                     | j         d         S )za
		*pattern_factory* (:class:`~collections.abc.Callable`) is the registered
		pattern factory.
		r   r   r   s    r   r   z&AlreadyRegisteredError.pattern_factoryq       
1r   )__name__
__module____qualname____doc__r    r	   r   r   r   propertyr   rk   r   __classcell__r   s   @r   r   r   K  s         
** VHg-.* 	* * * * * * c    ( 3    ( hx'89    (    r   r   c                        e Zd ZdZdedededdf fdZedefd            Zedefd	            Zedefd
            Z	edefd            Z
 xZS )ri   zM
	The :exc:`RecursionError` exception is raised when recursion is detected.
	rb   rc   rd   r   Nc                 N    t                                          |||           dS )a'  
		Initializes the :exc:`RecursionError` instance.

		*real_path* (:class:`str`) is the real path that recursion was encountered
		on.

		*first_path* (:class:`str`) is the first path encountered for *real_path*.

		*second_path* (:class:`str`) is the second path encountered for *real_path*.
		Nr   )r   rb   rc   rd   r   s       r   r   zRecursionError.__init__  s'      ''9j+66666r   c                     | j         d         S )zx
		*first_path* (:class:`str`) is the first path encountered for
		:attr:`self.real_path <RecursionError.real_path>`.
		r   r   r   s    r   rc   zRecursionError.first_path  r   r   c                 8    d| j         d| j        d| j        dS )r   z
Real path z was encountered at z
 and then r   ra   r   s    r   r   zRecursionError.message  s=    % % %do % %% % %r   c                     | j         d         S )zV
		*real_path* (:class:`str`) is the real path that recursion was
		encountered on.
		r   r   r   s    r   rb   zRecursionError.real_path  r   r   c                     | j         d         S )zz
		*second_path* (:class:`str`) is the second path encountered for
		:attr:`self.real_path <RecursionError.real_path>`.
		r   r   r   s    r   rd   zRecursionError.second_path  r   r   )r   r   r   r   r    r   r   rc   r   rb   rd   r   r   s   @r   ri   ri   z  s	        77 7 	7
 7 7 7 7 7 7$     ( c    (     ( #    (    r   ri   T)frozenc                   R    e Zd ZU dZdZeed<   	 ee         ed<   	 ee	         ed<   dS )CheckResultze
	The :class:`CheckResult` class contains information about the file and which
	pattern matched it.
	)r&   r+   r-   r&   r+   r-   N)
r   r   r   r   	__slots__r   __annotations__r   boolintr   r   r   r   r     s`            4.
 	 r   r   c                   2    e Zd ZdZdZdee         ddfdZdS )r4   z>
	The :class:`.MatchDetail` class contains information about
	rF   r%   r   Nc                     || _         dS )z
		Initialize the :class:`.MatchDetail` instance.

		*patterns* (:class:`~collections.abc.Sequence` of :class:`.Pattern`)
		contains the patterns that matched the file in the order they were encountered.
		NrF   )r   r%   s     r   r   zMatchDetail.__init__  s     $- r   )r   r   r   r   r   r   r   r   r   r   r   r4   r4     sL         
 hw/ D      r   c            
           e Zd ZdZdZdededej        dej        ddf
d	Zdd
e	e
         de
fdZdd
e	e
         de
fdZde
fdZdd
e	e
         dej        fdZdS )rS   zP
	The :class:`TreeEntry` class contains information about a file-system entry.
	_lstatrk   r   _statrk   r   lstatrl   r   Nc                 D    || _         	 || _        	 || _        	 || _        dS )aM  
		Initialize the :class:`TreeEntry` instance.

		*name* (:class:`str`) is the base name of the entry.

		*path* (:class:`str`) is the relative path of the entry.

		*lstat* (:class:`os.stat_result`) is the stat result of the direct entry.

		*stat* (:class:`os.stat_result`) is the stat result of the entry,
		potentially linked.
		Nr   )r   rk   r   r   rl   s        r   r   zTreeEntry.__init__  s?    ( !&$+ $) $)  $$* r   rN   c                 \    |d}|r| j         n| j        }t          j        |j                  S )a<  
		Get whether the entry is a directory.

		*follow_links* (:class:`bool` or :data:`None`) is whether to follow symbolic
		links. If this is :data:`True`, a symlink to a directory will result in
		:data:`True`. Default is :data:`None` for :data:`True`.

		Returns whether the entry is a directory (:class:`bool`).
		NT)r   r   rl   S_ISDIRst_moder   rN   rw   s      r   r!   zTreeEntry.is_dir  4     <(9djjdk)	i'	(	((r   c                 \    |d}|r| j         n| j        }t          j        |j                  S )aE  
		Get whether the entry is a regular file.

		*follow_links* (:class:`bool` or :data:`None`) is whether to follow symbolic
		links. If this is :data:`True`, a symlink to a regular file will result in
		:data:`True`. Default is :data:`None` for :data:`True`.

		Returns whether the entry is a regular file (:class:`bool`).
		NT)r   r   rl   S_ISREGr   r   s      r   ro   zTreeEntry.is_file,  r   r   c                 >    t          j        | j        j                  S )zC
		Returns whether the entry is a symbolic link (:class:`bool`).
		)rl   S_ISLNKr   r   r   s    r   rn   zTreeEntry.is_symlink<  s     
dk)	*	**r   c                 *    |d}|r| j         n| j        S )a9  
		Get the cached stat result for the entry.

		*follow_links* (:class:`bool` or :data:`None`) is whether to follow symbolic
		links. If this is :data:`True`, the stat result of the linked file will be
		returned. Default is :data:`None` for :data:`True`.

		Returns that stat result (:class:`os.stat_result`).
		NT)r   r   )r   rN   s     r   rl   zTreeEntry.statB  s"     <#	44r   rA   )r   r   r   r   r   r    r"   stat_resultr   r   r   r!   ro   rn   rl   r   r   r   rS   rS     s        
 1&& 	& 
	&
 	& & & & &P) ) )$ ) ) ) ) ) )$ )4 ) ) ) ) + + + + +5 5htn 5 5 5 5 5 5 5r   rA   r)   )@r   r"   os.pathpathlibr   rl   collections.abcr   r   r   r   dataclassesr   typingr   r	   r
   r   r   r   r.   r   _typingr   r   r    PathLikeStrPathr   r   altsepr   r|   Pathr$   tupler   r   r1   dictr>   r7   rG   rK   rR   rm   r\   rZ   rO   ry   r}   r,   r   r   r   r   r   	Exceptionr   ri   r   objectr4   rS   r   r   r   <module>r      s    
			                  
                    
 
 
 
 
 
        R[%%
&7:W--- vry!   
   #    (  $)  ) E#w,'() 
)  tn)  8D>8C=()	)  )  )  ) ^  $+ +G++ tn+ 
#}
	+ + + +\G	%W
   (L L L L L L J L L L L 26 $[ [[HgY_-.[ ~[ k	[ [ [ [BLL
L CH~L WItO$	L
 L kL L L Lb 26 $Y YYHgY_-.Y ~Y c]	Y Y Y YD;;
; CH~; WItO$	;
 ; c]; ; ; ;|	# 	#6(G*;!< 	# 	# 	# 	#'* # $    (  G 	X  	 > *.% %%jo&% 	% % % %P   *. jo& 
#tG}
  	 H !. .
.F8W,-. D>. 
	. . . .>, , , , ,Y , , ,^7 7 7 7 7Y 7 7 7t $    '(#   >    &   0c5 c5 c5 c5 c5 c5 c5 c5 c5 c5r   