
    ziM#                        d Z ddlm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 ddlmZ ddlmZmZmZmZ dd	lmZ dd
lmZ d,d-dZd.dZd/d0dZd1dZ G d  d!          Z	 	 	 	 	 d2d3d(Zd4d)Z d5d+Z!dS )6a  Coverage data for coverage.py.

This file had the 4.x JSON data support, which is now gone.  This file still
has storage-agnostic helpers, and is kept to avoid changing too many imports.
CoverageData is now defined in sqldata.py, and imported here to keep the
imports working.

    )annotationsN)CallableIterable)Literal)CoverageExceptionNoDataError)PathAliases)Hasherfile_be_gonehuman_sortedplural)CoverageData)filename_matchFdatar   fullpathboolreturndict[str, int]c                    i }|rd }nt           j        j        }|                                 D ]6}|                     |          }|J t          |          | ||          <   7|S )aH  Return a dict summarizing the line coverage data.

    Keys are based on the file names, and values are the number of executed
    lines.  If `fullpath` is true, then the keys are the full pathnames of
    the files, otherwise they are the basenames of the files.

    Returns a dict mapping file names to counts of lines.

    c                    | S N )fs    X/var/www/tmov.alphamb/tmov_inventario/venv/lib/python3.11/site-packages/coverage/data.py<lambda>zline_counts.<locals>.<lambda>+   s         )ospathbasenamemeasured_fileslineslen)r   r   summfilename_fnfilenamer!   s         r   line_countsr&      s~     D '!kg&'')) 1 1

8$$   &)%jj[[""##Kr   r%   strhasherr
   Nonec                4   |                                  r8|                    t          |                     |          pg                      n#|                    t	          | |                     |                    |                     |                     dS )zContribute `filename`'s data to the `hasher`.

    `hasher` is a `coverage.misc.Hasher` instance to be updated with
    the file's data.  It should only get the results data, not the run
    data.

    N)has_arcsupdatesortedarcssorted_linesfile_tracer)r   r%   r(   s      r   add_data_to_hashr1   5   s     }} 4fTYYx006B778888l422333
MM$""8,,-----r   	data_file
data_pathsIterable[str] | None	list[str]c                   t           j                            t           j                            |                     \  }}|p|g}g }|D ]}t           j                            |          r3|                    t           j                            |                     Tt           j                            |          rzt          j        t           j        	                    t           j                            |          |                    dz   }|
                    t          j        |                     t          d| d          d |D             }t          |          S )zMake a list of data files to be combined.

    `data_file` is a path to a data file.  `data_paths` is a list of files or
    directories of files.

    Returns a list of absolute file paths.
    z.*z)Couldn't combine from non-existent path ''c                <    g | ]}|                     d           |S )z-journal)endswith).0fnms     r   
<listcomp>z$combinable_files.<locals>.<listcomp>[   s)    XXXs||J?W?WXXXXr   )r   r   splitabspathisfileappendisdirglobescapejoinextendr   r-   )r2   r3   data_dirlocalfiles_to_combineppatterns          r   combinable_filesrK   D   s5    gmmBGOOI$>$>??OHe)zJ P P7>>! 	P##BGOOA$6$67777W]]1 	Pk"',,rwq/A/A5"I"IJJTQG##DIg$6$67777N!NNNOOO YX'7XXX
 "###r   
dbfilenamec                6   t          |           }|r|d         r|d         S t          | d          5 }t          j        dd          }|                    |                                           ddd           n# 1 swxY w Y   |                                S )z%Get the hash of the data in the file.hashrbsha3_256F)usedforsecurityN)r   openhashlibnewr,   read	hexdigest)rL   mfobjr(   s       r   hash_for_data_filerY   c   s    z""A "QvY "y*d## 	't[UCCCFMM$))++&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' !!!s   >A<<B B c                  "    e Zd ZdZd
dZddZd	S )DataFileClassifierz.Track what files to combine and which to skip.r   r)   c                ,    t                      | _        d S r   )setfile_hashes)selfs    r   __init__zDataFileClassifier.__init__r   s    %(UUr   r   r'   Literal['combine', 'skip']c                    	 t          |          }n# t          $ r Y dS w xY w|| j        v rdS | j                            |           dS )z/Determine whether to combine or skip this file.combineskip)rY   	Exceptionr^   add)r_   r   shas      r   classifyzDataFileClassifier.classifyu   sk    	$Q''CC 	 	 	 99	 $"""6  %%%9s    
  N)r   r)   )r   r'   r   ra   )__name__
