optionfile.py 573 B

123456789101112131415161718
  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 get(self, section, option):
  13. value = configparser.RawConfigParser.get(self, section, option)
  14. return self.__remove_quotes(value)