| 785 | yield CScriptOp(opcode) |
| 786 | |
| 787 | def __repr__(self): |
| 788 | # For Python3 compatibility add b before strings so testcases don't |
| 789 | # need to change |
| 790 | def _repr(o): |
| 791 | if isinstance(o, bytes): |
| 792 | return b"x('%s')" % hexlify(o).decode('ascii') |
| 793 | else: |
| 794 | return repr(o) |
| 795 | |
| 796 | ops = [] |
| 797 | i = iter(self) |
| 798 | while True: |
| 799 | op = None |
| 800 | try: |
| 801 | op = _repr(next(i)) |
| 802 | except CScriptTruncatedPushDataError as err: |
| 803 | op = '%s...<ERROR: %s>' % (_repr(err.data), err) |
| 804 | break |
| 805 | except CScriptInvalidError as err: |
| 806 | op = '<ERROR: %s>' % err |
| 807 | break |
| 808 | except StopIteration: |
| 809 | break |
| 810 | finally: |
| 811 | if op is not None: |
| 812 | ops.append(op) |
| 813 | |
| 814 | return "CScript([%s])" % ', '.join(ops) |
| 815 | |
| 816 | def GetSigOpCount(self, fAccurate): |
| 817 | """Get the SigOp count. |