
     hֱ                       S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJrJrJr  SSKJrJrJr  SSKJrJrJr  SSKJrJ r   SSK!J"r"J#r#  SS	K$J%r%J&r&J'r'  SS
K(J)r)  SSK*J+r+J,r,J-r-J.r.J/r/J0r0  SSK1J2r2  \#" \5      rSr3Sr4SS jr5 " S S5      r6 " S S5      r7SS jr8g)zSQLite coverage data.    )annotationsN)
CollectionMappingSequence)AnyCallablecast)NoDebugging	auto_reprfile_summary)CoverageException	DataError)file_be_goneisolate_module)numbits_to_numsnumbits_unionnums_to_numbits)SqliteDb)AnyCallableFilePathTArc	TDebugCtlTLineNoTWarnFn)__version__   a  CREATE TABLE coverage_schema (
    -- One row, to record the version of the schema in this db.
    version integer
);

CREATE TABLE meta (
    -- Key-value pairs, to record metadata about the data
    key text,
    value text,
    unique (key)
    -- Possible keys:
    --  'has_arcs' boolean      -- Is this data recording branches?
    --  'sys_argv' text         -- The coverage command line that recorded the data.
    --  'version' text          -- The version of coverage.py that made the file.
    --  'when' text             -- Datetime when the file was created.
);

CREATE TABLE file (
    -- A row per file measured.
    id integer primary key,
    path text,
    unique (path)
);

CREATE TABLE context (
    -- A row per context measured.
    id integer primary key,
    context text,
    unique (context)
);

CREATE TABLE line_bits (
    -- If recording lines, a row per context per file executed.
    -- All of the line numbers for that file/context are in one numbits.
    file_id integer,            -- foreign key to `file`.
    context_id integer,         -- foreign key to `context`.
    numbits blob,               -- see the numbits functions in coverage.numbits
    foreign key (file_id) references file (id),
    foreign key (context_id) references context (id),
    unique (file_id, context_id)
);

CREATE TABLE arc (
    -- If recording branches, a row per context per from/to line transition executed.
    file_id integer,            -- foreign key to `file`.
    context_id integer,         -- foreign key to `context`.
    fromno integer,             -- line number jumped from.
    tono integer,               -- line number jumped to.
    foreign key (file_id) references file (id),
    foreign key (context_id) references context (id),
    unique (file_id, context_id, fromno, tono)
);

CREATE TABLE tracer (
    -- A row per file indicating the tracer used for that file.
    file_id integer primary key,
    tracer text,
    foreign key (file_id) references file (id)
);
c                J   ^  [         R                  " T 5      SU 4S jj5       nU$ )z4A decorator for methods that should hold self._lock.c                  > U R                   R                  S5      (       a6  U R                   R                  SU R                  < STR                   35        U R                     U R                   R                  S5      (       a6  U R                   R                  SU R                  < STR                   35        T" U /UQ70 UD6sS S S 5        $ ! , (       d  f       g = f)NlockzLocking z for zLocked )_debugshouldwrite_lock__name__)selfargskwargsmethods      n/root/racknerd_01/codex-conversation/amazon-q-terraform/.venv/lib/python3.13/site-packages/coverage/sqldata.py_wrapped_locked.<locals>._wrappedt   s    ;;f%%KKeFOO;LMNZZ{{!!&))!!GDJJ>v>O"PQ$000 ZZs   $A"C
C)r%   CoverageDatar&   r   r'   r   returnr   )	functoolswraps)r(   r*   s   ` r)   _lockedr0   q   s'     __V1 1 O    c                  6    \ rS rSrSrSS jrS	S jrS
S jrSrg)NumbitsUnionAgg   z9SQLite aggregate function for computing union of numbits.c                    SU l         g )Nr1   resultr%   s    r)   __init__NumbitsUnionAgg.__init__   s	    r1   c                :    [        U R                  U5      U l        g)z%Process one value in the aggregation.N)r   r7   )r%   values     r)   stepNumbitsUnionAgg.step   s    #DKK7r1   c                    U R                   $ )z#Return the final aggregated result.r6   r8   s    r)   finalizeNumbitsUnionAgg.finalize   s    {{r1   r6   Nr-   None)r<   bytesr-   rC   r-   rD   )	r$   
__module____qualname____firstlineno____doc__r9   r=   r@   __static_attributes__ r1   r)   r3   r3      s    C8r1   r3   c                  *   \ rS rSrSr     S-           S.S jjr\rS/S jrS0S jr	S0S jr
S1S2S jjrS0S	 jrS0S
 jrS3S jrS4S jrS5S jrS6S jrS7S jrS1S8S jjrS9S jr\S:S j5       rS0S jrS;S jrS;S jr\S<S j5       r\S=S j5       rS>S?S jjr\S@S j5       rSASBS jjrSCSDS jjrSES jr  SC     SFS jjr!S1SGS jjr"S0S jr#S0S  jr$S0S! jr%S5S" jr&SHS# jr'SHS$ jr(SIS% jr)SJS& jr*SKS' jr+SLS( jr,SMS) jr-SNS* jr.\/SOS+ j5       r0S,r1g)Pr,      a  Manages collected coverage data, including file storage.

This class is the public supported API to the data that coverage.py
collects during program execution.  It includes information about what code
was executed. It does not include information from the analysis phase, to
determine what lines could have been executed, or what lines were not
executed.

.. note::

    The data file is currently a SQLite database file, with a
    :ref:`documented schema <dbschema>`. The schema is subject to change
    though, so be careful about querying it directly. Use this API if you
    can to isolate yourself from changes.

There are a number of kinds of data that can be collected:

* **lines**: the line numbers of source lines that were executed.
  These are always available.

* **arcs**: pairs of source and destination line numbers for transitions
  between source lines.  These are only available if branch coverage was
  used.

* **file tracer names**: the module names of the file tracer plugins that
  handled each file in the data.

Lines, arcs, and file tracer names are stored for each source file. File
names in this API are case-sensitive, even on platforms with
case-insensitive file systems.

