
    &`i	F                     D   d 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 ej
        ej        fD             Z	 i Z	 ddZd ZddZdd	ZeZd
 Zd Zd Zd ZddZddZddZddZ G d de          Z G d d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string_typesunicodec                 6    g | ]}||t           j        k    |S  )	posixpathsep).0r   s     y/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/_private/thirdparty/pathspec/util.py
<listcomp>r      s)    ZZZsSZSIMEYEYsEYEYEY    c                 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:`~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`).
	Nr   )
isinstancer   listincludematchpatternsappendMatchDetail)	r   filesall_matches	all_filesreturn_filespatternresult_filesresult_filefiles	            r   detailed_match_filesr       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                 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 a iterable (:class:`bool`).
	)r   r   r   bytes)values    r   _is_iterabler$   F   s+     	5(##OJuw>N,O,O(OOr   c              #      K   |1t          |          s"t          d                    |                    |d}t          t          j                            |           di ||          D ]}|V  dS )a  
	Walks the specified directory for all files and directories.

	*root* (:class:`str`) 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.Iterable` yielding each file or
	directory entry (:class:`.TreeEntry`) relative to *root*.
	Non_error:{!r} is not callable.T )callable	TypeErrorformat_iter_tree_entries_nextospathabspathrooton_errorfollow_linksentrys       r   iter_tree_entriesr4   Q   s      * (!3!3299(CCDDD,%bgood&;&;RX|\\  U++++ r   c              #     K   |1t          |          s"t          d                    |                    |d}t          t          j                            |           di ||          D ] }|                    |          s	|j        V  !dS )a  
	Walks the specified directory for all files.

	*root* (:class:`str`) 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.Iterable` yielding the path to
	each file (:class:`str`) relative to *root*.
	Nr&   Tr'   )r(   r)   r*   r+   r,   r-   r.   is_dirr/   s       r   iter_tree_filesr7   p   s      * (!3!3299(CCDDD,%bgood&;&;RX|\\  U	l	#	# 	 r   c              #     K   t           j                            | |          }t           j                            |          }||vr|||<   nt	          |||         |          t          j        |          D ]R}t           j                            ||          }t           j                            | |          }		 t          j        |	          }
n$# t          $ r}| ||           Y d}~ud}~ww xY wt          j	        |
j
                  r<d}	 t          j        |	          }n(# t          $ r}| ||           Y d}~d}~ww xY wd}|
}t          j        |j
                  r4|s|s0t          |||
|          V  t          | ||||          D ]}|V  #t          j        |j
                  s|rt          |||
|          V  T||= dS )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_pathNTF)r,   r-   joinrealpathRecursionErrorlistdirlstatOSErrorstatS_ISLNKst_modeS_ISDIR	TreeEntryr+   S_ISREG)	root_fulldir_relmemor1   r2   dir_fulldir_real	node_namenode_rel	node_full
node_lstateis_link	node_statr3   s                  r   r+   r+      s)     * GLLG,,GX&&
 D$x..d8nRYZZZZ*X&& #? #?YW\\'9--(gll9h//)##::	   HQKKK8888
 
\*$%% 7	""II
   Xa[[[HHHH
 79	\)#$$ 
?, 
?g 
? 
9h
I	>	>>>>'	8T8\ZZ  u
KKKK |I%&& ?' ?	9h
I	>	>>>> 
(^^^s0   <C
C2C--C2D&&
E0EE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)names    r   lookup_patternrW      s     	T""r   c                 `    d}| D ](}|j         ||                    |f          v r|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   r   )r   r   matchedr   s       r   
match_filerZ      sF       W_ 
gmmTG$$$$oGr   c                    t          |t                    r|nt          |          }t                      }| D ]P}|j        G|                    |          }|j        r|                    |           ;|                    |           Q|S )a^  
	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`).
	)r   r   r   setr   r   updatedifference_update)r   r   r   r   r   r   s         r   match_filesr_     s     !
33DUUe 1 1W_ --	**<o 1%%%%""<000r   c                 F    i }| D ]}||t          |j        |          <   |S )a  
	Normalizes the entry paths to use the POSIX path separator.

	*entries* (:class:`~collections.abc.Iterable` of :class:`.TreeEntry`)
	contains the entries 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 the each normalized file path (:class:`str`)
	to the entry (:class:`.TreeEntry`)
	
separators)normalize_filer-   )entriesrb   
norm_filesr3   s       r   _normalize_entriesrf     s<      H HUBG*^EJ:>>>??r   c                     |t           }t          |           }|D ]"}|                    |t          j                  }#|                    d          r
|dd         }|S )aS  
	Normalizes the file path to use the POSIX path separator (i.e., ``'/'``).

	*file* (:class:`str` or :class:`pathlib.PurePath`) 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 :data:`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`).
	Nz./   )NORMALIZE_PATH_SEPSstrreplacer
   r   
startswith)r   rb   	norm_filer   s       r   rc   rc   -  so      "* YY 4 4SY]33))  m)r   c                 <    i }| D ]}||t          ||          <   |S )a  
	Normalizes the file paths to use the POSIX path separator.

	*files* (:class:`~collections.abc.Iterable` of :class:`str` or
	:class:`pathlib.PurePath`) 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 the each normalized file path (:class:`str`)
	to the original file path (:class:`str`)
	ra   )rc   )r   rb   re   r-   s       r   normalize_filesro   M  s:      A AT<@*^DZ88899r   c                 6   t          | t                    s"t          d                    |                     t	          |          s"t          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:{!r} is not a string.z%pattern_factory:{!r} is not callable.N)r   r   r)   r*   r(   rU   AlreadyRegisteredError)rV   pattern_factoryoverrides      r   register_patternrt   a  s      	4&& =.55d;;<<<!! S9@@QQRRR    t%9$%?@@@-dr   c                   d     e Zd ZdZ fdZed             Zed             Zed             Z xZ	S )rq   z|
	The :exc:`AlreadyRegisteredError` exception is raised when a pattern
	factory is registered under a name already in use.
	c                 Z    t          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)superrq   __init__)selfrV   rr   	__class__s      r   rx   zAlreadyRegisteredError.__init__  s,     %%..t_EEEEEr   c                 D    d                     | j        | j                  S )4
		*message* (:class:`str`) is the error message.
		zG{name!r} is already registered for pattern factory:{pattern_factory!r}.)rV   rr   )r*   rV   rr   ry   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   rV   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   rr   z&AlreadyRegisteredError.pattern_factory       
1r   )
__name__
__module____qualname____doc__rx   propertyr~   rV   rr   __classcell__rz   s   @r   rq   rq   z  s         
	F 	F 	F 	F 	F   (   (   (    r   rq   c                   z     e Zd ZdZ fdZed             Zed             Zed             Zed             Z	 xZ
S )r>   zN
	The :exc:`RecursionError` exception is raised when recursion is
	detected.
	c                 \    t          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*.
		N)rw   r>   rx   )ry   r9   r:   r;   rz   s       r   rx   zRecursionError.__init__  s-     &&y*kJJJJ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   r:   zRecursionError.first_path  r   r   c                 P    d                     | j        | j        | j                  S )r|   zDReal path {real!r} was encountered at {first!r} and then {second!r}.)realfirstsecond)r*   r9   r:   r;   r}   s    r   r~   zRecursionError.message  s3    
 
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   r9   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>`.
		rh   r   r}   s    r   r;   zRecursionError.second_path  r   r   )r   r   r   r   rx   r   r:   r~   r9   r;   r   r   s   @r   r>   r>     s         
