from configparser import ConfigParser from .directory import Directory from .server import Server class Config: def __init__(self): self._parser = ConfigParser() @classmethod def from_file(cls, path): o = cls() o._parser.read(path) return o @property def directories(self): for section in self._parser.sections(): if section.startswith("Directory "): yield Directory.from_config(self._parser[section]) @property def server(self): return Server.from_config(self._parser["Server"])