Skip to content

Commit 2e556c6

Browse files
committed
PEP479 - Python 3.7 support
1 parent 1aec6a0 commit 2e556c6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pyevmasm/evmasm.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,6 @@ def assemble_all(asmcode, pc=0):
586586
''')
587587
588588
"""
589-
590589
asmcode = asmcode.split('\n')
591590
asmcode = iter(asmcode)
592591
for line in asmcode:
@@ -618,7 +617,10 @@ def disassemble_one(bytecode, pc=0):
618617
bytecode = bytearray(bytecode.encode('latin-1'))
619618

620619
bytecode = iter(bytecode)
621-
opcode = next(bytecode)
620+
try:
621+
opcode = next(bytecode)
622+
except StopIteration:
623+
return
622624

623625
assert isinstance(opcode, int)
624626

@@ -669,6 +671,8 @@ def disassemble_all(bytecode, pc=0):
669671
bytecode = iter(bytecode)
670672
while True:
671673
instr = disassemble_one(bytecode, pc=pc)
674+
if not instr:
675+
return
672676
pc += instr.size
673677
yield instr
674678

@@ -751,7 +755,7 @@ def assemble_hex(asmcode, pc=0):
751755
""" Assemble an EVM program
752756
753757
:param asmcode: an evm assembler program
754-
:type asmcode: str
758+
:type asmcode: str | iterator[Instruction]
755759
:param pc: program counter of the first instruction(optional)
756760
:type pc: int
757761
:return: the hex representation of the bytecode
@@ -768,4 +772,6 @@ def assemble_hex(asmcode, pc=0):
768772
...
769773
"0x6060604052600261010"
770774
"""
775+
if isinstance(asmcode, list):
776+
return '0x' + hexlify(b''.join([x.bytes for x in asmcode])).decode('ascii')
771777
return '0x' + hexlify(assemble(asmcode, pc=pc)).decode('ascii')

0 commit comments

Comments
 (0)