mirror of
https://github.com/linux-system-roles/network.git
synced 2026-07-21 10:18:27 +00:00
library: cleanup Util.boolean() implementation
This commit is contained in:
parent
0098878895
commit
d3f4fe715b
1 changed files with 6 additions and 7 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue