1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-06-26 16:45:52 +00:00
Radicale/radicale/hook/__init__.py

44 lines
1.1 KiB
Python
Raw Normal View History

2020-08-17 02:14:04 +02:00
import json
2020-08-17 02:05:02 +02:00
from radicale import utils
2020-08-17 02:14:04 +02:00
from enum import Enum
2020-08-17 02:05:02 +02:00
INTERNAL_TYPES = ("none", "rabbitmq")
def load(configuration):
"""Load the storage module chosen in configuration."""
return utils.load_plugin(
INTERNAL_TYPES, "hook", "Hook", configuration)
class BaseHook:
def __init__(self, configuration):
"""Initialize BaseHook.
``configuration`` see ``radicale.config`` module.
The ``configuration`` must not change during the lifetime of
this object, it is kept as an internal reference.
"""
self.configuration = configuration
2020-08-17 02:14:04 +02:00
def notify(self, notification_item):
2020-08-17 02:05:02 +02:00
"""Upload a new or replace an existing item."""
raise NotImplementedError
2020-08-17 02:14:04 +02:00
class HookNotificationItemTypes(Enum):
UPSERT = "upsert"
DELETE = "delete"
class HookNotificationItem:
def __init__(self, notification_item_type, content):
self.type = notification_item_type.value
self.content = content
def to_json(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)