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/lib/python3.10/site-packages/coverage/__pycache__/sqldata.cpython-310.pyc
o

!weE��@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZmZmZmZmZmZmZmZmZmZmZmZmZddlmZm Z ddl!m"Z"m#Z#ddl$m%Z%ddl&m'Z'm(Z(dd	l)m*Z*m+Z+m,Z,dd
l-m.Z.ddl/m0Z0m1Z1m2Z2m3Z3m4Z4ddl5m6Z6e(e�Zd
Z7dZ8ededefd�Z9ddd�Z:Gdd�d�Z;ddd�Z<dS)zSQLite coverage data.�)�annotationsN)
�cast�Any�Callable�
Collection�Dict�List�Mapping�Optional�Sequence�Set�Tuple�TypeVar�Union)�NoDebugging�	auto_repr)�CoverageException�	DataError)�PathAliases)�file_be_gone�isolate_module)�numbits_to_nums�
numbits_union�nums_to_numbits)�SqliteDb)�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)
);
�TMethod.)�bound�method�returncst���d
�fdd��}|S)z4A decorator for methods that should hold self._lock.�self�CoverageData�argsr�kwargsr%cs�|j�d�r|j�d|j�d�j���|j�'|j�d�r,|j�d|j�d�j����|g|�Ri|��Wd�S1sAwYdS)N�lockzLocking z for zLocked  )�_debug�should�write�_lock�__name__)r&r(r)�r$��I/home/arjun/projects/env/lib/python3.10/site-packages/coverage/sqldata.py�_wrappedvs$�z_locked.<locals>._wrappedN)r&r'r(rr)rr%r)�	functools�wraps)r$r3r1r0r2�_lockedtsr6c@s�eZdZdZ					d}d~dd�ZeZddd�Zddd�Zddd�Z	ddd�Z
d�dd�Zd�dd�Zd�d d!�Z
d�d#d$�Zd�d&d'�Zd�d�d,d-�Zd�d/d0�Zed�d2d3��Zdd4d5�Zd�d6d7�Zd�d8d9�Zed�d<d=��Zed�d@dA��Zd�d�dDdE�Zed�dHdI��Zd�d�dLdM�Zd�d�dPdQ�Zd�dRdS�Zd�d�dWdX�Zd�d�dZd[�Zdd\d]�Z dd^d_�Z!dd`da�Z"d�dbdc�Z#d�dedf�Z$d�dgdh�Z%d�didj�Z&d�dkdl�Z'd�dodp�Z(d�drds�Z)d�dudv�Z*d�dxdy�Z+e,d�d{d|��Z-dS)�r'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.

    NF�basename�Optional[FilePath]�suffix�Optional[Union[str, bool]]�no_disk�bool�warn�Optional[TWarnFn]�debug�Optional[TDebugCtl]r%�NonecCs�||_tj�|p	d�|_||_||_|pt�|_|�	�i|_
i|_t��|_
t��|_d|_d|_d|_d|_d|_d|_dS)a�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�_warnrr+�_choose_filename�	_file_map�_dbs�getpid�_pid�	threading�RLockr.�
_have_used�
_has_lines�	_has_arcs�_current_context�_current_context_id�_query_context_ids)r&r7r9r;r=r?r1r1r2�__init__�s 


zCoverageData.__init__cCs@|jrd|_dS|j|_t|j�}|r|jd|7_dSdS)z.Set self._filename based on inited attributes.�:memory:�.N)rB�	_filenamerF�filename_suffixrG)r&r9r1r1r2rIs

�zCoverageData._choose_filenamecCs:|js|j��D]}|��qi|_i|_d|_d|_dS)zReset our attributes.FN)rBrK�values�closerJrPrT)r&�dbr1r1r2�_resets

