|
49 | 49 |
|
50 | 50 | if sys.version_info[0] < 3: |
51 | 51 | # Python 2 |
52 | | - import StringIO |
| 52 | + from StringIO import StringIO |
53 | 53 |
|
54 | 54 | else: |
55 | 55 | # Python 3+ |
56 | | - import io as StringIO |
| 56 | + from io import BytesIO as StringIO |
57 | 57 |
|
58 | 58 | # ------------------------------------------------------------------------------ |
59 | 59 |
|
@@ -103,22 +103,22 @@ def loads(string): |
103 | 103 | :param string: A Java data string |
104 | 104 | :return: The deserialized object |
105 | 105 | """ |
106 | | - f = StringIO.StringIO(string) |
| 106 | + f = StringIO(string) |
107 | 107 | marshaller = JavaObjectUnmarshaller(f) |
108 | 108 | marshaller.add_transformer(DefaultObjectTransformer()) |
109 | 109 | return marshaller.readObject() |
110 | 110 |
|
111 | 111 |
|
112 | | -def dumps(object): |
| 112 | +def dumps(obj): |
113 | 113 | """ |
114 | 114 | Serializes Java primitive data and objects unmarshaled by load(s) before |
115 | 115 | into string. |
116 | 116 |
|
117 | | - :param object: A Python primitive object, or one loaded using load(s) |
| 117 | + :param obj: A Python primitive object, or one loaded using load(s) |
118 | 118 | :return: The serialized data as a string |
119 | 119 | """ |
120 | 120 | marshaller = JavaObjectMarshaller() |
121 | | - return marshaller.dump(object) |
| 121 | + return marshaller.dump(obj) |
122 | 122 |
|
123 | 123 | # ------------------------------------------------------------------------------ |
124 | 124 |
|
@@ -421,6 +421,11 @@ def do_classdesc(self, parent=None, ident=0): |
421 | 421 | clazz.name = ba |
422 | 422 | log_debug("Class name: %s" % ba, ident) |
423 | 423 | (serialVersionUID, newHandle, classDescFlags) = self._readStruct(">LLB") |
| 424 | + |
| 425 | + # FIXME: Fix for 1.6 ? |
| 426 | + if serialVersionUID == 0: |
| 427 | + serialVersionUID = newHandle |
| 428 | + |
424 | 429 | clazz.serialVersionUID = serialVersionUID |
425 | 430 | clazz.flags = classDescFlags |
426 | 431 |
|
@@ -822,7 +827,7 @@ def dump(self, obj): |
822 | 827 | Dumps the given object in the Java serialization format |
823 | 828 | """ |
824 | 829 | self.object_obj = obj |
825 | | - self.object_stream = StringIO.StringIO() |
| 830 | + self.object_stream = StringIO() |
826 | 831 | self._writeStreamHeader() |
827 | 832 | self.writeObject(obj) |
828 | 833 | return self.object_stream.getvalue() |
@@ -873,8 +878,7 @@ def _writeString(self, string): |
873 | 878 |
|
874 | 879 | :param string: String to serialize |
875 | 880 | """ |
876 | | - len = len(string) |
877 | | - self._writeStruct(">H", 2, (len,)) |
| 881 | + self._writeStruct(">H", 2, (len(string),)) |
878 | 882 | self.object_stream.write(string) |
879 | 883 |
|
880 | 884 |
|
@@ -914,61 +918,61 @@ class JavaList(list, JavaObject): |
914 | 918 | class JavaMap(dict, JavaObject): |
915 | 919 | pass |
916 | 920 |
|
917 | | - def transform(self, object): |
| 921 | + def transform(self, java_object): |
918 | 922 | """ |
919 | 923 | Transforms a deserialized Java object into a Python object |
920 | 924 |
|
921 | | - :param object: A JavaObject instance |
| 925 | + :param java_object: A JavaObject instance |
922 | 926 | :return: The Python form of the object, or the original JavaObject |
923 | 927 | """ |
924 | | - # Get the Java object class name |
925 | | - classname = object.get_class().name |
| 928 | + # Get the Java java_object class name |
| 929 | + classname = java_object.get_class().name |
926 | 930 |
|
927 | 931 | if classname == "java.util.ArrayList": |
928 | 932 | # @serialData The length of the array backing the <tt>ArrayList</tt> |
929 | 933 | # instance is emitted (int), followed by all of its |
930 | 934 | # elements (each an <tt>Object</tt>) in the proper order |
931 | 935 | log_debug("---") |
932 | 936 | log_debug("java.util.ArrayList") |
933 | | - log_debug(object.annotations) |
| 937 | + log_debug(java_object.annotations) |
934 | 938 | log_debug("---") |
935 | 939 |
|
936 | 940 | new_object = self.JavaList() |
937 | | - object.copy(new_object) |
938 | | - new_object.extend(object.annotations[1:]) |
| 941 | + java_object.copy(new_object) |
| 942 | + new_object.extend(java_object.annotations[1:]) |
939 | 943 |
|
940 | | - log_debug(">>> object: {0}".format(new_object)) |
| 944 | + log_debug(">>> java_object: {0}".format(new_object)) |
941 | 945 | return new_object |
942 | 946 |
|
943 | 947 | elif classname == "java.util.LinkedList": |
944 | 948 | log_debug("---") |
945 | 949 | log_debug("java.util.LinkedList") |
946 | | - log_debug(object.annotations) |
| 950 | + log_debug(java_object.annotations) |
947 | 951 | log_debug("---") |
948 | 952 |
|
949 | 953 | new_object = self.JavaList() |
950 | | - object.copy(new_object) |
951 | | - new_object.extend(object.annotations[1:]) |
| 954 | + java_object.copy(new_object) |
| 955 | + new_object.extend(java_object.annotations[1:]) |
952 | 956 |
|
953 | | - log_debug(">>> object: {0}".format(new_object)) |
| 957 | + log_debug(">>> java_object: {0}".format(new_object)) |
954 | 958 | return new_object |
955 | 959 |
|
956 | | - elif object.get_class().name == "java.util.HashMap": |
| 960 | + elif java_object.get_class().name == "java.util.HashMap": |
957 | 961 | log_debug("---") |
958 | 962 | log_debug("java.util.HashMap") |
959 | | - log_debug(object.annotations) |
| 963 | + log_debug(java_object.annotations) |
960 | 964 | log_debug("---") |
961 | 965 |
|
962 | 966 | new_object = self.JavaMap() |
963 | | - object.copy(new_object) |
| 967 | + java_object.copy(new_object) |
964 | 968 |
|
965 | | - for i in range((len(object.annotations) - 1) / 2): |
966 | | - new_object[object.annotations[i * 2 + 1]] = \ |
967 | | - object.annotations[i * 2 + 2] |
| 969 | + for i in range((len(java_object.annotations) - 1) / 2): |
| 970 | + new_object[java_object.annotations[i * 2 + 1]] = \ |
| 971 | + java_object.annotations[i * 2 + 2] |
968 | 972 |
|
969 | | - log_debug(">>> object: {0}".format(new_object)) |
| 973 | + log_debug(">>> java_object: {0}".format(new_object)) |
970 | 974 | return new_object |
971 | 975 |
|
972 | 976 | else: |
973 | 977 | # Return the JavaObject by default |
974 | | - return object |
| 978 | + return java_object |
0 commit comments