a
    e	gX                     @   sH  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Zddlm	Z
mZ ddl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mZmZmZ ddlmZ ej d	kree!ee! f Z"nee!ef Z"ed
e"dZ#dd ej$ej%fD Z&i Z'ej(e!dddZ)eee*ef  e!eee+ ee* f dddZ,dDee ee! ee+ ee!df dddZ-ee eee*ef  dddZ.ee+dddZ/dEe"eee0gdf  ee+ ed dd d!Z1e!e!ee!e!f ee0gdf e+ed d"d#d$Z2dFe"eee0gdf  ee+ ee! dd%d&Z3dGd'd(Z4e!eegef d)d*d+Z5ee e!e+dd,d-Z6ee ee! ee! d.d/d0Z7dHe"ee	e!  e!d1d2d3Z8dIee" ee	e!  ee!ee" f d4d5d6Z9dJe!eegef ee+ dd7d8d9Z:G d:d; d;e;Z<G d<d= d=e;Z=ed>d?G d@dA dAee# Z>G dBd de?Z@G dCd de?ZAdS )KzC
This module provides utility methods for dealing with path-specs.
    N)
CollectionIterable)	dataclass)PathLike)AnyAnyStrCallabler   DictGenericr   IteratorListOptionalSequenceSetTupleTypeVarUnion   )Pattern)   	   TStrPath)boundc                 C   s   g | ]}|r|t jkr|qS  )	posixpathsep).0Z__sepr   r   P/var/www/html/llm_bihealth/app/venv/lib/python3.9/site-packages/pathspec/util.py
<listcomp>1   s   r   )pathreturnc                 C   s   t | }|  r|tj7 }|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osr   )r   Zstr_pathr   r   r   append_dir_sepD   s    
r$   )patternsfiler    c                 C   s@   d}d}| D ]*\}}|j dur||dur|j }|}q||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 actual
	pattern (:class:`~pathspec.pattern.Pattern`).

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

	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include
match_file)r%   r&   Zout_includeZ	out_indexindexpatternr   r   r   check_match_fileV   s    r,   MatchDetail)r%   filesall_matchesr    c           	      C   s   t |tr|nt|}i }| D ]v}|jdur||}|jr|D ]@}||v rr|rb|| j| q||| jd< q@t|g||< q@q|D ]
}||= qq|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:`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   )
isinstanceCollectionTypelistr(   matchr%   appendr-   )	r%   r.   r/   	all_filesreturn_filesr+   Zresult_filesZresult_filer&   r   r   r   detailed_match_filesr   s    


r7   r%   r    c                 C   s   dd t | D S )a&  
	Filters out null-patterns.

	*patterns* (:class:`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:`~pathspec.pattern.Pattern`).
	c                 S   s"   g | ]\}}|j d ur||fqS Nr(   )r   Z__index__patr   r   r   r      s   
z*_filter_check_patterns.<locals>.<listcomp>)	enumerater%   r   r   r   _filter_check_patterns   s    r>   )valuer    c                 C   s   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`).
	)r0   IterableTyper!   bytes)r?   r   r   r   _is_iterable   s    rB   	TreeEntry)rooton_errorfollow_linksr    c                 c   sN   |dur t |s td|d|du r,d}ttj| di ||E dH  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*.
	Nz	on_error: is not callable.T )callable	TypeError_iter_tree_entries_nextr#   r   abspathrD   rE   rF   r   r   r   iter_tree_entries   s
    rN   )	root_fulldir_relmemorE   rF   r    c                 c   s  t j| |}t j|}||vr,|||< nt||| |dt |:}|D ]"}t j||j}	z|jdd}
W n@ ty } z(|dur|| W Y d}~qPW Y d}~n
d}~0 0 |	 rz| }W nB ty } z(|dur|| W Y d}~qPW Y d}~n
d}~0 0 n|
}|j
|drPt|j|	|
|V  t| |	|||E dH  qP| sb|	 rPt|j|	|
|V  qPW d   n1 s0    Y  ||= 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_pathF)follow_symlinksN)r#   r   joinrealpathRecursionErrorscandirnamestatOSError
is_symlinkr"   rC   rK   is_file)rO   rP   rQ   rE   rF   Zdir_fullZdir_realZ	scan_iterZnode_entZnode_relZ
node_lstate	node_statr   r   r   rK      s8    

"
$4rK   c                 c   s*   t | ||dD ]}||s|jV  q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*.
	rE   rF   N)rN   r"   r   )rD   rE   rF   entryr   r   r   iter_tree_files3  s    
rc   c                 C   s   t jdtdd t| ||d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.   
stacklevelra   )warningswarnDeprecationWarningrc   rM   r   r   r   	iter_treeR  s
    rj   )rZ   r    c                 C   s   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)rZ   r   r   r   lookup_pattern]  s    	rl   c                 C   s0   d}| D ]"}|j dur||dur|j }q|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`.
	FNr'   )r%   r&   matchedr+   r   r   r   r)   i  s
    r)   )r%   r.   r    c                 C   sR   t jt dt dtdd dd | D }t }|D ]}t||r4|| q4|S )a  
	DEPRECATED: This is an old function no longer used. Use the
	:func:`~pathspec.util.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`).
	z".match_files() is deprecated. Use z-.match_file() with a loop for better results.rd   re   c                 S   s   g | ]}|j d ur|qS r9   r:   )r   r;   r   r   r   r         zmatch_files.<locals>.<listcomp>)rg   rh   __name__ri   setr)   add)r%   r.   Zuse_patternsr6   r&   r   r   r   match_files}  s    
