Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of config tri-state bool values (like acl_public) #940

Merged
merged 1 commit into from
Mar 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions S3/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ def config_unicodise(string, encoding = "utf-8", errors = "replace"):
except UnicodeDecodeError:
raise UnicodeDecodeError("Conversion to unicode failed: %r" % string)

def is_true(value):
"""Check to see if a string is true, yes, on, or 1

value may be a str, or unicode.

Return True if it is
"""
return value.lower() in ("true", "yes", "on", "1")

def is_false(value):
"""Check to see if a string is false, no, off, or 0

value may be a str, or unicode.

Return True if it is
"""
return value.lower() in ("false", "no", "off", "0")

def is_bool(value):
"""Check a string value to see if it is bool"""
return is_true(value) or is_false(value)

class Config(object):
_instance = None
_parsed_files = []
Expand Down Expand Up @@ -347,10 +369,12 @@ def update_option(self, option, value):
raise ValueError("Config: value of option %s must have suffix m, k, or nothing, not '%s'" % (option, value))

## allow yes/no, true/false, on/off and 1/0 for boolean options
elif type(getattr(Config, option)) is type(True): # bool
if str(value).lower() in ("true", "yes", "on", "1"):
## Some options default to None, if that's the case check the value to see if it is bool
elif (type(getattr(Config, option)) is type(True) or # Config is bool
(getattr(Config, option) is None and is_bool(value))): # Config is None and value is bool
if is_true(value):
value = True
elif str(value).lower() in ("false", "no", "off", "0"):
elif is_false(value):
value = False
else:
raise ValueError("Config: value of option '%s' must be Yes or No, not '%s'" % (option, value))
Expand Down