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 torubymarshal.classes.RubyStringif dumped with instance variables),nil(mapped toNonein Python),array(mapped tolist),hash(mapped todict),- symbols and other classes are mapped to specific Python classes.
Installation
pip install rubymarshal
Usage
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:
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:
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:
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:
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)
Infos
- Code is on github: https://github.com/d9pouces/RubyMarshal
- Documentation is on readthedocs: http://rubymarshal.readthedocs.org/en/latest/
- Tests are on travis-ci: https://travis-ci.org/d9pouces/RubyMarshal
Metadata
Release files for rubymarshal 0.9.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| rubymarshal-0.9.1.tar.gz | 8.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rubymarshal-0.9.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.2 kB
Release files / rubymarshal-0.9.1.tar.gz
| Download URL | rubymarshal-0.9.1.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0ac257f52c8b67e3d05cb9959bbbda08df1d604f0e8ba1eeaf2222a1ac68343b
|
|
BLAKE2b-256 checksum How to use checksums |
c635634ac1479fb0347a4a505d9d2d046578ade252552727a3aefb7b8e943753
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.0
|
Release files / rubymarshal-0.9.1-py3-none-any.whl
| Download URL | rubymarshal-0.9.1-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c64d1111da92f92d0a1c64cb3c18003e7c25ee4f070c890d9e73903cad296aac
|
|
BLAKE2b-256 checksum How to use checksums |
5ef6b98b9834a6c2cf98cf06fcaced781465c451abffe32d770da29146787daf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.0
|
Security for rubymarshal 0.9.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.