1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
3 NAMEBASE= python-rubymarshal
7 SDESC[v11]= Read and write Ruby-marshalled data (3.11)
8 SDESC[v12]= Read and write Ruby-marshalled data (3.12)
9 HOMEPAGE= https://github.com/d9pouces/RubyMarshal
10 CONTACT= Python_Automaton[python@ironwolf.systems]
13 SITES[main]= GITHUB/d9pouces:RubyMarshal:1.2.10
14 DISTFILE[1]= generated:main
19 OPTIONS_AVAILABLE= PY311 PY312
20 OPTIONS_STANDARD= none
21 VOPTS[v11]= PY311=ON PY312=OFF
22 VOPTS[v12]= PY311=OFF PY312=ON
26 [PY311].USES_ON= python:v11,sutools
28 [PY312].USES_ON= python:v12,sutools
30 [FILE:2417:descriptions/desc.single]
34 Read and write Ruby-marshalled data.
35 Only basics Ruby data types can be directly read and written, but you can
36 use any custom Python and Ruby types:
41 * `str` (mapped to `rubymarshal.classes.RubyString` if dumped with
43 * `nil` (mapped to `None` in Python),
44 * `array` (mapped to `list`),
45 * `hash` (mapped to `dict`),
46 * symbols and other classes are mapped to specific Python classes.
52 pip install rubymarshal
59 from rubymarshal.reader import loads, load
60 from rubymarshal.writer import writes, write
61 with open('my_file', 'rb') as fd:
63 with open('my_file', 'wb') as fd:
65 loads(b"\x04\bi\xfe\x00\xff")
69 You can map custom Ruby types to Python ones:
72 from rubymarshal.reader import loads
73 from rubymarshal.classes import RubyObject, registry
75 class DomainError(RubyObject):
76 ruby_class_name = "Math::DomainError"
78 registry.register(DomainError)
80 loads(b'\x04\x08c\x16Math::DomainError')
83 You can use custom registries instead of the global one:
86 from rubymarshal.reader import loads
87 from rubymarshal.classes import RubyObject, ClassRegistry
89 class DomainError(RubyObject):
90 ruby_class_name = "Math::DomainError"
92 registry = ClassRegistry()
93 registry.register(DomainError)
95 loads(b'\x04\x08c\x16Math::DomainError', registry=registry)
98 You can use Ruby's symbols:
101 from rubymarshal.reader import loads
102 from rubymarshal.writer import writes
103 from rubymarshal.classes import Symbol
106 dump = writes(Symbol("test"))
111 The default Writer class is customizable to write custom Python classes:
114 from rubymarshal.writer import writes, Writer
115 from rubymarshal.classes import Symbol
118 def __init__(self, name):
121 class ConstantWriter(Writer):
122 def write_python_object(self, obj):
123 if isinstance(obj, Constant):
124 return self.write(Symbol(obj.name))
125 super().write_python_object(obj)
127 dump = writes([Constant("test")], cls=ConstantWriter)
134 a09bccd8125e8e09f9c11146fafaba5283d16c369d0751f9765ddc009321df9e 49095 d9pouces-RubyMarshal-1.2.10.tar.gz