Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced all types that are either missing or deprecated in Python3 with suitable alternatives that are still compatible with Python2. #82

Merged
merged 18 commits into from
Dec 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
627c3fd
base/database: updated all references to the `basestring` class to in…
arizvisa Nov 25, 2020
6c247d9
base/segment: updated all references to the `basestring` class to ins…
arizvisa Nov 25, 2020
9d1ba1b
base/structure: updated all references to the `basestring` class to i…
arizvisa Nov 25, 2020
e546809
base/instruction: updated all references to the `basestring` class to…
arizvisa Nov 25, 2020
6d305d1
base/enumeration: updated all references to the `basestring` class to…
arizvisa Nov 25, 2020
458d590
base/function: updated all references to the `basestring` class to in…
arizvisa Nov 25, 2020
4bf7b64
internal/interface: updated all references to the `basestring` class …
arizvisa Nov 25, 2020
367cbc8
internal/utils: updated all references to the `basestring` class to i…
arizvisa Nov 25, 2020
516f112
custom/tags: updated all references to the `basestring` class to inst…
arizvisa Nov 25, 2020
7d4a3be
misc/ui: updated all references to the `basestring` class to instead …
arizvisa Nov 25, 2020
b8b3b68
internal/interface: deprecated all instances of `types.NoneType` from…
arizvisa Nov 26, 2020
4e0c625
base/structure: deprecated all instances of `types.NoneType` from the…
arizvisa Nov 26, 2020
e23529e
base/segment: deprecated all instances of `types.NoneType` from the m…
arizvisa Nov 26, 2020
07e4ba8
base/instruction: deprecated all instances of `types.NoneType` from t…
arizvisa Nov 26, 2020
6e2f07f
base/function: deprecated all instances of `types.NoneType` from the …
arizvisa Nov 26, 2020
d79f182
base/database: deprecated all instances of `types.NoneType` from the …
arizvisa Nov 26, 2020
ecb2af2
internal/utils: replaced all references to `types.TypeType` which is …
arizvisa Nov 26, 2020
bea4032
base/instruction: removed all unnecessary casts to the `long` type si…
arizvisa Dec 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions base/_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ def __repr__(self):
return "<class '{:s}' index={:d} dtype={:s} name='{!s}' position={:d}{:+d}>".format(cls.__name__, self.id, dt, internal.utils.string.escape(self.name, '\''), self.position, self.size)

def __eq__(self, other):
if isinstance(other, basestring):
if isinstance(other, six.string_types):
return self.name.lower() == other.lower()
elif isinstance(other, register_t):
return self is other
Expand Down Expand Up @@ -1186,7 +1186,7 @@ def use(cls, regs):
_instruction = sys.modules.get('instruction', __import__('instruction'))

# convert any regs that are strings into their correct object type
regs = { _instruction.architecture.by_name(r) if isinstance(r, basestring) else r for r in regs }
regs = { _instruction.architecture.by_name(r) if isinstance(r, six.string_types) else r for r in regs }

