Skip to main content

library to manage Python Locations Table

Project description

About linetable

linetable is a library parse and generate co_linetable attributes in Python code objects.

Installing

linetable can be installed from pypi:

pip install linetable

should just work for most of the users

Usage

Existing linetable can be parsed using linetable.parse_linetable:

>>> def testfunc():
...   x = 3
...   y = x + 1
...   return y

>>> list(linetable.parse_linetable(testfunc.__code__.co_linetable))
[
    (1, 1, 1, 0, 0),
    (1, 2, 2, 6, 7),
    (1, 2, 2, 2, 3),
    (1, 3, 3, 6, 7),
    (1, 3, 3, 10, 11),
    (2, 3, 3, 6, 11),
    (1, 3, 3, 2, 3),
    (1, 4, 4, 9, 10),
    (1, 4, 4, 2, 10),
]

If you prefer the output in the format of dis.Positions objects, you can create them from the yielded values:

>>> [dis.Positions(*e[1:]) for e in linetable.parse_linetable(testfunc.__code__.co_linetable)]
[Positions(lineno=1, end_lineno=1, col_offset=0, end_col_offset=0), Positions(lineno=2, end_lineno=2, col_offset=8, end_col_offset=9), Positions(lineno=2, end_lineno=2, col_offset=4, end_col_offset=5), Positions(lineno=3, end_lineno=3, col_offset=8, end_col_offset=9), Positions(lineno=3, end_lineno=3, col_offset=12, end_col_offset=13), Positions(lineno=3, end_lineno=3, col_offset=8, end_col_offset=13), Positions(lineno=3, end_lineno=3, col_offset=4, end_col_offset=5), Positions(lineno=4, end_lineno=4, col_offset=11, end_col_offset=12), Positions(lineno=4, end_lineno=4, col_offset=4, end_col_offset=12)]

If you have the linetable, you can generate back the binary encoded version using linetable.generate_linetable:

>>> lt = [
...     (1, 1, 1, 0, 0),
...     (1, 2, 2, 6, 7),
...     (1, 2, 2, 2, 3),
...     (1, 3, 3, 6, 7),
...     (1, 3, 3, 10, 11),
...     (2, 3, 3, 6, 11),
...     (1, 3, 3, 2, 3),
...     (1, 4, 4, 9, 10),
...     (1, 4, 4, 2, 10),
... ]
>>> linetable.generate_linetable(lt)
b"\x80\x00\xd8\x06\x07\x80!\xd8\x06\x07\x88!\x81e\x80!\xd8\t\n\x80("

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linetable-0.0.1.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file linetable-0.0.1.tar.gz.

File metadata

  • Download URL: linetable-0.0.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for linetable-0.0.1.tar.gz
Algorithm Hash digest
SHA256 02a890879ee76750df9f315cbd1e7a51c88aa8197e4cc2a188f93d60bc574536
MD5 6dfc83af4d31506b04782658f8997683
BLAKE2b-256 4e9e32e4269579839ea89a52571da4948b8e9510023fdff46c6327b309e8161d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page