hostkeymap: Fix sanitize_keymap on python3

And add test cases to cover the failure

https://bugzilla.redhat.com/show_bug.cgi?id=1585574
This commit is contained in:
Cole Robinson
2018-06-07 11:33:37 -04:00
parent c58f8514ab
commit 4dfc6b03e8
2 changed files with 9 additions and 4 deletions

View File

@@ -40,3 +40,11 @@ class TestHostkeymap(unittest.TestCase):
hostkeymap._xorg_keymap(
_open("xorg-rhel5.txt")),
"us")
def testSanitize(self):
def san(inp):
return hostkeymap.sanitize_keymap(inp)
self.assertEqual(san("pt"), "pt")
self.assertEqual(san("de-us"), "de")
self.assertEqual(san("en_us"), "en-us")

View File

@@ -186,11 +186,8 @@ def sanitize_keymap(kt):
# Try a more intelligent lookup: strip out all '-' and '_', sort
# the keytable keys putting the longest first, then compare
# by string prefix
def len_cmp(a, b):
return len(b) - len(a)
clean_kt = kt.replace("-", "").replace("_", "")
sorted_keys = sorted(list(keytable.keys()), len_cmp)
sorted_keys = sorted(list(keytable.keys()), key=len)
for key in sorted_keys:
origkey = key