tnz§
TN3270 terminal class.
Low level APIs for telnet-3270 for Z tool and library.
Usage
from tnz import tnz
Environment variables used
SESSION_PS_SIZE SESSION_SECLEVEL SESSION_SSL_VERIFY TNZ_COLORS TNZ_LOGGING ZTI_SECLEVEL
Copyright 2021, 2024 IBM Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
Classes§
Tnz §
One instance for each terminal and the connection.
Methods for actions taken at the terminal
attn ATTN enter ENTER clear CLEAR key_backspace Backspace key_backtab Backtab key_curdown Down key_curleft Left key_curright Right key_curup Up key_data characters/string key_delete Delete key_end (End) key_eraseeof Erase EOF key_eraseinput ERASE INPUT key_home Home key_insdata insert characters/string key_newline NL key_tab Tab key_wordl (Word Left) key_wordr (Word Right) pa2, pa2, pa3 PAx pfX (pf1, pf2, … pf24) PFxx
Additional methods to enhance the terminal experience
paste_data multiline characters/string
Characters in the terminal
scrstr Method to get characters/string
Attributes in the terminal
plane_fa Field attributes plane_eh Extended highlighting plane_fg Forground color plane_bg Background color
Various methods perform actions taken by the remote application. Use the wait method to wait for the remote application to request actions and for the instance to process them.
The data in the 3270 terminal is located by an address. This may be different from other applications that use a row and column or an x position and a y position. In addition, vectors described using addresses typically wrap - for instance from address 2 to address 1 produces a vector start at address 2, continues to the end of the terminal, continues at the beginning of the terminal, and terminates at address 1.
The send method and the send_* methods send data to the remote host.
Attributes§
Functions§
address §
address(address_bytes)
Return an integer buffer address for the input encoded byte string address.
address_bytes §
address_bytes(address)
Return an encoded byte string for the input integer buffer address.
connect §
connect(
host=None,
port=None,
secure=False,
verifycert=True,
*,
event=None
)
Connect to the host.
field §
field(address)
Return field address and attribute value as tuple.
Get the field address and attribute value associated with the input address.
get_file §
get_file(parms, filename, assist=True)
Get host file into local file.
Would be nice, when the local system is Z, to transfer in binary. However, when transfer is done in binary, no information about the record format comes across. So, there is no knowledge if the host records were fixed-80 or variable length - so there is no indication as to where the line breaks should be.
Transfering using the ASCII CRLF options seems to cause the host to convert between cp037 and iso8859-1. If something other than cp037 is expected/needed, support must be added to translate back from iso8859-1 to cp037. Then using the desired code page (e.g. cp1047) to translate to Unicode.
group_addrs §
group_addrs(saddr, eaddr)
A generator of character data address range groups.
A generator function that iterates through groups of characters. The characters in each group have all the same attributes. Each iteration returns a tuple with the start and end addresses.
It is assumed that the input address(es) are valid for the current buffer size. They are in the range from 0 to buffer_size-1, inclusive.
is_detectable_attr staticmethod
§
is_detectable_attr(attr)
Return whether or not the input field attribute is for a selector-pen-detectable field.
is_displayable_attr staticmethod
§
is_displayable_attr(attr)
Return whether or not the input field attribute is for a displayable field.
is_intensified_attr staticmethod
§
is_intensified_attr(attr)
Return whether or not the input field attribute is for an intensified field.
is_modified_attr staticmethod
§
is_modified_attr(attr)
Return whether or not the input field attribute is for a modified field.
is_normal_attr staticmethod
§
is_normal_attr(attr)
Return whether or not the input field attribute is for a normal field.
is_numeric_attr staticmethod
§
is_numeric_attr(attr)
Return whether or not the input field attribute is for a numeric field.
is_pen_detectable §
is_pen_detectable(address)
Return True or False to indicate if the address is selector-pen detectable
is_protected_attr staticmethod
§
is_protected_attr(attr)
Return whether or not the input field attribute is for a protected field.
iterow §
iterow(saddr, eaddr)
Iterate through rows of bytes in the input bytearray.
Note that the inputs are addresses and the outputs are positions. In other words, the outputs for each iteration will always have the start less than the end and buffer_size is used when the vector goes to the end of the bytearray.
key_backspace §
key_backspace(zti=None)
Process backspace key, which behaves like a cursor left followed by a delete as long as cursor is not on a field attribute nor is there a field attribute to the left.
key_end §
key_end()
Process End key - go to end of text in field.
End is not a 3270 key, but common on modern keyboard.
Cursor will move onto a null character in the current field where the character to the left is not a null character and all characters to the right are null characters.
If cursor is in an unprotected field and the field does not end in a null character, the cursor will be put on the last character in the field.
If cursor is in a protected field and the field does not end in a null character, the cursor will be put on the field attribute of the next field.
next_field §
next_field(saddr, eaddr=None, offset=1)
Get the address and attribute value of the next field.
Get the address and attribute value associated with the next field relative to the input field address. The first location for searching is the address AFTER the input saddr. If eaddr is specified.
rcba staticmethod
§
rcba(value, start, stop)
read circular byte array
value: byte array start: first index into byte array stop: last index into byte array returns copy of data from array
scrstr §
scrstr(saddr=0, eaddr=0, rstrip=None)
Return a string representation of the character buffer.
send §
send(data=None)
Send input byte array as data to the host. This method will escape IAC bytes.
send_3270_data §
send_3270_data(value)
Send input byte array as a 3270-DATA record to the host. This method will escape IAC bytes and send EOR after the data.
send_aid §
send_aid(aid, short=None)
Process the sending of an AID (enter command). Used by methods with the name of the AID (e.g. enter).
send_command §
send_command(code)
Send telnet command to the host.
Send a single-byte telnet command to the remote.
Supported commands
NAME CODE MEANING NOP 241 No operation. Data Mark 242 The data stream portion of a Synch. Break 243 NVT character BRK. Interrupt Process 244 The function IP. Abort output 245 The function AO. Are You There 246 The function AYT. Erase character 247 The function EC. Erase Line 248 The function EL. Go ahead 249 The GA signal.
See other methods for other commands
NAME METHOD EOR send_rec() SE send_sub() SB send_sub() WILL send_will() WON'T send_wont() DO send_do() DON'T send_dont()
send_rec §
send_rec(value)
Send input byte array as a record to the host. This method will escape IAC bytes and send EOR after the data.
send_sub §
send_sub(value, buffer=False)
Send input subcommand data to the host. This method will bookend the data with IAC SB adn IAC SE.
set_cursor_position §
set_cursor_position(row, col)
Set the cursor address from the input row and column.
First (row, col) is (1, 1).
ucba staticmethod
§
ucba(dst, start, src, begidx=0, endidx=None)
update circular byte array
dst: target circular byte array start: first index into target byte array src: data to copy to array begidx: start index in data to copy (default is 0) endidx: end index in data to copy (default is len(src))
wait §
wait(timeout=None, zti=None, key=None)
Wait for event.
Returns after timeout seconds or when data is received.
TnzError §
Bases: Exception
General Tnz error.
Functions§
bit6 §
bit6(control_int)
Translate 6-bit control characters to printable characters. This is used for bytes that have bits 0 and 1 reserved in order to make the byte a printable character. See figure D-1 in Data Stream Programmers Reference.
connect §
connect(
host=None,
port=None,
secure=None,
verifycert=None,
name=None,
*,
event=None
)
Create a new Tnz object and connect to the host.
secure = False if do not care about security secure = True for encrypted connection verifycert only has meaning when secure is True