zCoverageData._resetcCsD|j�d�r|j�d|j���t|j|j�|jt��<|��dS)z0Open an existing db file, and read its metadata.�dataiozOpening data file N)	r+r,r-rYrrKrN�	get_ident�_read_db�r&r1r1r2�_open_dbszCoverageData._open_dbcCsD|jt����}z
|�d�}|dusJ�Wn(ty=}zdt|�vr)|�|�n
td�|j	|��|�WYd}~nd}~ww|d}|t
krPtd�|j	|t
���|�d�}|durgtt|d��|_
|j
|_|�d��}|D]	\}}||j|<qoWd�n1s�wYWd�dSWd�dS1s�wYdS)	zARead the metadata from a database so that we are ready to use it.z#select version from coverage_schemaNzno such table: coverage_schemaz:Data file {!r} doesn't seem to be a coverage data file: {}rz;Couldn't use data file {!r}: wrong schema: {} instead of {}z-select value from meta where key = 'has_arcs'�select id, path from file)rKrNr`�execute_one�	Exception�str�_init_dbr�formatrY�SCHEMA_VERSIONr<�intrRrQ�executerJ)r&r]�row�exc�schema_version�cur�file_idrDr1r1r2ra"sH
������
��

���"�zCoverageData._read_dbr]rcCs�|j�d�r|j�d|j���|�t�|�dtf�dtfg}|j�d�r>|�	dt
ttdd��fd	t
j
���d
�fg�|�d|�dS)z+Write the initial contents of the database.r_zIniting data file z0insert into coverage_schema (version) values (?)�version�process�sys_argv�argvN�whenz%Y-%m-%d %H:%M:%S�5insert or ignore into meta (key, value) values (?, ?))r+r,r-rY�
executescript�SCHEMA�execute_voidrjr �extendrg�getattr�sys�datetime�now�strftime�executemany_void)r&r]�	meta_datar1r1r2rhCs
��zCoverageData._init_dbcCs$t��|jvr|��|jt��S)zGet the SqliteDb object to use.)rNr`rKrcrbr1r1r2�_connectVszCoverageData._connectc	Cs�t��|jvrtj�|j�sdSz<|���-}|�d��}t	t
|��Wd�Wd�WS1s4wYWd�WdS1sEwYWdStyVYdSw)NFzselect * from file limit 1)rNr`rKrCrD�existsrYr�rlr<�listr)r&�conrpr1r1r2�__bool__\s

��&��zCoverageData.__bool__�bytescCsh|j�d�r|j�d|j���|���}|��}dt�|�d��Wd�S1s-wYdS)aSerialize 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

        r_zDumping data from data file �z�utf-8N)	r+r,r-rYr��dump�zlib�compress�encode)r&r��scriptr1r1r2�dumpsfs
$�zCoverageData.dumps�datacCs�|j�d�r|j�d|j���|dd�dkr)td|dd��dt|��d	���t�|dd���d
�}t	|j|j�|j
t��<}|�
|�
|�Wd�n1sUwY|��d|_dS)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

        r_zLoading data into data file N�r�zUnrecognized serialization: �(z
 (head of z bytes)r�T)r+r,r-rYr�lenr��
