From bdb0f645bc1bd040cf87be6247fb9f89e9b52f17 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 31 Dec 2016 22:59:17 +0200 Subject: Fix names to not override builtin hex --- pgpwordlist/funcs.py | 14 +++++++------- pgpwordlist/funcs_tests.py | 22 +++++++++++----------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pgpwordlist/funcs.py b/pgpwordlist/funcs.py index 84d3d0d..4e11b9f 100644 --- a/pgpwordlist/funcs.py +++ b/pgpwordlist/funcs.py @@ -21,22 +21,22 @@ import pgpwordlist _words = pgpwordlist.pgp_word_list -def get_word(hex, offset): - hex = hex.lower() - t = _words.get(hex) +def get_word(hexstr, offset): + hexstr = hexstr.lower() + t = _words.get(hexstr) if t is None: - raise KeyError(hex) + raise KeyError(hexstr) return t[offset % 2] def get_hex(word): - for hex, t in _words.items(): + for hexstr, t in _words.items(): if word.lower() in t: - return hex.lower() + return hexstr.lower() def hex_to_words(hexstr): - words = [get_word(hex, i) for i, hex in enumerate(_hex_bytes(hexstr))] + words = [get_word(h, i) for i, h in enumerate(_hex_bytes(hexstr))] return ' '.join(words) diff --git a/pgpwordlist/funcs_tests.py b/pgpwordlist/funcs_tests.py index 5473ac8..2697e43 100644 --- a/pgpwordlist/funcs_tests.py +++ b/pgpwordlist/funcs_tests.py @@ -31,9 +31,9 @@ class WordListQueriesTests(unittest.TestCase): even_words = set() odd_words = set() for i in range(256): - hex = '%02x' % i - even_word = pgpwordlist.get_word(hex, 0) - odd_word = pgpwordlist.get_word(hex, 1) + hexstr = '%02x' % i + even_word = pgpwordlist.get_word(hexstr, 0) + odd_word = pgpwordlist.get_word(hexstr, 1) self.assertNotIn(even_word, even_words) self.assertNotIn(odd_word, odd_words) even_words.add(even_word) @@ -41,16 +41,16 @@ class WordListQueriesTests(unittest.TestCase): def test_round_trip_works(self): for i in range(256): - hex = '%02x' % i - even_word = pgpwordlist.get_word(hex, 0) - odd_word = pgpwordlist.get_word(hex, 1) - self.assertEqual(pgpwordlist.get_hex(even_word), hex) - self.assertEqual(pgpwordlist.get_hex(odd_word), hex) + hexstr = '%02x' % i + even_word = pgpwordlist.get_word(hexstr, 0) + odd_word = pgpwordlist.get_word(hexstr, 1) + self.assertEqual(pgpwordlist.get_hex(even_word), hexstr) + self.assertEqual(pgpwordlist.get_hex(odd_word), hexstr) class WordStringTests(unittest.TestCase): def test_roundtrip_works(self): - hex = 'cafef00d' - words = pgpwordlist.hex_to_words(hex) - self.assertEqual(pgpwordlist.words_to_hex(words), hex) + hexstr = 'cafef00d' + words = pgpwordlist.hex_to_words(hexstr) + self.assertEqual(pgpwordlist.words_to_hex(words), hexstr) -- cgit v1.2.1