Lib.marshal.py Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jython Show documentation
Show all versions of jython Show documentation
Jython is an implementation of the high-level, dynamic, object-oriented
language Python written in 100% Pure Java, and seamlessly integrated with
the Java platform. It thus allows you to run Python on any Java platform.
"""Marshal module written in Python.
This doesn't marshal code objects, but supports everything else.
Performance or careful error checking is not an issue.
"""
import cStringIO
from _marshal import Marshaller, Unmarshaller
def dump(x, f, version=2):
Marshaller(f, version).dump(x)
# XXX - added just for debugging. remove!
def load(f, debug=False):
u = Unmarshaller(f)
if debug:
u._debug()
return u.load()
def dumps(x, version=2):
f = cStringIO.StringIO()
dump(x, f, version)
return f.getvalue()
def loads(s):
f = cStringIO.StringIO(s)
return load(f)