mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-01-06 11:09:57 -08:00
79cf61c53e
* Bump rumps from 0.3.0 to 0.4.0 Bumps [rumps](https://github.com/jaredks/rumps) from 0.3.0 to 0.4.0. - [Release notes](https://github.com/jaredks/rumps/releases) - [Changelog](https://github.com/jaredks/rumps/blob/master/CHANGES.rst) - [Commits](https://github.com/jaredks/rumps/commits) --- updated-dependencies: - dependency-name: rumps dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Update rumps==0.4.0 Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> [skip ci]
41 lines
1004 B
Python
41 lines
1004 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
import traceback
|
|
|
|
from . import _internal
|
|
|
|
|
|
class EventEmitter(object):
|
|
def __init__(self, name):
|
|
self.name = name
|
|
self.callbacks = set()
|
|
self._executor = _internal.call_as_function_or_method
|
|
|
|
def register(self, func):
|
|
self.callbacks.add(func)
|
|
return func
|
|
|
|
def unregister(self, func):
|
|
try:
|
|
self.callbacks.remove(func)
|
|
return True
|
|
except KeyError:
|
|
return False
|
|
|
|
def emit(self, *args, **kwargs):
|
|
#print('EventEmitter("%s").emit called' % self.name)
|
|
for callback in self.callbacks:
|
|
try:
|
|
self._executor(callback, *args, **kwargs)
|
|
except Exception:
|
|
traceback.print_exc()
|
|
|
|
__call__ = register
|
|
|
|
|
|
before_start = EventEmitter('before_start')
|
|
on_notification = EventEmitter('on_notification')
|
|
on_sleep = EventEmitter('on_sleep')
|
|
on_wake = EventEmitter('on_wake')
|
|
before_quit = EventEmitter('before_quit')
|