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

using types directly for python2/3 cross compatibility #101

Merged
merged 1 commit into from Jun 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions python/distorm3/__init__.py
Expand Up @@ -30,6 +30,9 @@
from os import name as os_name
import sys

if sys.version_info[0] >= 3:
xrange = range

#==============================================================================
# Load the diStorm DLL

Expand Down Expand Up @@ -550,8 +553,8 @@ def DecodeGenerator(codeOffset, code, dt):
di = result[index]
asm = di.mnemonic.p
if len(di.operands.p):
asm += " " + di.operands.p
pydi = (di.offset, di.size, asm, di.instructionHex.p)
asm += b" " + di.operands.p
pydi = (di.offset, di.size, asm.decode(), di.instructionHex.p.decode())
instruction_off += di.size
yield pydi

Expand Down Expand Up @@ -677,7 +680,7 @@ def _getFC(metaflags):
try:
return FlowControlFlags[realvalue]
except IndexError:
print ("Bad meta-flags: %d", realvalue)
print ("Bad meta-flags: {}".format(realvalue))
raise

def _getMnem(opcode):
Expand Down
8 changes: 3 additions & 5 deletions setup.py
Expand Up @@ -26,8 +26,6 @@
from distutils.core import setup, Extension
from distutils.errors import DistutilsSetupError

from types import ListType, StringType, TupleType

from shutil import ignore_patterns

def get_sources():
Expand Down Expand Up @@ -70,16 +68,16 @@ def finalize_options (self):

if self.include_dirs is None:
self.include_dirs = self.distribution.include_dirs or []
if type(self.include_dirs) is StringType:
if type(self.include_dirs) in (bytes, str):
self.include_dirs = string.split(self.include_dirs,
os.pathsep)

def get_source_files_for_lib(self, lib_name, build_info):
sources = build_info.get('sources', [])
if callable(sources):
sources = sources()
if (sources is None or
type(sources) not in (ListType, TupleType) or
if (sources is None or
type(sources) not in (list, tuple) or
len(sources) == 0):
raise DistutilsSetupError ("in 'libraries' option (library '%s'), 'sources' must be present and must be a list of source filenames") % lib_name
return sources
Expand Down