Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 4 additions & 65 deletions tnz/tnz.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,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
Expand Down Expand Up @@ -1938,7 +1937,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.
Expand Down Expand Up @@ -2673,60 +2672,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
Expand Down Expand Up @@ -3008,7 +2965,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]

Expand All @@ -3028,24 +2985,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:
Expand Down
29 changes: 18 additions & 11 deletions tnz/zti.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -2042,15 +2044,15 @@ def disable_readlines_pa2():
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
Expand Down Expand Up @@ -2098,15 +2100,15 @@ def disable_readlines_pa2():
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
Expand Down Expand Up @@ -3362,6 +3364,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
Expand All @@ -3388,8 +3391,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):
Expand Down Expand Up @@ -3447,7 +3451,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
Expand Down
Loading