2424 limitations under the License.
2525"""
2626
27+ from __future__ import absolute_import
28+
2729from enum import Enum , IntEnum
2830from typing import Any , Dict , List , Optional , Set
2931import logging
3032
3133from .stream import DataStreamReader
3234from ..constants import ClassDescFlags , TypeCode
33- from ..modifiedutf8 import decode_modified_utf8
35+ from ..modifiedutf8 import decode_modified_utf8 , byte_to_int
3436from ..utils import UNICODE_TYPE
3537
3638
@@ -75,7 +77,7 @@ class FieldType(IntEnum):
7577 OBJECT = TypeCode .TYPE_OBJECT .value
7678
7779
78- class ParsedJavaContent :
80+ class ParsedJavaContent ( object ) :
7981 """
8082 Generic representation of data parsed from the stream
8183 """
@@ -112,7 +114,7 @@ class ExceptionState(ParsedJavaContent):
112114
113115 def __init__ (self , exception_object , data ):
114116 # type: (ParsedJavaContent, bytes) -> None
115- super ().__init__ (ContentType .EXCEPTIONSTATE )
117+ super (ExceptionState , self ).__init__ (ContentType .EXCEPTIONSTATE )
116118 self .exception_object = exception_object
117119 self .stream_data = data
118120 self .handle = exception_object .handle
@@ -142,7 +144,7 @@ class JavaString(ParsedJavaContent):
142144
143145 def __init__ (self , handle , data ):
144146 # type: (int, bytes) -> None
145- super ().__init__ (ContentType .STRING )
147+ super (JavaString , self ).__init__ (ContentType .STRING )
146148 self .handle = handle
147149 value , length = decode_modified_utf8 (data )
148150 self .value = value # type: str
@@ -207,7 +209,7 @@ class JavaClassDesc(ParsedJavaContent):
207209
208210 def __init__ (self , class_desc_type ):
209211 # type: (ClassDescType) -> None
210- super ().__init__ (ContentType .CLASSDESC )
212+ super (JavaClassDesc , self ).__init__ (ContentType .CLASSDESC )
211213
212214 # Type of class description
213215 self .class_type = class_desc_type # type: ClassDescType
@@ -350,10 +352,12 @@ class JavaInstance(ParsedJavaContent):
350352 """
351353
352354 def __init__ (self ):
353- super ().__init__ (ContentType .INSTANCE )
355+ super (JavaInstance , self ).__init__ (ContentType .INSTANCE )
354356 self .classdesc = None # type: JavaClassDesc
355357 self .field_data = {} # type: Dict[JavaClassDesc, Dict[JavaField, Any]]
356- self .annotations = {} # type: Dict[JavaClassDesc, List[ParsedJavaContent]]
358+ self .annotations = (
359+ {}
360+ ) # type: Dict[JavaClassDesc, List[ParsedJavaContent]]
357361
358362 def __str__ (self ):
359363 return "[instance 0x{0:x}: type {1}]" .format (
@@ -445,7 +449,7 @@ class JavaClass(ParsedJavaContent):
445449
446450 def __init__ (self , handle , class_desc ):
447451 # type: (int, JavaClassDesc) -> None
448- super ().__init__ (ContentType .CLASS )
452+ super (JavaClass , self ).__init__ (ContentType .CLASS )
449453 self .handle = handle
450454 self .classdesc = class_desc
451455
@@ -469,7 +473,7 @@ class JavaEnum(ParsedJavaContent):
469473
470474 def __init__ (self , handle , class_desc , value ):
471475 # type: (int, JavaClassDesc, JavaString) -> None
472- super ().__init__ (ContentType .ENUM )
476+ super (JavaEnum , self ).__init__ (ContentType .ENUM )
473477 self .handle = handle
474478 self .classdesc = class_desc
475479 self .value = value
@@ -542,7 +546,7 @@ class BlockData(ParsedJavaContent):
542546
543547 def __init__ (self , data ):
544548 # type: (bytes) -> None
545- super ().__init__ (ContentType .BLOCKDATA )
549+ super (BlockData , self ).__init__ (ContentType .BLOCKDATA )
546550 self .data = data
547551
548552 def __str__ (self ):
@@ -555,11 +559,11 @@ def __repr__(self):
555559
556560 def __eq__ (self , other ):
557561 if isinstance (other , (str , UNICODE_TYPE )):
558- other_data = other . encode ( "latin1" )
562+ other_data = tuple ( byte_to_int ( x ) for x in other )
559563 elif isinstance (other , bytes ):
560- other_data = other
564+ other_data = tuple ( byte_to_int ( x ) for x in other )
561565 else :
562566 # Can't compare
563567 return False
564568
565- return other_data == self .data
569+ return other_data == tuple ( byte_to_int ( x ) for x in self .data )
0 commit comments