Improve TN3270E support

This commit is contained in:
Andrew Kay
2023-01-18 07:52:27 -06:00
parent dd8f476771
commit eff4903789
5 changed files with 35 additions and 11 deletions

View File

@@ -4,8 +4,8 @@ oec.tn3270
"""
import logging
from tn3270 import Telnet, Emulator, AttributeCell, CharacterCell, AID, Color, Highlight, \
OperatorError, ProtectedCellOperatorError, FieldOverflowOperatorError
from tn3270 import Telnet, TN3270EFunction, Emulator, AttributeCell, CharacterCell, AID, Color, \
Highlight, OperatorError, ProtectedCellOperatorError, FieldOverflowOperatorError
from tn3270.ebcdic import DUP, FM
from .session import Session, SessionDisconnectedError
@@ -47,7 +47,7 @@ AID_KEY_MAP = {
class TN3270Session(Session):
"""TN3270 session."""
def __init__(self, terminal, host, port, device_names, character_encoding):
def __init__(self, terminal, host, port, device_names, character_encoding, tn3270e_profile):
super().__init__(terminal)
self.logger = logging.getLogger(__name__)
@@ -56,6 +56,7 @@ class TN3270Session(Session):
self.port = port
self.device_names = device_names
self.character_encoding = character_encoding
self.tn3270e_profile = tn3270e_profile
self.telnet = None
self.emulator = None
@@ -191,12 +192,14 @@ class TN3270Session(Session):
self.logger.info(f'Terminal Type = {terminal_type}')
self.telnet = Telnet(terminal_type)
tn3270e_args = _get_tn3270e_args(self.tn3270e_profile)
self.telnet = Telnet(terminal_type, **tn3270e_args)
self.telnet.open(self.host, self.port, self.device_names)
if self.telnet.is_tn3270e_negotiated:
self.logger.info(f'TN3270E mode negotiated: Device Type = {self.telnet.device_type}, Device Name = {self.telnet.device_name}')
self.logger.info(f'TN3270E mode negotiated: Device Type = {self.telnet.device_type}, Device Name = {self.telnet.device_name}, Functions = {self.telnet.tn3270e_functions}')
else:
self.logger.debug('Unable to negotiate TN3270E mode')
@@ -311,3 +314,18 @@ def _map_formatting(formatting):
byte |= 0xc0
return byte
def _get_tn3270e_args(profile):
is_tn3270e_enabled = True
tn3270e_functions = [TN3270EFunction.RESPONSES]
if profile == 'off':
is_tn3270e_enabled = False
tn3270e_functions = None
elif profile == 'basic':
tn3270e_functions = []
return {
'is_tn3270e_enabled': is_tn3270e_enabled,
'tn3270e_functions': tn3270e_functions
}