__init__.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import json
  2. from enum import Enum
  3. from radicale import utils
  4. INTERNAL_TYPES = ("none", "rabbitmq")
  5. def load(configuration):
  6. """Load the storage module chosen in configuration."""
  7. return utils.load_plugin(
  8. INTERNAL_TYPES, "hook", "Hook", configuration)
  9. class BaseHook:
  10. def __init__(self, configuration):
  11. """Initialize BaseHook.
  12. ``configuration`` see ``radicale.config`` module.
  13. The ``configuration`` must not change during the lifetime of
  14. this object, it is kept as an internal reference.
  15. """
  16. self.configuration = configuration
  17. def notify(self, notification_item):
  18. """Upload a new or replace an existing item."""
  19. raise NotImplementedError
  20. class HookNotificationItemTypes(Enum):
  21. UPSERT = "upsert"
  22. DELETE = "delete"
  23. class HookNotificationItem:
  24. def __init__(self, notification_item_type, content):
  25. self.type = notification_item_type.value
  26. self.content = content
  27. def to_json(self):
  28. return json.dumps(
  29. self,
  30. default=lambda o: o.__dict__,
  31. sort_keys=True,
  32. indent=4
  33. )