1import configparser
2
3
4class Parser(configparser.RawConfigParser):
5 def __init__(self, **kwargs):
6 kwargs["allow_no_value"] = True
7 configparser.RawConfigParser.__init__(self, **kwargs)
8
9 def __remove_quotes(self, value):
10 quotes = ["'", '"']
11 for quote in quotes:
12 if len(value) >= 2 and value[0] == value[-1] == quote:
13 return value[1:-1]
14 return value
15
16 def optionxform(self, key):
17 return key.lower().replace("_", "-")
18
19 def get(self, section, option):
20 value = configparser.RawConfigParser.get(self, section, option)
21 return self.__remove_quotes(value)