Skip to content

Commit

Permalink
Threw a dryer sheet into the code.
Browse files Browse the repository at this point in the history
(i.e., removed some code lint)
  • Loading branch information
freakboy3742 committed Dec 17, 2016
1 parent 2f8e5e1 commit b733f45
Show file tree
Hide file tree
Showing 18 changed files with 1,344 additions and 379 deletions.
21 changes: 11 additions & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[isort]
combine_as_imports = true
default_section = THIRDPARTY
include_trailing_comma = true
line_length = 79
multi_line_output = 5
not_skip = __init__.py
known_standard_library = marshal
known_first_party = voc
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
[flake8]
# https://flake8.readthedocs.org/en/latest/
exclude=settings.py,wsgi.py,manage.py,*/migrations/*
max-complexity = 10
max-line-length = 119
[metadata]
description-file = README.md
[pep8]
# https://pep8.readthedocs.org/en/latest/
# W503 raised if operators are after line break
ignore = W503
1 change: 1 addition & 0 deletions voc/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ def main():
verbosity=args.verbosity
)


if __name__ == '__main__':
main()
12 changes: 6 additions & 6 deletions voc/java/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import codecs

from . import mutf_8
from .attributes import *
from .constants import *
from .fields import Field
from .klass import Class
from .methods import Method
from .opcodes import *
from .attributes import * # noqa
from .constants import * # noqa
from .fields import Field # noqa
from .klass import Class # noqa
from .methods import Method # noqa
from .opcodes import * # noqa

# Register the MUTF-8 codec
codecs.register(mutf_8.search_function)
1 change: 1 addition & 0 deletions voc/java/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def dump(filename):
with open(filename, 'rb') as infile:
Class.read(infile, debug=sys.stdout)


if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: voc.java <path to .class file>")
Expand Down
338 changes: 261 additions & 77 deletions voc/java/attributes.py

Large diffs are not rendered by default.

93 changes: 74 additions & 19 deletions voc/java/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

def multieq(obj1, obj2, *attrs):
"Compare two objects using the provided attributes"
return type(obj1) == type(obj2) and all(getattr(obj1, attr) == getattr(obj2, attr) for attr in attrs)
return (
type(obj1) == type(obj2)
and all(getattr(obj1, attr) == getattr(obj2, attr) for attr in attrs)
)


def multihash(obj, *attrs):
Expand Down Expand Up @@ -322,7 +325,12 @@ def __repr__(self):
return '<Fieldref %s.%s (%s)>' % (self.class_name, self.name, self.descriptor)

def __eq__(self, other):
return isinstance(other, Fieldref) and other.tag == self.tag and other.klass == self.klass and other.name_and_type == self.name_and_type
return (
isinstance(other, Fieldref)
and other.tag == self.tag
and other.klass == self.klass
and other.name_and_type == self.name_and_type
)

def __hash__(self):
return multihash(self, 'tag', 'klass', 'name_and_type')
Expand Down Expand Up @@ -394,7 +402,12 @@ def __repr__(self):
return '<Methodref %s.%s %s>' % (self.class_name, self.name, self.name_and_type.descriptor)

def __eq__(self, other):
return isinstance(other, Methodref) and other.tag == self.tag and other.klass == self.klass and other.name_and_type == self.name_and_type
return (
isinstance(other, Methodref)
and other.tag == self.tag
and other.klass == self.klass
and other.name_and_type == self.name_and_type
)

def __hash__(self):
return multihash(self, 'tag', 'klass', 'name_and_type')
Expand Down Expand Up @@ -455,7 +468,12 @@ def __repr__(self):
return '<InterfaceMethodref %s.%s %s>' % (self.class_name, self.name, self.name_and_type.descriptor)

def __eq__(self, other):
return isinstance(other, InterfaceMethodref) and other.tag == self.tag and other.klass == self.klass and other.name_and_type == self.name_and_type
return (
isinstance(other, InterfaceMethodref)
and other.tag == self.tag
and other.klass == self.klass
and other.name_and_type == self.name_and_type
)

def __hash__(self):
return multihash(self, 'tag', 'klass', 'name_and_type')
Expand Down Expand Up @@ -779,7 +797,12 @@ def __repr__(self):
return '<NameAndType: name:%s descriptor:%s>' % (self.name, self.descriptor)

def __eq__(self, other):
return isinstance(other, NameAndType) and other.tag == self.tag and other.name == self.name and other.descriptor == self.descriptor
return (
isinstance(other, NameAndType)
and other.tag == self.tag
and other.name == self.name
and other.descriptor == self.descriptor
)

def __hash__(self):
return multihash(self, 'tag', 'name', 'descriptor')
Expand Down Expand Up @@ -987,23 +1010,41 @@ def bytes(self):
# The items of the CONSTANT_MethodHandle_info structure are the following:

# tag
# The tag item of the CONSTANT_MethodHandle_info structure has the value CONSTANT_MethodHandle (15).
# The tag item of the CONSTANT_MethodHandle_info structure has the value
# CONSTANT_MethodHandle (15).

# reference_kind
# The value of the reference_kind item must be in the range 1 to 9. The value denotes the kind of this method handle, which characterizes its bytecode behavior (§5.4.3.5).
# The value of the reference_kind item must be in the range 1 to 9. The value
# denotes the kind of this method handle, which characterizes its bytecode
# behavior (§5.4.3.5).

# reference_index
# The value of the reference_index item must be a valid index into the constant_pool table.
# The value of the reference_index item must be a valid index into the
# constant_pool table.

# If the value of the reference_kind item is 1 (REF_getField), 2 (REF_getStatic), 3 (REF_putField), or 4 (REF_putStatic), then the constant_pool entry at that index must be a CONSTANT_Fieldref_info (§4.4.2) structure representing a field for which a method handle is to be created.
# If the value of the reference_kind item is 1 (REF_getField), 2
# (REF_getStatic), 3 (REF_putField), or 4 (REF_putStatic), then the
# constant_pool entry at that index must be a CONSTANT_Fieldref_info (§4.4.2)
# structure representing a field for which a method handle is to be created.

# If the value of the reference_kind item is 5 (REF_invokeVirtual), 6 (REF_invokeStatic), 7 (REF_invokeSpecial), or 8 (REF_newInvokeSpecial), then the constant_pool entry at that index must be a CONSTANT_Methodref_info structure (§4.4.2) representing a class's method or constructor (§2.9) for which a method handle is to be created.
# If the value of the reference_kind item is 5 (REF_invokeVirtual), 6
# (REF_invokeStatic), 7 (REF_invokeSpecial), or 8 (REF_newInvokeSpecial), then
# the constant_pool entry at that index must be a CONSTANT_Methodref_info
# structure (§4.4.2) representing a class's method or constructor (§2.9) for
# which a method handle is to be created.

# If the value of the reference_kind item is 9 (REF_invokeInterface), then the constant_pool entry at that index must be a CONSTANT_InterfaceMethodref_info (§4.4.2) structure representing an interface's method for which a method handle is to be created.
# If the value of the reference_kind item is 9 (REF_invokeInterface), then the
# constant_pool entry at that index must be a CONSTANT_InterfaceMethodref_info
# (§4.4.2) structure representing an interface's method for which a method
# handle is to be created.

# If the value of the reference_kind item is 5 (REF_invokeVirtual), 6 (REF_invokeStatic), 7 (REF_invokeSpecial), or 9 (REF_invokeInterface), the name of the method represented by a CONSTANT_Methodref_info structure must not be <init> or <clinit>.
# If the value of the reference_kind item is 5 (REF_invokeVirtual), 6
# (REF_invokeStatic), 7 (REF_invokeSpecial), or 9 (REF_invokeInterface), the
# name of the method represented by a CONSTANT_Methodref_info structure must
# not be <init> or <clinit>.

# If the value is 8 (REF_newInvokeSpecial), the name of the method represented by a CONSTANT_Methodref_info structure must be <init>.
# If the value is 8 (REF_newInvokeSpecial), the name of the method represented
# by a CONSTANT_Methodref_info structure must be <init>.

# ------------------------------------------------------------------------
# 4.4.9. The CONSTANT_MethodType_info Structure
Expand All @@ -1018,16 +1059,24 @@ def bytes(self):
# The items of the CONSTANT_MethodType_info structure are as follows:

# tag
# The tag item of the CONSTANT_MethodType_info structure has the value CONSTANT_MethodType (16).
# The tag item of the CONSTANT_MethodType_info structure has the value
# CONSTANT_MethodType (16).

# descriptor_index
# The value of the descriptor_index item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Utf8_info (§4.4.7) structure representing a method descriptor (§4.3.3).
# The value of the descriptor_index item must be a valid index into the
# constant_pool table. The constant_pool entry at that index must be a
# CONSTANT_Utf8_info (§4.4.7) structure representing a method descriptor
# (§4.3.3).

# ------------------------------------------------------------------------
# 4.4.10. The CONSTANT_InvokeDynamic_info Structure
# ------------------------------------------------------------------------

# The CONSTANT_InvokeDynamic_info structure is used by an invokedynamic instruction (§invokedynamic) to specify a bootstrap method, the dynamic invocation name, the argument and return types of the call, and optionally, a sequence of additional constants called static arguments to the bootstrap method.
# The CONSTANT_InvokeDynamic_info structure is used by an invokedynamic
# instruction (§invokedynamic) to specify a bootstrap method, the dynamic
# invocation name, the argument and return types of the call, and optionally, a
# sequence of additional constants called static arguments to the bootstrap
# method.

# CONSTANT_InvokeDynamic_info {
# u1 tag;
Expand All @@ -1037,10 +1086,16 @@ def bytes(self):
# The items of the CONSTANT_InvokeDynamic_info structure are as follows:

# tag
# The tag item of the CONSTANT_InvokeDynamic_info structure has the value CONSTANT_InvokeDynamic (18).
# The tag item of the CONSTANT_InvokeDynamic_info structure has the value
# CONSTANT_InvokeDynamic (18).

# bootstrap_method_attr_index
# The value of the bootstrap_method_attr_index item must be a valid index into the bootstrap_methods array of the bootstrap method table (§4.7.21) of this class file.
# The value of the bootstrap_method_attr_index item must be a valid index into
# the bootstrap_methods array of the bootstrap method table (§4.7.21) of this
# class file.

# name_and_type_index
# The value of the name_and_type_index item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_NameAndType_info (§4.4.6) structure representing a method name and method descriptor (§4.3.3).
# The value of the name_and_type_index item must be a valid index into the
# constant_pool table. The constant_pool entry at that index must be a
# CONSTANT_NameAndType_info (§4.4.6) structure representing a method name and
# method descriptor (§4.3.3).
4 changes: 3 additions & 1 deletion voc/java/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ def read(reader, dump=None):
('enum', Field.ACC_ENUM),
]
] if f)
reader.debug(" " * dump, ' Flags: 0x%04x%s' % (access_flags, ' (%s)') % access_description if access_description else '')
reader.debug(" " * dump, ' Flags: 0x%04x%s' % (access_flags, ' (%s)') % (
access_description if access_description else ''
))

reader.debug(" " * dump, ' Attributes: (%s)' % attributes_count)

Expand Down
8 changes: 6 additions & 2 deletions voc/java/klass.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ def read(infile, debug=None):
('enum', Class.ACC_ENUM),
]
] if f)
reader.debug(" " * dump, ' Flags: 0x%04x%s' % (access_flags, ' (%s)') % (access_description if access_description else ''))
reader.debug(" " * dump, ' Flags: 0x%04x%s' % (access_flags, ' (%s)') % (
access_description if access_description else ''
))

interfaces_count = reader.read_u2()
if dump is not None:
Expand Down Expand Up @@ -518,7 +520,9 @@ def attributes_count(self):

class Class(BaseClass):
def __init__(self, name, extends=None, implements=None, public=True, final=False, abstract=False):
super(Class, self).__init__(name, extends, implements=implements, public=public, final=final, abstract=abstract)
super(Class, self).__init__(
name, extends, implements=implements, public=public, final=final, abstract=abstract
)


class Interface(BaseClass):
Expand Down
4 changes: 3 additions & 1 deletion voc/java/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ def read(reader, dump=None):
('synthetic', Method.ACC_SYNTHETIC),
]
] if f)
reader.debug(" " * dump, ' Flags: 0x%04x%s' % (access_flags, ' (%s)') % (access_description if access_description else ''))
reader.debug(" " * dump, ' Flags: 0x%04x%s' % (access_flags, ' (%s)') % (
access_description if access_description else ''
))

reader.debug(" " * dump, ' Attributes: (%s)' % attributes_count)

Expand Down
2 changes: 1 addition & 1 deletion voc/java/mutf_8.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def decode(self, input, errors='strict'):
return self.decoder.decode(input, final=False), len(input)


### encodings module API
# encodings module API

def search_function(encoding):
if normalize_encoding(encoding) == 'mutf_8':
Expand Down
Loading

0 comments on commit b733f45

Please sign in to comment.