only convert input bytes if they are a string and we are in python 3

in python 2 'str' and 'bytes' are the same. if input bytes are not
a string or bytes, then raise a TypeError.
This commit is contained in:
anthony cantor 2013-09-05 17:29:25 -06:00 • committed by Siu Kwan Lam
commit 3743146121

View file

@ -194,11 +194,10 @@ class Disassembler(object):
llvm.mc.Instr llvm.mc.Instr
''' '''
if not isinstance(bs, bytes): if isinstance(bs, str) and sys.version_info.major >= 3:
if sys.version_info.major < 3: bs = bytes(map(lambda c: ord(c), bs))
bs = bytes(bs) elif not isinstance(bs, bytes):
else: raise TypeError("expected bs to be either 'str' or 'bytes' but got %s" % type(bs))
bs = bytes(map(lambda c: ord(c), bs))
code = api.llvm.StringRefMemoryObject.new(bs, base_addr) code = api.llvm.StringRefMemoryObject.new(bs, base_addr)
idx = 0 idx = 0