1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# -*- coding: utf-8 -*-
"""
pyee supplies a ``EventEmitter`` class that is similar to the
``EventEmitter`` class from Node.js. In addition, it supplies the subclasses
``AsyncIOEventEmitter``, ``TwistedEventEmitter`` and ``ExecutorEventEmitter``
for supporting async and threaded execution with asyncio, twisted, and
concurrent.futures Executors respectively, as supported by the environment.
Example
-------
::
In [1]: from pyee.base import EventEmitter
In [2]: ee = EventEmitter()
In [3]: @ee.on('event')
...: def event_handler():
...: print('BANG BANG')
...:
In [4]: ee.emit('event')
BANG BANG
In [5]:
"""
from warnings import warn
from pyee.base import EventEmitter as EventEmitter
from pyee.base import PyeeException
class BaseEventEmitter(EventEmitter):
"""
BaseEventEmitter is deprecated and an alias for EventEmitter.
"""
def __init__(self):
warn(
DeprecationWarning(
"pyee.BaseEventEmitter is deprecated and will be removed in a "
"future major version; you should instead use pyee.EventEmitter."
)
)
super(BaseEventEmitter, self).__init__()
__all__ = ["BaseEventEmitter", "EventEmitter", "PyeeException"]
try:
from pyee.asyncio import AsyncIOEventEmitter as _AsyncIOEventEmitter # noqa
class AsyncIOEventEmitter(_AsyncIOEventEmitter):
"""
AsyncIOEventEmitter has been moved to the pyee.asyncio module.
"""
def __init__(self, loop=None):
warn(
DeprecationWarning(
"pyee.AsyncIOEventEmitter has been moved to the pyee.asyncio "
"module."
)
)
super(AsyncIOEventEmitter, self).__init__(loop=loop)
__all__.append("AsyncIOEventEmitter")
except ImportError:
pass
try:
from pyee.twisted import TwistedEventEmitter as _TwistedEventEmitter # noqa
class TwistedEventEmitter(_TwistedEventEmitter):
"""
TwistedEventEmitter has been moved to the pyee.twisted module.
"""
def __init__(self):
warn(
DeprecationWarning(
"pyee.TwistedEventEmitter has been moved to the pyee.twisted "
"module."
)
)
super(TwistedEventEmitter, self).__init__()
__all__.append("TwistedEventEmitter")
except ImportError:
pass
try:
from pyee.executor import ExecutorEventEmitter as _ExecutorEventEmitter # noqa
class ExecutorEventEmitter(_ExecutorEventEmitter):
"""
ExecutorEventEmitter has been moved to the pyee.executor module.
"""
def __init__(self, executor=None):
warn(
DeprecationWarning(
"pyee.ExecutorEventEmitter has been moved to the pyee.executor "
"module."
)
)
super(ExecutorEventEmitter, self).__init__(executor=executor)
__all__.append("ExecutorEventEmitter")
except ImportError:
pass
try:
from pyee.trio import TrioEventEmitter as _TrioEventEmitter # noqa
class TrioEventEmitter(_TrioEventEmitter):
"""
TrioEventEmitter has been moved to the pyee.trio module.
"""
def __init__(self, nursery=None, manager=None):
warn(
DeprecationWarning(
"pyee.TrioEventEmitter has been moved to the pyee.trio module."
)
)
super(TrioEventEmitter, self).__init__(nursery=nursery, manager=manager)
__all__.append("TrioEventEmitter")
except (ImportError, SyntaxError):
pass
|