optionfile.py 658 B

1234567891011121314151617181920212223
  1. from ._compat import PY2
  2. if PY2:
  3. import ConfigParser as configparser
  4. else:
  5. import configparser
  6. class Parser(configparser.RawConfigParser):
  7. def __init__(self, **kwargs):
  8. kwargs['allow_no_value'] = True
  9. configparser.RawConfigParser.__init__(self, **kwargs)
  10. def __remove_quotes(self, value):
  11. quotes = ["'", "\""]
  12. for quote in quotes:
  13. if len(value) >= 2 and value[0] == value[-1] == quote:
  14. return value[1:-1]
  15. return value
  16. def get(self, section, option):
  17. value = configparser.RawConfigParser.get(self, section, option)
  18. return self.__remove_quotes(value)