1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-06-06 20:29:34 +00:00

Fix hexdump loader for Python 3

This commit is contained in:
Mike Naberezny 2013-10-26 16:51:49 -07:00
parent 0a4663c875
commit ab4688c64c

View File

@ -44,7 +44,11 @@ class Loader:
def _parse_address(self, piece):
try:
addr_bytes = [ord(c) for c in a2b_hex(piece)]
binstr = a2b_hex(piece.encode('utf-8'))
if isinstance(binstr, str):
addr_bytes = [ ord(b) for b in binstr ]
else: # Python 3
addr_bytes = [ b for b in binstr ]
except (TypeError, ValueError):
msg = "Could not parse address: %s" % piece
raise ValueError(msg)
@ -73,10 +77,14 @@ class Loader:
else:
try:
bytes = [ord(c) for c in a2b_hex(piece)]
binstr = a2b_hex(piece.encode('utf-8'))
if isinstance(binstr, str):
data_bytes = [ ord(b) for b in binstr ]
else: # Python 3
data_bytes = [ b for b in binstr ]
except (TypeError, ValueError):
msg = "Could not parse data: %s" % piece
raise ValueError(msg)
self.current_address += len(bytes)
self.data.extend(bytes)
self.current_address += len(data_bytes)
self.data.extend(data_bytes)