A data file either stores lines, or arcs, but not both.

A data file is associated with the data when the :class:`CoverageData`
is created, using the parameters `basename`, `suffix`, and `no_disk`. The
base name can be queried with :meth:`base_filename`, and the actual file
name being used is available from :meth:`data_filename`.

To read an existing coverage.py data file, use :meth:`read`.  You can then
access the line, arc, or file tracer data with :meth:`lines`, :meth:`arcs`,
or :meth:`file_tracer`.

The :meth:`has_arcs` method indicates whether arc data is available.  You
can get a set of the files in the data with :meth:`measured_files`.  As
with most Python containers, you can determine if there is any data at all
by using this object as a boolean value.

The contexts for each line in a file can be read with
:meth:`contexts_by_lineno`.

To limit querying to certain contexts, use :meth:`set_query_context` or
:meth:`set_query_contexts`. These will narrow the focus of subsequent
:meth:`lines`, :meth:`arcs`, and :meth:`contexts_by_lineno` calls. The set
of all measured context names can be retrieved with
:meth:`measured_contexts`.

Most data files will be created by coverage.py itself, but you can use
methods here to create data files if you like.  The :meth:`add_lines`,
:meth:`add_arcs`, and :meth:`add_file_tracers` methods add data, in ways
that are convenient for coverage.py.

To record data for contexts, use :meth:`set_context` to set a context to
be used for subsequent :meth:`add_lines` and :meth:`add_arcs` calls.

To add a source file without any measured data, use :meth:`touch_file`,
or :meth:`touch_files` for a list of such files.

Write the data to its file with :meth:`write`.

You can clear the data in memory with :meth:`erase`.  Data for specific
files can be removed from the database with :meth:`purge_files`.

Two data collections can be combined by using :meth:`update` on one
:class:`CoverageData`, passing it the other.

Data in a :class:`CoverageData` can be serialized and deserialized with
:meth:`dumps` and :meth:`loads`.

The methods used during the coverage.py collection phase
(:meth:`add_lines`, :meth:`add_arcs`, :meth:`set_context`, and
:meth:`add_file_tracers`) are thread-safe.  Other methods may not be.

