
    AeN                        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ZddlmZ	m
Z ddlmZ ddlmZmZmZmZmZm
Z
mZmZmZmZmZmZ ddlmZ ej4                  ej6                  fD  cg c]  } | r| ej4                  k7  r|  c} Z	 i Z	 dej<                  d	e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   fdZ#ded	e!fdZ$	 	 d0deeef   dee   dee!   d	ed   fdZ%dededeeef   dede!d	ed   fdZ&	 	 d0deeef   dee   dee!   d	ee   fdZ'd0dZ(ded	eegef   fdZ)de
e   d ed	e!fd!Z*de
e   de
e   d	ee   fd"Z+	 d/d eeef   d#eee      d	efd$Z,	 d/de
eeef      d#eee      d	eeeeeef      f   fd%Z-	 d/ded&eegef   d'ee!   d	dfd(Z. G d) d*e/      Z0 G d+ d,e/      Z1 G d- de2      Z3 G d. de2      Z4yc c} w )1zC
This module provides utility methods for dealing with path-specs.
    N)
CollectionIterable)PathLike)AnyAnyStrCallabler   Dictr   IteratorListOptionalSequenceSetUnion   )Patternpathreturnc                 b    t        |       }| j                         r|t        j                  z  }|S )a5  
	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ossep)r   str_paths     -lib/python3.12/site-packages/pathspec/util.pyappend_dir_sepr   4   s)     IKKM
bff(    patternsfilesall_matchesMatchDetailc                 X   t        |t              r|n
t        |      }i }| D ]  }|j                  |j	                  |      }|j                  rO|D ]I  }||v r4|r||   j
                  j                  |       (|||   j
                  d<   ;t        |g      ||<   K ||D ]  }||=   |S )a  
	Matches the files to the patterns, and returns which patterns matched
	the files.

	*patterns* (:class:`~collections.abc.Iterable` of :class:`~pathspec.pattern.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:`boot` 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`).
	r   )
isinstanceCollectionTypelistincludematchr   appendr    )	r   r   r   	all_filesreturn_filespatternresult_filesresult_filefiles	            r   detailed_match_filesr.   F   s    , !7UT%[ W__ --	*<oo# 9|#	K ))009/6|K ))!,"-wi"8l;9  	d	!& 	r   c                 D    | D cg c]  }|j                   | c}S c c}w )z
	Filters out null-patterns.

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

	Returns the patterns (:class:`list` of :class:`.Pattern`).
	)r%   )r   __pats     r   _filter_patternsr1   t   s.     	
]] 	  	s   valuec                 T    t        | t              xr 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 a iterable (:class:`bool`).
	)r"   IterableTyper   bytes)r2   s    r   _is_iterabler6      s$     	5,'O
53,0O,OOr   rooton_errorfollow_links	TreeEntryc              #      K   |t        |      st        d|d      |d}t        t        j                  j                  |       di ||      E d{    y7 w)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*.
	Nz	on_error: is not callable.T )callable	TypeError_iter_tree_entries_nextr   r   abspathr7   r8   r9   s      r   iter_tree_entriesrC      sX     4 (!3Ih\):;<<,#BGGOOD$92r8\ZZZs   AAAA	root_fulldir_relmemoc           	   #   x  K   t         j                  j                  | |      }t         j                  j                  |      }||vr|||<   nt	        |||   |      t        j
                  |      5 }|D ]  }t         j                  j                  ||j                        }		 |j                  d      }
|j                         r	 |j                         }n|
}|j                  |      r2t        |j                  |	|
|       t        | |	|||      E d{    |j                         s|j                         st        |j                  |	|
|        	 ddd       ||= y# t        $ r}| ||       Y d}~d}~ww xY w# t        $ r}| ||       Y d}~,d}~ww xY w7 # 1 sw Y   ||= yxY ww)aq  
	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   r:   r@   is_file)rD   rE   rF   r8   r9   dir_fulldir_real	scan_iternode_entnode_rel
node_lstate	node_stats                r   r@   r@      s    6 GGLLG,GGX&
 D$x.d8nRYZZjj !Di Dhggll7HMM28u5J Y Ioolo3 HMM8Z