decompress�decoderrKrNr`rxrarP)r&r�r�r]r1r1r2�loads}s��
zCoverageData.loads�filenamerg�add�
Optional[int]cCsV||jvr%|r%|���}|�d|f�|j|<Wd�n1s wY|j�|�S)z�Get 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)rJr��execute_for_rowid�get)r&r�r�r�r1r1r2�_file_id�s

��zCoverageData._file_id�contextcCsv|dusJ�|��|���#}|�d|f�}|dur(tt|d�Wd�S	Wd�dS1s4wYdS)zGet the id for a context.N�(select id from context where context = ?r)�_start_usingr�rerrk)r&r�r�rmr1r1r2�_context_id�s
�$�zCoverageData._context_id�
Optional[str]cCs.|j�d�r|j�d|���||_d|_dS)z�Set 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

        �dataopzSetting context: N)r+r,r-rSrT)r&r�r1r1r2�set_context�s

zCoverageData.set_contextcCsd|jpd}|�|�}|dur||_dS|���}|�d|f�|_Wd�dS1s+wYdS)z4Use the _current_context to set _current_context_id.�Nz(insert into context (context) values (?))rSr�rTr�r�)r&r��
context_idr�r1r1r2�_set_context_id�s



�"�zCoverageData._set_context_idcC�|jS)zLThe base filename for storing data.

        .. versionadded:: 5.0

        )rFrbr1r1r2�
base_filename��zCoverageData.base_filenamecCr�)zBWhere is the data stored?

        .. versionadded:: 5.0

        )rYrbr1r1r2�
data_filename�r�zCoverageData.data_filename�	line_data�!Mapping[str, Collection[TLineNo]]c

Cs|j�d�r|j�dt|�tdd�|��D��f�|��|jdd�|s)dS|���U}|�	�|�
�D]C\}}t|�}|j|dd�}d	}|�
|||jf��}t|�}	Wd�n1s_wY|	rot||	d
d
�}|�d||j|f�q6Wd�dS1s�wYdS)z�Add 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 totalcss�|]	}tt|��VqdS�N)r<r�)�.0�linesr1r1r2�	<genexpr>�s�z)CoverageData.add_lines.<locals>.<genexpr>T�r�N�r�zBselect numbits from line_bits where file_id = ? and context_id = ?rzQinsert or replace into line_bits  (file_id, context_id, numbits) values (?, ?, ?))r+r,r-r��sumr[r��_choose_lines_or_arcsr�r��itemsrr�rlrTr�rrz)
r&r�r�r��linenos�linemaprq�queryrp�existingr1r1r2�	add_lines�s2	�

�
��"�zCoverageData.add_lines�arc_data�Mapping[str, Collection[TArc]]cs��j�d�r�j�dt|�tdd�|��D��f�����jdd�|s)dS����0}��	�|�
�D]\}}|s=q6�j|dd����fd	d
�|D�}|�d|�q6Wd�dS1s`wYdS)z�Add 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 totalcss�|]}t|�VqdSr�)r�)r��arcsr1r1r2r�
s�z(CoverageData.add_arcs.<locals>.<genexpr>T�r�Nr�csg|]\}}��j||f�qSr1)rT)r��fromno�tono�rqr&r1r2�
<listcomp>sz)CoverageData.add_arcs.<locals>.<listcomp>�Qinsert or ignore into arc (file_id, context_id, fromno, tono) values (?, ?, ?, ?))
r+r,r-r�r�r[r�r�r�r�r�r�r�)r&r�r�r�r�r�r1r�r2�add_arcss*
�
��"�zCoverageData.add_arcsr�r�cCs�|s|sJ�|r|rJ�|r!|jr!|j�d�r|j�d�td��|r6|jr6|j�d�r2|j�d�td��|jse|jsg||_||_|���}|�ddtt	|��f�Wd�dS1s^wYdSdSdS)	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 datarw�has_arcsN)
rRr+r,r-rrQr�rzrgrk)r&r�r�r�r1r1r2r� s(


�"��z"CoverageData._choose_lines_or_arcs�file_tracers�Mapping[str, str]cCs�|j�d�r|j�dt|�f�|sdS|��|���8}|��D]*\}}|j|dd�}|�|�}|rB||krAt	d�
|||���q"|rL|�d||f�q"Wd�dS1sXwYdS)zdAdd per-file plugin information.

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

        r�zAdding file tracers: %d 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_tracerrrirz)r&r�r�r��plugin_namerq�existing_pluginr1r1r2�add_file_tracers5s2

������"�zCoverageData.add_file_tracersr�r�cCs|�|g|�dS)z�Ensure 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&r�r�r1r1r2�
touch_fileRszCoverageData.touch_file�	filenames�Collection[str]cCs�|j�d�r|j�d|���|��|���(|js"|js"td��|D]}|j|dd�|r6|�	||i�q$Wd�dS1sBwYdS)z�Ensure 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�rRrQrr�r�)r&r�r�r�r1r1r2r�Zs
��"�zCoverageData.touch_filescCs�|j�d�r|j�d|���|��|���1}|jrd}n
|jr$d}ntd��|D]}|j|dd�}|dur8q*|�	||f�q*Wd�dS1sKwYdS)	zdPurge any existing coverage data for the given `filenames`.

        .. versionadded:: 7.2

        r�zPurging data for z%delete from line_bits where file_id=?zdelete from arc where file_id=?z*Can't purge files in an empty CoverageDataFr�N)
