Skip to content

Commit ae23e48

Browse files
committed
Formated code with black
1 parent a0bd51c commit ae23e48

File tree

3 files changed

+53
-25
lines changed

3 files changed

+53
-25
lines changed

javaobj/v2/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def load_array(self, reader, field_type, size):
7878
:param size: Number of elements in the array
7979
"""
8080
return None
81-
81+
8282
def load_custom_writeObject(self, parser, reader, name):
8383
"""
8484
Reads content stored from a custom writeObject.

javaobj/v2/beans.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class ContentType(IntEnum):
6060
BLOCKDATA = 6
6161
EXCEPTIONSTATE = 7
6262

63+
6364
class ClassDataType(IntEnum):
6465
"""
6566
Class data types
@@ -191,6 +192,7 @@ def __hash__(self):
191192
def __eq__(self, other):
192193
return self.value == other
193194

195+
194196
class JavaField:
195197
"""
196198
Represents a field in a Java class description
@@ -318,13 +320,20 @@ def fields_types(self):
318320

319321
@property
320322
def data_type(self):
321-
if (ClassDescFlags.SC_SERIALIZABLE & self.desc_flags):
322-
return ClassDataType.WRCLASS if (ClassDescFlags.SC_WRITE_METHOD & self.desc_flags) else ClassDataType.NOWRCLASS
323-
elif (ClassDescFlags.SC_EXTERNALIZABLE & self.desc_flags):
324-
return ClassDataType.OBJECT_ANNOTATION if (ClassDescFlags.SC_WRITE_METHOD & self.desc_flags) else ClassDataType.EXTERNAL_CONTENTS
325-
323+
if ClassDescFlags.SC_SERIALIZABLE & self.desc_flags:
324+
return (
325+
ClassDataType.WRCLASS
326+
if (ClassDescFlags.SC_WRITE_METHOD & self.desc_flags)
327+
else ClassDataType.NOWRCLASS
328+
)
329+
elif ClassDescFlags.SC_EXTERNALIZABLE & self.desc_flags:
330+
return (
331+
ClassDataType.OBJECT_ANNOTATION
332+
if (ClassDescFlags.SC_WRITE_METHOD & self.desc_flags)
333+
else ClassDataType.EXTERNAL_CONTENTS
334+
)
335+
326336
raise ValueError("Unhandled Class Data Type")
327-
328337

329338
def is_array_class(self):
330339
# type: () -> bool

javaobj/v2/core.py

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def _read_content(self, type_code, block_data, class_desc=None):
293293
try:
294294
handler = self.__type_code_handlers[type_code]
295295
except KeyError:
296-
'''Looking for an external reader'''
296+
"""Looking for an external reader"""
297297
if class_desc and class_desc.data_type == ClassDataType.WRCLASS:
298298
return self._custom_readObject(class_desc.name)
299299
raise ValueError("Unknown type code: 0x{0:x}".format(type_code))
@@ -327,7 +327,7 @@ def _read_new_string(self, type_code):
327327
raise ValueError("Invalid string length: {0}".format(length))
328328
elif length < 65536:
329329
self._log.warning("Small string stored as a long one")
330-
330+
331331
# Parse the content
332332
data = self.__fd.read(length)
333333
java_str = JavaString(handle, data)
@@ -356,7 +356,7 @@ def _do_classdesc(self, type_code):
356356
handle = self._new_handle()
357357
desc_flags = self.__reader.read_byte()
358358
nb_fields = self.__reader.read_short()
359-
359+
360360
if nb_fields < 0:
361361
raise ValueError("Invalid field count: {0}".format(nb_fields))
362362

@@ -375,9 +375,9 @@ def _do_classdesc(self, type_code):
375375
"Invalid field type char: 0x{0:x}".format(field_type)
376376
)
377377

378-
fields.append(JavaField(
379-
FieldType(field_type), field_name, class_name
380-
))
378+
fields.append(
379+
JavaField(FieldType(field_type), field_name, class_name)
380+
)
381381

382382
# Setup the class description bean
383383
class_desc = JavaClassDesc(ClassDescType.NORMALCLASS)
@@ -418,19 +418,19 @@ def _do_classdesc(self, type_code):
418418
# Store the reference to the parsed bean
419419
self._set_handle(handle, class_desc)
420420
return class_desc
421-
422-
raise ValueError("Expected a valid class description starter")
423421

422+
raise ValueError("Expected a valid class description starter")
424423

425424
def _custom_readObject(self, class_name):
426425
self.__fd.seek(-1, os.SEEK_CUR)
427426
for transformer in self.__transformers:
428-
class_data = transformer.load_custom_writeObject(self, self.__reader, class_name)
427+
class_data = transformer.load_custom_writeObject(
428+
self, self.__reader, class_name
429+
)
429430
if class_data:
430431
return class_data
431432
raise ValueError("Custom readObject can not be processed")
432-
433-
433+
434434
def _read_class_annotations(self, class_desc=None):
435435
# type: () -> List[ParsedJavaContent]
436436
"""
@@ -494,8 +494,14 @@ def _do_object(self, type_code=0):
494494
return instance
495495

496496
def _is_default_supported(self, class_name):
497-
default_transf = [x for x in self.__transformers if isinstance(x, DefaultObjectTransformer)]
498-
return len(default_transf) and class_name in default_transf[0]._type_mapper
497+
default_transf = [
498+
x
499+
for x in self.__transformers
500+
if isinstance(x, DefaultObjectTransformer)
501+
]
502+
return (
503+
len(default_transf) and class_name in default_transf[0]._type_mapper
504+
)
499505

500506
def _read_class_data(self, instance):
501507
# type: (JavaInstance) -> None
@@ -512,11 +518,22 @@ def _read_class_data(self, instance):
512518
for cd in classes:
513519
values = {} # type: Dict[JavaField, Any]
514520
cd.validate()
515-
if cd.data_type == ClassDataType.NOWRCLASS or cd.data_type == ClassDataType.WRCLASS:
516-
read_custom_data = cd.data_type == ClassDataType.WRCLASS and cd.is_super_class and not self._is_default_supported(cd.name)
517-
if read_custom_data or cd.data_type == ClassDataType.WRCLASS and instance.is_external_instance:
521+
if (
522+
cd.data_type == ClassDataType.NOWRCLASS
523+
or cd.data_type == ClassDataType.WRCLASS
524+
):
525+
read_custom_data = (
526+
cd.data_type == ClassDataType.WRCLASS
527+
and cd.is_super_class
528+
and not self._is_default_supported(cd.name)
529+
)
530+
if (
531+
read_custom_data
532+
or cd.data_type == ClassDataType.WRCLASS
533+
and instance.is_external_instance
534+
):
518535
annotations[cd] = self._read_class_annotations(cd)
519-
else:
536+
else:
520537
for field in cd.fields:
521538
values[field] = self._read_field_value(field.type)
522539
all_data[cd] = values
@@ -568,7 +585,9 @@ def _read_field_value(self, field_type):
568585
if sub_type_code == TerminalCode.TC_REFERENCE:
569586
return self._do_classdesc(sub_type_code)
570587
elif sub_type_code != TerminalCode.TC_ARRAY:
571-
raise ValueError("Array type listed, but type code != TC_ARRAY")
588+
raise ValueError(
589+
"Array type listed, but type code != TC_ARRAY"
590+
)
572591

573592
content = self._read_content(sub_type_code, False)
574593
if content is not None and content.is_exception:

0 commit comments

Comments
 (0)