From 30e18200f8abc4203d7b5c51c28e941c1b7cd006 Mon Sep 17 00:00:00 2001 From: Andrew Kay Date: Mon, 8 Jun 2020 18:25:14 -0500 Subject: [PATCH] Simplify the TN3270 attribute mapping --- oec/tn3270.py | 17 ++--------------- tests/test_tn3270.py | 8 +++++++- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/oec/tn3270.py b/oec/tn3270.py index 66683ba..5468689 100644 --- a/oec/tn3270.py +++ b/oec/tn3270.py @@ -197,21 +197,8 @@ class TN3270Session(Session): self.operator_error = None def _map_attribute(self, attribute): - # NOTE: This mapping may not be correct and does not take into account - # lightpen detectable fields. - if attribute.hidden: - return 0xcc - - if attribute.protected: - if attribute.intensified: - return 0xe8 - - return 0xe0 - - if attribute.intensified: - return 0xc8 - - return 0xc0 + # Only map the protected and display bits - ignore numeric, skip and modified. + return 0xc0 | (attribute.value & 0x2c) def _map_character(self, byte): if byte == DUP: diff --git a/tests/test_tn3270.py b/tests/test_tn3270.py index 873fc75..3a7f5b5 100644 --- a/tests/test_tn3270.py +++ b/tests/test_tn3270.py @@ -58,7 +58,7 @@ class SessionHandleHostTestCase(unittest.TestCase): self.terminal.display.flush.assert_called() - self.assertEqual(self.terminal.display.buffer[:105], bytes.fromhex('e0afb1aeb3a4a2b3a4a3e8afb1aeb3a4a2b3a4a300a8adb3a4adb2a8a5a8a4a3ccafb1aeb3a4a2b3a4a300a7a8a3a3a4adc0b4adafb1aeb3a4a2b3a4a3c8b4adafb1aeb3a4a2b3a4a300a8adb3a4adb2a8a5a8a4a3ccb4adafb1aeb3a4a2b3a4a300a7a8a3a3a4ade0')) + self.assertEqual(self.terminal.display.buffer[:105], bytes.fromhex('e0afb1aeb3a4a2b3a4a3e8afb1aeb3a4a2b3a4a300a8adb3a4adb2a8a5a8a4a3ecafb1aeb3a4a2b3a4a300a7a8a3a3a4adc0b4adafb1aeb3a4a2b3a4a3c8b4adafb1aeb3a4a2b3a4a300a8adb3a4adb2a8a5a8a4a3ccb4adafb1aeb3a4a2b3a4a300a7a8a3a3a4ade0')) self.assertTrue(all([byte == 0x00 for byte in self.terminal.display.buffer[105:]])) self.assertEqual(self.terminal.display.cursor_index, 8) @@ -282,6 +282,12 @@ class MockAttribute: self.intensified = intensified self.hidden = hidden + @property + def value(self): + display = 2 if self.intensified else 3 if self.hidden else 0 + + return (0x20 if self.protected else 0) | (display << 2) + def _create_screen_cells(rows, columns): return [CharacterCell(0x00) for address in range(rows * columns)]