From d3f4fe715bade7ecec8c0ec9157be26e4dfafdad Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 25 Jan 2018 12:16:59 +0100 Subject: [PATCH] library: cleanup Util.boolean() implementation --- library/network_connections.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/library/network_connections.py b/library/network_connections.py index 061e7a6..90ce70f 100755 --- a/library/network_connections.py +++ b/library/network_connections.py @@ -228,19 +228,18 @@ class Util: @staticmethod def boolean(arg): - BOOLEANS_TRUE = ['y', 'yes', 'on', '1', 'true', 1, True] - BOOLEANS_FALSE = ['n', 'no', 'off', '0', 'false', 0, False] - if arg is None or isinstance(arg, bool): return arg + arg0 = arg if isinstance(arg, Util.STRING_TYPE): arg = arg.lower() - if arg in BOOLEANS_TRUE: + + if arg in ['y', 'yes', 'on', '1', 'true', 1, True]: return True - elif arg in BOOLEANS_FALSE: + if arg in ['n', 'no', 'off', '0', 'false', 0, False]: return False - else: - raise MyError('value "%s" is not a boolean' % (arg)) + + raise MyError('value "%s" is not a boolean' % (arg0)) @staticmethod def parse_ip(addr, family=None):