summaryrefslogtreecommitdiff
path: root/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'config.py')
-rw-r--r--config.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/config.py b/config.py
index 88826cb..7fd35ad 100644
--- a/config.py
+++ b/config.py
@@ -1,19 +1,25 @@
try:
- from configparser import ConfigParser
+ from configparser import ConfigParser, NoOptionError
except ImportError:
- from ConfigParser import ConfigParser
+ from ConfigParser import ConfigParser, NoOptionError
class Config(object):
- def __init__(self, filename = 'config'):
- self.config_section = 'foo'
+ config_section = 'foo'
+ def __init__(self, filename = 'config'):
self.config = ConfigParser()
self.config.read(filename)
- def get(self, key):
- return self.config.get(self.config_section, key)
+ def get(self, key, section = config_section, default = None):
+ try:
+ return self.config.get(section, key)
+ except NoOptionError:
+ if default != None:
+ return default
+ else:
+ raise
- def getint(self, key):
- return self.config.getint(self.config_section, key)
+ def getint(self, key, section = config_section):
+ return self.config.getint(section, key)
config = Config()