polyapi-python 0.2.4.dev0__tar.gz → 0.2.4.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {polyapi_python-0.2.4.dev0/polyapi_python.egg-info → polyapi_python-0.2.4.dev1}/PKG-INFO +1 -1
- polyapi_python-0.2.4.dev1/polyapi/error_handler.py +78 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1/polyapi_python.egg-info}/PKG-INFO +1 -1
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/pyproject.toml +1 -1
- polyapi_python-0.2.4.dev0/polyapi/error_handler.py +0 -52
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/LICENSE +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/README.md +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/__init__.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/__main__.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/api.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/auth.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/cli.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/client.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/config.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/constants.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/exceptions.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/execute.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/function_cli.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/generate.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/py.typed +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/schema.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/server.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/typedefs.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/utils.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/variables.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi/webhook.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi_python.egg-info/SOURCES.txt +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi_python.egg-info/dependency_links.txt +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi_python.egg-info/requires.txt +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi_python.egg-info/top_level.txt +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/setup.cfg +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/tests/test_api.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/tests/test_auth.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/tests/test_function_cli.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/tests/test_server.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/tests/test_utils.py +0 -0
- {polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/tests/test_variables.py +0 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import copy
|
|
3
|
+
import socketio # type: ignore
|
|
4
|
+
from typing import Any, Callable, Dict, List, Optional
|
|
5
|
+
|
|
6
|
+
from polyapi.config import get_api_key_and_url
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
active_handlers: List[Dict[str, Any]] = []
|
|
10
|
+
client = None
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def prepare():
|
|
14
|
+
loop = asyncio.get_event_loop()
|
|
15
|
+
loop.run_until_complete(get_client_and_connect())
|
|
16
|
+
print("Client initialized!")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
async def get_client_and_connect():
|
|
21
|
+
_, base_url = get_api_key_and_url()
|
|
22
|
+
global client
|
|
23
|
+
client = socketio.AsyncClient()
|
|
24
|
+
await client.connect(base_url, transports=["websocket"], namespaces=["/events"])
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
async def unregister(data: Dict[str, Any]):
|
|
28
|
+
print(f"stopping error handler for '{data['path']}'...")
|
|
29
|
+
assert client
|
|
30
|
+
await client.emit(
|
|
31
|
+
"unregisterErrorHandler",
|
|
32
|
+
data,
|
|
33
|
+
"/events",
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
async def unregister_all():
|
|
38
|
+
_, base_url = get_api_key_and_url()
|
|
39
|
+
# need to reconnect because maybe socketio client disconnected after Ctrl+C?
|
|
40
|
+
await client.connect(base_url, transports=["websocket"], namespaces=["/events"])
|
|
41
|
+
await asyncio.gather(*[unregister(handler) for handler in active_handlers])
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
async def on(
|
|
45
|
+
path: str, callback: Callable, options: Optional[Dict[str, Any]] = None
|
|
46
|
+
) -> None:
|
|
47
|
+
print(f"starting error handler for {path}...")
|
|
48
|
+
|
|
49
|
+
if not client:
|
|
50
|
+
raise Exception("Client not initialized. Please call error_handler.prepare() first.")
|
|
51
|
+
|
|
52
|
+
api_key, _ = get_api_key_and_url()
|
|
53
|
+
handler_id = None
|
|
54
|
+
data = copy.deepcopy(options or {})
|
|
55
|
+
data["path"] = path
|
|
56
|
+
data["apiKey"] = api_key
|
|
57
|
+
|
|
58
|
+
def registerCallback(id: int):
|
|
59
|
+
nonlocal handler_id
|
|
60
|
+
handler_id = id
|
|
61
|
+
client.on(f"handleError:{handler_id}", callback, namespace="/events")
|
|
62
|
+
active_handlers.append({"path": path, "id": handler_id, "apiKey": api_key})
|
|
63
|
+
|
|
64
|
+
await client.emit("registerErrorHandler", data, "/events", registerCallback)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def start(*args):
|
|
68
|
+
loop = asyncio.get_event_loop()
|
|
69
|
+
loop.run_until_complete(get_client_and_connect())
|
|
70
|
+
asyncio.gather(*args)
|
|
71
|
+
|
|
72
|
+
try:
|
|
73
|
+
loop.run_forever()
|
|
74
|
+
except KeyboardInterrupt:
|
|
75
|
+
pass
|
|
76
|
+
finally:
|
|
77
|
+
loop.run_until_complete(unregister_all())
|
|
78
|
+
loop.stop()
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
import copy
|
|
3
|
-
import socketio # type: ignore
|
|
4
|
-
from typing import Any, Callable, Dict, Optional
|
|
5
|
-
|
|
6
|
-
from polyapi.config import get_api_key_and_url
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
local_error_handlers: Dict[str, Any] = {}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def on(path: str, callback: Callable, options: Optional[Dict[str, Any]] = None) -> Callable:
|
|
13
|
-
assert not local_error_handlers
|
|
14
|
-
socket = socketio.AsyncClient()
|
|
15
|
-
api_key, base_url = get_api_key_and_url()
|
|
16
|
-
|
|
17
|
-
async def _inner():
|
|
18
|
-
await socket.connect(base_url, transports=["websocket"], namespaces=["/events"])
|
|
19
|
-
|
|
20
|
-
handler_id = None
|
|
21
|
-
data = copy.deepcopy(options or {})
|
|
22
|
-
data["path"] = path
|
|
23
|
-
data["apiKey"] = api_key
|
|
24
|
-
|
|
25
|
-
def registerCallback(id: int):
|
|
26
|
-
nonlocal handler_id, socket
|
|
27
|
-
handler_id = id
|
|
28
|
-
socket.on(f"handleError:{handler_id}", callback, namespace="/events")
|
|
29
|
-
|
|
30
|
-
await socket.emit("registerErrorHandler", data, "/events", registerCallback)
|
|
31
|
-
if local_error_handlers.get(path):
|
|
32
|
-
local_error_handlers[path].append(callback)
|
|
33
|
-
else:
|
|
34
|
-
local_error_handlers[path] = [callback]
|
|
35
|
-
|
|
36
|
-
async def unregister():
|
|
37
|
-
nonlocal handler_id, socket
|
|
38
|
-
if handler_id and socket:
|
|
39
|
-
await socket.emit(
|
|
40
|
-
"unregisterErrorHandler",
|
|
41
|
-
{"id": handler_id, "path": path, "apiKey": api_key},
|
|
42
|
-
namespace="/events",
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
if local_error_handlers.get(path):
|
|
46
|
-
local_error_handlers[path].remove(callback)
|
|
47
|
-
|
|
48
|
-
await socket.wait()
|
|
49
|
-
|
|
50
|
-
return unregister
|
|
51
|
-
|
|
52
|
-
return asyncio.run(_inner())
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi_python.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi_python.egg-info/requires.txt
RENAMED
|
File without changes
|
{polyapi_python-0.2.4.dev0 → polyapi_python-0.2.4.dev1}/polyapi_python.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|