Skip to content

Commit 4617ca9

Browse files
committed
Removed PyDev warnings (unused locals, ...)
1 parent 346a6cc commit 4617ca9

File tree

1 file changed

+50
-32
lines changed

1 file changed

+50
-32
lines changed

javaobj.py

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@
4848
import struct
4949
import sys
5050

51-
if sys.version_info[0] < 3:
51+
try:
5252
# Python 2
5353
from StringIO import StringIO as BytesIO
5454

55-
else:
55+
except ImportError:
5656
# Python 3+
5757
from io import BytesIO
5858

@@ -350,7 +350,8 @@ def __init__(self, stream=None):
350350
self.TC_BLOCKDATA: self.do_blockdata,
351351
self.TC_REFERENCE: self.do_reference,
352352
self.TC_ENUM: self.do_enum,
353-
self.TC_ENDBLOCKDATA: self.do_null, # note that we are reusing of do_null
353+
# note that we are reusing do_null:
354+
self.TC_ENDBLOCKDATA: self.do_null,
354355
}
355356
self.current_object = None
356357
self.reference_counter = 0
@@ -365,7 +366,8 @@ def readObject(self):
365366
Reads an object from the input stream
366367
"""
367368
try:
368-
opcode, res = self._read_and_exec_opcode(ident=0) # TODO: add expects
369+
# TODO: add expects
370+
_, res = self._read_and_exec_opcode(ident=0)
369371

370372
position_bak = self.object_stream.tell()
371373
the_rest = self.object_stream.read()
@@ -502,9 +504,10 @@ def do_classdesc(self, parent=None, ident=0):
502504

503505
self._add_reference(clazz)
504506

505-
log_debug("Serial: 0x%X newHandle: 0x%X. classDescFlags: 0x%X" % (serialVersionUID, newHandle, classDescFlags), ident)
507+
log_debug("Serial: 0x{0:X} newHandle: 0x{1:X}. classDescFlags: 0x{2:X}"\
508+
.format(serialVersionUID, newHandle, classDescFlags), ident)
506509
(length,) = self._readStruct(">H")
507-
log_debug("Fields num: 0x%X" % length, ident)
510+
log_debug("Fields num: 0x{0:X}".format(length), ident)
508511

509512
clazz.fields_names = []
510513
clazz.fields_types = []
@@ -515,32 +518,44 @@ def do_classdesc(self, parent=None, ident=0):
515518
field_type = self._convert_char_to_type(typecode)
516519

517520
if field_type == self.TYPE_ARRAY:
518-
opcode, field_type = self._read_and_exec_opcode(ident=ident + 1, expect=[self.TC_STRING, self.TC_REFERENCE])
521+
_, field_type = self._read_and_exec_opcode(ident=ident + 1,
522+
expect=(self.TC_STRING,
523+
self.TC_REFERENCE))
519524
assert type(field_type) is str
520525
# if field_type is not None:
521526
# field_type = "array of " + field_type
522527
# else:
523528
# field_type = "array of None"
529+
524530
elif field_type == self.TYPE_OBJECT:
525-
opcode, field_type = self._read_and_exec_opcode(ident=ident + 1, expect=[self.TC_STRING, self.TC_REFERENCE])
531+
_, field_type = self._read_and_exec_opcode(ident=ident + 1,
532+
expect=(self.TC_STRING,
533+
self.TC_REFERENCE))
526534
assert type(field_type) is str
527535

528-
log_debug("FieldName: 0x%X" % typecode + " " + str(field_name) + " " + str(field_type), ident)
536+
log_debug("FieldName: 0x{0:X} Name:{1} Type:{2} ID:{3}"\
537+
.format(typecode, field_name, field_type, fieldId), ident)
529538
assert field_name is not None
530539
assert field_type is not None
531540

532541
clazz.fields_names.append(field_name)
533542
clazz.fields_types.append(field_type)
543+
534544
if parent:
535545
parent.__fields = clazz.fields_names
536546
parent.__types = clazz.fields_types
547+
537548
# classAnnotation
538549
(opid,) = self._readStruct(">B")
539-
log_debug("OpCode: 0x%X" % opid, ident)
550+
log_debug("OpCode: 0x{0:X}".format(opid), ident)
540551
if opid != self.TC_ENDBLOCKDATA:
541552
raise NotImplementedError("classAnnotation isn't implemented yet")
553+
542554
# superClassDesc
543-
opcode, superclassdesc = self._read_and_exec_opcode(ident=ident + 1, expect=[self.TC_CLASSDESC, self.TC_NULL, self.TC_REFERENCE])
555+
_, superclassdesc = self._read_and_exec_opcode(ident=ident + 1,
556+
expect=(self.TC_CLASSDESC,
557+
self.TC_NULL,
558+
self.TC_REFERENCE))
544559
log_debug(str(superclassdesc), ident)
545560
clazz.superclass = superclassdesc
546561

@@ -574,8 +589,9 @@ def do_class(self, parent=None, ident=0):
574589
# TC_CLASS classDesc newHandle
575590
log_debug("[class]", ident)
576591

577-
# TODO: what to do with "(ClassDesc)prevObject". (see 3rd line for classDesc:)
578-
opcode, classdesc = self._read_and_exec_opcode(ident=ident + 1,
592+
# TODO: what to do with "(ClassDesc)prevObject".
593+
# (see 3rd line for classDesc:)
594+
_, classdesc = self._read_and_exec_opcode(ident=ident + 1,
579595
expect=(self.TC_CLASSDESC,
580596
self.TC_PROXYCLASSDESC,
581597
self.TC_NULL,
@@ -599,7 +615,8 @@ def do_object(self, parent=None, ident=0):
599615
log_debug("java_object.annotations just after instantiation: {0}"\
600616
.format(java_object.annotations), ident)
601617

602-
# TODO: what to do with "(ClassDesc)prevObject". (see 3rd line for classDesc:)
618+
# TODO: what to do with "(ClassDesc)prevObject".
619+
# (see 3rd line for classDesc:)
603620
opcode, classdesc = self._read_and_exec_opcode(ident=ident + 1,
604621
expect=(self.TC_CLASSDESC,
605622
self.TC_PROXYCLASSDESC,
@@ -616,7 +633,8 @@ def do_object(self, parent=None, ident=0):
616633

617634
if classdesc.flags & self.SC_EXTERNALIZABLE \
618635
and not classdesc.flags & self.SC_BLOCK_DATA:
619-
raise NotImplementedError("externalContents isn't implemented yet") # TODO:
636+
# TODO:
637+
raise NotImplementedError("externalContents isn't implemented yet")
620638

621639
if classdesc.flags & self.SC_SERIALIZABLE:
622640
# create megalist
@@ -699,11 +717,11 @@ def do_array(self, parent=None, ident=0):
699717
"""
700718
# TC_ARRAY classDesc newHandle (int)<size> values[size]
701719
log_debug("[array]", ident)
702-
opcode, classdesc = self._read_and_exec_opcode(ident=ident + 1,
703-
expect=(self.TC_CLASSDESC,
704-
self.TC_PROXYCLASSDESC,
705-
self.TC_NULL,
706-
self.TC_REFERENCE))
720+
_, classdesc = self._read_and_exec_opcode(ident=ident + 1,
721+
expect=(self.TC_CLASSDESC,
722+
self.TC_PROXYCLASSDESC,
723+
self.TC_NULL,
724+
self.TC_REFERENCE))
707725

