polyapi-python 0.2.2__py3-none-any.whl → 0.2.3.dev1__py3-none-any.whl

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.
@@ -0,0 +1,52 @@
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())
polyapi/generate.py CHANGED
@@ -76,14 +76,11 @@ def cache_specs(specs: List[SpecificationDto]):
76
76
 
77
77
  full_path = os.path.dirname(os.path.abspath(__file__))
78
78
  full_path = os.path.join(full_path, "poly")
79
- try:
80
- if not os.path.exists(full_path):
81
- os.makedirs(full_path)
82
-
83
- with open(os.path.join(full_path, "specs.json"), "w") as f:
84
- f.write(json.dumps(supported))
85
- except Exception as e:
86
- print("Failed to cache specs", e)
79
+ if not os.path.exists(full_path):
80
+ os.makedirs(full_path)
81
+
82
+ with open(os.path.join(full_path, "specs.json"), "w") as f:
83
+ f.write(json.dumps(supported))
87
84
 
88
85
 
89
86
  def read_cached_specs() -> List[SpecificationDto]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.2.2
3
+ Version: 0.2.3.dev1
4
4
  Summary: The PolyAPI Python Client
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -5,10 +5,11 @@ polyapi/auth.py,sha256=p2KSLt6q52t9gnqPmgXTOQ2_lmdFilZkIoGmQrRTPLQ,5330
5
5
  polyapi/cli.py,sha256=wMv4RpNDEz2qIQ5NjlRTop-ImfeeqCSkx22ZIrzwA50,2086
6
6
  polyapi/config.py,sha256=S8TU10upy5OW1_vX-CqQTJD-ZOB6329aMjiUCmukfUI,2292
7
7
  polyapi/constants.py,sha256=NGjso6K5rGnE8TGdrXmdEfvvr-HI3DTVGwOYiWO68LM,511
8
+ polyapi/error_handler.py,sha256=vl6ZBtsHmC3eu13IMpmZEXBTDJbrPrzmViBCCrEspd4,1621
8
9
  polyapi/exceptions.py,sha256=Zh7i7eCUhDuXEdUYjatkLFTeZkrx1BJ1P5ePgbJ9eIY,89
9
10
  polyapi/execute.py,sha256=06XWTxGJqtsDiLY10RjRebIMFRfhtAIMmBRbuWu3e8A,1873
10
11
  polyapi/function_cli.py,sha256=5e6hJ3nitKxbQNSkp4jbuAzbJvykj3de1_aSsc1MBnY,7331
11
- polyapi/generate.py,sha256=XGhr0Re-Lwasvc309aYCGaD3V_0BgITmo4u9GQaCJOc,9064
12
+ polyapi/generate.py,sha256=ZZVkA3uL5yPWisnFhIBjoFAYfr96h9m6I0XOCbEpiyk,8970
12
13
  polyapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
14
  polyapi/schema.py,sha256=1a7nIO867Xy3bagmPUNdYMxtS5OoCAv8oKIbYgj55dk,2957
14
15
  polyapi/server.py,sha256=mcbH8pG16fFMiFL52wdii0217ZLsznQnElAFEvXZ7IA,2211
@@ -16,8 +17,8 @@ polyapi/typedefs.py,sha256=RZ3I6sgJm_5MuuORG1QjUE-UJy_z2WRXNdiWjEdLvQg,1371
16
17
  polyapi/utils.py,sha256=wZQrwSOst5wyoYYLoMk1DnAEbVsJ0-2YkmmDQ9gI3FY,5399
17
18
  polyapi/variables.py,sha256=d36-trnfTL_8m2NkorMiImb4O3UrJbiFV38CHxV5i0A,4200
18
19
  polyapi/webhook.py,sha256=A89eNnYcVpVe9doJPDLfscIhF-C7Q2AI3vu-SzGxMBg,2923
19
- polyapi_python-0.2.2.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
20
- polyapi_python-0.2.2.dist-info/METADATA,sha256=VAxKcFB7eUp5MRe8O0sfpYVN-lXVNP82I4bBo5JbZuE,4818
21
- polyapi_python-0.2.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
22
- polyapi_python-0.2.2.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
23
- polyapi_python-0.2.2.dist-info/RECORD,,
20
+ polyapi_python-0.2.3.dev1.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
21
+ polyapi_python-0.2.3.dev1.dist-info/METADATA,sha256=9IbEwxs-o-u_OMvTeOW_MjVIMMCQr98eqKAhPRWSy3s,4823
22
+ polyapi_python-0.2.3.dev1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
23
+ polyapi_python-0.2.3.dev1.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
24
+ polyapi_python-0.2.3.dev1.dist-info/RECORD,,