optionfile.py 651 B

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