Nc                   X0l         [        R                  R                  U=(       d    S5      U l        X l        X@l        U=(       d
    [        5       U l        U R                  5         0 U l
        0 U l        [        R                  " 5       U l        [        R                  " 5       U l        SU l        SU l        SU l        SU l        SU l        SU l        g)a1  Create a :class:`CoverageData` object to hold coverage-measured data.

Arguments:
    basename (str): the base name of the data file, defaulting to
        ".coverage". This can be a path to a file in another directory.
    suffix (str or bool): has the same meaning as the `data_suffix`
        argument to :class:`coverage.Coverage`.
    no_disk (bool): if True, keep all data in memory, and don't
        write any disk file.
    warn: a warning callback function, accepting a warning message
        argument.
    debug: a `DebugControl` object (optional)

z	.coverageFN)_no_diskospathabspath	_basename_suffix_warnr
   r    _choose_filename	_file_map_dbsgetpid_pid	threadingRLockr#   
_have_used
_has_lines	_has_arcs_current_context_current_context_id_query_context_ids)r%   basenamesuffixno_diskwarndebugs         r)   r9   CoverageData.__init__   s    ,  )@[A
,{})+)+	IIK	__&
  ,0/3 48r1   c           	         U R                   R                  S5      (       a/  U R                   R                  U SU< S[        U5       S35        gg)z2A helper for debug messages which are all similar.dataio z ()N)r    r!   r"   r   )r%   msgfilenames      r)   _debug_dataioCoverageData._debug_dataio  sG    ;;h''KKQxl"\(5K4LANO (r1   c                    U R                   (       a  S[        R                  " 5        S3U l        gU R                  U l        [        U R                  5      nU(       a  U =R                  SU 3-  sl        gg)z.Set self._filename based on inited attributes.zfile:coverage-z?mode=memory&cache=shared.N)rO   uuiduuid4	_filenamerS   filename_suffixrT   )r%   rd   s     r)   rV   CoverageData._choose_filename  sU    ==-djjl^;TUDN!^^DN$T\\2FAfX,. r1   c                p    U R                   (       d  U R                  5         0 U l        SU l        SU l        g)zReset our attributes.FN)rO   closerW   r]   ra   r8   s    r)   _resetCoverageData._reset$  s(    }}JJL#' r1   c                   U R                   R                  S5      (       a+  U R                   R                  SU SU R                   35        U R                  R	                  5        H  nUR                  US9  M     0 U l        g)z&Really close all the database objects.rj   zClosing dbs, force=: )forceN)r    r!   r"   rX   valuesry   )r%   r~   dbs      r)   ry   CoverageData.close,  sg    ;;h''KK 3E7"TYYKHI))""$BHH5H! %	r1   c                    U R                  SU R                  5        [        U R                  U R                  U R                  5      U R
                  [        R                  " 5       '   U R                  5         g)z0Open an existing db file, and read its metadata.zOpening data fileN)	ro   ru   r   r    rO   rX   r[   	get_ident_read_dbr8   s    r)   _open_dbCoverageData._open_db4  sO    .?+3DNNDKKQUQ^Q^+_		)%%'(r1   c                   U R                   [        R                  " 5           n UR                  S5      nUc   e US   nU[        :w  a*  [        SR                  U R                  U[        5      5      e UR                  S5      nUb2  [        [        US   5      5      U l        U R                  (       + U l        UR                  S5       nU H  u  pgX`R                   U'   M     SSS5        SSS5        g! [         aP  nS[        U5      ;   a  U R                  U5         SnAN[        SR                  U R                  U5      5      UeSnAff = f! , (       d  f       Nt= f! , (       d  f       g= f)	zARead the metadata from a database so that we are ready to use it.z#select version from coverage_schemaNr   z;Couldn't use data file {!r}: wrong schema: {} instead of {}zno such table: coverage_schemaz:Data file {!r} doesn't seem to be a coverage data file: {}z-select value from meta where key = 'has_arcs'zselect id, path from file)rX   r[   r   execute_oneSCHEMA_VERSIONr   formatru   	Exceptionstr_init_dbboolintr_   r^   executerW   )r%   r   rowschema_versionexccurfile_idrQ   s           r)   r   CoverageData._read_db:  sL   YYy**,-nn%JK& "%Q!^3#U\\ NN**  4 ..!PQC!%c#a&k!2&*nn"478C%(MG+2NN4( &) 9= .-  	3s3x?MM"%%#T[[ NN
 		4 98= .-sR   E&C8BE&E'E&8
E E"E&'&EEE&
E#	E&&
E4c           
        U R                  SU R                  5        UR                  [        5        UR	                  S[
        45        S[        4/nU R                  R                  S5      (       aZ  UR                  S[        [        [        SS5      5      4S[        R                  R                  5       R                  S	5      4/5        UR!                  S
U5        g)z+Write the initial contents of the database.zIniting data filez0INSERT INTO coverage_schema (version) VALUES (?)versionprocesssys_argvargvNwhenz%Y-%m-%d %H:%M:%S5INSERT OR IGNORE INTO meta (key, value) VALUES (?, ?))ro   ru   executescriptSCHEMAexecute_voidr   r   r    r!   extendr   getattrsysdatetimenowstrftimeexecutemany_void)r%   r   	meta_datas      r)   r   CoverageData._init_db^  s    .?
 
J^L]^
 $
	 ;;i((WS&$%?!@AX..224==>QRS 	SU^_r1   c                    [         R                  " 5       U R                  ;  a  U R                  5         U R                  [         R                  " 5          $ )zGet the SqliteDb object to use.)r[   r   rX   r   r8   s    r)   _connectCoverageData._connectr  s8     		1MMOyy,,.//r1   c                   [         R                  " 5       U R                  ;  a/  [        R                  R                  U R                  5      (       d  g U R                  5        nUR                  S5       n[        [        U5      5      sS S S 5        sS S S 5        $ ! , (       d  f       O= f S S S 5        g ! , (       d  f       g = f! [         a     gf = f)NFzSELECT * FROM file LIMIT 1)r[   r   rX   rP   rQ   existsru   r   r   r   listr   )r%   conr   s      r)   __bool__CoverageData.__bool__x  s     		1"''..:X:X	C[[!=>#S	? ?> !>>> ! ! 		sN   C	 $B86B
	B8	C	 
B+	'B8/C	 8
CC	 C	 	
CCc                    U R                  SU R                  5        U R                  5        nUR                  5       nS[        R
                  " UR                  S5      5      -   sSSS5        $ ! , (       d  f       g= f)a  Serialize the current data to a byte string.

The format of the serialized data is not documented. It is only
suitable for use with :meth:`loads` in the same version of
coverage.py.

Note that this serialization is not what gets stored in coverage data
files.  This method is meant to produce bytes that can be transmitted
elsewhere and then deserialized with :meth:`loads`.

Returns:
    A byte string of serialized data.

.. versionadded:: 5.0

zDumping data from data file   zutf-8N)ro   ru   r   dumpzlibcompressencode)r%   r   scripts      r)   dumpsCoverageData.dumps  sS    " 	8$..I]]_XXZF$--g(>?? __s   8A//
A=c                   U R                  SU R                  5        USS S:w  a  [        SUSS < S[        U5       S35      e[        R
                  " USS 5      R                  S	5      n[        U R                  U R                  U R                  5      =U R                  [        R                  " 5       '   nU   UR                  U5        SSS5        U R                  5         S
U l        g! , (       d  f       N&= f)a  Deserialize data from :meth:`dumps`.

Use with a newly-created empty :class:`CoverageData` object.  It's
undefined what happens if the object already has data in it.

Note that this is not for reading data from a coverage data file.  It
is only for use on data you produced with :meth:`dumps`.

Arguments:
    data: A byte string of serialized data produced by :meth:`dumps`.

.. versionadded:: 5.0

zLoading data into data fileN   r   zUnrecognized serialization: (   z
 (head of z bytes)r   T)ro   ru   r   lenr   
decompressdecoder   r    rO   rX   r[   r   r   r   r]   )r%   datar   r   s       r)   loadsCoverageData.loads  s     	8$..I8t.tCRym:c$i[PWX  ab*11':08VZVcVc0dd		)%%'(2V$  Rs   <C..
C<c                    XR                   ;  a@  U(       a9  U R                  5        nUR                  SU45      U R                   U'   SSS5        U R                   R                  U5      $ ! , (       d  f       N)= f)zGet the file id for `filename`.

If filename is not in the database yet, add it if `add` is True.
If `add` is not True, return None.
z-INSERT OR REPLACE INTO file (path) VALUES (?)N)rW   r   execute_for_rowidget)r%   rn   addr   s       r)   _file_idCoverageData._file_id  sa     >>)]]_/2/D/DG!0DNN8, %
 ~~!!(++ %_s   !A++
A9c                    Uc   eU R                  5         U R                  5        nUR                  SU45      nUb  [        [        US   5      sSSS5        $  SSS5        g! , (       d  f       g= f)zGet the id for a context.N(SELECT id FROM context WHERE context = ?r   )_start_usingr   r   r	   r   )r%   contextr   r   s       r)   _context_idCoverageData._context_id  sa    """]]_//"LwjYCCQ( _
  __s   )A#A##
A1c                    U R                   R                  S5      (       a  U R                   R                  SU< 35        Xl        SU l        g)zSet the current context for future :meth:`add_lines` etc.

`context` is a str, the name of the context to use for the next data
additions.  The context persists until the next :meth:`set_context`.

.. versionadded:: 5.0

dataopzSetting coverage context: N)r    r!   r"   r`   ra   )r%   r   s     r)   set_contextCoverageData.set_context  sA     ;;h''KK :7+FG '#' r1   c                    U R                   =(       d    SnU R                  U5      nUb  X l        gU R                  5        nUR	                  SU45      U l        SSS5        g! , (       d  f       g= f)z4Use the _current_context to set _current_context_id. Nz(INSERT INTO context (context) VALUES (?))r`   r   ra   r   r   )r%   r   
context_idr   s       r)   _set_context_idCoverageData._set_context_id  s^    ''-2%%g.
!'1$C+.+@+@>J,( !s   A##
A1c                    U R                   $ )z<The base filename for storing data.

.. versionadded:: 5.0

)rS   r8   s    r)   base_filenameCoverageData.base_filename       ~~r1   c                    U R                   $ )z2Where is the data stored?

.. versionadded:: 5.0

)ru   r8   s    r)   data_filenameCoverageData.data_filename  r   r1   c           	        U R                   R                  S5      (       a  U R                   R                  S[        U5      [	        S UR                  5        5       5      4-  5        U R                   R                  S5      (       aC  [        UR                  5       5       H&  u  p#U R                   R                  SU SU 35        M(     U R                  5         U R                  SS9  U(       d  g	U R                  5        nU R                  5         UR                  5        H  u  p#[        U5      nU R                  USS
9nSnUR                  XvU R                  45       n[!        U5      n	S	S	S	5        W	(       a  [#        XYS   S   5      nUR%                  SX`R                  U45        M     S	S	S	5        g	! , (       d  f       NQ= f! , (       d  f       g	= f)zAdd measured line data.

`line_data` is a dictionary mapping file names to iterables of ints::

    { filename: { line1, line2, ... }, ...}

r   z&Adding lines: %d files, %d lines totalc              3  8   #    U  H  n[        U5      v   M     g 7fNr   ).0liness     r)   	<genexpr>)CoverageData.add_lines.<locals>.<genexpr>  s     C0BuE

0B   dataop2  r}   Tr   Nr   zBSELECT numbits FROM line_bits WHERE file_id = ? AND context_id = ?r   z
                    INSERT OR REPLACE INTO line_bits
                    (file_id, context_id, numbits) VALUES (?, ?, ?)
                    )r    r!   r"   r   sumr   sorteditemsr   _choose_lines_or_arcsr   r   r   r   r   ra   r   r   r   )
r%   	line_datarn   linenosr   	line_bitsr   queryr   existings
             r)   	add_linesCoverageData.add_lines  s    ;;h''KK8	NC	0@0@0BCC {{!!),,)/	0A)B%HKK%%8*Bwi&@A *C""".]]_  "%.__%6!+G4	--d-;\[[$2J2J(KLPS#CyH M -i!Q HI   66	B &7 _ ML _s&   A G
"F9.AG
9
GG


Gc           
     2   U R                   R                  S5      (       a  U R                   R                  S[        U5      [	        S UR                  5        5       5      4-  5        U R                   R                  S5      (       aC  [        UR                  5       5       H&  u  p#U R                   R                  SU SU 35        M(     U R                  5         U R                  SS9  U(       d  g	U R                  5        nU R                  5         UR                  5        HR  u  p#U(       d  M  U R                  USS
9nU VVs/ s H  u  pgXPR                  Xg4PM     nnnUR                  SU5        MT     S	S	S	5        g	s  snnf ! , (       d  f       g	= f)zAdd measured arc data.

`arc_data` is a dictionary mapping file names to iterables of pairs of
ints::

    { filename: { (l1,l2), (l1,l2), ... }, ...}

r   z$Adding arcs: %d files, %d arcs totalc              3  8   #    U  H  n[        U5      v   M     g 7fr   r   )r   arcss     r)   r   (CoverageData.add_arcs.<locals>.<genexpr>3  s     @.?dD		.?r   r   r   r}   Tr   Nr   z
                    INSERT OR IGNORE INTO arc
                    (file_id, context_id, fromno, tono) VALUES (?, ?, ?, ?)
                    )r    r!   r"   r   r   r   r   r   r   r   r   r   r   ra   r   )	r%   arc_datarn   r   r   r   fromnotonor   s	            r)   add_arcsCoverageData.add_arcs$  sW    ;;h''KK6M@hoo.?@@ {{!!),,&,X^^-=&>NHKK%%8*Btf&=> '?"""-]]_  ""*.."2--d-;^bc^blf":":FI^bc$$  #3 _ d _s   AFF
 FF
Fc           
        U(       d	  U(       d   eU(       a	  U(       a   eU(       aW  U R                   (       aF  U R                  R                  S5      (       a  U R                  R                  S5        [	        S5      eU(       aW  U R
                  (       aF  U R                  R                  S5      (       a  U R                  R                  S5        [	        S5      eU R                   (       d^  U R
                  (       dL  Xl        X l         U R                  5        nUR                  SS[        [        U5      5      45        SSS5        ggg! , (       d  f       g= f)	z5Force the data file to choose between lines and arcs.r   z:Error: Can't add line measurements to existing branch dataz3Can't add line measurements to existing branch dataz:Error: Can't add branch measurements to existing line dataz3Can't add branch measurements to existing line datar   has_arcsN)
r_   r    r!   r"   r   r^   r   r   r   r   )r%   r   r   r   s       r)   r   "CoverageData._choose_lines_or_arcsL  s    }d##T^^{{!!(++!!"^_QRRDOO{{!!(++!!"^_QRR~~doo#O!NC  KSY0 ! '6~ !s   'E
Ec           	        U R                   R                  S5      (       a(  U R                   R                  S[        U5       S35        U(       d  gU R	                  5         U R                  5        nUR                  5        Hl  u  p4U R                  USS9nU R                  U5      nU(       a#  Xd:w  a  [        SR                  UUU5      5      eMP  U(       d  MY  UR                  SXT45        Mn     SSS5        g! , (       d  f       g= f)	zTAdd per-file plugin information.

`file_tracers` is { filename: plugin_name, ... }

r   zAdding file tracers: z filesNTr   3Conflicting file tracer name for '{}': {!r} vs {!r}z2INSERT INTO TRACER (file_id, tracer) VALUES (?, ?))r    r!   r"   r   r   r   r   r   file_tracerr   r   r   )r%   file_tracersr   rn   plugin_namer   existing_plugins          r)   add_file_tracersCoverageData.add_file_tracersa  s     ;;h''KK 5c,6G5HOP]]_)5););)=%--d-;"&"2"28"<"&5'QXX ( / +  6 ![$$L . *> __s   1A&C;C;;
D	c                *    U R                  U/U5        g)zEnsure that `filename` appears in the data, empty if needed.

`plugin_name` is the name of the plugin responsible for this file.
It is used to associate the right filereporter, etc.
N)touch_files)r%   rn   r  s      r)   
touch_fileCoverageData.touch_file  s     	([1r1   c                   U R                   R                  S5      (       a  U R                   R                  SU< 35        U R                  5         U R	                  5          U R
                  (       d  U R                  (       d  [        S5      eU H.  nU R                  USS9  U(       d  M  U R                  X205        M0     SSS5        g! , (       d  f       g= f)zEnsure that `filenames` appear in the data, empty if needed.

`plugin_name` is the name of the plugin responsible for these files.
It is used to associate the right filereporter, etc.
r   z	Touching z*Can't touch files in an empty CoverageDataTr   N)
r    r!   r"   r   r   r_   r^   r   r   r  )r%   	filenamesr  rn   s       r)   r  CoverageData.touch_files  s     ;;h''KK	)78]]_>>$// LMM%hD1;))8*AB	 &	 __s    AC,C
Cc                   U R                   R                  S5      (       a  U R                   R                  SU< 35        U R                  5         U R	                  5        nU R
                  (       a  SnOU R                  (       a  SnO[        S5      eU H*  nU R                  USS9nUc  M  UR                  X545        M,     SSS5        g! , (       d  f       g= f)	zTPurge any existing coverage data for the given `filenames`.

.. versionadded:: 7.2

r   zPurging data for z%DELETE FROM line_bits WHERE file_id=?zDELETE FROM arc WHERE file_id=?z*Can't purge files in an empty CoverageDataFr   N)
r    r!   r"   r   r   r^   r_   r   r   r   )r%   r  r   sqlrn   r   s         r)   purge_filesCoverageData.purge_files  s     ;;h''KK 1)?@]]_=7 LMM%--e-<?  j1	 & __s    A$C
Cc           
     P   U R                   R                  S5      (       a5  U R                   R                  SR                  [	        USS5      5      5        U R
                  (       a  UR                  (       a
  [        SSS9eU R                  (       a  UR
                  (       a
  [        SSS9eU=(       d    S	 nU R                  5         UR                  5         UR                  5           S
S
S
5        U R                  5        nUR                  c   eSUR                  l        UR                  R                  SS[        5        UR                  R                  SSU5        UR                  R                  SS[         5        UR#                  SUR%                  5       45        UR#                  S5        UR'                  S5       n[)        U5      nU(       a$  US   u  pgn[        SR                  UUU5      5      e S
S
S
5        UR#                  S5        UR#                  S5        UR'                  S5       nU R*                  R-                  U V	Vs0 s H  u  pXi_M	     snn	5        S
S
S
5        UR'                  S5       nUR/                  5       u  pS
S
S
5        W
(       a1  U R1                  SS9  UR#                  S5        UR#                  S5        W(       a   U R1                  SS9  UR#                  S5        UR#                  S 5        S
S
S
5        U R2                  (       d!  U R5                  5         U R                  5         g
g
! , (       d  f       GNe= f! , (       d  f       GNd= fs  snn	f ! , (       d  f       GN= f! , (       d  f       N= f! , (       d  f       N= f)!zUpdate this data with data from another :class:`CoverageData`.

If `map_path` is provided, it's a function that re-map paths to match
the local machine's.  Note: `map_path` is None only when called
directly from the test suite.

r   zUpdating with data from {!r}ru   z???z6Can't combine branch coverage data with statement datazcant-combine)slugz6Can't combine statement coverage data with branch datac                    U $ r   rK   )ps    r)   <lambda>%CoverageData.update.<locals>.<lambda>  s    !r1   N	IMMEDIATEr      map_pathr   numbits_union_aggzATTACH DATABASE ? AS other_dbz
                CREATE TEMP TABLE other_file_mapped AS
                SELECT
                    other_file.id as other_file_id,
                    map_path(other_file.path) as mapped_path
                FROM other_db.file AS other_file
            aH  
                SELECT other_file_mapped.mapped_path,
                       COALESCE(main.tracer.tracer, ''),
                       COALESCE(other_db.tracer.tracer, '')
                FROM main.file
                LEFT JOIN main.tracer ON main.file.id = main.tracer.file_id
                INNER JOIN other_file_mapped ON main.file.path = other_file_mapped.mapped_path
                LEFT JOIN other_db.tracer ON other_file_mapped.other_file_id = other_db.tracer.file_id
                WHERE COALESCE(main.tracer.tracer, '') != COALESCE(other_db.tracer.tracer, '')
            r   r  z
                INSERT OR IGNORE INTO main.file (path)
                SELECT DISTINCT mapped_path FROM other_file_mapped
            z
                INSERT OR IGNORE INTO main.context (context)
                SELECT context FROM other_db.context
            zSELECT id, path FROM filez
                SELECT
                    EXISTS(SELECT 1 FROM other_db.arc),
                    EXISTS(SELECT 1 FROM other_db.line_bits)
            Tr   au  
                    CREATE TEMP TABLE context_mapping AS
                    SELECT
                        other_context.id as other_id,
                        main_context.id as main_id
                    FROM other_db.context AS other_context
                    INNER JOIN main.context AS main_context ON other_context.context = main_context.context
                a  
                    INSERT OR IGNORE INTO main.arc (file_id, context_id, fromno, tono)
                    SELECT
                        main_file.id,
                        context_mapping.main_id,
                        other_arc.fromno,
                        other_arc.tono
                    FROM other_db.arc AS other_arc
                    INNER JOIN other_file_mapped ON other_arc.file_id = other_file_mapped.other_file_id
                    INNER JOIN context_mapping ON other_arc.context_id = context_mapping.other_id
                    INNER JOIN main.file AS main_file ON other_file_mapped.mapped_path = main_file.path
                r   a  
                    INSERT OR REPLACE INTO main.line_bits (file_id, context_id, numbits)
                    SELECT
                        main_file.id,
                        main_context.id,
                        numbits_union(
                            COALESCE((
                                SELECT numbits FROM main.line_bits
                                WHERE file_id = main_file.id AND context_id = main_context.id
                            ), X''),
                            aggregated.combined_numbits
                        )
                    FROM (
                        SELECT
                            other_file_mapped.mapped_path,
                            other_context.context,
                            numbits_union_agg(other_line_bits.numbits) as combined_numbits
                        FROM other_db.line_bits AS other_line_bits
                        INNER JOIN other_file_mapped ON other_line_bits.file_id = other_file_mapped.other_file_id
                        INNER JOIN other_db.context AS other_context ON other_line_bits.context_id = other_context.id
                        GROUP BY other_file_mapped.mapped_path, other_context.context
                    ) AS aggregated
                    INNER JOIN main.file AS main_file ON aggregated.mapped_path = main_file.path
                    INNER JOIN main.context AS main_context ON aggregated.context = main_context.context
                a  
                INSERT OR IGNORE INTO main.tracer (file_id, tracer)
                SELECT
                    main_file.id,
                    other_tracer.tracer
                FROM other_db.tracer AS other_tracer
                INNER JOIN other_file_mapped ON other_tracer.file_id = other_file_mapped.other_file_id
                INNER JOIN main.file AS main_file ON other_file_mapped.mapped_path = main_file.path
            )r    r!   r"   r   r   r^   r_   r   r   readr   r   isolation_levelcreate_functionr   create_aggregater3   r   r   r   r   rW   updatefetchoner   rO   rz   )r%   
other_datar"  r   r   	conflictsrQ   this_tracerother_traceridr  	has_liness               r)   r(  CoverageData.update  s:    ;;h''KK.55JU;
 ??z33H~  >>j33H~  , 	   " # ]]_77&&&&1CGG# GG##OQFGG##J8<GG$$# <z?W?W?Y>[\     	 	  I	6?l3D|#MTT '(  	,       89S%%&DHBtx&DE :    &)lln# ***5    "     "  ***6    " 6   E X }}KKMIIK _ #":	 	F 'E :9  _st   *M
CN7M?;N:M4M.#M4+NNA8N

M
M+	&N.M44
N	>N
N	N
N%c                0   U R                  5         U R                  (       a  gU R                  SU R                  5        [	        U R                  5        U(       a  [
        R                  R                  U R                  5      u  p#[
        R                  R                  [
        R                  R                  U5      U5      n[        R                  " U5      S-   n[        R                  " U5       H   nU R                  SU5        [	        U5        M"     gg)zErase the data in this object.

If `parallel` is true, then also deletes data files created from the
basename by parallel-mode.

NzErasing data filez.*zErasing parallel data file)rz   rO   ro   ru   r   rP   rQ   splitjoinrR   globescape)r%   paralleldata_dirlocallocal_abs_pathpatternrn   s          r)   eraseCoverageData.eraseh  s     	==.?T^^$ ggmmDNN;OHWW\\"''//(*CUKNkk.1D8G IIg.""#?JX& /	 r1   c                    [         R                  R                  U R                  5      (       a!  U R	                  5          SU l        SSS5        gg! , (       d  f       g= f)z"Start using an existing data file.TN)rP   rQ   r   ru   r   r]   r8   s    r)   r$  CoverageData.read|  s;    77>>$..))"& ! * s   A
Ac                <    U R                  SU R                  5        g)z,Ensure the data is written to the data file.zWriting (no-op) data fileN)ro   ru   r8   s    r)   r"   CoverageData.write  s    6Gr1   c                   U R                   [        R                  " 5       :w  a:  U R                  5         U R	                  5         [        R                  " 5       U l         U R
                  (       d  U R                  5         SU l        g)z+Call this before using the database at all.TN)rZ   rP   rY   rz   rV   r]   r;  r8   s    r)   r   CoverageData._start_using  sM    99		#KKM!!#		DIJJLr1   c                ,    [        U R                  5      $ )z4Does the database have arcs (True) or lines (False).)r   r_   r8   s    r)   r  CoverageData.has_arcs  s    DNN##r1   c                ,    [        U R                  5      $ )zA set of all files that have been measured.

Note that a file may be mentioned as measured even though no lines or
arcs for that file are present in the data.

)setrW   r8   s    r)   measured_filesCoverageData.measured_files  s     4>>""r1   c                   U R                  5         U R                  5        nUR                  S5       nU Vs1 s H  o3S   iM	     nnSSS5        SSS5        W$ s  snf ! , (       d  f       N= f! , (       d  f       W$ = f)zGA set of all contexts that have been measured.

.. versionadded:: 5.0

z%SELECT DISTINCT(context) FROM contextr   N)r   r   r   )r%   r   r   r   contextss        r)   measured_contextsCoverageData.measured_contexts  sp     	]]_DE.12csFc2 F   3 FE _ s3   A0AAAA0A
A-	)A00
A?c                   U R                  5         U R                  5        nU R                  U5      nUc
   SSS5        gUR                  SU45      nUb  US   =(       d    SsSSS5        $  SSS5        g! , (       d  f       g= f)zGet the plugin name of the file tracer for a file.

Returns the name of the plugin that handles this file.  If the file was
measured, but didn't use a plugin, then "" is returned.  If the file
was not measured, then None is returned.

Nz+SELECT tracer FROM tracer WHERE file_id = ?r   r   )r   r   r   r   )r%   rn   r   r   r   s        r)   r	  CoverageData.file_tracer  su     	]]_mmH-G _ //"ORYQ[\C1v| _  __s   A7 #A7-A77
Bc                ,   U R                  5         U R                  5        nUR                  SU45       nUR                  5        Vs/ s H  oDS   PM	     snU l        SSS5        SSS5        gs  snf ! , (       d  f       N= f! , (       d  f       g= f)a4  Set a context for subsequent querying.

The next :meth:`lines`, :meth:`arcs`, or :meth:`contexts_by_lineno`
calls will be limited to only one context.  `context` is a string which
must match a context exactly.  If it does not, no exception is raised,
but queries will return no data.

.. versionadded:: 5.0

r   r   N)r   r   r   fetchallrb   )r%   r   r   r   r   s        r)   set_query_contextCoverageData.set_query_context  sp     	]]_G'TX[=@\\^*L^cq6^*L' U _*L UT _s4   BA4A/A4B/A44
B	>B
Bc                   U R                  5         U(       a~  U R                  5        nSR                  S/[        U5      -  5      nUR	                  SU-   U5       nUR                  5        Vs/ s H  oUS   PM	     snU l        SSS5        SSS5        gSU l        gs  snf ! , (       d  f       N$= f! , (       d  f       g= f)a  Set a number of contexts for subsequent querying.

The next :meth:`lines`, :meth:`arcs`, or :meth:`contexts_by_lineno`
calls will be limited to the specified contexts.  `contexts` is a list
of Python regular expressions.  Contexts will be matched using
:func:`re.search <python:re.search>`.  Data will be included in query
results if they are part of any of the contexts matched.

.. versionadded:: 5.0

z or zcontext REGEXP ?zSELECT id FROM context WHERE r   N)r   r   r3  r   r   rP  rb   )r%   rJ  r   context_clauser   r   s         r)   set_query_contextsCoverageData.set_query_contexts  s     	C!'.@-ACM-Q!R[[!@>!QS[\`cAD.P#1v.PD+ ] !
 '+D# /Q ]\ !s5   4B4B#/B=B#B4B##
B1	-B44
Cc                   U R                  5         U R                  5       (       aV  U R                  U5      nUbB  [        R                  R                  U5      n[        U Vs1 s H  oDS:  d  M
  UiM     sn5      $ U R                  5        nU R                  U5      nUc
   SSS5        gSnU/nU R                  b@  SR                  S[        U R                  5      -  5      n	USU	-   S-   -  nXR                  -  nUR                  Xx5       n
[        U
5      nSSS5        [        5       nW H   nUR                  [        US   5      5        M"     [        U5      sSSS5        $ s  snf ! , (       d  f       NW= f! , (       d  f       g= f)aB  Get the list of lines executed for a source file.

If the file was not measured, returns None.  A file might be measured,
and have no lines executed, in which case an empty list is returned.

If the file was executed, returns a list of integers, the line numbers
executed in the file. The list is in no particular order.

Nr   z/SELECT numbits FROM line_bits WHERE file_id = ?, ? AND context_id IN (rl   )r   r  r   	itertoolschainfrom_iterabler   r   r   rb   r3  r   r   rF  r(  r   )r%   rn   r   	all_lineslr   r   r   r   	ids_arrayr   bitmapsnumsr   s                 r)   r   CoverageData.lines  sK    	==??99X&D%OO99$?		;	1UQ	;<<]]_mmH-G _
 Jy**6 $		#D4K4K0L*L MI3i?#EEE333D[[-"3iG .u"CKKA 78 #Dz! _ < .- _s8   "	E&/E&E<+A#E<E+AE<+
E9	5E<<
F
c                   U R                  5         U R                  5        nU R                  U5      nUc
   SSS5        gSnU/nU R                  b@  SR	                  S[        U R                  5      -  5      nUSU-   S-   -  nXPR                  -  nUR                  XE5       n[        U5      sSSS5        sSSS5        $ ! , (       d  f       O= f SSS5        g! , (       d  f       g= f)an  Get the list of arcs executed for a file.

If the file was not measured, returns None.  A file might be measured,
and have no arcs executed, in which case an empty list is returned.

If the file was executed, returns a list of 2-tuples of integers. Each
pair is a starting line number and an ending line number for a
transition from one line to another. The list is in no particular
order.

Negative numbers have special meaning.  If the starting line number is
-N, it represents an entry to the code object that starts at line N.
If the ending ling number is -N, it's an exit from the code object that
starts at line N.

Nz7SELECT DISTINCT fromno, tono FROM arc WHERE file_id = ?rX  rY  rZ  rl   )r   r   r   rb   r3  r   r   r   )r%   rn   r   r   r   r   r`  r   s           r)   r   CoverageData.arcs  s    " 	]]_mmH-G _
 Ry**6 $		#D4K4K0L*L MI3i?#EEE333D[[-9 .- _ .-- __s*   C A#C#C.	C
C	C
C*c                R   U R                  5         U R                  5        nU R                  U5      nUc  0 sSSS5        $ [        R                  " [
        5      nU R                  5       (       a  SnU/nU R                  b@  SR                  S[        U R                  5      -  5      nUSU-   S-   -  nX`R                  -  nUR                  XV5       nU H:  u  pnU	S:  a  XI   R                  U5        U
S:  d  M'  XJ   R                  U5        M<     SSS5        OSnU/nU R                  b@  SR                  S[        U R                  5      -  5      nUS	U-   S-   -  nX`R                  -  nUR                  XV5       nU H*  u  p[        U5       H  nXM   R                  U5        M     M,     SSS5        SSS5        WR                  5        VVs0 s H  u  pU[        U5      _M     snn$ ! , (       d  f       NE= f! , (       d  f       NV= f! , (       d  f       N_= fs  snnf )
zGet the contexts for each line in a file.

Returns:
    A dict mapping line numbers to a list of context names.

.. versionadded:: 5.0

Nz
                    SELECT arc.fromno, arc.tono, context.context
                    FROM arc, context
                    WHERE arc.file_id = ? AND arc.context_id = context.id
                rX  rY  z AND arc.context_id IN (rl   r   z
                    SELECT l.numbits, c.context FROM line_bits l, context c
                    WHERE l.context_id = c.id
                    AND file_id = ?
                z AND l.context_id IN ()r   r   r   collectionsdefaultdictrF  r  rb   r3  r   r   r   r   r   r   )r%   rn   r   r   lineno_contexts_mapr   r   r`  r   r   r  r   numbitslinenorJ  s                  r)   contexts_by_linenoCoverageData.contexts_by_lineno$  s    	]]_mmH-G _
 #."9"9#">}}
  y**6 $		#D4K4K0L*L MI7)CcIIE333D[[-14-g!A:/7;;GD!8/599'B	 25 .-
  y**6 $		#D4K4K0L*L MI5	ACGGE333D[[-,/(&5g&>F/7;;GD '? -0 .E N @S?X?X?Z[?Z+;6X&?Z[[- .-" .-E _N \sO   HBH&G0=G0A,H 1H1HH#0
G>	:H
H	H
H c                   [        S[        5       S9 nUR                  S5       nU Vs/ s H  o3S   PM	     nnSSS5        UR                  S5       nU Vs/ s H  o3S   PM	     nnSSS5        [        R                  " SR                  W5      SS	9nSSS5        S
[        R                  4SW4SW4/$ s  snf ! , (       d  f       N= fs  snf ! , (       d  f       Nn= f! , (       d  f       NS= f)zQOur information for `Coverage.sys_info`.

Returns a list of (key, value) pairs.

z:memory:)rg   zPRAGMA temp_storer   NzPRAGMA compile_optionsrX  K   )widthsqlite3_sqlite_versionsqlite3_temp_storesqlite3_compile_options)r   r
   r   textwrapwrapr3  sqlite3sqlite_version)clsr   r   r   
temp_storecoptss         r)   sys_infoCoverageData.sys_infoW  s     j6"/0C034!f
4 145+./3CQ3/ 6MM$))E"2"=E 7 &w'='=>!:.&.
 	
 5 10 0 65 76s[   C!B:B5B:C!CC&C(,C!5B::
C	C!C
C	C!!
C/)rS   r`   ra   rX   r    rW   ru   r_   r^   r]   r#   rO   rZ   rb   rT   rU   )NNFNN)rc   zFilePath | Nonerd   str | bool | Nonere   r   rf   zTWarnFn | Nonerg   zTDebugCtl | Noner-   rC   )rm   r   rn   r   r-   rC   rB   )F)r~   r   r-   rC   )r   r   r-   rC   )r-   r   )r-   r   rE   )r   rD   r-   rC   )rn   r   r   r   r-   
int | None)r   r   r-   r~  )r   
str | Noner-   rC   )r-   r   )r   z!Mapping[str, Collection[TLineNo]]r-   rC   )r   zMapping[str, Collection[TArc]]r-   rC   )FF)r   r   r   r   r-   rC   )r
  zMapping[str, str]r-   rC   )r   )rn   r   r  r   r-   rC   r   )r  Collection[str]r  r  r-   rC   )r  r  r-   rC   )r*  r,   r"  zCallable[[str], str] | Noner-   rC   )r6  r   r-   rC   )r-   zset[str])rn   r   r-   r  )r   r   r-   rC   )rJ  zSequence[str] | Noner-   rC   )rn   r   r-   zlist[TLineNo] | None)rn   r   r-   zlist[TArc] | None)rn   r   r-   zdict[TLineNo, list[str]])r-   zlist[tuple[str, Any]])2r$   rF   rG   rH   rI   r9   r   __repr__ro   rV   rz   ry   r   r   r   r   r   r   r   r   r   r0   r   r   r   r   r   r  r   r  r  r  r  r(  r;  r$  r"   r   r  rG  rK  r	  rQ  rU  r   r   rl  classmethodr{  rJ   rK   r1   r)   r,   r,      s   Rl %)$(#"&-9!-9 "-9 	-9
 -9  -9 
-9^ HP
/("3H`(0@,6,	 ( ( ( (T % %N*  <2C&24 15t t .t 
	tl'('H	$#
$M +*!"F%@1\f 
 
r1   r,   c                h  ^^ U SL a  [         R                  " [        R                  " S5      5      m[        R
                  [        R                  -   mSR                  UU4S j[        S5       5       5      n[        R                  " 5        S[        R                  " 5        SU S3n U $ U S	L a  S
n U $ )zCompute a filename suffix for a data file.

If `suffix` is a string or None, simply return it. If `suffix` is True,
then build a suffix incorporating the hostname, process id, and a random
number.

Returns a string or None.

T   r   c              3  F   >#    U  H  nTR                  T5      v   M     g 7fr   )choice)r   _dieletterss     r)   r   "filename_suffix.<locals>.<genexpr>}  s     >X

7++Xs   !   rr   z.XxFN)randomRandomrP   urandomstringascii_uppercaseascii_lowercaser3  rangesocketgethostnamerY   )rd   rollsr  r  s     @@r)   rv   rv   l  s     ~
 mmBJJqM*((6+A+AA>U1X>>&&()299;-r%B M 
5Mr1   )r(   r   r-   r   )rd   r}  r-   r  )9rI   
__future__r   rg  r   r.   r4  r[  rP   r  r  rv  r  r   rt  r[   rs   r   collections.abcr   r   r   typingr   r   r	   coverage.debugr
   r   r   coverage.exceptionsr   r   coverage.miscr   r   coverage.numbitsr   r   r   coverage.sqlitedbr   coverage.typesr   r   r   r   r   r   coverage.versionr   r   r   r0   r3   r,   rv   rK   r1   r)   <module>r     s     "      	     
     9 9 & & ? ? < 6 L L & S S (B
 <
~ Z
 Z
zr1   