diff options
author | Rob Austein <sra@hactrn.net> | 2009-07-08 18:39:53 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2009-07-08 18:39:53 +0000 |
commit | e73c9f214ee02779169dcf6b4a5eb180a895d597 (patch) | |
tree | 3b93fda6cadb6d7c40211556d02c733d47fbb9b8 | |
parent | b0efb7fe8e09cefd2ef7a595809efc8b33c2a06a (diff) |
Refactor slightly, add getboolean() method, extend documentation.
svn path=/rpkid/rpki/config.py; revision=2599
-rw-r--r-- | rpkid/rpki/config.py | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/rpkid/rpki/config.py b/rpkid/rpki/config.py index 5a25fbfe..ca4e3e8a 100644 --- a/rpkid/rpki/config.py +++ b/rpkid/rpki/config.py @@ -36,6 +36,15 @@ PERFORMANCE OF THIS SOFTWARE. import ConfigParser class parser(ConfigParser.RawConfigParser): + """ + Extensions to stock Python ConfigParser: + + Read config file and set default section while initializing parser object. + + Support for OpenSSL-style subscripted options. + + get-methods with default values and default section name. + """ def __init__(self, filename = None, section = None): """ @@ -64,13 +73,29 @@ class parser(ConfigParser.RawConfigParser): matches.sort() return [match[1] for match in matches] - def get(self, option, default = None, section = None): + def _get_wrapper(self, method, section, option, default): """ - Get an option, perhaps with a default value. + Wrapper method to add default value and default section support to + ConfigParser methods. """ if section is None: section = self.default_section if default is None or self.has_option(section, option): - return ConfigParser.RawConfigParser.get(self, section, option) + return method(self, section, option) else: return default + + + def get(self, option, default = None, section = None): + """ + Get an option, perhaps with a default value. + """ + return self._get_wrapper(ConfigParser.RawConfigParser.get, + section, option, default) + + def getboolean(self, option, default = None, section = None): + """ + Get a boolean option, perhaps with a default value. + """ + return self._get_wrapper(ConfigParser.RawConfigParser.getboolean, + section, option, default) |