$93 GRAYBYTE WORDPRESS FILE MANAGER $93

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/cloudlinux/venv/lib/python3.11/site-packages/coverage/

HOME
Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/coverage//numbits.py
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt

"""
Functions to manipulate packed binary representations of number sets.

To save space, coverage stores sets of line numbers in SQLite using a packed
binary representation called a numbits.  A numbits is a set of positive
integers.

A numbits is stored as a blob in the database.  The exact meaning of the bytes
in the blobs should be considered an implementation detail that might change in
the future.  Use these functions to work with those binary blobs of data.

"""

from __future__ import annotations

import json
import sqlite3

from itertools import zip_longest
from typing import Iterable, List


def nums_to_numbits(nums: Iterable[int]) -> bytes:
    """Convert `nums` into a numbits.

    Arguments:
        nums: a reusable iterable of integers, the line numbers to store.

    Returns:
        A binary blob.
    """
    try:
        nbytes = max(nums) // 8 + 1
    except ValueError:
        # nums was empty.
        return b""
    b = bytearray(nbytes)
    for num in nums:
        b[num//8] |= 1 << num % 8
    return bytes(b)


def numbits_to_nums(numbits: bytes) -> List[int]:
    """Convert a numbits into a list of numbers.

    Arguments:
        numbits: a binary blob, the packed number set.

    Returns:
        A list of ints.

    When registered as a SQLite function by :func:`register_sqlite_functions`,
    this returns a string, a JSON-encoded list of ints.

    """
    nums = []
    for byte_i, byte in enumerate(numbits):
        for bit_i in range(8):
            if (byte & (1 << bit_i)):
                nums.append(byte_i * 8 + bit_i)
    return nums


def numbits_union(numbits1: bytes, numbits2: bytes) -> bytes:
    """Compute the union of two numbits.

    Returns:
        A new numbits, the union of `numbits1` and `numbits2`.
    """
    byte_pairs = zip_longest(numbits1, numbits2, fillvalue=0)
    return bytes(b1 | b2 for b1, b2 in byte_pairs)


def numbits_intersection(numbits1: bytes, numbits2: bytes) -> bytes:
    """Compute the intersection of two numbits.

    Returns:
        A new numbits, the intersection `numbits1` and `numbits2`.
    """
    byte_pairs = zip_longest(numbits1, numbits2, fillvalue=0)
    intersection_bytes = bytes(b1 & b2 for b1, b2 in byte_pairs)
    return intersection_bytes.rstrip(b"\0")


def numbits_any_intersection(numbits1: bytes, numbits2: bytes) -> bool:
    """Is there any number that appears in both numbits?

    Determine whether two number sets have a non-empty intersection. This is
    faster than computing the intersection.

    Returns:
        A bool, True if there is any number in both `numbits1` and `numbits2`.
    """
    byte_pairs = zip_longest(numbits1, numbits2, fillvalue=0)
    return any(b1 & b2 for b1, b2 in byte_pairs)


def num_in_numbits(num: int, numbits: bytes) -> bool:
    """Does the integer `num` appear in `numbits`?

    Returns:
        A bool, True if `num` is a member of `numbits`.
    """
    nbyte, nbit = divmod(num, 8)
    if nbyte >= len(numbits):
        return False
    return bool(numbits[nbyte] & (1 << nbit))


def register_sqlite_functions(connection: sqlite3.Connection) -> None:
    """
    Define numbits functions in a SQLite connection.

    This defines these functions for use in SQLite statements:

    * :func:`numbits_union`
    * :func:`numbits_intersection`
    * :func:`numbits_any_intersection`
    * :func:`num_in_numbits`
    * :func:`numbits_to_nums`

    `connection` is a :class:`sqlite3.Connection <python:sqlite3.Connection>`
    object.  After creating the connection, pass it to this function to
    register the numbits functions.  Then you can use numbits functions in your
    queries::

        import sqlite3
        from coverage.numbits import register_sqlite_functions

        conn = sqlite3.connect("example.db")
        register_sqlite_functions(conn)
        c = conn.cursor()
        # Kind of a nonsense query:
        # Find all the files and contexts that executed line 47 in any file:
        c.execute(
            "select file_id, context_id from line_bits where num_in_numbits(?, numbits)",
            (47,)
        )
    """
    connection.create_function("numbits_union", 2, numbits_union)
    connection.create_function("numbits_intersection", 2, numbits_intersection)
    connection.create_function("numbits_any_intersection", 2, numbits_any_intersection)
    connection.create_function("num_in_numbits", 2, num_in_numbits)
    connection.create_function("numbits_to_nums", 1, lambda b: json.dumps(numbits_to_nums(b)))

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
17 Dec 2025 3.08 AM
root / root
0755
__pycache__
--
14 Aug 2025 9.24 PM
root / root
0755
fullcoverage
--
14 Aug 2025 9.24 PM
root / root
0755
htmlfiles
--
14 Aug 2025 9.24 PM
root / root
0755
__init__.py
1.254 KB
17 Apr 2025 8.10 PM
root / root
0644
__main__.py
0.251 KB
17 Apr 2025 8.10 PM
root / root
0644
annotate.py
3.67 KB
17 Apr 2025 8.10 PM
root / root
0644
bytecode.py
0.696 KB
17 Apr 2025 8.10 PM
root / root
0644
cmdline.py
33.62 KB
17 Apr 2025 8.10 PM
root / root
0644
collector.py
20.076 KB
17 Apr 2025 8.10 PM
root / root
0644
config.py
21.474 KB
17 Apr 2025 8.10 PM
root / root
0644
context.py
2.425 KB
17 Apr 2025 8.10 PM
root / root
0644
control.py
50.493 KB
17 Apr 2025 8.10 PM
root / root
0644
data.py
7.332 KB
17 Apr 2025 8.10 PM
root / root
0644
debug.py
17.388 KB
17 Apr 2025 8.10 PM
root / root
0644
disposition.py
1.871 KB
17 Apr 2025 8.10 PM
root / root
0644
env.py
5.938 KB
17 Apr 2025 8.10 PM
root / root
0644
exceptions.py
1.33 KB
17 Apr 2025 8.10 PM
root / root
0644
execfile.py
11.849 KB
17 Apr 2025 8.10 PM
root / root
0644
files.py
18.92 KB
17 Apr 2025 8.10 PM
root / root
0644
html.py
22.622 KB
17 Apr 2025 8.10 PM
root / root
0644
inorout.py
23.34 KB
17 Apr 2025 8.10 PM
root / root
0644
jsonreport.py
4.643 KB
17 Apr 2025 8.10 PM
root / root
0644
lcovreport.py
4.823 KB
17 Apr 2025 8.10 PM
root / root
0644
misc.py
11.887 KB
17 Apr 2025 8.10 PM
root / root
0644
multiproc.py
3.756 KB
17 Apr 2025 8.10 PM
root / root
0644
numbits.py
4.56 KB
17 Apr 2025 8.10 PM
root / root
0644
parser.py
55.391 KB
17 Apr 2025 8.10 PM
root / root
0644
phystokens.py
7.622 KB
17 Apr 2025 8.10 PM
root / root
0644
plugin.py
19.067 KB
17 Apr 2025 8.10 PM
root / root
0644
plugin_support.py
10.108 KB
17 Apr 2025 8.10 PM
root / root
0644
py.typed
0.07 KB
17 Apr 2025 8.10 PM
root / root
0644
python.py
7.877 KB
17 Apr 2025 8.10 PM
root / root
0644
pytracer.py
14.082 KB
17 Apr 2025 8.10 PM
root / root
0644
report.py
10.374 KB
17 Apr 2025 8.10 PM
root / root
0644
report_core.py
3.973 KB
17 Apr 2025 8.10 PM
root / root
0644
results.py
13.07 KB
17 Apr 2025 8.10 PM
root / root
0644
sqldata.py
50.093 KB
17 Apr 2025 8.10 PM
root / root
0644
templite.py
10.695 KB
17 Apr 2025 8.10 PM
root / root
0644
tomlconfig.py
7.392 KB
17 Apr 2025 8.10 PM
root / root
0644
tracer.cpython-311-x86_64-linux-gnu.so
28.773 KB
17 Apr 2025 8.11 PM
root / root
0755
types.py
5.396 KB
17 Apr 2025 8.10 PM
root / root
0644
version.py
1.397 KB
17 Apr 2025 8.10 PM
root / root
0644
xmlreport.py
9.565 KB
17 Apr 2025 8.10 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF