Skip to main content

Python Struct Reflector

Project description

Pystrector

The Py(thon) Str(uct) (Refl)ector


The package for displaying and changing core Python structures.
Do you want to see how objects in Python actually work?
Then this package is for you.

from pystrector import Binder
binder = Binder()
some_object = 1
reflector = binder.bind(some_object)
print(reflector.ob_base.ob_refcnt.pretty_value)

Python

To download the package enter the command.

python3 -m pip install pystrector

Git

git clone https://github.com/bontail/pystrector.git

Documentation

To access the view of core structures you need to create a binder object

from pystrector import Binder
binder = Binder()

You can now call the bind method to get an object of the class that represents the structure

some_object = 1
reflector = binder.bind(some_object)

Reflector has all the same fields that are in the structure

// core structure
struct _longobject {
     PyObject ob_base;
    _PyLongValue long_value;
};
print(reflector.ob_base)
print(reflector.long_value)

For each type you can call pretty_value and bytes_value
pretty_value - will result in the most similar type in python
bytes_value - always returns bytearray

print(reflector.ob_base.pretty_value)
print(reflector.ob_base.bytes_value)

You can also set values
bytes_value - only accepts bytearray
pretty_value - accepts a similar Python type
without any properties - takes another object from pystrector

reflector.ob_base.ob_refcnt.bytes_value = bytearray(1)
reflector.ob_base.ob_refcnt.pretty_value = 1000
reflector.ob_base.ob_refcnt = binder.bind(1).ob_base.ob_refcnt

There is also work with pointers and arrays as in C

x = [1, 2, 3]
print(binder.bind(x).ob_item[j][1])
print(+(binder.bind(x).ob_item[j]))
print(+(binder.bind(x).ob_item[j] + 1))

You can cast objects into other data types

from pystrector.core_datatypes import _longobject

x = [1, 2, 3]

binder.bind(x).ob_item[0][0].cast_to(_longobject) # need to cast because list saves PyObjects

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

pystrector-0.3.2.tar.gz (115.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pystrector-0.3.2-py3-none-any.whl (119.1 kB view details)

Uploaded Python 3

File details

Details for the file pystrector-0.3.2.tar.gz.

File metadata

  • Download URL: pystrector-0.3.2.tar.gz
  • Upload date:
  • Size: 115.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for pystrector-0.3.2.tar.gz
Algorithm Hash digest
SHA256 c9711e5d7249170e76f0603d0f19467be85be1f1eca59e1851003261a769bc2f
MD5 01b9bbdcb9572b5a1d35d1ec5aca2329
BLAKE2b-256 cf88709186a9fe5445ca8c904f39ae71bdc06cbd92e1bcc3458ffde8d7281958

See more details on using hashes here.

File details

Details for the file pystrector-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: pystrector-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 119.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for pystrector-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4f794854293991baf93bb44151922ecdae530389e5b83ddf0ceac10ac4e6f7cf
MD5 8fa4924459e83db719465ba720fc4929
BLAKE2b-256 2ecf8ad787b5357212759c7f4a3e0058b7616d4b0b4899e395514550ad1c8cb4

See more details on using hashes here.

Supported by

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