Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
B

ü¡?ã6oÁã@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZmZmZddlmZmZddlmZddlmZmZmZddlmZmZmZddlm Z eeƒZd	Z!d
Z"Gdd„deƒZ#d
d„Z$Gdd„deƒZ%dd„Z&dS)zSqlite coverage data.éN)ÚNoDebuggingÚSimpleReprMixinÚclipped_repr)ÚCoverageExceptionÚ	DataError)ÚPathAliases)ÚcontractÚfile_be_goneÚisolate_module)Únumbits_to_numsÚ
numbits_unionÚnums_to_numbits)Ú__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)
    -- 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@sveZdZdZdTdd„Zdd„Zdd	„Zd
d„Zdd
„Zdd„Z	dd„Z
dd„Zdd„Ze
dddd„ƒZe
dddd„ƒZdUdd„Zdd „Zed!d"„ƒZd#d$„Zd%d&„Zd'd(„Zed)d*„ƒZed+d,„ƒZdVd-d.„Zed/d0„ƒZdWd2d3„ZdXd4d5„ZdYd6d7„ZdZd8d9„Zd:d;„Zd<d=„Zd>d?„Z d@dA„Z!dBdC„Z"dDdE„Z#dFdG„Z$dHdI„Z%dJdK„Z&dLdM„Z'dNdO„Z(dPdQ„Z)e*dRdS„ƒZ+dS)[ÚCoverageDataa%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`.  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.

    NFcCs€||_tj |pd¡|_||_||_|p,tƒ|_| 	¡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Ú_warnrÚ_debugÚ_choose_filenameÚ	_file_mapÚ_dbsÚgetpidÚ_pidÚ	threadingÚLockÚ_lockÚ
_have_usedÚ
_has_linesÚ	_has_arcsÚ_current_contextÚ_current_context_idÚ_query_context_ids)ÚselfÚbasenameÚsuffixZno_diskÚwarnÚdebug©r,ú/build/wlanpi-profiler-7IIg1Q/wlanpi-profiler-1.0.11/debian/wlanpi-profiler/opt/wlanpi-profiler/lib/python3.7/site-packages/coverage/sqldata.pyÚ__init__¿s 

zCoverageData.__init__cst ˆ¡‡fdd„ƒ}|S)z4A decorator for methods that should hold self._lock.c	s"|jˆ|f|ž|ŽSQRXdS)N)r )r'ÚargsÚkwargs)Úmethodr,r-Ú_wrappedèsz&CoverageData._locked.<locals>._wrapped)Ú	functoolsÚwraps)r1r2r,)r1r-Ú_lockedæszCoverageData._lockedcCs:|jrd|_n(|j|_t|jƒ}|r6|jd|7_dS)z.Set self._filename based on inited attributes.z:memory:Ú.N)rÚ	_filenamerÚfilename_suffixr)r'r)r,r,r-rïs
zCoverageData._choose_filenamecCs>|jr"x|j ¡D]}| ¡qWi|_i|_d|_d|_dS)zReset our attributes.FN)rÚvaluesÚcloserr!r%)r'Údbr,r,r-Ú_resetùszCoverageData._resetc
Csž|j d¡r |j d|j›¡t|j|jƒ|jt ¡<}|T| t	¡| 
dtf¡| ddt
ttddƒƒfdtfd	tj ¡ d
¡fg¡WdQRXdS)zgCreate a db file that doesn't exist yet.

        Initializes the schema and certain metadata.
        ÚdataiozCreating data file z0insert into coverage_schema (version) values (?)z+insert into meta (key, value) values (?, ?)Zsys_argvÚargvNÚversionÚwhenz%Y-%m-%d %H:%M:%S)rÚshouldÚwriter7ÚSqliteDbrrÚ	get_identÚ
