From e0f8c0c2a13ee4fe9dcc58ca5cb28fdaf400cd67 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Wed, 10 Jul 2024 01:03:12 +0200 Subject: [PATCH] Porting to Python 3 --- infernal_interpreter/AsciiPainter.py | 1 - infernal_interpreter/Emulator.py | 4 +-- infernal_interpreter/Junk.py | 4 +-- README.md => infernal_interpreter/__init__.py | 4 +-- infernal_interpreter/{main.py => __main__.py} | 27 +++++++------------ 5 files changed, 15 insertions(+), 25 deletions(-) rename README.md => infernal_interpreter/__init__.py (99%) rename infernal_interpreter/{main.py => __main__.py} (83%) mode change 100755 => 100644 diff --git a/infernal_interpreter/AsciiPainter.py b/infernal_interpreter/AsciiPainter.py index 103d412..c4d3bf4 100644 --- a/infernal_interpreter/AsciiPainter.py +++ b/infernal_interpreter/AsciiPainter.py @@ -1,5 +1,4 @@ -import re import subprocess NORMAL_COLOR = '\033[0m' diff --git a/infernal_interpreter/Emulator.py b/infernal_interpreter/Emulator.py index f1af3d2..df82349 100644 --- a/infernal_interpreter/Emulator.py +++ b/infernal_interpreter/Emulator.py @@ -1,8 +1,8 @@ import re -import Junk -from opcodes import OPCODES +from . import Junk +from .opcodes import OPCODES REGISTERS=["%rax", "%rbx", "%rcx", "%rdx", "%rsp", "%rbp", "%rsi", "%rdi", "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15"] diff --git a/infernal_interpreter/Junk.py b/infernal_interpreter/Junk.py index 9dce275..8fd5baa 100644 --- a/infernal_interpreter/Junk.py +++ b/infernal_interpreter/Junk.py @@ -6,8 +6,8 @@ class JunkComparisonException (BaseException): class Junk: - def __init__ (self, represents = None): - assert(represents == None or isinstance(represents, basestring)) + def __init__ (self, represents: str = None): + assert represents is None or isinstance(represents, str) self.repr = represents def __str__ (self): diff --git a/README.md b/infernal_interpreter/__init__.py similarity index 99% rename from README.md rename to infernal_interpreter/__init__.py index 1cfe49a..b05803c 100644 --- a/README.md +++ b/infernal_interpreter/__init__.py @@ -1,4 +1,4 @@ - +""" # Infernal Interpreter & Devious Stack Painter ################################# A very simple interpreter and stack tracer for the AMD x86-64 ABI written in @@ -22,4 +22,4 @@ License is `beerware`: this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return. - +""" diff --git a/infernal_interpreter/main.py b/infernal_interpreter/__main__.py old mode 100755 new mode 100644 similarity index 83% rename from infernal_interpreter/main.py rename to infernal_interpreter/__main__.py index f1e1446..b8128de --- a/infernal_interpreter/main.py +++ b/infernal_interpreter/__main__.py @@ -1,27 +1,18 @@ #!/usr/bin/python2 -ARG_DESC = ''' -A silly x86-64 emulator and stack visualizer. -''' - -LICENSE = ''' -This program is BEER-WARE. - - wrote this program. As long as you retain this -notice you can do whatever you want with this stuff. If we meet some -day, and you think this stuff is worth it, you can buy me a beer in -return. -''' - import sys import re import argparse -from Emulator import Emulator, CodeParseException, REGISTERS -from TikzPainter import TikzPainter -from AsciiPainter import AsciiPainter -import Junk +from .Emulator import Emulator, REGISTERS +from .TikzPainter import TikzPainter +from .AsciiPainter import AsciiPainter +from . import Junk + +ARG_DESC = ''' +A silly x86-64 emulator and stack visualizer. +''' PAINTER_ID_TO_CLASS = { 'ascii': AsciiPainter, @@ -29,7 +20,7 @@ PAINTER_ID_TO_CLASS = { } def parse_args (): - parser = argparse.ArgumentParser(description = ARG_DESC, epilog = LICENSE) + parser = argparse.ArgumentParser(description = ARG_DESC) parser.add_argument('-i', '--input-file', default='-', help = 'File to use as input', dest = 'input-file') parser.add_argument('-o', '--output-file', default='-', help = 'File to use as output', dest = 'output-file') parser.add_argument('-p', '--painter', default='ascii', help = 'Drawer to use', dest = 'painter-name', choices=PAINTER_ID_TO_CLASS.keys())