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
'''
if not isinstance(bs, bytes):
if sys.version_info.major < 3:
bs = bytes(bs)
else:
bs = bytes(map(lambda c: ord(c), bs))
if isinstance(bs, str) and sys.version_info.major >= 3:
bs = bytes(map(lambda c: ord(c), bs))
elif not isinstance(bs, bytes):
raise TypeError("expected bs to be either 'str' or 'bytes' but got %s" % type(bs))
code = api.llvm.StringRefMemoryObject.new(bs, base_addr)
idx = 0