rr   )r&   
separatorsr    c                 C   s`   |du rt }t| }|D ]}||tj}q|drF|dd }n|dr\|dd }|S )ay  
	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
	``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 ``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./rd   )NORMALIZE_PATH_SEPSr#   fspathreplacer   r   
startswith)r&   rs   	norm_filer   r   r   r   normalize_file  s    


rz   )r.   rs   r    c                 C   sP   t jdtdd i }| D ]2}t||d}||v r@|| | q|g||< q|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.rd   re   )rs   )rg   rh   ri   rz   r4   )r.   rs   Z
norm_filesr   ry   r   r   r   normalize_files  s    r{   )rZ   pattern_factoryoverrider    c                 C   sX   t | tstd| dt|s2td|d| tv rL|sLt| 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:rG   N)r0   r!   rJ   rI   rk   AlreadyRegisteredError)rZ   r|   r}   r   r   r   register_pattern  s    
r   c                       st   e Zd ZdZeeegef dd fddZe	edddZ
e	edd	d
Ze	eegef dddZ  ZS )r~   z|
	The :exc:`AlreadyRegisteredError` exception is raised when a pattern
	factory is registered under a name already in use.
	N)rZ   r|   r    c                    s   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)superr~   __init__)selfrZ   r|   	__class__r   r   r     s    zAlreadyRegisteredError.__init__r    c                 C   s   dj | j| jdS )4
		*message* (:class:`str`) is the error message.
		zG{name!r} is already registered for pattern factory:{pattern_factory!r}.)rZ   r|   )formatrZ   r|   r   r   r   r   message   s    zAlreadyRegisteredError.messagec                 C   s
   | j d S )zB
		*name* (:class:`str`) is the name of the registered pattern.
		r   argsr   r   r   r   rZ   *  s    zAlreadyRegisteredError.namec                 C   s
   | j d S )za
		*pattern_factory* (:class:`~collections.abc.Callable`) is the
		registered pattern factory.
		r   r   r   r   r   r   r|   1  s    z&AlreadyRegisteredError.pattern_factory)ro   
__module____qualname____doc__r!   r   r   r   r   propertyr   rZ   r|   __classcell__r   r   r   r   r~     s   	r~   c                       st   e Zd ZdZeeedd fddZeedddZeedd	d
ZeedddZ	eedddZ
  ZS )rX   zN
	The :exc:`RecursionError` exception is raised when recursion is
	detected.
	N)rR   rS   rT   r    c                    s   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)r   rX   r   )r   rR   rS   rT   r   r   r   r   @  s    zRecursionError.__init__r   c                 C   s
   | j d S )zx
		*first_path* (:class:`str`) is the first path encountered for
		:attr:`self.real_path <RecursionError.real_path>`.
		r   r   r   r   r   r   rS   T  s    zRecursionError.first_pathc                 C   s   dj | j| j| jdS )r   zDReal path {real!r} was encountered at {first!r} and then {second!r}.)realfirstsecond)r   rR   rS   rT   r   r   r   r   r   \  s
    zRecursionError.messagec                 C   s
   | j d S )zV
		*real_path* (:class:`str`) is the real path that recursion was
		encountered on.
		r   r   r   r   r   r   rR   g  s    zRecursionError.real_pathc                 C   s
   | j d S )zz
		*second_path* (:class:`str`) is the second path encountered for
		:attr:`self.real_path <RecursionError.real_path>`.
		rd   r   r   r   r   r   rT   o  s    zRecursionError.second_path)ro   r   r   r   r!   r   r   rS   r   rR   rT   r   r   r   r   r   rX   :  s   
rX   T)frozenc                   @   s6   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)
ro   r   r   r   	__slots__r   __annotations__r   boolintr   r   r   r   r   x  s   
r   c                   @   s(   e Zd ZdZdZee ddddZdS )r-   z>
	The :class:`.MatchDetail` class contains information about
	r=   Nr8   c                 C   s
   || _ 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=   )r   r%   r   r   r   r     s    	zMatchDetail.__init__)ro   r   r   r   r   r   r   r   r   r   r   r   r-     s   c                   @   s   e Zd ZdZdZeeejejddddZde	e
 e
ddd	Zde	e
 e
dd
dZe
dddZde	e
 ejdddZdS )rC   zR
	The :class:`.TreeEntry` class contains information about a file-system
	entry.
	_lstatrZ   r   _statN)rZ   r   lstatr[   r    c                 C   s   || _ || _|| _|| _dS )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   rZ   r   r   r[   r   r   r   r     s
    zTreeEntry.__init__)rF   r    c                 C   s(   |du rd}|r| j n| j}t|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   r[   S_ISDIRst_moder   rF   r`   r   r   r   r"     s    
zTreeEntry.is_dirc                 C   s(   |du rd}|r| j n| j}t|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   r[   S_ISREGr   r   r   r   r   r^     s    
zTreeEntry.is_filer   c                 C   s   t | jjS )zC
		Returns whether the entry is a symbolic link (:class:`bool`).
		)r[   S_ISLNKr   r   r   r   r   r   r]     s    zTreeEntry.is_symlinkc                 C   s   |du r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`).
		NT)r   r   )r   rF   r   r   r   r[     s    
zTreeEntry.stat)N)N)N)ro   r   r   r   r   r!   r#   stat_resultr   r   r   r"   r^   r]   r[   r   r   r   r   rC     s   +)N)NN)NN)NN)N)N)N)Br   r#   os.pathpathlibr   r[   sysrg   collections.abcr   r1   r   r@   Zdataclassesr   r   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r   r+   r   version_infor!   ZStrPathr   r   altsepru   rk   Pathr$   r   r   r,   r7   r>   rB   r\   rN   rK   rc   rj   rl   r)   rr   rz   r{   r   	Exceptionr~   rX   r   objectr-   rC   r   r   r   r   <module>   s   D

 
/  $
S  
# 
* 
(  />