__module____qualname____doc__r`   rh   r   r   r   r[   r[   o   sB        88+ + + +     r   r[   aliasesPathAliases | NonestrictkeepmessageCallable[[str], None] | Nonec                   t          |                                 |          }|r|st          d          |d}nt          j        |j                  }t                      }d}	|D ]}
|
|                                 k    r8| j        	                    d          r| j        
                    d|
           S	 t          j                            |
          }n# t          $ r |
}Y nw xY w|                    |
          }| }|dk    r| j        	                    d          r| j        
                    d|
           	 t!          |
| j                  }|                                 |                     ||	           d
}	|r |d|            ne# t&          $ rH}| j        r"|                     t+          |                     |r |d| d|            d}Y d}~nd}~ww xY w|r |d|            |rF| j        	                    d          r| j        
                    d|
           t-          |
           |r|	st          d          dS dS )a  Combine a number of data files together.

    `data` is a CoverageData.

    Treat `data.filename` as a file prefix, and combine the data from all
    of the data files starting with that prefix plus a dot.

    If `aliases` is provided, it's a `PathAliases` object that is used to
    re-map paths to match the local machine's.

    If `data_paths` is provided, it is a list of directories or files to
    combine.  Directories are searched for files that start with
    `data.filename` plus dot as a prefix, and those files are combined.

    If `data_paths` is not provided, then the directory portion of
    `data.filename` is used as the directory to search for data files.

    Unless `keep` is True every data file found and combined is then deleted
    from disk. If a file cannot be read, a warning will be issued, and the
    file will not be deleted.

    If `strict` is true, and no files are found to combine, an error is
    raised.

    `message` is a function to use for printing messages to the user.

    zNo data to combineNFdataiozSkipping combining ourself: rc   zCombining data file )debug)map_pathTzCombined data file zCouldn't combine data file : zSkipping duplicate data zDeleting data file zNo usable data files)rK   base_filenamer   	functoolscachemapr[   data_filename_debugshouldwriter   r   relpath
ValueErrorrh   r   rU   r,   r   _warnr'   r   )r   rm   r3   ro   rp   rq   rH   rv   
classifiercombined_anyr   rel_file_namefile_actiondelete_this_onenew_dataexcs                   r   combine_parallel_datar      s   F ((:(:(<(<jII 0& 0.///?7;//#%%JL - -""$$$$ {!!(++ H!!"F"F"FGGG	GOOA..MM 	 	 	 MMM		 !))!,,"()##{!!(++ @!!">">">???C'=== Hx888# CGA-AABBB % ( ( (: ) JJs3xx((( RGP-PP3PPQQQ"'(  DB=BBCCC 	{!!(++ ?!!"="="=>>>OOO 2l 201112 2 2 2s*   :CC)(C)*F
G( >G##G(c                   t          |           }|                                } t          d|             t          j                            |           st          d           dS |                                 t          d|                                           t          |d          }t          |
                                          }t          |          }t          t          |d           d           |D ]L}| d	t          ||         d
           }|                    |          }|r	|d| dz  }t          |           MdS )z(Implementation of 'coverage debug data'.zpath: z%No data collected: file doesn't existNz
has_arcs: T)r   file:rw   linez [])r   r|   printr   r   existsrU   r+   r&   r   keysr"   r   r0   )r%   r   summary	filenamesnfilesr   r   plugins           r   debug_data_filer      sT   !!D!!##H	
8

7>>(## 5666IIKKK	
*t}}
*
*+++$...GW\\^^,,I^^F	VFF##
&
&
&'''  33vgaj&1133!!!$$ 	#NNNN"Dd r   	list[int]c                N    |                      |          }t          |pg           S )z+Get the sorted lines for a file, for tests.)r!   r-   )r   r%   r!   s      r   r/   r/      s%    JJx  E%+2r   )F)r   r   r   r   r   r   )r   r   r%   r'   r(   r
   r   r)   r   )r2   r'   r3   r4   r   r5   )rL   r'   r   r'   )NNFFN)r   r   rm   rn   r3   r4   ro   r   rp   r   rq   rr   r   r)   )r%   r'   r   r)   )r   r   r%   r'   r   r   )"rl   
__future__r   ry   rB   rS   os.pathr   collections.abcr   r   typingr   coverage.exceptionsr   r   coverage.filesr	   coverage.miscr
   r   r   r   coverage.sqldatar   r   r&   r1   rK   rY   r[   r   r   r/   r   r   r   <module>r      s    # " " " " "        . . . . . . . .       > > > > > > > > & & & & & & D D D D D D D D D D D D 9 9 9 9 9 9 + + + + + +    0. . . .$ $ $ $ $>	" 	" 	" 	"       . #''+,0`2 `2 `2 `2 `2F   ,     r   