def __init__(self, data, memory=b'\x00', memory_pointer=0): ''' Parse, execute and store output of code in data ''' try: # Process the input and convert it to dict() self.data = self.process_input(data) except (OSError, IOError, TypeError, ValueError, IndexError) as e: std.exit_failure("BF_PROCESS_INPUT", \ std.create_error_msg("PYTHON", e)) try: # Execute the programme in self.data self.output, self.memory, self.memory_pointer = \ self.execute_code(self.data, bytearray(memory), memory_pointer) except (OSError, TypeError, ValueError, IndexError, KeyError) as e: std.exit_failure("BF_EXECUTE_CODE", std.create_error_msg("PYTHON", e)) self.output = ''.join(self.output)
def __init__(self, filename): ''' Decode, parse and execute program in PNG format ''' try: # try to decode the png self.png = image_png.PngReader(filename) except (IOError, image_png.PNGErrorCRC32, image_png.PNGMissingIDAT,\ image_png.PNGMissingIEND, image_png.PNGMissingIHDR) as e: std.exit_failure("BC_DECODE_PNG", \ std.create_error_msg("PYTHON", e)) try: # and try to create a brainfuck program from it self.data = self.process_input(self.png.rgb) except (TypeError, ValueError, KeyError, IndexError) as e: std.exit_failure("BC_PROCESS_INPUT", \ std.create_error_msg("INTERNAL", e)) self.program = BrainFuck(self.data)