executescriptÚSCHEMAÚexecuteÚSCHEMA_VERSIONÚexecutemanyÚstrÚgetattrÚsysrÚdatetimeÚnowÚstrftime)r'r;r,r,r-Ú
_create_dbs
zCoverageData._create_dbcCsD|j d¡r |j d|j›¡t|j|jƒ|jt ¡<| ¡dS)z0Open an existing db file, and read its metadata.r=zOpening data file N)	rrArBr7rCrrrDÚ_read_db)r'r,r,r-Ú_open_dbszCoverageData._open_dbcCsÔ|jt ¡¼}y| d¡\}Wn6tk
rV}ztd |j|¡ƒ|‚Wdd}~XYnX|tkrttd |j|t¡ƒ‚x.| 	d¡D] }t
t|dƒƒ|_|j|_
q€Wx | 	d¡D]\}}||j|<q°WWdQRXdS)zARead the metadata from a database so that we are ready to use it.z#select version from coverage_schemaz:Data file {!r} doesn't seem to be a coverage data file: {}Nz;Couldn't use data file {!r}: wrong schema: {} instead of {}z-select value from meta where key = 'has_arcs'rzselect path, id from file)rrrDÚexecute_oneÚ	ExceptionrÚformatr7rHrGÚboolÚintr#r"r)r'r;Zschema_versionÚexcÚrowrÚfile_idr,r,r-rQs"
zCoverageData._read_dbcCs<t ¡|jkr.tj |j¡r&| ¡n| ¡|jt ¡S)zGet the SqliteDb object to use.)	rrDrrrÚexistsr7rRrP)r'r,r,r-Ú_connect8s

zCoverageData._connectc	Csdt ¡|jkr tj |j¡s dSy*| ¡}| d¡}t	t
|ƒƒSQRXWntk
r^dSXdS)NFzselect * from file limit 1)rrDrrrr[r7r\rGrVÚlistr)r'ÚconÚrowsr,r,r-Ú__bool__As

zCoverageData.__bool__Úbytes)Zreturnsc	CsL|j d¡r |j d|j›¡| ¡}dt | ¡ d¡¡SQRXdS)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 ózzutf-8N)	rrArBr7r\ÚzlibÚcompressÚdumpÚencode)r'r^r,r,r-ÚdumpsKs
zCoverageData.dumps)Údatac	Cs²|j d¡r |j d|j›¡|dd…dkrRtd|dd…›dt|ƒ›d	ƒ‚t |dd…¡ d
¡}t	|j|jƒ|j
t ¡<}|| 
|¡WdQRX| ¡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érbzUnrecognized serialization: é(z
 (head of z bytes)zutf-8T)rrArBr7rÚlenrcÚ
decompressÚdecoderCrrrDrErQr!)r'rhÚscriptr;r,r,r-Úloadsbs zCoverageData.loadsc	CsH||jkr<|r<| ¡ }| d|f¡}|j|j|<WdQRX|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)rr\rGÚ	lastrowidÚget)r'ÚfilenameÚaddr^Úcurr,r,r-Ú_file_ids

zCoverageData._file_idc	CsN|dk	st‚| ¡| ¡(}| d|f¡}|dk	r<|dSdSWdQRXdS)zGet the id for a context.Nz(select id from context where context = ?r)ÚAssertionErrorÚ_start_usingr\rS)r'Úcontextr^rYr,r,r-Ú_context_idŒs
zCoverageData._context_idcCs.|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)rrArBr$r%)r'rxr,r,r-Úset_context—s
zCoverageData.set_contextc	CsR|jpd}| |¡}|dk	r$||_n*| ¡}| d|f¡}|j|_WdQRXdS)z4Use the _current_context to set _current_context_id.ÚNz(insert into context (context) values (?))r$ryr%r\rGrp)r'rxZ
context_idr^rtr,r,r-Ú_set_context_id¦s


zCoverageData._set_context_idcCs|jS)zLThe base filename for storing data.

        .. versionadded:: 5.0

        )r)r'r,r,r-Ú
base_filename±szCoverageData.base_filenamecCs|jS)zBWhere is the data stored?

        .. versionadded:: 5.0

        )r7)r'r,r,r-Ú
data_filename¹szCoverageData.data_filenamec		Csâ|j d¡r6|j dt|ƒtdd„| ¡Dƒƒf¡| ¡|jdd|sRdS| ¡~}| 	¡xn| 
¡D]b\}}t|ƒ}|j|dd}d	}t
| |||jf¡ƒ}|r¼t||d
d
ƒ}| d||j|f¡qnWWdQRXdS)z¥Add measured line data.

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

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

        rzz&Adding lines: %d files, %d lines totalcss|]}t|ƒVqdS)N)rk)Ú.0Úlinesr,r,r-ú	<genexpr>Ìsz)CoverageData.add_lines.<locals>.<genexpr>T)rN)rszBselect numbits from line_bits where file_id = ? and context_id = ?rzQinsert or replace into line_bits  (file_id, context_id, numbits) values (?, ?, ?))rrArBrkÚsumr9rwÚ_choose_lines_or_arcsr\r}Úitemsr
rur]rGr%r)	r'Z	line_datar^rrZlinenosZlinemaprZÚqueryÚexistingr,r,r-Ú	add_linesÁs&	"
zCoverageData.add_linesc	s¶ˆj d¡r6ˆj dt|ƒtdd„| ¡Dƒƒf¡ˆ ¡ˆjdd|sRdSˆ ¡R}ˆ 	¡xB| 
¡D]6\}}ˆj|dd‰‡‡fd	d
„|Dƒ}| d|¡qnWWdQRXdS)z¸Add measured arc data.

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

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

        rzz$Adding arcs: %d files, %d arcs totalcss|]}t|ƒVqdS)N)rk)r€Úarcsr,r,r-r‚îsz(CoverageData.add_arcs.<locals>.<genexpr>T)r‰N)rscsg|]\}}ˆˆj||f‘qSr,)r%)r€ÚfromnoÚtono)rZr'r,r-ú
<listcomp>øsz)CoverageData.add_arcs.<locals>.<listcomp>zQinsert or ignore into arc (file_id, context_id, fromno, tono) values (?, ?, ?, ?))
rrArBrkrƒr9rwr„r\r}r…rurI)r'Zarc_datar^rrr‰rhr,)rZr'r-Úadd_arcsâs
"
zCoverageData.add_arcsc	Cs„|s|st‚|r|rt‚|r*|jr*tdƒ‚|r<|jr<tdƒ‚|js€|js€||_||_| ¡}| ddtt|ƒƒf¡WdQRXdS)z5Force the data file to choose between lines and arcs.z3Can't add line measurements to existing branch dataz3Can't add branch measurements to existing line dataz+insert into meta (key, value) values (?, ?)Úhas_arcsN)rvr#rr"r\rGrJrW)r'rr‰r^r,r,r-r„ÿs


z"CoverageData._choose_lines_or_arcsc	CsÀ|j d¡r"|j dt|ƒf¡|s*dS| ¡| ¡|}xt| ¡D]h\}}| |¡}|dkrptd|›dƒ‚| 	|¡}|rš||kr®td 
|||¡ƒ‚qF|rF| d||f¡qFWWdQRXdS)zdAdd per-file plugin information.

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

        rzzAdding file tracers: %d filesNz0Can't add file tracer data for unmeasured file 'ú'z3Conflicting file tracer name for '{}': {!r} vs {!r}z2insert into tracer (file_id, tracer) values (?, ?))rrArBrkrwr\r…rurÚfile_tracerrUrG)r'Zfile_tracersr^rrÚplugin_namerZZexisting_pluginr,r,r-Úadd_file_tracerss*


zCoverageData.add_file_tracersr|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'rrr‘r,r,r-Ú
touch_file2szCoverageData.touch_filec	Cs€|j d¡r|j d|›¡| ¡| ¡H|jsD|jsDtdƒ‚x,|D]$}|j|dd|rJ| 	||i¡qJWWdQRXdS)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.
        rzz	Touching z*Can't touch files in an empty CoverageDataT)rsN)
rrArBrwr\r#r"rrur’)r'Ú	filenamesr‘rrr,r,r-r“:s

