mirror of https://github.com/langgenius/dify.git
Merge 4db6ba1a15 into 0589fa423b
This commit is contained in:
commit
6234f012d4
|
|
@ -0,0 +1,25 @@
|
||||||
|
class _EventHook:
|
||||||
|
def __init__(self):
|
||||||
|
self._handlers = []
|
||||||
|
|
||||||
|
def __iadd__(self, handler):
|
||||||
|
self._handlers.append(handler)
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __isub__(self, handler):
|
||||||
|
try:
|
||||||
|
self._handlers.remove(handler)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __call__(self, *args, **kwargs):
|
||||||
|
for handler in list(self._handlers):
|
||||||
|
handler(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class Events:
|
||||||
|
def __getattr__(self, name):
|
||||||
|
hook = _EventHook()
|
||||||
|
setattr(self, name, hook)
|
||||||
|
return hook
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
def test_local_events_exports_compat_events_class():
|
||||||
|
import events
|
||||||
|
|
||||||
|
evt = events.Events()
|
||||||
|
called = []
|
||||||
|
|
||||||
|
evt.request_start += lambda *args, **kwargs: called.append((args, kwargs))
|
||||||
|
evt.request_start("GET", "/_search")
|
||||||
|
|
||||||
|
assert len(called) == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_opensearch_import_works_with_local_events_package():
|
||||||
|
from opensearchpy import OpenSearch
|
||||||
|
|
||||||
|
assert OpenSearch is not None
|
||||||
Loading…
Reference in New Issue