CC&y(D(LYYYh113
HMM8Z
CC?D!DP 
(^A  a[  qk Z;!DP 
(^s   A0F:20F+#E'5F+FAF+F)%F+>F+F:'	F0
F :F+ FF+	F&
F!F+!F&&F++F70
F:c              #   r   K   t        | ||      D ]"  }|j                  |      r|j                   $ yw)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*.
	r8   r9   N)rC   r   r   )r7   r8   r9   entrys       r   iter_tree_filesr`     s6     4  xlS U	l	#	s   #77c                 V    t        j                  dt        d       t        | ||      S )zg
	DEPRECATED: The :func:`.iter_tree` function is an alias for the
	:func:`.iter_tree_files` function.
	zCutil.iter_tree() is deprecated. Use util.iter_tree_files() instead.   
stacklevelr^   )warningswarnDeprecationWarningr`   rB   s      r   	iter_treerh   "  s)    
 
G1& 	xlKKr   rP   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)rP   s    r   lookup_patternrk   -  s     	T""r   r-   c                 n    d}| D ]-  }|j                   |j                  |      "|j                   }/ |S )a7  
	Matches the file to the patterns.

	*patterns* (:class:`~collections.abc.Iterable` of :class:`~pathspec.pattern.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`.
	F)r%   
match_file)r   r-   matchedr*   s       r   rm   rm   9  sC      W__ *ooG
 	r   c                     t        j                  dt        d       t        |       }t	               }|D ]   }t        ||      s|j                  |       " |S )a  
	DEPRECATED: This is an old function 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:`~pathspec.pattern.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`).
	zWutil.match_files() is deprecated. Use util.match_file() with a loop for better results.rb   rc   )re   rf   rg   r1   setrm   add)r   r   use_patternsr)   r-   s        r   match_filesrs   N  s\    $ 
1&
 !* Td#D 	r   
separatorsc                     |t         }t        |       }|D ]"  }|j                  |t        j                        }$ |j                  d      r|dd }|S |j                  d      r|dd }|S )a  
	Normalizes the file path to use the POSIX path separator (i.e.,
	:data:`'/'`), and make the paths relative (remove leading :data:`'/'`).

	*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 (:data:`'/'`),
	but including it will not affect the results. Default is :data:`None`
	for :data:`NORMALIZE_PATH_SEPS`. To prevent normalization, pass an
	empty container (e.g., an empty tuple :data:`()`).

	Returns the normalized file path (:class:`str`).
	N/r   z./rb   )NORMALIZE_PATH_SEPSr   replace	posixpathr   
