From fffe1efa9bd2bb8cc9db0922a57c53b1ce45dcde Mon Sep 17 00:00:00 2001 From: James Lu Date: Thu, 9 Nov 2017 09:05:58 -0800 Subject: [PATCH] Hashes: remove duplicate check for hashlib.algorithms_available This code is never wrap()'ed if the attribute is unavailable, so it isn't necessary to check for it in runtime twice. --- plugins/Hashes/plugin.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/plugins/Hashes/plugin.py b/plugins/Hashes/plugin.py index 40a93eecb..ffbf13bdf 100644 --- a/plugins/Hashes/plugin.py +++ b/plugins/Hashes/plugin.py @@ -84,10 +84,8 @@ class Hashes(callbacks.Plugin): """ Returns the list of available algorithms.""" - try: - irc.reply(utils.str.format("%L", hashlib.algorithms_available)) - except AttributeError: - pass # allow building but not using, usually python <2.7 + irc.reply(utils.str.format("%L", hashlib.algorithms_available)) + if hasattr(hashlib, 'algorithms_available'): algorithms = wrap(algorithms) @@ -96,12 +94,7 @@ class Hashes(callbacks.Plugin): """ Returns TEXT after it has been hashed with ALGORITHM. See the 'algorithms' command in this plugin to return the algorithms available on this system.""" - algos = [] - try: - algos = hashlib.algorithms_available - except: - pass # allow building but not using, usually python <2.7 - if algorithm not in algos: + if algorithm not in hashlib.algorithms_available: irc.error("Algorithm not available.") else: irc.reply(hashlib.new(algorithm, text.encode('utf8')).hexdigest())