Get rid of the SimpleNamespace for configuration since it complicates config change detection
SimpleNamespace's documentation does not say anything about equality tests, which is why the update_config methods checked the relevant values using a tuple instead. But as more config values are added, this makes the comparisons unnecessarily long. A dict simplifies this. As a side-effect, the constraints of the maps keys being a valid identifier are no longer relevant either.
@@ -23,11 +22,6 @@ class InvalidConfig(Exception):
'''Error in configuration file'''
def _mapping_to_namespace(d):
'''Converts a mapping (e.g. dict) to a types.SimpleNamespace, recursively'''
return types.SimpleNamespace(**{key: _mapping_to_namespace(value) if isinstance(value, collections.abc.Mapping) else value for key, value in d.items()})
def is_valid_pem(path, withCert):
'''Very basic check whether something looks like a valid PEM certificate'''
# Ensure that the key is a valid Python identifier since it will be set as an attribute in the namespace.
#TODO: Support for fancier identifiers (PEP 3131)?
if not isinstance(key, str) or not key or key.strip('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_') != '' or key[0].strip('0123456789') == '':
self._paths = {map_.webpath: (map_.ircchannel, f'Basic {base64.b64encode(map_.auth.encode("utf-8")).decode("utf-8")}' if map_.auth else False) for map_ in config.maps.__dict__.values()}
self._paths = {map_['webpath']: (map_['ircchannel'], f'Basic {base64.b64encode(map_["auth"].encode("utf-8")).decode("utf-8")}' if map_['auth'] else False) for map_ in config['maps'].values()}
needRebind = self.config['web'] != config['web']
self.config = config
if needRebind:
#TODO
@@ -387,7 +376,7 @@ class WebServer:
async def run(self, stopEvent):
runner = aiohttp.web.AppRunner(self._app)
await runner.setup()
site = aiohttp.web.TCPSite(runner, self.config.web.host, self.config.web.port)
site = aiohttp.web.TCPSite(runner, self.config['web']['host'], self.config['web']['port'])