Skip to content

Commit

Permalink
Implement bytes.hex() myself as it is not included in Python 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
iafisher committed Feb 13, 2019
1 parent b3d5909 commit 39d3c93
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions hera/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def main_assemble(path: str, settings: Settings) -> None:
program = load_program_from_file(path, settings)
raw_code, raw_data = assemble(program)

code = "\n".join(b.hex() for b in raw_code)
data = "\n".join(b.hex() for b in raw_data)
code = "\n".join(bytes_to_hex(b) for b in raw_code)
data = "\n".join(bytes_to_hex(b) for b in raw_data)

if settings.stdout:
if settings.data:
Expand Down Expand Up @@ -256,6 +256,14 @@ def dump_state(vm, settings):
nprint("\n{} warning{} emitted.".format(c, "" if c == 1 else "s"))


def bytes_to_hex(b):
try:
return b.hex()
except AttributeError:
# bytes.hex is not implemented in Python 3.4.
return "".join("{:0>2x}".format(c) for c in b)


FLAGS = {
"--big-stack",
"--code",
Expand Down

0 comments on commit 39d3c93

Please sign in to comment.