Source code for yell
__version__ = "0.3.2"
import registry
[docs]class Notification(object):
"""
Base class for any kind of notifications. Inherit from this class to create
your own notification types and backends.
Subclasses need to implement :meth:`notify`.
"""
__metaclass__ = MetaNotification
name = None
"""
A name for this notification.
"""
[docs] def notify(self, *args, **kwargs):
"""
A method that delivers a notification.
"""
raise NotImplementedError
[docs]def notify(name, *args, **kwargs):
"""
Send notifications. If ``backends==None``, all backends with the same name
will be used to deliver a notification.
If ``backends`` is a list, only the specified backends will be used.
:param name: The notification to send
:param backends: A list of backends to be used or ``None`` to use all associated backends
"""
assert name in registry.notifications, "'{0}' is not a valid notification.".format(repr(name))
backends = kwargs.pop('backends', None)
if backends is None:
backends = registry.notifications[name]
results = []
for Backend in backends:
backend = Backend()
results.append(backend.notify(*args, **kwargs))
return results