__init__.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. """
  17. The web module for the website at ``/.web``.
  18. Take a look at the class ``BaseWeb`` if you want to implement your own.
  19. """
  20. from importlib import import_module
  21. from radicale.log import logger
  22. INTERNAL_TYPES = ("none", "internal")
  23. def load(configuration):
  24. """Load the web module chosen in configuration."""
  25. web_type = configuration.get("web", "type")
  26. if web_type in INTERNAL_TYPES:
  27. module = "radicale.web.%s" % web_type
  28. else:
  29. module = web_type
  30. try:
  31. class_ = import_module(module).Web
  32. except Exception as e:
  33. raise RuntimeError("Failed to load web module %r: %s" %
  34. (module, e)) from e
  35. logger.info("Web type is %r", web_type)
  36. return class_(configuration)
  37. class BaseWeb:
  38. def __init__(self, configuration):
  39. """Initialize BaseWeb.
  40. ``configuration`` see ``radicale.config`` module.
  41. The ``configuration`` must not change during the lifetime of
  42. this object, it is kept as an internal reference.
  43. """
  44. self.configuration = configuration
  45. def get(self, environ, base_prefix, path, user):
  46. """GET request.
  47. ``base_prefix`` is sanitized and never ends with "/".
  48. ``path`` is sanitized and always starts with "/.web"
  49. ``user`` is empty for anonymous users.
  50. """
  51. raise NotImplementedError