def parse(script): f = script, 0 while pack.size(f): opcode_str, f = pack.read(f, 1) opcode = ord(opcode_str) opcode_name, read_func = opcodes[opcode] opcode_arg, f = read_func(f) yield opcode_name, opcode_arg
def read(self, file): obj, file = self.inner.read(file) data = self.inner.pack(obj) calculated_checksum = self.checksum_func(data) checksum, file = pack.read(file, len(calculated_checksum)) if checksum != calculated_checksum: raise ValueError('invalid checksum') return obj, file
def protoPUSH(length): return lambda f: pack.read(f, length)
def _(f): length_str, f = pack.read(f, size_len) length = math.string_to_natural(length_str[::-1].lstrip(chr(0))) data, f = pack.read(f, length) return data, f