Tweakify is_valid_boolstr().

This function used a few backslashes for continuation.  According to
HACKING, we prefer to not use this.  This code gets rid of them by
changing the way the checks are done.

Look at those backslashes ... sitting there at the end of the line.
It's like they're looking down on the code that precedes them, as if
they are somehow superior to the other characters.  Banish them from
this utility function!

Also add a unit test for this code.

Part of greenprint bored-on-an-airplane.

Change-Id: If88b6e63ab078916ce1b9cf2f5e99623c402996c
This commit is contained in:
Russell Bryant
2013-02-01 03:29:01 -05:00
parent 7f618b7285
commit 1e53f04e40

View File

@@ -876,11 +876,8 @@ def is_int_like(val):
def is_valid_boolstr(val):
"""Check if the provided string is a valid bool string or not."""
val = str(val).lower()
return val == 'true' or val == 'false' or \
val == 'yes' or val == 'no' or \
val == 'y' or val == 'n' or \
val == '1' or val == '0'
boolstrs = ('true', 'false', 'yes', 'no', 'y', 'n', '1', '0')
return str(val).lower() in boolstrs
def is_valid_ipv4(address):