Skip to main content

Python bindings to the Katsuba libraries in Rust

Project description

Katsuba

Python bindings to the Katsuba libraries.

Error handling

Most errors are represented either as native Python exceptions where it makes sense, or as a katsuba.KatsubaError for custom errors from the Rust side.

Bindings

katsuba.op

Bindings to core functionality from the katsuba-object-property crate.

from katsuba.op import *
from katsuba.utils import string_id

# Open a type list from file system
type_list = TypeList.open("types.json")

# Configure serializer options
opts = SerializerOptions()
opts.flags |= STATEFUL_FLAGS
opts.shallow = False

# Construct the serializer
ser = Serializer(opts, type_list)

# Deserialize a file
with open("TemplateManifest.xml", "rb") as f:
    manifest = f.read()
    assert manifest[:4] == b"BINd"

manifest = ser.deserialize(manifest[4:])

# Make sure we deserialized the right object:
assert manifest.type_hash == string_id("class TemplateManifest")

# Iterate the templates in the resulting object:
for location in manifest["m_serializedTemplates"]:
    print(f"Template {location['m_id']} at {location['m_filename']}")

katsuba.wad

Bindings to core functionality from the katsuba-wad crate.

from katsuba.op import Serializer
from katsuba.wad import Archive

# See `katsuba.op` above.
s = Serializer(...)

# Open an archive memory-mapped:
a = Archive.mmap("/path/to/Root.wad")

print(f"{len(a)} files in archive!")

# Deserialize a file out of the given archive:
if "TemplateManifest.xml" in a:
    a.deserialize("TemplateManifest.xml", s)

# Iterate over files in the archive and get their contents:
for path in a:
    data = a[path]

# With a glob pattern for filtering files:
for path in a.iter_glob("ObjectData/**/*.xml"):
    data = a[path]

katsuba.utils

Bindings to useful components from the katsuba-utils crate.

For the time being, this features the hash functions djb2 and string_id.

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

katsuba-0.1.1.tar.gz (48.6 kB view hashes)

Uploaded Source

Built Distributions

katsuba-0.1.1-cp310-abi3-win_amd64.whl (694.7 kB view hashes)

Uploaded CPython 3.10+ Windows x86-64

katsuba-0.1.1-cp310-abi3-win32.whl (628.6 kB view hashes)

Uploaded CPython 3.10+ Windows x86

katsuba-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (728.1 kB view hashes)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ARM64

katsuba-0.1.1-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.whl (810.8 kB view hashes)

Uploaded CPython 3.10+ manylinux: glibc 2.5+ x86-64

katsuba-0.1.1-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl (801.1 kB view hashes)

Uploaded CPython 3.10+ manylinux: glibc 2.5+ i686

katsuba-0.1.1-cp310-abi3-macosx_11_0_arm64.whl (663.7 kB view hashes)

Uploaded CPython 3.10+ macOS 11.0+ ARM64

katsuba-0.1.1-cp310-abi3-macosx_10_12_x86_64.whl (750.6 kB view hashes)

Uploaded CPython 3.10+ macOS 10.12+ x86-64

katsuba-0.1.1-cp310-abi3-macosx_10_7_x86_64.whl (774.4 kB view hashes)

Uploaded CPython 3.10+ macOS 10.7+ x86-64

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