zCoverageData.touch_filesc	s&|j d¡r&|j d t|ddƒ¡¡|jr:|jr:tdƒ‚|jrN|jrNtdƒ‚ˆpVtƒ‰| 	¡| 
¡| ¡¶}| d¡}‡fdd	„|Dƒ‰| 
¡| d
¡}dd„|Dƒ}| 
¡| d
¡}‡fdd„|Dƒ}| 
¡| d¡}‡fdd	„|Dƒ}| 
¡| d¡}‡fdd	„|Dƒ}| 
¡WdQRX| ¡Ö}d|j_dd	„| d¡Dƒ}	|	 ‡fdd	„| d¡Dƒ¡| ddd„ˆ ¡Dƒ¡dd	„| d¡Dƒ‰| ddd„|Dƒ¡dd	„| d¡Dƒ‰i}
xVˆ ¡D]J}|	 |¡}| |d ¡}
|dk	r||
krtd! |||
¡ƒ‚|
|
|<qØW‡‡fd"d„|Dƒ}| d¡}xB|D]:\}}}ˆ |¡|f}||krzt|||ƒ}|||<qJW| 
¡|r®|jd#d$| d%|¡|rê|jd#d&| d'¡| d(‡‡fd)d„| ¡Dƒ¡| d*‡fd+d„|
 ¡Dƒ¡WdQRX| ¡| 
¡dS),zÙ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.
        rzzUpdating with data from {!r}r7z???z%Can't combine arc data with line dataz%Can't combine line data with arc datazselect path from filecsi|]\}ˆ |¡|“qSr,)Úmap)r€r)Úaliasesr,r-ú
<dictcomp>gsz'CoverageData.update.<locals>.<dictcomp>zselect context from contextcSsg|]
\}|‘qSr,r,)r€rxr,r,r-rŒlsz'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‘qSr,r,)r€rrxrŠr‹)Úfilesr,r-rŒvszª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_idcs i|]\}}}|ˆ||f“qSr,r,)r€rrxÚnumbits)r™r,r-r˜€szPselect file.path, tracer from tracer inner join file on file.id = tracer.file_idcsi|]\}}|ˆ|“qSr,r,)r€rÚtracer)r™r,r-r˜‰sNZ	IMMEDIATEcSsi|]\}d|“qS)r|r,)r€rr,r,r-r˜“scsi|]\}}|ˆ |¡“qSr,)r–)r€rr›)r—r,r-r˜”sz,insert or ignore into file (path) values (?)css|]}|fVqdS)Nr,)r€Úfiler,r,r-r‚Ÿsz&CoverageData.update.<locals>.<genexpr>cSsi|]\}}||“qSr,r,)r€Úidrr,r,r-r˜¡szselect id, path from filez2insert or ignore into context (context) values (?)css|]}|fVqdS)Nr,)r€rxr,r,r-r‚§scSsi|]\}}||“qSr,r,)r€rrxr,r,r-r˜©szselect id, context from contextr|z3Conflicting file tracer name for '{}': {!r} vs {!r}c3s*|]"\}}}}ˆ|ˆ|||fVqdS)Nr,)r€rœrxrŠr‹)Úcontext_idsÚfile_idsr,r-r‚ÂsT)r‰zQinsert or ignore into arc (file_id, context_id, fromno, tono) values (?, ?, ?, ?))rzdelete from line_bitszEinsert into line_bits (file_id, context_id, numbits) values (?, ?, ?)cs&g|]\\}}}ˆ|ˆ||f‘qSr,r,)r€rœrxrš)ržrŸr,r-rŒåsz<insert or ignore into tracer (file_id, tracer) values (?, ?)c3s|]\}}ˆ||fVqdS)Nr,)r€rrr›)rŸr,r-r‚ës)rrArBrUrKr"r#rrrwÚreadr\rGr:r^Zisolation_levelÚupdaterIr9rqr–rr„r…r<)r'Z
other_datar—ÚconnrtÚcontextsr‰rZtracersZthis_tracersZ
tracer_maprZthis_tracerZother_tracerZarc_rowsrxršÚkeyr,)r—ržrŸr™r-r¡Ms¢