K K K K K   (   (   (   (    r   r>   c                       e Zd ZdZdZd ZdS )r   z>
	The :class:`.MatchDetail` class contains information about
	r   c                     || _         dS )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   )ry   r   s     r   rx   zMatchDetail.__init__  s     $- r   N)r   r   r   r   	__slots__rx   r	   r   r   r   r     s4         
     r   r   c                   :    e Zd ZdZdZd Zd	dZd	dZd Zd	dZ	dS )
rF   zR
	The :class:`.TreeEntry` class contains information about a file-system
	entry.
	_lstatrV   r-   _statc                 D    || _         	 || _        	 || _        	 || _        dS )aR  
		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   )ry   rV   r-   r@   rB   s        r   rx   zTreeEntry.__init__   s?     $+
 $) $) $* r   Nc                 \    |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   rB   rE   rD   ry   r2   rS   s      r   r6   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   rB   rG   rD   r   s      r   is_filezTreeEntry.is_file5  r   r   c                 >    t          j        | j        j                  S )zC
		Returns whether the entry is a symbolic link (:class:`bool`).
		)rB   rC   r   rD   r}   s    r   
is_symlinkzTreeEntry.is_symlinkE  s     
dk)	*	**r   c                 *    |d}|r| j         n| j        S )a:  
		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   )ry   r2   s     r   rB   zTreeEntry.statK  s"     <#	44r   N)
r   r   r   r   r   rx   r6   r   r   rB   r	   r   r   rF   rF     s          1# # #J) ) ) ) ) ) ) ) + + +5 5 5 5 5 5r   rF   r   )NN)!r   r,   os.pathr
   rB   compatr   r   r   r   r   altsepri   rU   r    r$   r4   r7   	iter_treer+   rW   rZ   r_   rf   rc   ro   rt   	Exceptionrq   r>   objectr   rF   r	   r   r   <module>r      s1    
			       ? ? ? ? ? ? ? ? ? ? ? ?ZZrvry&9ZZZ   ' ' ' 'TP P P   >   B 	J J JZ	# 	# 	#  (  0   (   @   (. . . .2( ( ( ( (Y ( ( (V6 6 6 6 6Y 6 6 6r    &   2a5 a5 a5 a5 a5 a5 a5 a5 a5 a5r   