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
@@ -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()
