Extract method loader()

This commit is contained in:
Unrud
2020-01-14 22:43:48 +01:00
parent dcca9bb6f3
commit 8543f3ea1d
5 changed files with 47 additions and 62 deletions

View File

@ -21,27 +21,14 @@ Take a look at the class ``BaseWeb`` if you want to implement your own.
"""
from importlib import import_module
from radicale.log import logger
from radicale import utils
INTERNAL_TYPES = ("none", "internal")
def load(configuration):
"""Load the web module chosen in configuration."""
web_type = configuration.get("web", "type")
if web_type in INTERNAL_TYPES:
module = "radicale.web.%s" % web_type
else:
module = web_type
try:
class_ = import_module(module).Web
except Exception as e:
raise RuntimeError("Failed to load web module %r: %s" %
(module, e)) from e
logger.info("Web type is %r", web_type)
return class_(configuration)
return utils.loader(INTERNAL_TYPES, "web", "Web", configuration)
class BaseWeb: