From 7f8cbb9c8dd8f6a6759d713abf257f8aed31cb3a Mon Sep 17 00:00:00 2001 From: Neil Johnson Date: Tue, 27 Oct 2026 15:00:07 -0400 Subject: [PATCH] fix host control Signed-off-by: Neil Johnson --- tnz/tnz.py | 69 ++++-------------------------------------------------- tnz/zti.py | 29 ++++++++++++++--------- 2 files changed, 22 insertions(+), 76 deletions(-) diff --git a/tnz/tnz.py b/tnz/tnz.py index c200435..74a5753 100644 --- a/tnz/tnz.py +++ b/tnz/tnz.py @@ -146,7 +146,6 @@ def __init__(self, name=None): self.__readlines_maxrow = 0 self.__indstr = "" - self.__indsdict = {} # ddm limits for inbound and outbound # 32767 is what HOD documents as the max @@ -1936,7 +1935,7 @@ def uploading(self): if not self.__indstemp: return False - return self.__indsfile + return self.__indsfile and self.__ddmupload def wait(self, timeout=None, zti=None, key=None): """Wait for event. @@ -2671,60 +2670,18 @@ def _process_ddm_0xd00012(self, b_str, start, stop, zti=None): isf = (len(isf)+2).to_bytes(2, byteorder="big")+isf rec += isf + self.ddmdict = indsdict = {} indstr = self.__indstr if not self.__indsfile and indstr: self.__indstr = "" try: - indsdict = json.loads(indstr) + self.ddmdict = indsdict = json.loads(indstr) except ValueError: self.__log_error("Not valid json: %r", indstr) else: self.__log_debug("indsdict: %r", indsdict) - filename = indsdict.get("filename", None) - enc = indsdict.get("encoding", None) - cmd = indsdict.get("command", None) - mode = "r" if ddmupload else "w" - if enc == "binary": - mode += "b" - enc = None - elif not enc: - enc = self.encoding - - if ddmupload and cmd and filename: - os.system(cmd) - - try: - if ddmupload and cmd and not filename: - self.__indsfile = os.popen(cmd) - elif filename: - self.__indsfile = open(filename, mode) - - except OSError: - self.__indstemp = False - # Open Request Error - rec = b"\x88" # SF (Structured Field AID) - isf = b"\xd0\x00\x08" # D00008 Open Error - isf += b"\x69\x04" # Error Code Header - isf += b"\x01\x00" # Open Failed Exception - isf = (len(isf)+2).to_bytes(2, byteorder="big")+isf - rec += isf - self.__log_debug("DDM Open Failed Exception send") - self.send_3270_data(rec) - self.__log_error("sf[14]=%r", b_str[start+14]) - self.__log_error("DDM Open File failed") - return - - except Exception: - self.__indstemp = False - self.__logger.exception("open file error") - - else: - self.__indstemp = True - self.__indspend = b"" - self.__indsenc = enc - self.__indsdict = {} if ddmupload else indsdict if (not self.__indsfile and ((not ddmupload and not self.ddmrecv) or @@ -3006,7 +2963,7 @@ def _process_ddm_0xd04704(self, b_str, start, stop, zti=None): # unsolicited if self.__ddmrecnum == 1: self.__ddmtdat = "" - if self.__indsdict: + if self.ddmdict: if data.endswith(b"\x1a"): data = data[:-1] @@ -3026,24 +2983,6 @@ def _process_ddm_0xd04704(self, b_str, start, stop, zti=None): self.__ddmfile = self.__indsfile self.__indsfile = None self.__indstemp = False - indsdict = self.__indsdict - self.ddmdict = indsdict - if indsdict: - self.__indsdict = {} - cmd = indsdict.get("command", None) - nowait = indsdict.get("async", None) - try: - if cmd and not nowait: - os.system(cmd) - elif cmd and nowait: - import subprocess - subprocess.Popen(cmd, - stdin=None, - stdout=None, - stderr=None, - close_fds=True) - except Exception: - self.__logger.exception("command error") else: if self.__indsfile is self.file_appends: diff --git a/tnz/zti.py b/tnz/zti.py index 383cf6d..2a4e600 100644 --- a/tnz/zti.py +++ b/tnz/zti.py @@ -157,6 +157,7 @@ def __init__(self, stdin=None, stdout=None): self.downloads = [] self.__downcnt = 0 self.downloadaction = False + self.downloaded = False self.__sessel_y = None self.__sessel_x = 0 @@ -548,6 +549,7 @@ def do_goto(self, arg): try: self.ddmrecv = True # allow host-initiated ind$file get self.ddmsend = True # allow host-initiated ind$file put + self.downloaded = False self.__prog_mode() try: r2d2rv = self.__r2d2(self.stdscr, _WAIT_GOTO, -1) @@ -2023,15 +2025,15 @@ def __r2d2(self, win, waitc, timeout): if tns.seslost: return 12 - if tns.ddmdata or tns.ddmdict: - # TODO what if keylock_aidbuf? - return 10 # have ddmdata - if self.downloadaction: self.downloadaction = False # TODO what if keylock_aidbuf? return 11 # have download action + if tns.uploading() or self.downloaded: + # TODO what if keylock_aidbuf? + return 10 # have ddmdata + if ((self.rewrite or self.__dirty_ranges or self.rewrite_cursor or @@ -2079,15 +2081,15 @@ def __r2d2(self, win, waitc, timeout): if tns.seslost: return 12 # seslost - if tns.ddmdata or tns.ddmdict: - # TODO what if keylock_aidbuf? - return 10 # have ddmdata - if self.downloadaction: self.downloadaction = False # TODO what if keylock_aidbuf? return 11 # have download action + if tns.uploading() or self.downloaded: + # TODO what if keylock_aidbuf? + return 10 # have ddmdata + # check for Alt+letter shortcut altc = 0 @@ -3336,6 +3338,7 @@ def __init__(self, zti, tns): self.closed = False self.removed = False self.lastcmd = tns.lastcmd + self.ddmdict = tns.ddmdict.copy() self.downloadaction = None self.actiontaken = False self.zti = zti @@ -3362,8 +3365,9 @@ def close(self): self.tns = None self.file.close() zti = self.zti - if zti and not zti.downloadaction: - if self.downloadaction: + if zti: + zti.downloaded = True + if not zti.downloadaction and self.downloadaction: zti.downloadaction = True def error(self): @@ -3421,7 +3425,10 @@ def __repr__(self): else: stat = "Open" - if self.downloadaction: + if self.ddmdict: + import json + actcmd = json.dumps(self.ddmdict) + elif self.downloadaction: actcmd = self.downloadaction else: actcmd = self.lastcmd