"zCoverageData.updatecCs®| ¡|jrdS|j d¡r2|j d|j›¡t|jƒ|rªtj 	|j¡\}}|d}tj 
tj |¡|¡}x8t |¡D]*}|j d¡rž|j d|›¡t|ƒq|WdS)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<rrrArBr7r	rrÚsplitÚjoinrÚglob)r'ÚparallelÚdata_dirÚlocalZlocaldotÚpatternrrr,r,r-Úeraseòs
zCoverageData.erasec	Cs| ¡d|_WdQRXdS)z"Start using an existing data file.TN)r\r!)r'r,r,r-r s
zCoverageData.readcCsdS)z,Ensure the data is written to the data file.Nr,)r'r,r,r-rB
szCoverageData.writecCs@|jt ¡kr(| ¡| ¡t ¡|_|js6| ¡d|_dS)z+Call this before using the database at all.TN)rrrr<rr!r¬)r'r,r,r-rws
zCoverageData._start_usingcCs
t|jƒS)z4Does the database have arcs (True) or lines (False).)rVr#)r'r,r,r-rŽszCoverageData.has_arcscCs
t|jƒS)z*A set of all files that had been measured.)Úsetr)r'r,r,r-Úmeasured_files szCoverageData.measured_filesc	Cs4| ¡| ¡}dd„| d¡Dƒ}WdQRX|S)zWA set of all contexts that have been measured.

        .. versionadded:: 5.0

        cSsh|]}|d’qS)rr,)r€rYr,r,r-ú	<setcomp>,sz1CoverageData.measured_contexts.<locals>.<setcomp>z%select distinct(context) from contextN)rwr\rG)r'r^r£r,r,r-Úmeasured_contexts$s
zCoverageData.measured_contextsc	CsX| ¡| ¡>}| |¡}|dkr(dS| d|f¡}|dk	rJ|dpHdSdSQRXdS)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|)rwr\rurS)r'rrr^rZrYr,r,r-r/s

zCoverageData.file_tracerc	CsB| ¡| ¡(}| d|f¡}dd„| ¡Dƒ|_WdQRXdS)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

        z(select id from context where context = ?cSsg|]}|d‘qS)rr,)r€rYr,r,r-rŒOsz2CoverageData.set_query_context.<locals>.<listcomp>N)rwr\rGÚfetchallr&)r'rxr^rtr,r,r-Úset_query_contextAs
zCoverageData.set_query_contextc	Csd| ¡|rZ| ¡>}d dgt|ƒ¡}| d||¡}dd„| ¡Dƒ|_WdQRXnd|_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 cSsg|]}|d‘qS)rr,)r€rYr,r,r-rŒbsz3CoverageData.set_query_contexts.<locals>.<listcomp>N)rwr\r¦rkrGr±r&)r'r£r^Zcontext_clausertr,r,r-Úset_query_contextsQs
 zCoverageData.set_query_contextsc	Csî| ¡| ¡r@| |¡}|dk	r@tj |¡}tdd„|DƒƒS| ¡œ}| |¡}|dkr`dSd}|g}|j	dk	r¢d 
dt|j	ƒ¡}|d|d7}||j	7}t| ||¡ƒ}	t
ƒ}
x|	D]}|
 t|d	ƒ¡q¾Wt|
ƒSWdQRXdS)
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|’qS)rr,)r€Úlr,r,r-r¯usz%CoverageData.lines.<locals>.<setcomp>z/select numbits from line_bits where file_id = ?z, ú?z and context_id in (ú)r)rwrŽr‰Ú	itertoolsÚchainÚ
from_iterabler]r\rur&r¦rkrGr­r¡r)r'rrr‰Z	all_linesr^rZr†rhÚ	ids_arrayZbitmapsÚnumsrYr,r,r-rfs*






zCoverageData.linesc	CsŒ| ¡| ¡r}| |¡}|dkr(dSd}|g}|jdk	rjd dt|jƒ¡}|d|d7}||j7}| ||¡}t|ƒSWdQRXdS)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 = ?z, rµz and context_id in (r¶)rwr\rur&r¦rkrGr])r'rrr^rZr†rhrºr‰r,r,r-r‰ˆs



zCoverageData.arcsc
	Csf| ¡| ¡<}| |¡}|dkr*iSt t¡}| ¡rÈd}|g}|jdk	r~d dt	|jƒ¡}|d|d7}||j7}xÊ| 
||¡D]6\}}	}
|dkr¬|| |
¡|	dkrŒ||	 |
¡qŒWn‚d}|g}|jdk	rd dt	|jƒ¡}|d	|d7}||j7}x<| 
||¡D],\}}
x t|ƒD]}|| |
¡q,WqWWdQRXd
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.idz, rµz and arc.context_id in (r¶rzaselect 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|ƒ|“qSr,)r])r€Úlinenor£r,r,r-r˜×sz3CoverageData.contexts_by_lineno.<locals>.<dictcomp>)rwr\ruÚcollectionsÚdefaultdictr­rŽr&r¦rkrGrsrr…)
r'rrr^rZZlineno_contexts_mapr†rhrºrŠr‹rxršr¼r,r,r-Úcontexts_by_lineno¨s8	




$zCoverageData.contexts_by_linenoc	s€tdtƒdL}dd„| d¡Dƒ}dd„| d¡Dƒ‰‡fdd„td	tˆƒd
ƒDƒ‰WdQRXdtjfd
tjfd|fdˆfgS)zaOur information for `Coverage.sys_info`.

        Returns a list of (key, value) pairs.

        z:memory:)r+cSsg|]}|d‘qS)rr,)r€rYr,r,r-rŒász)CoverageData.sys_info.<locals>.<listcomp>zpragma temp_storecSsg|]}|d‘qS)rr,)r€rYr,r,r-rŒâszpragma compile_optionscs"g|]}d ˆ||d…¡‘qS)z; é)r¦)r€Úi)Úcoptsr,r-rŒåsrrÀNZsqlite3_versionZsqlite3_sqlite_versionZsqlite3_temp_storeZsqlite3_compile_options)rCrrGÚrangerkÚsqlite3r?Zsqlite_version)Úclsr;Z
temp_storer,)rÂr-Úsys_infoÙs(zCoverageData.sys_info)NNFNN)F)FF)r|)r|)N)F),Ú__name__Ú
__module__Ú__qualname__Ú__doc__r.r5rr<rPrRrQr\r`rrgroruryr{r}r~rrˆrr„r’r”r“r¡r¬r rBrwrŽr®r°rr²r³rr‰r¿ÚclassmethodrÆr,r,r,r-rlsPQ
'	

	


!
"


&
" 1rcCs:|dkr6t t d¡¡ dd¡}dt ¡t ¡|f}|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.%06d)ÚrandomÚRandomrÚurandomÚrandintÚsocketÚgethostnamer)r)Zdicer,r,r-r8ïs
r8c@sdeZdZdZdd„Zdd„Zdd„Zdd	„Zd
d„Zdd
d„Z	ddd„Z
dd„Zdd„Zdd„Z
dS)rCa(A simple abstraction over a SQLite database.

    Use as a context manager, then you can use it like a
    :class:`python:sqlite3.Connection` object::

        with SqliteDb(filename, debug_control) as db:
            db.execute("insert into schema (version) values (?)", (SCHEMA_VERSION,))

    cCs*| d¡r|nd|_||_d|_d|_dS)NÚsqlr)rAr+rrÚnestr^)r'rrr+r,r,r-r.