# returns an iterable of bools that returns whether r is a subset of any of the registers in `regs`.
match = lambda r, regs=regs: any(itertools.imap(r.relatedQ, regs))
Expand Down Expand Up @@ -1341,7 +1341,7 @@ class ref_t(namedtypedtuple):
optional as not all references will provide it.
"""
_fields = ('address', 'opnum', 'reftype')
_types = (six.integer_types, (six.integer_types, types.NoneType), reftype_t)
_types = (six.integer_types, (six.integer_types, None.__class__), reftype_t)

def __repr__(self):
cls = self.__class__
Expand Down
18 changes: 9 additions & 9 deletions base/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ def result(wrapped):

# validate type arguments
for n, t in t_args.iteritems():
if not isinstance(t, (types.TypeType, types.TupleType)) and t not in {callable}:
error_keywords = ("{:s}={!s}".format(n, t.__name__ if isinstance(t, types.TypeType) or t in {callable} else '|'.join(t_.__name__ for t_ in t) if hasattr(t, '__iter__') else "{!r}".format(t)) for n, t in t_args.iteritems())
if not isinstance(t, (builtins.type, builtins.tuple)) and t not in {callable}:
error_keywords = ("{:s}={!s}".format(n, t.__name__ if isinstance(t, builtins.type) or t in {callable} else '|'.join(t_.__name__ for t_ in t) if hasattr(t, '__iter__') else "{!r}".format(t)) for n, t in t_args.iteritems())
raise internal.exceptions.InvalidParameterError(u"@{:s}({:s}) : The value ({!s}) specified for parameter \"{:s}\" is not a supported type.".format('.'.join([__name__, cls.__name__]), ', '.join(error_keywords), t, string.escape(n, '"')))
continue

Expand All @@ -214,12 +214,12 @@ def result(wrapped):
for c in other:
cls.ex_function(c)
except:
error_keywords = ("{:s}={!s}".format(n, t.__name__ if isinstance(t, types.TypeType) or t in {callable} else '|'.join(t_.__name__ for t_ in t) if hasattr(t, '__iter__') else "{!r}".format(t)) for n, t in t_args.iteritems())
error_keywords = ("{:s}={!s}".format(n, t.__name__ if isinstance(t, builtins.type) or t in {callable} else '|'.join(t_.__name__ for t_ in t) if hasattr(t, '__iter__') else "{!r}".format(t)) for n, t in t_args.iteritems())
raise internal.exceptions.InvalidParameterError(u"@{:s}({:s}) : The specified callable{:s} {!r} {:s} not of a valid type.".format('.'.join([__name__, cls.__name__]), ', '.join(error_keywords), '' if len(other) == 1 else 's', other, 'is' if len(other) == 1 else 'are'))

# throw an exception if we were given an unexpected number of arguments
if len(other) > 1:
error_keywords = ("{:s}={!s}".format(n, t.__name__ if isinstance(t, types.TypeType) or t in {callable} else '|'.join(t_.__name__ for t_ in t) if hasattr(t, '__iter__') else "{!r}".format(t)) for n, t in t_args.iteritems())
error_keywords = ("{:s}={!s}".format(n, t.__name__ if isinstance(t, builtins.type) or t in {callable} else '|'.join(t_.__name__ for t_ in t) if hasattr(t, '__iter__') else "{!r}".format(t)) for n, t in t_args.iteritems())
raise internal.exceptions.InvalidParameterError(u"@{:s}({:s}) : More than one callable ({:s}) was specified to add a case to. Refusing to add cases to more than one callable.".format('.'.join([__name__, cls.__name__]), ', '.join(error_keywords), ', '.join("\"{:s}\"".format(string.escape(c.co_name if isinstance(c, types.CodeType) else c.__name__, '"')) for c in other)))
return result

Expand Down Expand Up @@ -260,7 +260,7 @@ def Fargsiter(names=args, values=parameters):
continue

param_type = parameters[item]
if isinstance(param_type, types.TypeType) or param_type in {callable}:
if isinstance(param_type, builtins.type) or param_type in {callable}:
yield item, param_type.__name__
elif hasattr(param_type, '__iter__'):
yield item, '|'.join(t.__name__ for t in flatten(param_type))
Expand Down Expand Up @@ -379,7 +379,7 @@ def reconstructor(cls, n):
return lambda f: type(n)(f)
if isinstance(n, types.InstanceType):
return lambda f: types.InstanceType(type(n), dict(f.__dict__))
if isinstance(n, (types.TypeType, types.ClassType)):
if isinstance(n, (builtins.type, types.ClassType)):
return lambda f: type(n)(n.__name__, n.__bases__, dict(f.__dict__))
raise internal.exceptions.InvalidTypeOrValueError(type(n))

Expand Down Expand Up @@ -436,7 +436,7 @@ def __init__(self):
def __attrib__(self, *attribute):
if not attribute:
return lambda n: n
res = [(operator.attrgetter(a) if isinstance(a, basestring) else a) for a in attribute]
res = [(operator.attrgetter(a) if isinstance(a, six.string_types) else a) for a in attribute]
return lambda o: tuple(x(o) for x in res) if len(res) > 1 else res[0](o)
def attribute(self, type, *attribute):
attr = self.__attrib__(*attribute)
Expand Down Expand Up @@ -756,7 +756,7 @@ def repr(cls, item):
All unicode strings are encoded to UTF-8 in order to guarantee
the resulting string can be emitted.
"""
if isinstance(item, basestring):
if isinstance(item, six.string_types):
res = cls.escape(item, '\'')
if all(six.byte2int(ch) < 0x100 for ch in item):
return "'{:s}'".format(res)
Expand Down Expand Up @@ -1006,7 +1006,7 @@ def constructor(cls, callable):
return lambda method, mt=callable.__class__: types.InstanceType(mt, dict(method.__dict__))

# otherwise if it's a class or a type, then we just need to create the object with its bases
elif isinstance(n, (types.TypeType, types.ClassType)):
elif isinstance(n, (builtins.type, types.ClassType)):
return lambda method, t=callable.__class__, name=callable.__name__, bases=callable.__bases__: t(name, bases, dict(method.__dict__))

# if we get here, then we have no idea what kind of type `callable` is
Expand Down
Loading