|
| 1 | +"""Provides functions for reading and writing (writing is WIP currently) Java objects |
| 2 | +serialized or will be deserialized by ObjectOutputStream. This form of object |
| 3 | +representation is a standard data interchange format in Java world. |
| 4 | +
|
| 5 | +javaobj module exposes an API familiar to users of the standard library marshal, pickle and json modules. |
| 6 | +
|
| 7 | +See: http://download.oracle.com/javase/6/docs/platform/serialization/spec/protocol.html |
| 8 | +""" |
| 9 | + |
1 | 10 | import StringIO |
2 | 11 | import struct |
3 | 12 |
|
4 | | -def loads(object): |
| 13 | +__version__ = "$Revision: 20 $" |
| 14 | + |
| 15 | +def load(file_object): |
5 | 16 | """ |
6 | 17 | Deserializes Java primitive data and objects serialized by ObjectOutputStream |
| 18 | + from a file-like object. |
| 19 | + """ |
| 20 | + marshaller = JavaObjectUnmarshaller(file_object) |
| 21 | + return marshaller.readObject() |
| 22 | + |
| 23 | + |
| 24 | +def loads(string): |
| 25 | + """ |
| 26 | + Deserializes Java objects and primitive data serialized by ObjectOutputStream |
7 | 27 | from a string. |
8 | | - See: http://download.oracle.com/javase/6/docs/platform/serialization/spec/protocol.html |
9 | 28 | """ |
10 | | - f = StringIO.StringIO(object) |
| 29 | + f = StringIO.StringIO(string) |
11 | 30 | marshaller = JavaObjectUnmarshaller(f) |
12 | 31 | return marshaller.readObject() |
13 | 32 |
|
| 33 | + |
14 | 34 | def dumps(object): |
15 | 35 | """ |
16 | 36 | Serializes Java primitive data and objects unmarshaled by load(s) before into string. |
@@ -41,6 +61,7 @@ class JavaObject(object): |
41 | 61 | def get_class(self): |
42 | 62 | return self.classdesc |
43 | 63 |
|
| 64 | + |
44 | 65 | class JavaObjectConstants: |
45 | 66 |
|
46 | 67 | STREAM_MAGIC = 0xaced |
@@ -408,7 +429,7 @@ def _oops_dump_state(self): |
408 | 429 | print "Warning!!!!: Stream still has %s bytes left." % len(the_rest) |
409 | 430 | print self._create_hexdump(the_rest) |
410 | 431 | print "=" * 30 |
411 | | - # ===================================================================================== |
| 432 | + |
412 | 433 |
|
413 | 434 | class JavaObjectMarshaller(JavaObjectConstants): |
414 | 435 |
|
|
0 commit comments