Browse Source

allow a default value for attribute_to_bool(); rework config.xml structure slightly

tags/v0.1^2
Ben Kurtovic 13 years ago
parent
commit
26e0058ca3
1 changed files with 7 additions and 6 deletions
  1. +7
    -6
      core/config.py

+ 7
- 6
core/config.py View File

@@ -67,20 +67,21 @@ def make_new_config():
def are_passwords_encrypted(): def are_passwords_encrypted():
"""Determine if the passwords in our config file are encrypted, returning """Determine if the passwords in our config file are encrypted, returning
either True or False.""" either True or False."""
data = _config.getElementsByTagName("config")[0]
element = data.getElementsByTagName("encrypt-passwords")[0]
return attribute_to_bool(element, "enabled")
element = _config.getElementsByTagName("config")[0]
return attribute_to_bool(element, "encrypt-passwords", default=False)


def attribute_to_bool(element, attribute):
def attribute_to_bool(element, attribute, default=None):
"""Return True if the value of element's attribute is 'true', '1', or 'on'; """Return True if the value of element's attribute is 'true', '1', or 'on';
return False if it is 'false', '0', or 'off' (regardless of return False if it is 'false', '0', or 'off' (regardless of
capitalization); raise TypeMismatchException if it does match any of
those."""
capitalization); return default if it is empty; raise TypeMismatchException
if it does match any of those."""
value = element.getAttribute(attribute).lower() value = element.getAttribute(attribute).lower()
if value in ["true", "1", "on"]: if value in ["true", "1", "on"]:
return True return True
elif value in ["false", "0", "off"]: elif value in ["false", "0", "off"]:
return False return False
elif value == '':
return default
else: else:
e = ("Expected a bool in attribute '{0}' of element '{1}', but " + e = ("Expected a bool in attribute '{0}' of element '{1}', but " +
"got '{2}'.").format(attribute, element.tagName, value) "got '{2}'.").format(attribute, element.tagName, value)


Loading…
Cancel
Save