__init__.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # This file is part of Radicale - CalDAV and CardDAV 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 typing import Sequence
  21. from radicale import config, httputils, types, utils
  22. INTERNAL_TYPES: Sequence[str] = ("none", "internal")
  23. def load(configuration: "config.Configuration") -> "BaseWeb":
  24. """Load the web module chosen in configuration."""
  25. return utils.load_plugin(INTERNAL_TYPES, "web", "Web", BaseWeb,
  26. configuration)
  27. class BaseWeb:
  28. configuration: "config.Configuration"
  29. def __init__(self, configuration: "config.Configuration") -> None:
  30. """Initialize BaseWeb.
  31. ``configuration`` see ``radicale.config`` module.
  32. The ``configuration`` must not change during the lifetime of
  33. this object, it is kept as an internal reference.
  34. """
  35. self.configuration = configuration
  36. def get(self, environ: types.WSGIEnviron, base_prefix: str, path: str,
  37. user: str) -> types.WSGIResponse:
  38. """GET request.
  39. ``base_prefix`` is sanitized and never ends with "/".
  40. ``path`` is sanitized and always starts with "/.web"
  41. ``user`` is empty for anonymous users.
  42. """
  43. return httputils.METHOD_NOT_ALLOWED
  44. def post(self, environ: types.WSGIEnviron, base_prefix: str, path: str,
  45. user: str) -> types.WSGIResponse:
  46. """POST 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. Use ``httputils.read*_request_body(self.configuration, environ)`` to
  51. read the body.
  52. """
  53. return httputils.METHOD_NOT_ALLOWED