pg_conf.py 660 Bytes
class Reader:
    def __init__(self, conf_file):
        self.conf = dict()
        with open(conf_file) as f:
            for line in f.readlines():
                s = line.strip()
                if not s:
                    continue
                if s[0] == '#':
                    continue
                t = s.split('#')
                t = t[0].split('=')
                key = t[0].strip()
                value = '='.join(t[1:])
                value = value.strip()
                self.conf[key] = value.strip("'")

    def __getitem__(self, key):
        return self.conf[key]

    def __contains__(self, key):
        return key in self.conf