HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib64/python3.10/site-packages/coverage/__pycache__/files.cpython-310.pyc
o

!we�K�@s�UdZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZm
Z
mZmZmZddlmZddlmZddlmZmZmZee�Zdad	ed
<iaded<dNdd�ZdOdd�ZdPdd�ZdPdd�ZdZ dPdd�Z!ej"r�iZ#ded<iZ$ded<dQdd �Z%ndQd!d �Z%dQd"d#�Z&dRd%d&�Z'dSd(d)�Z(dPd*d+�Z)dTd,d-�Z*dUd1d2�Z+Gd3d4�d4�Z,Gd5d6�d6�Z-Gd7d8�d8�Z.dVd:d;�Z/d<d=�d>D�Z0dWd@dA�Z1	B	BdXdYdFdG�Z2GdHdI�dI�Z3dZdLdM�Z4e�dS)[zFile wrangling.�)�annotationsN)�Callable�Dict�Iterable�List�Optional�Tuple)�env)�ConfigError)�human_sorted�isolate_module�
join_regex��str�RELATIVE_DIRzDict[str, str]�CANONICAL_FILENAME_CACHE�return�NonecCs4ttj�}|�tj�s|tj}tj�|�aiadS)z?Set the directory that `relative_filename` will be relative to.N)	�abs_file�os�curdir�endswith�sep�path�normcaserr)�
abs_curdir�r�G/home/arjun/projects/env/lib/python3.10/site-packages/coverage/files.py�set_relative_directorys


rcCstS)z=Return the directory that `relative_filename` is relative to.)rrrrr�relative_directory/�r�filenamecCs*tj�|�}|�t�r|tt�d�}|S)z�Return the relative form of `filename`.

    The file name will be relative to the current directory when the
    `set_relative_directory` was called.

    N)rrr�
startswithr�len)r!�fnormrrr�relative_filename4s
r%c	Cs�|tvrD|}tj�|�s<tjgtjD](}|durqtj�||�}ztj�|�}Wnty4d}Ynw|r;|}nqt	|�}|t|<t|S)zzReturn a canonical file name for `filename`.

    An absolute path with no redundant components and normalized case.

    NF)
rrr�isabsr�sys�join�exists�UnicodeErrorr)r!�cfr�fr)rrr�canonical_filenameAs&��r-�dcCsRt�|�\}}|rt�d|�d����dd�}d|�d�}nd}||�dd�S)	a7A base for a flat file name to correspond to this file.

    Useful for writing files about the code where you want all the files in
    the same directory, but need to differentiate same-named files from
    different directories.

    For example, the file a/b/c.py will return 'd_86bbcbe134d28fd2_c_py'

    �sha3_256zUTF-8N��d_�_r�.)�ntpath�split�hashlib�new�encode�	hexdigest�replace)r!�dirname�basename�fp�prefixrrr�
flat_rootname\s
r?�_ACTUAL_PATH_CACHEzDict[str, List[str]]�_ACTUAL_PATH_LIST_CACHErcCs�|tvrt|Stj�|�\}}|s|��}nG|s|}nBt|�}|tvr)t|}nzt�|�}Wnty;g}Ynw|t|<tj�	|�}|D]}tj�	|�|krV|}nqHtj�
||�}|t|<|S)z:Get the actual path of `path`, including the correct case.)r@rrr5�upper�actual_pathrA�listdir�	Exceptionrr()r�head�tail�actpath�files�normtailr,rrrrCts2

��rCcCs|S)z*The actual path for non-Windows platforms.r�rrrrrC�r cCsttj�tj�|���S)z.Return the absolute normalized form of `path`.)rCrr�abspath�realpathrKrrrr�sr�Optional[Tuple[str, str]]cCsJdD] }|�|t|��\}}}|r"||}tj�|�r"||fSqdS)z�Split a filename into a zipfile / inner name pair.

    Only return a pair if the zipfile exists.  No check is made if the inner
    name is in the zipfile.

    )z.zipz.whlz.eggz.pexN)�	partitionrrrr))r!�ext�zipbase�	extension�inner�zipfilerrr�zip_location�s�rU�boolcCs tj�|�rdSt|�rdSdS)z'Determine if a source file path exists.TF)rrr)rUrKrrr�
source_exists�s
rWcCstjjr
tj�|�}|S)z:Return the string as Python would describe this file name.)r	�
PYBEHAVIOR�report_absolute_filesrrrL�r!rrr�python_reported_file�sr[cCst�|�p	t�|�S)z)Is `filename` an absolute path on any OS?)r4r&�	posixpathrZrrr�isabs_anywhere�sr]�patterns�
Iterable[str]�	List[str]cCs8g}|pgD]}|�|�|�d�s|�t|��q|S)aPrepare the file patterns for use in a `GlobMatcher`.

    If a pattern starts with a wildcard, it is used as a pattern
    as-is.  If it does not start with a wildcard, then it is made
    absolute with the current directory.

    If `patterns` is None, an empty list is returned.

    )�*�?)�appendr"r)r^�prepped�prrr�
prep_patterns�s