startswith)r-   rt   	norm_filer   s       r   normalize_filer|   o  s    ( "* Y 4SY]]3)4 m) 		 4 m)r   c                     t        j                  dt        d       i }| D ].  }t        ||      }||v r||   j	                  |       )|g||<   0 |S )a  
	DEPRECATED: 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`).
	z_util.normalize_files() is deprecated. Use util.normalize_file() with a loop for better results.rb   rc   )rt   )re   rf   rg   r|   r'   )r   rt   
norm_filesr   r{   s        r   normalize_filesr     sk    * 
$1&
  "TTj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        | <   y)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:r<   N)r"   r   r?   r>   rj   AlreadyRegisteredError)rP   r   r   s      r   register_patternr     sk    ( 	4E$!2344!$_$77HI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.
	rP   r   r   Nc                 .    t         t        |   ||       y)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)superr   __init__)selfrP   r   	__class__s      r   r   zAlreadyRegisteredError.__init__  s     .t_Er   c                 P    dj                  | j                  | j                        S )4
		*message* (:class:`str`) is the error message.
		zG{name!r} is already registered for pattern factory:{pattern_factory!r}.)rP   r   )formatrP   r   r   s    r   messagezAlreadyRegisteredError.message  s.    
 
S	Y	Y		'' 
Z 
 r   c                      | j                   d   S )zB
		*name* (:class:`str`) is the name of the registered pattern.
		r   argsr   s    r   rP   zAlreadyRegisteredError.name  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_factory       
1r   )__name__
__module____qualname____doc__r   r   r   r   r   propertyr   rP   r   __classcell__r   s   @r   r   r     s    
FF VHg-.F 	F 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 )rN   zN
	The :exc:`RecursionError` exception is raised when recursion is
	detected.
	rH   rI   rJ   r   Nc                 0    t         t        |   |||       y)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*.
		N)r   rN   r   )r   rH   rI   rJ   r   s       r   r   zRecursionError.__init__  s    $ &y*kJr   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   rI   zRecursionError.first_path%  r   r   c                 f    dj                  | j                  | j                  | j                        S )r   zDReal path {real!r} was encountered at {first!r} and then {second!r}.)realfirstsecond)r   rH   rI   rJ   r   s    r   r   zRecursionError.message-  s5    
 
P	V	V	


 
W 
 r   c                      | j                   d   S )zV
		*real_path* (:class:`str`) is the real path that recursion was
		encountered on.
		r   r   r   s    r   rH   zRecursionError.real_path8  r   r   c                      | j                   d   S )zz
		*second_path* (:class:`str`) is the second path encountered for
		:attr:`self.real_path <RecursionError.real_path>`.
		rb   r   r   s    r   rJ   zRecursionError.second_path@  r   r   )r   r   r   r   r   r   r   rI   r   rH   rJ   r   r   s   @r   rN   rN     s    
KK K 	K
 K(    c      #  r   rN   c                   *    e Zd ZdZdZdee   ddfdZy)r    z>
	The :class:`.MatchDetail` class contains information about
	r   r   r   Nc                     || _         y)z
		Initialize the :class:`.MatchDetail` instance.

		*patterns* (:class:`~collections.abc.Sequence` of :class:`~pathspec.pattern.Pattern`)
		contains the patterns that matched the file in the order they were
		encountered.
		Nr   )r   r   s     r   r   zMatchDetail.__init__Q  s     $-r   )r   r   r   r   	__slots__r   r   r    r   r   r    r    I  s&    
 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y)r:   zR
	The :class:`.TreeEntry` class contains information about a file-system
	entry.
	_lstatrP   r   _statrP   r   lstatrQ   r   Nc                 B    || _         	 || _        	 || _        	 || _        y)aP  
		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   rP   r   r   rQ   s        r   r   zTreeEntry.__init__k  s:    * !&$+
 $) $)  $$*r   r9   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`).
		T)r   r   rQ   S_ISDIRst_moder   r9   r\   s      r   r   zTreeEntry.is_dir  5     <(djjdkk)	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`).
		T)r   r   rQ   S_ISREGr   r   s      r   rT   zTreeEntry.is_file  r   r   c                 T    t        j                  | j                  j                        S )zC
		Returns whether the entry is a symbolic link (:class:`bool`).
		)rQ   S_ISLNKr   r   r   s    r   rS   zTreeEntry.is_symlink  s     
dkk))	**r   c                 >    |d}|r| j                   S | 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`).
		T)r   r   )r   r9   s     r   rQ   zTreeEntry.stat  s$     <#44r   N)r   r   r   r   r   r   r   stat_resultr   r   boolr   rT   rS   rQ   r   r   r   r:   r:   b  s     1)) 	) 
	)
 	) )V) )$ ) )$ )4 ) + +5htn 5 5r   r   )NN)5r   r   os.pathpathlibry   rQ   re   collections.abcr   r#   r   r4   r   typingr   r   r   r	   r
   r   r   r   r   r   r*   r   r   altseprw   rj   Pathr   r   r   r.   r1   r6   rC   r@   r`   rh   rk   rm   rs   r|   r   r   	Exceptionr   rN   objectr    r:   )__seps   0r   <module>r      st   
        

 vvryy!
	ey}}$  
   # *  $+G++ tn+ 
#}
	+\x0 T']  P P P !% $ [S(] [H [ ~ [ k	 [FNN
N CH~N 	N
 N kNf !% $S(]H ~ c]	>L	# 	#6(G*;!< 	#'* # $ *G 	XF *.%S(]%jo&% 	%T *."sH}%&"jo&" 
#tE#x-()
)*"P !.
.F8W,-. D>. 
	.@,Y ,^;Y ;|& 2g5 g5Cs   %G