signals.py 665 B

1234567891011121314151617181920212223242526272829303132333435
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. from typing import Callable, TYPE_CHECKING
  4. from blinker import Namespace
  5. _signals = Namespace()
  6. post_updated = _signals.signal('post_updated')
  7. if TYPE_CHECKING:
  8. from blinker import Signal
  9. def handler(event):
  10. # type:(Signal)->Callable[object, object]
  11. """Signal decorator to allow use of callback functions as class decorators."""
  12. def decorator(fn):
  13. def call(cls):
  14. event.connect(fn, sender=cls)
  15. return cls
  16. fn.call = call
  17. return fn
  18. return decorator
  19. def post_updated_handler(sender, document, **kwargs):
  20. print sender
  21. print document