Skip to content

Commit 934afc9

Browse files
committed
JavaString inherits UNICODE_TYPE instead of str
This ensures to load a usable unicode string
1 parent 4009115 commit 934afc9

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

javaobj/core.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@
4141
import sys
4242

4343
from javaobj.modifiedutf8 import decode_modified_utf8
44-
from javaobj.utils import log_debug, log_error, read_to_str, to_bytes, to_str
44+
from javaobj.utils import (
45+
log_debug,
46+
log_error,
47+
read_to_str,
48+
to_bytes,
49+
to_str,
50+
to_unicode,
51+
UNICODE_TYPE
52+
)
4553

4654
try:
4755
# Python 2
@@ -256,17 +264,17 @@ def __eq__(self, other):
256264
return True
257265

258266

259-
class JavaString(str):
267+
class JavaString(UNICODE_TYPE):
260268
"""
261269
Represents a Java String
262270
"""
263271
def __hash__(self):
264-
return str.__hash__(self)
272+
return UNICODE_TYPE.__hash__(self)
265273

266274
def __eq__(self, other):
267-
if not isinstance(other, str):
275+
if not isinstance(other, UNICODE_TYPE):
268276
return False
269-
return str.__eq__(self, other)
277+
return UNICODE_TYPE.__eq__(self, other)
270278

271279

272280
class JavaEnum(JavaObject):
@@ -588,7 +596,7 @@ def _readString(self, length_fmt="H"):
588596
"""
589597
(length,) = self._readStruct(">{0}".format(length_fmt))
590598
ba = self.object_stream.read(length)
591-
return to_str(ba)
599+
return to_unicode(ba)
592600

593601
def do_classdesc(self, parent=None, ident=0):
594602
"""
@@ -1065,9 +1073,13 @@ def _add_reference(self, obj, ident=0):
10651073
:param obj: Reference to add
10661074
:param ident: Log indentation level
10671075
"""
1068-
log_debug("## New reference handle 0x{0:X}: {1} -> {2}"
1069-
.format(len(self.references) + self.BASE_REFERENCE_IDX,
1070-
type(obj).__name__, obj), ident)
1076+
log_debug(
1077+
"## New reference handle 0x{0:X}: {1} -> {2}".format(
1078+
len(self.references) + self.BASE_REFERENCE_IDX,
1079+
type(obj).__name__,
1080+
repr(obj)),
1081+
ident
1082+
)
10711083
self.references.append(obj)
10721084

10731085
def _oops_dump_state(self, ignore_remaining_data=False):

0 commit comments

Comments
 (0)