mirror of
https://github.com/lowobservable/oec.git
synced 2026-01-11 23:53:04 +00:00
Improve TN3270E support
This commit is contained in:
parent
dd8f476771
commit
eff4903789
@ -74,7 +74,7 @@ def _create_device(args, interface, device_address, _poll_response):
|
||||
|
||||
def _create_session(args, device):
|
||||
if args.emulator == 'tn3270':
|
||||
return TN3270Session(device, args.host, args.port, args.device_names, args.character_encoding)
|
||||
return TN3270Session(device, args.host, args.port, args.device_names, args.character_encoding, args.tn3270e_profile)
|
||||
|
||||
if args.emulator == 'vt100' and IS_VT100_AVAILABLE:
|
||||
host_command = [args.command, *args.command_args]
|
||||
|
||||
@ -25,7 +25,13 @@ def parse_args(args, is_vt100_available):
|
||||
tn3270_parser.add_argument('port', nargs='?', type=int, help=argparse.SUPPRESS)
|
||||
|
||||
tn3270_parser.add_argument('--codepage', metavar='encoding', default='ibm037',
|
||||
dest='character_encoding', type=get_character_encoding)
|
||||
dest='character_encoding', type=get_character_encoding,
|
||||
help='host EBCDIC code page')
|
||||
|
||||
tn3270_parser.add_argument('--tn3270e', choices=['off', 'basic', 'default'],
|
||||
metavar='profile', default='default',
|
||||
dest='tn3270e_profile',
|
||||
help='TN3270E profile: off, basic, default')
|
||||
|
||||
if is_vt100_available:
|
||||
vt100_parser = subparsers.add_parser('vt100', description='VT100 emulator',
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ ptyprocess==0.7.0
|
||||
pycoax==0.11.2
|
||||
pyserial==3.5
|
||||
pyte==0.8.1
|
||||
pytn3270==0.14.0
|
||||
pytn3270==0.15.0
|
||||
sliplib==0.6.2
|
||||
sortedcontainers==2.4.0
|
||||
wcwidth==0.2.5
|
||||
|
||||
@ -24,7 +24,7 @@ class SessionHandleHostTestCase(unittest.TestCase):
|
||||
|
||||
self.terminal = _create_terminal(self.interface)
|
||||
|
||||
self.session = TN3270Session(self.terminal, 'mainframe', 23, None, 'ibm037')
|
||||
self.session = TN3270Session(self.terminal, 'mainframe', 23, None, 'ibm037', 'default')
|
||||
|
||||
self.telnet = create_autospec(Telnet, instance=True)
|
||||
|
||||
@ -71,7 +71,7 @@ class SessionHandleKeyTestCase(unittest.TestCase):
|
||||
|
||||
self.terminal = _create_terminal(self.interface)
|
||||
|
||||
self.session = TN3270Session(self.terminal, 'mainframe', 23, None, 'ibm037')
|
||||
self.session = TN3270Session(self.terminal, 'mainframe', 23, None, 'ibm037', 'default')
|
||||
|
||||
self.session.emulator = create_autospec(Emulator, instance=True)
|
||||
|
||||
@ -251,7 +251,7 @@ class SessionRenderTestCase(unittest.TestCase):
|
||||
self.terminal.display.flush = Mock(wraps=self.terminal.display.flush)
|
||||
self.terminal.display.status_line.write = Mock(wraps=self.terminal.display.status_line.write)
|
||||
|
||||
self.session = TN3270Session(self.terminal, 'mainframe', 23, None, 'ibm037')
|
||||
self.session = TN3270Session(self.terminal, 'mainframe', 23, None, 'ibm037', 'default')
|
||||
|
||||
self.session.telnet = create_autospec(Telnet, instance=True)
|
||||
self.session.emulator = create_autospec(Emulator, instance=True)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user