77from typing import Any , Dict , List , Optional , Set
88import logging
99
10- from .constants import *
10+ from . import constants
11+ from .stream import DataStreamReader
1112from ..modifiedutf8 import decode_modified_utf8
1213
1314
@@ -40,19 +41,19 @@ class FieldType(IntEnum):
4041 Types of class fields
4142 """
4243
43- BYTE = TYPE_BYTE
44- CHAR = TYPE_CHAR
45- DOUBLE = TYPE_DOUBLE
46- FLOAT = TYPE_FLOAT
47- INTEGER = TYPE_INTEGER
48- LONG = TYPE_LONG
49- SHORT = TYPE_SHORT
50- BOOLEAN = TYPE_BOOLEAN
51- ARRAY = TYPE_ARRAY
52- OBJECT = TYPE_OBJECT
44+ BYTE = constants . TYPE_BYTE
45+ CHAR = constants . TYPE_CHAR
46+ DOUBLE = constants . TYPE_DOUBLE
47+ FLOAT = constants . TYPE_FLOAT
48+ INTEGER = constants . TYPE_INTEGER
49+ LONG = constants . TYPE_LONG
50+ SHORT = constants . TYPE_SHORT
51+ BOOLEAN = constants . TYPE_BOOLEAN
52+ ARRAY = constants . TYPE_ARRAY
53+ OBJECT = constants . TYPE_OBJECT
5354
5455
55- class Content :
56+ class ParsedJavaContent :
5657 """
5758 Generic representation of data parsed from the stream
5859 """
@@ -69,12 +70,12 @@ def validate(self) -> None:
6970 pass
7071
7172
72- class ExceptionState (Content ):
73+ class ExceptionState (ParsedJavaContent ):
7374 """
7475 Representation of a failed parsing
7576 """
7677
77- def __init__ (self , exception_object : Content , data : bytes ):
78+ def __init__ (self , exception_object : ParsedJavaContent , data : bytes ):
7879 super ().__init__ (ContentType .EXCEPTIONSTATE )
7980 self .exception_object = exception_object
8081 self .stream_data = data
@@ -86,11 +87,11 @@ class ExceptionRead(Exception):
8687 Exception used to indicate that an exception object has been parsed
8788 """
8889
89- def __init__ (self , content : Content ):
90+ def __init__ (self , content : ParsedJavaContent ):
9091 self .exception_object = content
9192
9293
93- class JavaString (Content ):
94+ class JavaString (ParsedJavaContent ):
9495 """
9596 Represents a Java string
9697 """
@@ -141,7 +142,7 @@ def validate(self, java_type: str) -> None:
141142 )
142143
143144
144- class JavaClassDesc (Content ):
145+ class JavaClassDesc (ParsedJavaContent ):
145146 """
146147 Represents the description of a class
147148 """
@@ -168,7 +169,7 @@ def __init__(self, class_desc_type: ClassDescType):
168169 self .inner_classes : List [JavaClassDesc ] = []
169170
170171 # List of annotations objects
171- self .annotations : List [Content ] = []
172+ self .annotations : List [ParsedJavaContent ] = []
172173
173174 # The super class of this one, if any
174175 self .super_class : JavaClassDesc = None
@@ -221,7 +222,9 @@ def validate(self):
221222 """
222223 Checks the validity of this class description
223224 """
224- serial_or_extern = SC_SERIALIZABLE | SC_EXTERNALIZABLE
225+ serial_or_extern = (
226+ constants .SC_SERIALIZABLE | constants .SC_EXTERNALIZABLE
227+ )
225228 if (self .desc_flags & serial_or_extern ) == 0 and self .fields :
226229 raise ValueError (
227230 "Non-serializable, non-externalizable class has fields"
@@ -230,7 +233,7 @@ def validate(self):
230233 if self .desc_flags & serial_or_extern == serial_or_extern :
231234 raise ValueError ("Class is both serializable and externalizable" )
232235
233- if self .desc_flags & SC_ENUM :
236+ if self .desc_flags & constants . SC_ENUM :
234237 if self .fields or self .interfaces :
235238 raise ValueError (
236239 "Enums shouldn't implement interfaces "
@@ -243,7 +246,7 @@ def validate(self):
243246 )
244247
245248
246- class JavaInstance (Content ):
249+ class JavaInstance (ParsedJavaContent ):
247250 """
248251 Represents an instance of Java object
249252 """
@@ -252,7 +255,7 @@ def __init__(self):
252255 super ().__init__ (ContentType .INSTANCE )
253256 self .classdesc : JavaClassDesc = None
254257 self .field_data : Dict [JavaClassDesc , Dict [JavaField , Any ]] = {}
255- self .annotations : Dict [JavaClassDesc , List [Content ]] = {}
258+ self .annotations : Dict [JavaClassDesc , List [ParsedJavaContent ]] = {}
256259
257260 def __str__ (self ):
258261 return "[instance 0x{0:x}: type {1}]" .format (
@@ -261,8 +264,24 @@ def __str__(self):
261264
262265 __repr__ = __str__
263266
267+ def load_from_blockdata (
268+ self , reader : DataStreamReader , indent : int = 0
269+ ) -> bool :
270+ """
271+ Reads content stored in a block data
272+ """
273+ return False
274+
275+ def load_from_instance (
276+ self , instance : "JavaInstance" , indent : int = 0
277+ ) -> bool :
278+ """
279+ Load content from a parsed instance object
280+ """
281+ return False
282+
264283
265- class JavaClass (Content ):
284+ class JavaClass (ParsedJavaContent ):
266285 """
267286 Represents a stored Java class
268287 """
@@ -278,7 +297,7 @@ def __str__(self):
278297 __repr__ = __str__
279298
280299
281- class JavaEnum (Content ):
300+ class JavaEnum (ParsedJavaContent ):
282301 """
283302 Represents an enumeration value
284303 """
@@ -297,7 +316,7 @@ def __str__(self):
297316 __repr__ = __str__
298317
299318
300- class JavaArray (Content ):
319+ class JavaArray (ParsedJavaContent ):
301320 """
302321 Represents a Java array
303322 """
@@ -323,7 +342,7 @@ def __str__(self):
323342 __repr__ = __str__
324343
325344
326- class BlockData (Content ):
345+ class BlockData (ParsedJavaContent ):
327346 """
328347 Represents a data block
329348 """
0 commit comments