# Buildsheet autogenerated by ravenadm tool -- Do not edit. NAMEBASE= python-rubymarshal VERSION= 1.2.10 KEYWORDS= python VARIANTS= v11 v12 SDESC[v11]= Read and write Ruby-marshalled data (3.11) SDESC[v12]= Read and write Ruby-marshalled data (3.12) HOMEPAGE= https://github.com/d9pouces/RubyMarshal CONTACT= Python_Automaton[python@ironwolf.systems] DOWNLOAD_GROUPS= main SITES[main]= GITHUB/d9pouces:RubyMarshal:1.2.10 DISTFILE[1]= generated:main DF_INDEX= 1 SPKGS[v11]= single SPKGS[v12]= single OPTIONS_AVAILABLE= PY311 PY312 OPTIONS_STANDARD= none VOPTS[v11]= PY311=ON PY312=OFF VOPTS[v12]= PY311=OFF PY312=ON GENERATED= yes [PY311].USES_ON= python:v11,sutools [PY312].USES_ON= python:v12,sutools [FILE:2417:descriptions/desc.single] RubyMarshal =========== Read and write Ruby-marshalled data. Only basics Ruby data types can be directly read and written, but you can use any custom Python and Ruby types: * `float`, * `bool`, * `int`, * `str` (mapped to `rubymarshal.classes.RubyString` if dumped with instance variables), * `nil` (mapped to `None` in Python), * `array` (mapped to `list`), * `hash` (mapped to `dict`), * symbols and other classes are mapped to specific Python classes. Installation ------------ `python3 pip install rubymarshal ` Usage ----- ```python3 from rubymarshal.reader import loads, load from rubymarshal.writer import writes, write with open('my_file', 'rb') as fd: content = load(fd) with open('my_file', 'wb') as fd: write(fd, my_object) loads(b"\x04\bi\xfe\x00\xff") writes(-256) ``` You can map custom Ruby types to Python ones: ```python3 from rubymarshal.reader import loads from rubymarshal.classes import RubyObject, registry class DomainError(RubyObject): ruby_class_name = "Math::DomainError" registry.register(DomainError) loads(b'\x04\x08c\x16Math::DomainError') ``` You can use custom registries instead of the global one: ```python3 from rubymarshal.reader import loads from rubymarshal.classes import RubyObject, ClassRegistry class DomainError(RubyObject): ruby_class_name = "Math::DomainError" registry = ClassRegistry() registry.register(DomainError) loads(b'\x04\x08c\x16Math::DomainError', registry=registry) ``` You can use Ruby's symbols: ```python3 from rubymarshal.reader import loads from rubymarshal.writer import writes from rubymarshal.classes import Symbol x = Symbol("test") dump = writes(Symbol("test")) y = loads(dump) assert y is x ``` The default Writer class is customizable to write custom Python classes: ```python3 from rubymarshal.writer import writes, Writer from rubymarshal.classes import Symbol class Constant: def __init__(self, name): self.name = name class ConstantWriter(Writer): def write_python_object(self, obj): if isinstance(obj, Constant): return self.write(Symbol(obj.name)) super().write_python_object(obj) dump = writes([Constant("test")], cls=ConstantWriter) print(dump) ``` [FILE:113:distinfo] a09bccd8125e8e09f9c11146fafaba5283d16c369d0751f9765ddc009321df9e 49095 d9pouces-RubyMarshal-1.2.10.tar.gz