�rfc@�:eZdZdZddd	d
�Zddd�Zddd�Zddd�ZdS)�TreeMatcherz�A matcher for files in a tree.

    Construct with a list of paths, either files or directories. Paths match
    with the `match` method if they are one of the files, or if they are
    somewhere in a subtree rooted at one of the directories.

    �unknown�pathsr_�namerrrcCs$t|�|_dd�|D�|_||_dS)NcSsg|]}tj�|��qSr)rrr)�.0rerrr�
<listcomp>�sz(TreeMatcher.__init__.<locals>.<listcomp>)r�original_pathsrjrk)�selfrjrkrrr�__init__�s

zTreeMatcher.__init__cC�d|j�d|j�d�S)Nz
<TreeMatcher � �>)rkrn�rorrr�__repr__��zTreeMatcher.__repr__r`cC�|jS�z4A list of strings for displaying when dumping state.)rnrtrrr�info��zTreeMatcher.info�fpathrVcCsLtj�|�}|jD]}|�|�r#||krdS|t|�tjkr#dSq	dS)z1Does `fpath` indicate a file in one of our trees?TF)rrrrjr"r#r)ror{rerrr�match�s

�zTreeMatcher.matchN�ri)rjr_rkrrr�rr�rr`�r{rrrV��__name__�
__module__�__qualname__�__doc__rpruryr|rrrrrh�s

rhc@rg)�
ModuleMatcherz A matcher for modules in a tree.ri�module_namesr_rkrrrcCst|�|_||_dS�N)�list�modulesrk)ror�rkrrrrp�s

zModuleMatcher.__init__cCrq)Nz<ModuleMatcher rrrs)rkr�rtrrrrurvzModuleMatcher.__repr__r`cCrwrx)r�rtrrrryrzzModuleMatcher.info�module_namerVcCsF|sdS|jD]}|�|�r ||krdS|t|�dkr dSqdS)z<Does `module_name` indicate a module in one of our packages?FTr3)r�r"r#)ror��mrrrr|
s

�zModuleMatcher.matchNr})r�r_rkrrrr~r)r�rrrVr�rrrrr��s

r�c@rg)�GlobMatcherz)A matcher for files by file name pattern.ri�patsr_rkrrrcCs&t|�|_t|jtjd�|_||_dS)N)�case_insensitive)r�r��globs_to_regexr	�WINDOWS�rerk)ror�rkrrrrps

zGlobMatcher.__init__cCrq)Nz
<GlobMatcher rrrs)rkr�rtrrrru!rvzGlobMatcher.__repr__r`cCrwrx)r�rtrrrry$rzzGlobMatcher.infor{rVcCs|j�|�duS)z1Does `fpath` match one of our file name patterns?N)r�r|)ror{rrrr|(szGlobMatcher.matchNr})r�r_rkrrrr~rr�r�rrrrr�s

r��scCs&t�d|�}r|d}|Stj}|S)z?Find the path separator used in this string, or os.sep if none.�[\\/]r)r��searchrr)r��	sep_match�the_seprrrr-s
�rcCsg|]\}}t�|�|f�qSr)r��compile)rl�rx�subrrrrm8srm))z\*\*\*+N)z
[^/]+\*\*+N)z
\*\*+[^/]+N)z	\*\*/\*\*N)z^\*+/�(.*[/\\\\])?)z/\*+$z	[/\\\\].*)z\*\*/r�)�/z[/\\\\])z\*z	[^/\\\\]*)z\?z[^/\\\\])z\[.*?\]�\g<0>)z[a-zA-Z0-9_-]+r�)z[\[\]]N)r3z\\\g<0>�patterncCs�|�dd�}d|vrd|}g}d}|t|�krItD](\}}|j||d�}rB|dur4td|d����|�|�|��|��}nq|t|�ksd�|�S)	z.Convert a file-path glob pattern into a regex.�\r�z**/r)�posNzFile pattern can't include r)	r:r#�G2RX_TOKENSr|r
rc�expand�endr()r��path_rxr�r�r�r�rrr�_glob_to_regexIs ��
r�Fr��partial�re.Pattern[str]cCsBd}|r	|tjO}ttt|��}|sd|�d�}tj||d�}|S)a{Convert glob patterns to a compiled regex that matches any of them.

    Slashes are always converted to match either slash or backslash, for
    Windows support, even when running elsewhere.

    If the pattern has no slash or backslash, then it is interpreted as
    matching a file name anywhere it appears in the tree.  Otherwise, the glob
    pattern must match the whole file path.

    If `partial` is true, then the pattern will match if the target string
    starts with the pattern. Otherwise, it must match the entire string.

    Returns: a compiled regex object.  Use the .match method to compare target
    strings.

    rz(?:z)\Z)�flags)r��
