Created
March 1, 2022 13:01
-
-
Save jsenin/245097d8afcb90c76546d85fc5a57f84 to your computer and use it in GitHub Desktop.
py-asterisk error from ExceptionBase need to provide a message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Asterisk/Util.py | |
class EventCollection(Logging.InstanceLogger): | |
''' | |
Utility class to allow grouping and automatic registration of event. | |
''' | |
def __init__(self, initial=None): | |
''' | |
If <initial> is not None, register functions from the list <initial> | |
waiting for events with the same name as the function. | |
''' | |
self.subscriptions = {} | |
self.log = self.getLogger() | |
if initial is not None: | |
for func in initial: | |
self.subscribe(func.__name__, func) | |
def subscribe(self, name, handler): | |
''' | |
Subscribe callable <handler> to event named <name>. | |
''' | |
if name not in self.subscriptions: | |
subscriptions = self.subscriptions[name] = [] | |
else: | |
subscriptions = self.subscriptions[name] | |
if handler in subscriptions: | |
raise SubscriptionError # pylint: disable=W0710 | |
subscriptions.append(handler) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(felix) jorge@penta:~$ ipython | |
Python 3.9.2 (default, Feb 28 2021, 17:03:44) | |
Type 'copyright', 'credits' or 'license' for more information | |
IPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help. | |
In [1]: from Asterisk.Util import SubscriptionError | |
In [2]: SubscriptionError | |
Out[2]: Asterisk.Util.SubscriptionError | |
In [3]: raise SubscriptionError | |
--------------------------------------------------------------------------- | |
TypeError Traceback (most recent call last) | |
<ipython-input-3-d76b471ae3a5> in <module> | |
----> 1 raise SubscriptionError | |
TypeError: __init__() missing 1 required positional argument: 'error' | |
In [4]: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Suscribing two times the same handler for an event, a SubscriptionError without explanation will be raised
this error need to have a message