From d16d273a40a87838fa53d994905b5c86f67cd9e5 Mon Sep 17 00:00:00 2001 From: Joe Subbiani Date: Mon, 26 Jul 2021 13:33:35 +0100 Subject: [PATCH] Compact 2 format functions to 1 In translate_ciphers.py there were 2 format functions that were virtually identical and a check was made beforehand to decide which one to call. Now the check is made inside a single function to reduce duplicate code Signed-off-by: Joe Subbiani --- tests/translate_ciphers.py | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/tests/translate_ciphers.py b/tests/translate_ciphers.py index 07affb290..d6b604dd3 100755 --- a/tests/translate_ciphers.py +++ b/tests/translate_ciphers.py @@ -97,33 +97,23 @@ def translate_ossl(m_cipher): return m_cipher -def format_g(m_ciphers): - #ciphers = (re.findall(r"TLS-.+\s*\\", m_ciphers)) - m_ciphers = m_ciphers.split() - g_ciphers = [] - for i in m_ciphers: - g_ciphers.append(translate_gnu(i)) - return " ".join(g_ciphers) - -def format_o(m_ciphers): - m_ciphers = m_ciphers.split() - o_ciphers = [] - for i in m_ciphers: - o_ciphers.append(translate_ossl(i)) - return " ".join(o_ciphers) +def format(mode, ciphers): + ciphers = ciphers.split() + t_ciphers = [] + if mode == "g": + for i in ciphers: + t_ciphers.append(translate_gnu(i)) + if mode == "o": + for i in ciphers: + t_ciphers.append(translate_ossl(i)) + return " ".join(t_ciphers) def main(): # print command line arguments if len(sys.argv) <= 2: exit(1) - if sys.argv[1] == "g": - print(format_g(sys.argv[2])) - exit(0) - elif sys.argv[1] == "o": - print(format_o(sys.argv[2])) - exit(0) else: - exit(1) + print(format(sys.argv[1], sys.argv[2])) if __name__ == "__main__": main()