708726
array = []
709727

@@ -717,12 +735,12 @@ def do_array(self, parent=None, ident=0):
717735
type_char = classdesc.name[1]
718736

719737
if type_char == self.TYPE_OBJECT or type_char == self.TYPE_ARRAY:
720-
for i in range(size):
721-
opcode, res = self._read_and_exec_opcode(ident=ident + 1)
738+
for _ in range(size):
739+
_, res = self._read_and_exec_opcode(ident=ident + 1)
722740
log_debug("Object value: {0}".format(res), ident)
723741
array.append(res)
724742
else:
725-
for i in range(size):
743+
for _ in range(size):
726744
res = self._read_value(type_char, ident)
727745
log_debug("Native value: {0}".format(res), ident)
728746
array.append(res)
@@ -764,13 +782,13 @@ def do_enum(self, parent=None, ident=0):
764782
"""
765783
# TC_ENUM classDesc newHandle enumConstantName
766784
enum = JavaObject()
767-
opcode, classdesc = self._read_and_exec_opcode(ident=ident + 1,
768-
expect=(self.TC_CLASSDESC,
769-
self.TC_PROXYCLASSDESC,
770-
self.TC_NULL,
771-
self.TC_REFERENCE))
785+
_, _ = self._read_and_exec_opcode(ident=ident + 1,
786+
expect=(self.TC_CLASSDESC,
787+
self.TC_PROXYCLASSDESC,
788+
self.TC_NULL,
789+
self.TC_REFERENCE))
772790
self._add_reference(enum)
773-
opcode, enumConstantName = self._read_and_exec_opcode(ident=ident + 1,
791+
_, enumConstantName = self._read_and_exec_opcode(ident=ident + 1,
774792
expect=(self.TC_STRING,
775793
self.TC_REFERENCE))
776794
return enumConstantName
@@ -831,7 +849,7 @@ def _read_value(self, field_type, ident, name=""):
831849
elif field_type == self.TYPE_DOUBLE:
832850
(res,) = self._readStruct(">d")
833851
elif field_type == self.TYPE_OBJECT or field_type == self.TYPE_ARRAY:
834-
opcode, res = self._read_and_exec_opcode(ident=ident + 1)
852+
_, res = self._read_and_exec_opcode(ident=ident + 1)
835853
else:
836854
raise RuntimeError("Unknown typecode: {0}".format(field_type))
837855

@@ -853,7 +871,7 @@ def _convert_char_to_type(self, type_char):
853871
if typecode in self.TYPECODES_LIST:
854872
return typecode
855873
else:
856-
raise RuntimeError("Typecode {0} ({1}) isn't supported."\
874+
raise RuntimeError("Typecode {0} ({1}) isn't supported." \
857875
.format(type_char, typecode))
858876

859877

@@ -973,7 +991,7 @@ def write_blockdata(self, obj, parent=None):
973991
self._writeStruct(">B", 1, (len(obj),))
974992
self.object_stream.write(obj)
975993
else:
976-
log_error("Not a str blockdata: %r" % obj)
994+
log_error("Not a str blockdata: {0:r}".format(obj))
977995

978996

979997
def write_object(self, obj, parent=None):

0 commit comments

Comments
 (0)