IGNORECASEr
�mapr�r�)r^r�r�r�r��compiledrrrr�\s
r�c@sBeZdZdZ		ddd
d�Zddd
�Zddd�Zefddd�ZdS)�PathAliasesa�A collection of aliases for paths.

    When combining data files from remote machines, often the paths to source
    code are different, for example, due to OS differences, or because of
    serialized checkouts on continuous integration machines.

    A `PathAliases` object tracks a list of pattern/result pairs, and can
    map a path through those aliases to produce a unified path.

    NF�debugfn�Optional[Callable[[str], None]]�relativerVrrcCs$g|_|pdd�|_||_d|_dS)NcSsdS)Nrr)�msgrrr�<lambda>�sz&PathAliases.__init__.<locals>.<lambda>F)�aliasesr�r��pprinted)ror�r�rrrrp�s
zPathAliases.__init__c	CsH|�d|j�d��|jD]\}}}|�d|�d|�d|j���q
dS)z;Dump the important parts of the PathAliases, for debugging.zAliases (relative=z):z Rule: � -> �
 using regex N)r�r�r�r�)ro�original_pattern�regex�resultrrr�pprint�s �zPathAliases.pprintr�rr�cCs�|}t|�}t|�dkr|�d�}|�d�rtd��|js,|�d�s,t||�s,t|�}|�|�s5||7}t	|gddd�}t|�}|�d�|}|j
�|||f�dS)a�Add the `pattern`/`result` pair to the list of aliases.

        `pattern` is an `glob`-style pattern.  `result` is a simple
        string.  When mapping paths, if a path starts with a match against
        `pattern`, then that match is replaced with `result`.  This models
        isomorphic source trees being rooted at different places on two
        different machines.

        `pattern` can't end with a wildcard component, since that would
        match an entire tree, and not just its root.

        �z\/raz$Pattern must not end with wildcards.T)r�r�N)rr#�rstriprr
r�r"r]rr�r�rc)ror�r�r��pattern_sepr��
result_seprrr�add�s



zPathAliases.addrr)�Callable[[str], bool]c
s�|js
|��d|_|jD]k\}}}|�|�}rx|�|d|�}|�t|�t|��}|js2t|�}|�d�o<t	|�dk}|�d�rJ|sJ|dd�}||�s`|�
d|�d|�d|�d	�d
�q
|�
d|�d|�d
|�d�d|���|Sq
|jr�t|�s�t�
d|�}	t	|	�dkr�|	d}
d|
���dt�|
��d�}|
�tj��}t�fdd�|jD��s�|�
d��d
|�d|���|j��t�|�|f�|j||d�S|�
d|�d��|S)a�Map `path` through the aliases.

        `path` is checked against all of the patterns.  The first pattern to
        match is used to replace the root of the path with the result root.
        Only one pattern is ever used.  If no patterns match, `path` is
        returned unchanged.

        The separator style in the result is made to match that of the result
        in the alias.

        `exists` is a function to determine if the resulting path actually
        exists.

        Returns the mapped path.  If a mapping has happened, this is a
        canonical path.  If no mapping has happened, it is the original value
        of `path` unchanged.

        Tr)z./z.\�NzRule z	 changed z to rrzwhich doesn't exist, continuingz
Matched path z	 to rule r�z, z
producing z[/\\]r�z*/z^(.*[\\/])?r�c3s�|]
\}}}|�kVqdSr�r)rlrer2�r�rr�	<genexpr>�s�z"PathAliases.map.<locals>.<genexpr>zGenerating rule: r�)r)zNo rules match, path z
 is unchanged)r�r�r�r|r:rr�r-r"r#r�r]r�r5�escaper�anyrcr�r�)rorr)r�r�r�r�r7�	dot_start�parts�dir1�	regex_patrr�rr��sR�����
�zPathAliases.map)NF)r�r�r�rVrr�rr)r�rr�rrr)rrr)r�rr)	r�r�r�r�rpr�r�rWr�rrrrr�{s�

'r�r;�include_namespace_packagesccsj�tt�|��D]*\}\}}}|s|dkrd|vr|dd�=q|D]}t�d|�r1tj�||�Vq!qdS)a|Yield all of the importable Python files in `dirname`, recursively.

    To be importable, the files have to be in a directory with a __init__.py,
    except for `dirname` itself, which isn't required to have one.  The
    assumption is that `dirname` was specified directly, so the user knows
    best, but sub-directories are checked for a __init__.py to be sure we only
    find the importable files.

    If `include_namespace_packages` is True, then the check for __init__.py
    files is skipped.

    Files with strange characters are skipped, since they couldn't have been
    imported, and are probably editor side-files.

    rz__init__.pyNz^[^.#~!$@%^&*()+=,]+\.pyw?$)�	enumerater�walkr�r|rr()r;r��i�dirpath�dirnames�	filenamesr!rrr�find_python_filess�
���r�r�r~)r!rrr)rrrr)r!rrrN)rrrrV)r!rrrV)r^r_rr`)r�rrr)r�rrr)FF)r^r_r�rVr�rVrr�)r;rr�rVrr_)5r��
__future__rr6r4r�os.pathr\r�r'�typingrrrrrr�coverager	�coverage.exceptionsr
�
coverage.miscrrr
r�__annotations__rrrr%r-�MAX_FLATr?r�r@rArCrrUrWr[r]rfrhr�r�rr�r�r�r�r�rrrr�<module>s\ 






!





#