szSqliteDb.__init__c
Cs¬|jdk	rdS|jr(|j d|j›¡ytj|jdd|_Wn<tjk
rz}ztd|j›d|›ƒ|‚Wdd}~XYnX|j ddt	¡| 
d	¡ ¡| 
d
¡ ¡dS)z2Connect to the db and do universal initialization.NzConnecting to F)Zcheck_same_threadzCouldn't use data file z: ÚREGEXPézpragma journal_mode=offzpragma synchronous=off)r^r+rBrrrÄÚconnectÚErrorrZcreate_functionÚ_regexprGr:)r'rXr,r,r-r\s
*zSqliteDb._connectcCs(|jdk	r$|jdkr$|j ¡d|_dS)z If needed, close the connection.Nz:memory:)r^rrr:)r'r,r,r-r:-s
zSqliteDb.closecCs.|jdkr| ¡|j ¡|jd7_|S)Nrri)rÔr\r^Ú	__enter__)r'r,r,r-rÚ3s


zSqliteDb.__enter__c
CsŒ|jd8_|jdkrˆy|j |||¡| ¡WnRtk
r†}z4|jr^|j d|›¡td|j›d|›ƒ|‚Wdd}~XYnXdS)NrirzEXCEPTION from __exit__: zCouldn't end data file z: )	rÔr^Ú__exit__r:rTr+rBrrr)r'Úexc_typeÚ	exc_valueÚ	tracebackrXr,r,r-rÛ:s
zSqliteDb.__exit__r,cCs|jr.|rd|›nd}|j d|›|›¡y2y|j ||¡Stk
r\|j ||¡SXWnªtjk
r
}zˆt|ƒ}y6t|j	dƒ }d}| 
t|ƒ¡|kr¨d}WdQRXWntk
rÈYnX|jrâ|j d|›¡td	|j	›d
|›ƒ|‚Wdd}~XYnXdS)z2Same as :meth:`python:sqlite3.Connection.execute`.z with r|z
Executing Úrbs&!coverage.py: This is a private formatzILooks like a coverage 4.x data file. Are you mixing versions of coverage?NzEXCEPTION from execute: zCouldn't use data file z: )
r+rBr^rGrTrÄrØrJÚopenrrr rkr)r'rÓÚ
parametersÚtailrXÚmsgZbad_fileZcov4_sigr,r,r-rGEs(zSqliteDb.executecCsRt| ||¡ƒ}t|ƒdkr dSt|ƒdkr4|dStd|›dt|ƒ›dƒ‚dS)a6Execute a statement and return the one row that results.

        This is like execute(sql, parameters).fetchone(), except it is
        correct in reading the entire result set.  This will raise an
        exception if more than one row results.

        Returns a row, or None if there were no rows.
        rNrizSQL z shouldn't return z rows)r]rGrkrv)r'rÓrár_r,r,r-rSds	zSqliteDb.execute_onecCs^|jr,t|ƒ}|j d|›dt|ƒ›d¡y|j ||¡Stk
rX|j ||¡SXdS)z6Same as :meth:`python:sqlite3.Connection.executemany`.zExecuting many z with z rowsN)r+r]rBrkr^rIrT)r'rÓrhr,r,r-rIuszSqliteDb.executemanycCs4|jr$|j d t|ƒt|dƒ¡¡|j |¡dS)z8Same as :meth:`python:sqlite3.Connection.executescript`.z"Executing script with {} chars: {}édN)r+rBrUrkrr^rE)r'rnr,r,r-rE‚s
zSqliteDb.executescriptcCsd |j ¡¡S)z9Return a multi-line string, the SQL dump of the database.Ú
)r¦r^Ziterdump)r'r,r,r-reŠsz
SqliteDb.dumpN)r,)r,)rÇrÈrÉrÊr.r\r:rÚrÛrGrSrIrErer,r,r,r-rCs	


rCcCst ||¡dk	S)zA regexp function for SQLite.N)ÚreÚsearch)Útextr«r,r,r-rُsrÙ)'rÊr½rMr3r§r·rrÍrærÑrÄrLrrcZcoverage.debugrrrZcoverage.exceptionsrrZcoverage.filesrZ
coverage.miscrr	r
Zcoverage.numbitsrrr
Zcoverage.versionrrHrFrr8rCrÙr,r,r,r-Ú<module>sDG