summaryrefslogtreecommitdiffstats
path: root/python/webiopi/utils/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/webiopi/utils/config.py')
-rw-r--r--python/webiopi/utils/config.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/python/webiopi/utils/config.py b/python/webiopi/utils/config.py
new file mode 100644
index 0000000..72302e5
--- /dev/null
+++ b/python/webiopi/utils/config.py
@@ -0,0 +1,35 @@
1from webiopi.utils.version import PYTHON_MAJOR
2
3if PYTHON_MAJOR >= 3:
4 import configparser as parser
5else:
6 import ConfigParser as parser
7
8class Config():
9
10 def __init__(self, configfile=None):
11 config = parser.ConfigParser()
12 config.optionxform = str
13 if configfile != None:
14 config.read(configfile)
15 self.config = config
16
17 def get(self, section, key, default):
18 if self.config.has_option(section, key):
19 return self.config.get(section, key)
20 return default
21
22 def getboolean(self, section, key, default):
23 if self.config.has_option(section, key):
24 return self.config.getboolean(section, key)
25 return default
26
27 def getint(self, section, key, default):
28 if self.config.has_option(section, key):
29 return self.config.getint(section, key)
30 return default
31
32 def items(self, section):
33 if self.config.has_section(section):
34 return self.config.items(section)
35 return {}