Преглед на файлове

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

tags/v0.1^2
Ben Kurtovic преди 13 години
родител
ревизия
26e0058ca3
променени са 1 файла, в които са добавени 7 реда и са изтрити 6 реда
  1. +7
    -6
      core/config.py

+ 7
- 6
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)


Зареждане…
Отказ
Запис