From 26e0058ca393b5ad6684be860e9b4c945253381a Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Thu, 16 Jun 2011 18:09:28 -0400 Subject: [PATCH] allow a default value for attribute_to_bool(); rework config.xml structure slightly --- core/config.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core/config.py b/core/config.py index f7c5785..294d432 100644 --- a/core/config.py +++ b/core/config.py @@ -67,20 +67,21 @@ def make_new_config(): def are_passwords_encrypted(): """Determine if the passwords in our config file are encrypted, returning 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 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() if value in ["true", "1", "on"]: return True elif value in ["false", "0", "off"]: return False + elif value == '': + return default else: e = ("Expected a bool in attribute '{0}' of element '{1}', but " + "got '{2}'.").format(attribute, element.tagName, value)