From 394911fad819eb922efcc88eee4462f1a1cf7145 Mon Sep 17 00:00:00 2001 From: Leo Liu Date: Mon, 25 Mar 2024 12:37:27 +0800 Subject: [PATCH] replace exclamation appended mode by extra trailing for more flexible setting. --- ReadMe.md | 10 +++++----- fakecall.py | 16 +++++++++------- fakesniff.py | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index a7832b8..bf88668 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -34,9 +34,9 @@ Note: **ptftpd** package should be installed (before running). fakecall.py, a companion for generic testbed ```sh -usage: fakecall.py [-h] [-v] [-a] [-l] [-e] [-t intermittent] [-n name] - [-d directory] [-f filename] [-i interpreted] [-o oriented] - [-r report] +usage: fakecall.py [-h] [-v] [-a] [-l] [-e extra_trailing] [-t intermittent] + [-n name] [-d directory] [-f filename] [-i interpreted] + [-o oriented] [-r report] CLI argument parsing @@ -45,8 +45,8 @@ optional arguments: -v, --verbose verbosity -a, --auto auto-mode -l, --linefeed LF only mode (instead of both CR and LF) - -e, --exclamation_appended - exclamation appended mode + -e extra_trailing, --extra_trailing extra_trailing + extra trailing string -t intermittent, --intermittent intermittent intermittent time in seconds -n name, --name name display name for specific handle diff --git a/fakecall.py b/fakecall.py index 52428cd..e31d251 100644 --- a/fakecall.py +++ b/fakecall.py @@ -9,11 +9,11 @@ from fakesniff import FakeSniff class FakeCall(FakeSniff): - def __init__(self, lf: bool = False, ea: bool = False) -> None: + def __init__(self, lf: bool = False, et: bool = False) -> None: super().__init__() #variables for pattern matching self.patt["deli_lf"] = lf - self.patt["deli_ea"] = ea + self.patt["deli_et"] = et self.patt["abort"] = True self.patt["capi"]["traffic_agent_reset"] = self.__silence self.patt["capi"]["traffic_agent_config"] = self.__silence @@ -146,9 +146,11 @@ def find_interpreting_handle(dir: str = ".", alias: str = None) -> tuple: action="store_true", help="LF only mode (instead of both CR and LF)") my_parser.add_argument("-e", - "--exclamation_appended", - action="store_true", - help="exclamation appended mode") + "--extra_trailing", + metavar="extra_trailing", + default="", + type=str, + help="extra trailing string") my_parser.add_argument("-t", "--intermittent", metavar="intermittent", @@ -205,7 +207,7 @@ def find_interpreting_handle(dir: str = ".", alias: str = None) -> tuple: logging.info("name: " + args.name) rpt = open(args.report, "w") fldr = FakeSniff.find_interpreting_directory(args.directory) - fc = FakeCall(lf = args.linefeed, ea = args.exclamation_appended) + fc = FakeCall(lf = args.linefeed, et = args.extra_trailing) for f in fldr: (hdl, filename) = FakeCall.find_interpreting_handle(f, args.name) for h in hdl: @@ -234,7 +236,7 @@ def find_interpreting_handle(dir: str = ".", alias: str = None) -> tuple: handle_invoke = args.oriented else: handle_invoke = args.oriented + ":" + args.interpreted.split(":")[1] - fc = FakeCall(lf = args.linefeed, ea = args.exclamation_appended) + fc = FakeCall(lf = args.linefeed, et = args.extra_trailing) time_begin = time.time() (ret, stat) = fc.interpret(dir = args.directory, fn = args.filename, handle = args.interpreted, handle_invoke = handle_invoke) time_end = time.time() diff --git a/fakesniff.py b/fakesniff.py index 8c75df2..c9d16f5 100644 --- a/fakesniff.py +++ b/fakesniff.py @@ -20,7 +20,7 @@ def __init__(self) -> None: self.patt["deli_rsp"] = "<--\s+" self.patt["deli_arg"] = "," self.patt["deli_lf"] = False - self.patt["deli_ea"] = False + self.patt["deli_et"] = "" self.patt["api_idx"] = int(0) self.patt["ret_idx"] = int(1) self.patt["abort"] = True @@ -174,7 +174,7 @@ def __invoke(self, argv: list) -> bool: if self.cfg["object_invoke"] is None: self.cfg["object_invoke"] = Telnet() self.cfg["object_invoke"].open(host = self.cfg["handle_invoke"].split(":")[0], port = int(self.cfg["handle_invoke"].split(":")[1])) - capi = self.patt["deli_arg"].join(argv) + ("" if self.patt["deli_ea"] is False else "!") + ("\r\n" if self.patt["deli_lf"] is False else "\n") + capi = self.patt["deli_arg"].join(argv) + ("" if self.patt["deli_et"] is None else self.patt["deli_et"]) + ("\r\n" if self.patt["deli_lf"] is False else "\n") self.cfg["object_invoke"].write(bytes(capi, "UTF-8")) rcv = self.cfg["object_invoke"].read_until((b"\r\n" if self.patt["deli_lf"] is False else b"\n"), invoke_running_tmo) if len(rcv) == 0: