__init__.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # This file is part of Radicale Server - Calendar Server
  2. # Copyright © 2017-2018 Unrud<unrud@outlook.com>
  3. #
  4. # This library is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  16. from importlib import import_module
  17. from radicale.log import logger
  18. INTERNAL_TYPES = ("none", "internal")
  19. def load(configuration):
  20. """Load the web module chosen in configuration."""
  21. web_type = configuration.get("web", "type")
  22. if web_type in INTERNAL_TYPES:
  23. module = "radicale.web.%s" % web_type
  24. else:
  25. module = web_type
  26. try:
  27. class_ = import_module(module).Web
  28. except Exception as e:
  29. raise RuntimeError("Failed to load web module %r: %s" %
  30. (web_type, e)) from e
  31. logger.info("Web type is %r", web_type)
  32. return class_(configuration)
  33. class BaseWeb:
  34. def __init__(self, configuration):
  35. self.configuration = configuration
  36. def get(self, environ, base_prefix, path, user):
  37. """GET request.
  38. ``base_prefix`` is sanitized and never ends with "/".
  39. ``path`` is sanitized and always starts with "/.web"
  40. ``user`` is empty for anonymous users.
  41. """
  42. raise NotImplementedError