r+r,r-r�r�rQrRrr�rz)r&r�r��sqlr�rqr1r1r2�purge_filesms 
�"�zCoverageData.purge_files�
other_data�aliases�Optional[PathAliases]c	s�|j�d�r|j�d�t|dd���|jr|jrtd��|jr'|jr'td���p+t��|�	�|�
�|����}|�d��}�fdd	�|D��Wd
�n1sRwY|�d��}dd
�|D�}Wd
�n1snwY|�d��}�fdd
�|D�}Wd
�n1s�wY|�d��'}i}|D]\}}	}
�||	f}||vr�t
|||
�}
|
||<q�Wd
�n1s�wY|�d��}�fdd	�|D�}Wd
�n1s�wYWd
�n1s�wY|����R}|jd
us�J�d|j_|�d��}dd	�|D�}
Wd
�n	1�swY|�d��}|
��fdd	�|D��Wd
�n	1�s=wY|�ddd����D��|�d��}dd	�|D��Wd
�n	1�sgwY|j���|�ddd�|D��|�d��}dd	�|D��Wd
�n	1�s�wYi}���D]%}|
�|�}|�|d�}|d
u�r�||k�r�td �|||���|||<�q���fd!d�|D�}|�d��(}|D]\}}	}
��|�|	f}||v�r�t
|||
�}
|
||<�q�Wd
�n	1�swY|�r|jd"d#�|�d$|�|�r3|jd"d%�|�d&�|�d'��fd(d
�|��D��|�d)�fd*d�|��D��Wd
�n	1�sMwY|j�s`|��|�
�d
Sd
S)+a*Update this data with data from several other :class:`CoverageData` instances.

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

        r�zUpdating with data from {!r}rYz???z%Can't combine arc data with line dataz%Can't combine line data with arc datazselect path from filecsi|]	\}|��|��qSr1��map�r�rD�r�r1r2�
<dictcomp>��z'CoverageData.update.<locals>.<dictcomp>Nzselect context from contextcSsg|]\}|�qSr1r1�r�r�r1r1r2r��sz'CoverageData.update.<locals>.<listcomp>z�select file.path, context.context, arc.fromno, arc.tono from arc inner join file on file.id = arc.file_id inner join context on context.id = arc.context_idcs$g|]\}}}}�||||f�qSr1r1)r�rDr�r�r���filesr1r2r��s
��z�select file.path, context.context, line_bits.numbits from line_bits inner join file on file.id = line_bits.file_id inner join context on context.id = line_bits.context_idzPselect file.path, tracer from tracer inner join file on file.id = tracer.file_idcsi|]	\}}�||�qSr1r1�r�rD�tracerr�r1r2r��r��	IMMEDIATEcSsi|]\}|d�qS�r�r1r�r1r1r2r���csi|]
\}}��|�|�qSr1r�r�r�r1r2r��s
��z,insert or ignore into file (path) values (?)cs��|]}|fVqdSr�r1)r��filer1r1r2r����z&CoverageData.update.<locals>.<genexpr>rdcS�i|]\}}||�qSr1r1)r��idrDr1r1r2r���z2insert or ignore into context (context) values (?)csr�r�r1r�r1r1r2r��r�zselect id, context from contextcSr�r1r1)r�r�r�r1r1r2r��r�r�r�c3s,�|]\}}}}�|�|||fVqdSr�r1)r�r�r�r�r���context_ids�file_idsr1r2r��s
�
�
�Tr�r�r�zdelete from line_bitszEinsert into line_bits (file_id, context_id, numbits) values (?, ?, ?)cs&g|]\\}}}�|�||f�qSr1r1)r�r�r��numbitsr�r1r2r�s
��z<insert or ignore into tracer (file_id, tracer) values (?, ?)c3s �|]\}}�||fVqdSr�r1)r�r�r�)r�r1r2r�&s�)r+r,r-rir|rQrRrrr��readr�rlrr��isolation_level�updater�r[rJr�r�r�rzr�rBr^)r&r�r�r�rp�contextsr�r�rDr�r��key�tracers�this_tracers�
tracer_map�this_tracer�other_tracer�arc_rowsr1)r�r�r�r�r2r��s�

�

���
���
������+��
��
����
����
���
����a�zCoverageData.update�parallelcCs�|��|jr	dS|j�d�r|j�d|j���t|j�|rVtj�	|j�\}}tj�
tj�|�|�}t�
|�d}t�|�D]}|j�d�rQ|j�d|���t|�q@dSdS)z�Erase the data in this object.

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

        Nr_zErasing data file z.*zErasing parallel data file )r^rBr+r,r-rYrrCrD�split�joinrE�glob�escape)r&r��data_dir�local�local_abs_path�patternr�r1r1r2�erase.s 

�zCoverageData.erasecCsFtj�|j�r!|���d|_Wd�dS1swYdSdS)z"Start using an existing data file.TN)rCrDr�rYr�rPrbr1r1r2r�Ds

"��zCoverageData.readcCsdS)z,Ensure the data is written to the data file.Nr1rbr1r1r2r-JszCoverageData.writecCs@|jt��kr|��|��t��|_|js|��d|_dS)z+Call this before using the database at all.TN)rMrCrLr^rIrPrrbr1r1r2r�Ns

zCoverageData._start_usingcC�
t|j�S)z4Does the database have arcs (True) or lines (False).)r<rRrbr1r1r2r�Ys
zCoverageData.has_arcs�Set[str]cCr)z�A 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.

        )�setrJrbr1r1r2�measured_files]s
zCoverageData.measured_filesc	Cs~|��|���-}|�d��}dd�|D�}Wd�n1s wYWd�|SWd�|S1s8wY|S)zWA set of all contexts that have been measured.

        .. versionadded:: 5.0

        z%select distinct(context) from contextcSsh|]}|d�qS�rr1�r�rmr1r1r2�	<setcomp>or�z1CoverageData.measured_contexts.<locals>.<setcomp>N)r�r�rl)r&r�rpr�r1r1r2�measured_contextsfs
�
��
��zCoverageData.measured_contextscCs�|��|���4}|�|�}|dur	Wd�dS|�d|f�}|dur3|dp+dWd�S	Wd�dS1s?wYdS)aGet 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 = ?rr�)r�r�r�re)r&r�r�rqrmr1r1r2r�rs

�
�$�zCoverageData.file_tracerc	Cs�|��|���2}|�d|f��}dd�|��D�|_Wd�n1s%wYWd�dSWd�dS1s=wYdS)adSet 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�cS�g|]}|d�qSrr1r	r1r1r2r��r�z2CoverageData.set_query_context.<locals>.<listcomp>N)r�r�rl�fetchallrU)r&r�r�rpr1r1r2�set_query_context�s
��"�zCoverageData.set_query_contextr��Optional[Sequence[str]]c	Cs�|��|rQ|���=}d�dgt|��}|�d||��}dd�|��D�|_Wd�n1s2wYWd�dSWd�dS1sJwYdSd|_dS)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 zcontext regexp ?zselect id from context where cSrrr1r	r1r1r2r��r�z3CoverageData.set_query_contexts.<locals>.<listcomp>N)r�r�r�r�rlr
rU)r&r�r��context_clauserpr1r1r2�set_query_contexts�s
��"�
zCoverageData.set_query_contexts�Optional[List[TLineNo]]c
	Cs0|��|��r |�|�}|dur tj�|�}tdd�|D��S|���j}|�|�}|dur7	Wd�dSd}|g}|j	durXd�
dt|j	��}|d|d7}||j	7}|�||��}	t|	�}
Wd�n1smwYt
�}|
D]}|�t|d	��qwt|�Wd�S1s�wYdS)
ajGet 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.

        NcSsh|]}|dkr|�qSrr1)r��lr1r1r2r
�sz%CoverageData.lines.<locals>.<setcomp>z/select numbits from line_bits where file_id = ?�, �?� and context_id in (�)r)r�r�r��	itertools�chain�
from_iterabler�r�r�rUr�r�rlrr�r)
r&r�r��	all_linesr�rqr�r��	ids_arrayrp�bitmaps�numsrmr1r1r2r��s2



�


�$�zCoverageData.lines�Optional[List[TArc]]c	Cs�|��|���]}|�|�}|dur	Wd�dSd}|g}|jdur<d�dt|j��}|d|d7}||j7}|�||��}t|�Wd�Wd�S1sXwYWd�dS1shwYdS)a�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 = ?rrrr)r�r�r�rUr�r�rlr�)r&r�r�rqr�r�rrpr1r1r2r��s$

�

��"�zCoverageData.arcs�Dict[TLineNo, List[str]]c	Cs�|��|����}|�|�}|duriWd�St�t�}|��rzd}|g}|jdurEd�dt	|j��}|d|d7}||j7}|�
||��&}|D]\}	}
}|	dkr^||	�|�|
dkri||
�|�qNWd�n1stwYnLd}|g}|jdur�d�dt	|j��}|d	|d7}||j7}|�
||��}|D]\}}t|�D]	}
||
�|�q�q�Wd�n1s�wYWd�n1s�wYd
d�|�
�D�S)z�Get the contexts for each line in a file.

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

        .. versionadded:: 5.0

        Nztselect arc.fromno, arc.tono, context.context from arc, context where arc.file_id = ? and arc.context_id = context.idrrz and arc.context_id in (rrzaselect 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 (cSsi|]	\}}|t|��qSr1)r�)r��linenor�r1r1r2r�r�z3CoverageData.contexts_by_lineno.<locals>.<dictcomp>)r�r�r��collections�defaultdictrr�rUr�r�rlr�rr�)r&r�r�rq�lineno_contexts_mapr�r�rrpr�r�r�r�r!r1r1r2�contexts_by_lineno�sT	

�
�

�����

�����'zCoverageData.contexts_by_lineno�List[Tuple[str, Any]]c	Cs�tdt�d��J}|�d��}dd�|D�}Wd�n1swY|�d��}dd�|D�}Wd�n1s;wYtjd	�|�d
d�}Wd�n1sTwYdtjfd
|fd|fgS)zaOur information for `Coverage.sys_info`.

        Returns a list of (key, value) pairs.

        rW)r?zpragma temp_storecSrrr1r	r1r1r2r�(r�z)CoverageData.sys_info.<locals>.<listcomp>Nzpragma compile_optionscSrrr1r	r1r1r2r�*r�r�K)�width�sqlite3_sqlite_version�sqlite3_temp_store�sqlite3_compile_options)rrrl�textwrap�wrapr��sqlite3�sqlite_version)�clsr]rp�
temp_store�coptsr1r1r2�sys_infos����zCoverageData.sys_info)NNFNN)r7r8r9r:r;r<r=r>r?r@r%rA)r%rA)r]rr%rA)r%r)r%r<)r%r�)r�r�r%rA)F)r�rgr�r<r%r�)r�rgr%r�)r�r�r%rA)r%rg)r�r�r%rA)r�r�r%rA)FF)r�r<r�r<r%rA)r�r�r%rAr�)r�rgr�rgr%rAr�)r�r�r�r�r%rA)r�r�r%rA)r�r'r�r�r%rA)r�r<r%rA)r%r)r�rgr%r�)r�rgr%rA)r�rr%rA)r�rgr%r)r�rgr%r)r�rgr%r )r%r&).r/�
__module__�__qualname__�__doc__rVr�__repr__rIr^rcrarhr�r�r�r�r�r�r6r�r�r�r�r�r�r�r�r�r�r�r�rr�r-r�r�rrr�rrr�r�r%�classmethodr3r1r1r1r2r'�shV�/






!








!
*





	




#
 3r'r9�Union[str, bool, None]�Union[str, None]cCsJ|durt�t�d���dd�}dt��t��|f}|S|dur#d}|S)z�Compute 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�ri?Bz
%s.%s.%06dFN)�random�RandomrC�urandom�randint�socket�gethostnamerL)r9�dicer1r1r2rZ4s
�rZ)r$r"r%r")r9r9r%r:)=r6�
__future__rr"r~r4r�rrCr<r@r.r}r,rNr��typingrrrrrrr	r
rrr
rr�coverage.debugrr�coverage.exceptionsrr�coverage.filesr�
coverage.miscrr�coverage.numbitsrrr�coverage.sqlitedbr�coverage.typesrrrrr�coverage.versionr rjryr"r6r'rZr1r1r1r2�<module>sL<>

: