Skip to content

Commit

Permalink
replace exclamation appended mode by extra trailing for more flexible…
Browse files Browse the repository at this point in the history
… setting.
  • Loading branch information
WFA-lliu committed Mar 25, 2024
1 parent d896890 commit 394911f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
10 changes: 5 additions & 5 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ Note: **ptftpd** package should be installed (before running).
<summary><i>fakecall.py</i>, a companion for generic testbed</summary>

```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

Expand All @@ -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
Expand Down
16 changes: 9 additions & 7 deletions fakecall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions fakesniff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 394911f

Please sign in to comment.