Ravenports generated: 04 Feb 2024 05:27
[ravenports.git] / bucket_34 / python-rubymarshal
1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
2
3 NAMEBASE=               python-rubymarshal
4 VERSION=                1.2.10
5 KEYWORDS=               python
6 VARIANTS=               v11 v12
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]
11
12 DOWNLOAD_GROUPS=        main
13 SITES[main]=            GITHUB/d9pouces:RubyMarshal:1.2.10
14 DISTFILE[1]=            generated:main
15 DF_INDEX=               1
16 SPKGS[v11]=             single
17 SPKGS[v12]=             single
18
19 OPTIONS_AVAILABLE=      PY311 PY312
20 OPTIONS_STANDARD=       none
21 VOPTS[v11]=             PY311=ON PY312=OFF
22 VOPTS[v12]=             PY311=OFF PY312=ON
23
24 GENERATED=              yes
25
26 [PY311].USES_ON=                        python:v11,sutools
27
28 [PY312].USES_ON=                        python:v12,sutools
29
30 [FILE:2417:descriptions/desc.single]
31 RubyMarshal
32 ===========
33
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: 
37
38   * `float`,
39   * `bool`,
40   * `int`,
41   * `str` (mapped to `rubymarshal.classes.RubyString` if dumped with
42 instance variables),
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.
47
48 Installation
49 ------------
50
51 `python3
52     pip install rubymarshal
53 `
54
55 Usage
56 -----
57
58 ```python3
59     from rubymarshal.reader import loads, load
60     from rubymarshal.writer import writes, write
61     with open('my_file', 'rb') as fd:
62         content = load(fd)
63     with open('my_file', 'wb') as fd:
64         write(fd, my_object)
65     loads(b"\x04\bi\xfe\x00\xff")
66     writes(-256)
67 ```
68
69 You can map custom Ruby types to Python ones:
70
71 ```python3
72     from rubymarshal.reader import loads
73     from rubymarshal.classes import RubyObject, registry
74
75     class DomainError(RubyObject):
76         ruby_class_name = "Math::DomainError"
77     
78     registry.register(DomainError)
79
80     loads(b'\x04\x08c\x16Math::DomainError')
81 ```
82
83 You can use custom registries instead of the global one:
84
85 ```python3
86     from rubymarshal.reader import loads
87     from rubymarshal.classes import RubyObject, ClassRegistry
88
89     class DomainError(RubyObject):
90         ruby_class_name = "Math::DomainError"
91     
92     registry = ClassRegistry()
93     registry.register(DomainError)
94
95     loads(b'\x04\x08c\x16Math::DomainError', registry=registry)
96 ```
97
98 You can use Ruby's symbols:
99
100 ```python3
101     from rubymarshal.reader import loads
102     from rubymarshal.writer import writes
103     from rubymarshal.classes import Symbol
104     
105     x = Symbol("test")
106     dump = writes(Symbol("test"))
107     y = loads(dump)
108     assert y is x
109 ```
110
111 The default Writer class is customizable to write custom Python classes:
112
113 ```python3
114     from rubymarshal.writer import writes, Writer
115     from rubymarshal.classes import Symbol
116     
117     class Constant:
118         def __init__(self, name):
119             self.name = name
120     
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)
126     
127     dump = writes([Constant("test")], cls=ConstantWriter)
128     print(dump)
129
130 ```
131
132
133 [FILE:113:distinfo]
134 a09bccd8125e8e09f9c11146fafaba5283d16c369d0751f9765ddc009321df9e        49095 d9pouces-RubyMarshal-1.2.10.tar.gz
135