polyapi-python 0.3.14.dev2__py3-none-any.whl → 0.3.14.dev4__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.
polyapi/__init__.py CHANGED
@@ -1,11 +1,16 @@
1
+ import copy
1
2
  import os
2
3
  import sys
3
- import copy
4
+ from contextvars import ContextVar, Token
5
+ from dataclasses import dataclass
6
+ from typing import Any, Dict, Literal, Optional, overload
7
+
4
8
  import truststore
5
- from typing import Any, Dict, Optional, overload, Literal
6
9
  from typing_extensions import TypedDict
10
+
11
+ from .cli_constants import CLI_COMMANDS
12
+
7
13
  truststore.inject_into_ssl()
8
- from .cli import CLI_COMMANDS
9
14
 
10
15
  __all__ = ["poly"]
11
16
 
@@ -19,83 +24,140 @@ if len(sys.argv) > 1 and sys.argv[1] not in CLI_COMMANDS:
19
24
 
20
25
  class PolyCustomDict(TypedDict, total=False):
21
26
  """Type definition for polyCustom dictionary."""
22
- executionId: Optional[str] # Read-only
27
+
28
+ executionId: Optional[str] # Read-only unless explicitly unlocked
23
29
  executionApiKey: Optional[str]
24
- responseStatusCode: int
30
+ userSessionId: Optional[str]
31
+ responseStatusCode: Optional[int]
25
32
  responseContentType: Optional[str]
26
- responseHeaders: Dict[str, str]
27
-
28
-
29
- class _PolyCustom:
30
- def __init__(self):
31
- self._internal_store = {
32
- "executionId": None,
33
- "executionApiKey": None,
34
- "responseStatusCode": 200,
35
- "responseContentType": None,
36
- "responseHeaders": {},
37
- }
38
- self._execution_id_locked = False
33
+ responseHeaders: Dict[str, Any]
34
+
35
+
36
+ @dataclass
37
+ class _PolyCustomState:
38
+ internal_store: Dict[str, Any]
39
+ execution_id_locked: bool = False
40
+
41
+
42
+ class PolyCustom:
43
+ def __init__(self) -> None:
44
+ object.__setattr__(
45
+ self,
46
+ "_default_store",
47
+ {
48
+ "executionId": None,
49
+ "executionApiKey": None,
50
+ "userSessionId": None,
51
+ "responseStatusCode": 200,
52
+ "responseContentType": None,
53
+ "responseHeaders": {},
54
+ },
55
+ )
56
+ object.__setattr__(self, "_state_var", ContextVar("_poly_custom_state", default=None))
57
+
58
+ def _make_state(self) -> _PolyCustomState:
59
+ return _PolyCustomState(internal_store=copy.deepcopy(self._default_store))
60
+
61
+ def _get_state(self) -> _PolyCustomState:
62
+ state = self._state_var.get()
63
+ if state is None:
64
+ state = self._make_state()
65
+ self._state_var.set(state)
66
+ return state
67
+
68
+ def push_scope(self, initial_values: Optional[Dict[str, Any]] = None) -> Token:
69
+ state = self._make_state()
70
+ if initial_values:
71
+ state.internal_store.update(copy.deepcopy(initial_values))
72
+ if state.internal_store.get("executionId") is not None:
73
+ state.execution_id_locked = True
74
+ return self._state_var.set(state)
75
+
76
+ def pop_scope(self, token: Token) -> None:
77
+ self._state_var.reset(token)
39
78
 
40
79
  def set_once(self, key: str, value: Any) -> None:
41
- if key == "executionId" and self._execution_id_locked:
42
- # Silently ignore attempts to overwrite locked executionId
80
+ state = self._get_state()
81
+ if key == "executionId" and state.execution_id_locked:
43
82
  return
44
- self._internal_store[key] = value
83
+ state.internal_store[key] = value
45
84
  if key == "executionId":
46
- # Lock executionId after setting it
47
- self.lock_execution_id()
85
+ state.execution_id_locked = True
48
86
 
49
87
  def get(self, key: str, default: Any = None) -> Any:
50
- return self._internal_store.get(key, default)
88
+ return self._get_state().internal_store.get(key, default)
51
89
 
52
90
  def lock_execution_id(self) -> None:
53
- self._execution_id_locked = True
91
+ self._get_state().execution_id_locked = True
54
92
 
55
93
  def unlock_execution_id(self) -> None:
56
- self._execution_id_locked = False
94
+ self._get_state().execution_id_locked = False
57
95
 
58
96
  @overload
59
97
  def __getitem__(self, key: Literal["executionId"]) -> Optional[str]: ...
60
-
98
+
61
99
  @overload
62
100
  def __getitem__(self, key: Literal["executionApiKey"]) -> Optional[str]: ...
63
-
101
+
64
102
  @overload
65
- def __getitem__(self, key: Literal["responseStatusCode"]) -> int: ...
66
-
103
+ def __getitem__(self, key: Literal["userSessionId"]) -> Optional[str]: ...
104
+
105
+ @overload
106
+ def __getitem__(self, key: Literal["responseStatusCode"]) -> Optional[int]: ...
107
+
67
108
  @overload
68
109
  def __getitem__(self, key: Literal["responseContentType"]) -> Optional[str]: ...
69
110
 
70
111
  @overload
71
- def __getitem__(self, key: Literal["responseHeaders"]) -> Dict[str, str]: ...
72
-
112
+ def __getitem__(self, key: Literal["responseHeaders"]) -> Dict[str, Any]: ...
113
+
73
114
  def __getitem__(self, key: str) -> Any:
74
115
  return self.get(key)
75
116
 
76
117
  @overload
77
118
  def __setitem__(self, key: Literal["executionApiKey"], value: Optional[str]) -> None: ...
78
-
119
+
120
+ @overload
121
+ def __setitem__(self, key: Literal["userSessionId"], value: Optional[str]) -> None: ...
122
+
79
123
  @overload
80
- def __setitem__(self, key: Literal["responseStatusCode"], value: int) -> None: ...
81
-
124
+ def __setitem__(self, key: Literal["responseStatusCode"], value: Optional[int]) -> None: ...
125
+
82
126
  @overload
83
127
  def __setitem__(self, key: Literal["responseContentType"], value: Optional[str]) -> None: ...
84
128
 
85
129
  @overload
86
- def __setitem__(self, key: Literal["responseHeaders"], value: Dict[str, str]) -> None: ...
87
-
130
+ def __setitem__(self, key: Literal["responseHeaders"], value: Dict[str, Any]) -> None: ...
131
+
88
132
  def __setitem__(self, key: str, value: Any) -> None:
89
133
  self.set_once(key, value)
90
134
 
91
- def __repr__(self) -> str:
92
- return f"PolyCustom({self._internal_store})"
135
+ def __getattr__(self, key: str) -> Any:
136
+ if key in self._default_store:
137
+ return self.get(key)
138
+ raise AttributeError(f"{type(self).__name__!r} object has no attribute {key!r}")
139
+
140
+ def __setattr__(self, key: str, value: Any) -> None:
141
+ if key.startswith("_"):
142
+ object.__setattr__(self, key, value)
143
+ return
144
+ self.set_once(key, value)
93
145
 
94
- def copy(self) -> '_PolyCustom':
95
- new = _PolyCustom()
96
- new._internal_store = copy.deepcopy(self._internal_store)
97
- new._execution_id_locked = self._execution_id_locked
146
+ def __repr__(self) -> str:
147
+ return f"PolyCustom({self._get_state().internal_store})"
148
+
149
+ def copy(self) -> "PolyCustom":
150
+ new = PolyCustom()
151
+ state = self._get_state()
152
+ new._state_var.set(
153
+ _PolyCustomState(
154
+ internal_store=copy.deepcopy(state.internal_store),
155
+ execution_id_locked=state.execution_id_locked,
156
+ )
157
+ )
98
158
  return new
99
159
 
100
160
 
101
- polyCustom: PolyCustomDict = _PolyCustom()
161
+ _PolyCustom = PolyCustom
162
+
163
+ polyCustom: PolyCustom = PolyCustom()
polyapi/cli.py CHANGED
@@ -3,6 +3,7 @@ import argparse
3
3
 
4
4
  from polyapi.utils import print_green, print_red
5
5
 
6
+ from .cli_constants import CLI_COMMANDS
6
7
  from .config import initialize_config, set_api_key_and_url
7
8
  from .generate import generate, clear
8
9
  from .function_cli import function_add_or_update, function_execute
@@ -11,9 +12,6 @@ from .prepare import prepare_deployables
11
12
  from .sync import sync_deployables
12
13
 
13
14
 
14
- CLI_COMMANDS = ["setup", "generate", "function", "clear", "help", "update_rendered_spec"]
15
-
16
-
17
15
  def _get_version_string():
18
16
  """Get the version string for the package."""
19
17
  try:
@@ -0,0 +1,10 @@
1
+ CLI_COMMANDS = (
2
+ "setup",
3
+ "generate",
4
+ "function",
5
+ "clear",
6
+ "help",
7
+ "update_rendered_spec",
8
+ "prepare",
9
+ "sync",
10
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polyapi-python
3
- Version: 0.3.14.dev2
3
+ Version: 0.3.14.dev4
4
4
  Summary: The Python Client for PolyAPI, the IPaaS by Developers for Developers
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -1,8 +1,9 @@
1
- polyapi/__init__.py,sha256=hw7x4j9JNJfPdkIOZqV0X9pbYcw3_5AH1iQFdSogH-c,3235
1
+ polyapi/__init__.py,sha256=vV1N9xtIMtpi4o-2jAI3775LkzRbC9JUo87MAnW9zgo,5201
2
2
  polyapi/__main__.py,sha256=V4zhAh_YGxno5f_KSrlkELxcuDh9bR3WSd0n-2r-qQQ,93
3
3
  polyapi/api.py,sha256=CzqX99GekhQJVqAAWlL03hUenIi_5iTln9cWgQzz6Ko,2784
4
4
  polyapi/auth.py,sha256=l0pGAoYvEWqa2TMsrM9GS8imXu3GsWvpn4eFPy1vksI,6195
5
- polyapi/cli.py,sha256=3M6XpMhpvQSHq4X8tBsq7N93YEwyVIqNFkz1tx_6aSs,11107
5
+ polyapi/cli.py,sha256=lWHm2yNx8LELtCqUQOY_N7e8QTa7fM0ZZgC5d2h3E3E,11055
6
+ polyapi/cli_constants.py,sha256=eZnAqAo8HLxHH3cdAoGWbrsALAtEWJFXRdSS2lvQvzE,144
6
7
  polyapi/client.py,sha256=DW6ljG_xCwAo2yz23A9QfLooE6ZUDvSpdA4e_dCQjiQ,1418
7
8
  polyapi/config.py,sha256=dnowfPKEau5sA4zwBzLK_dYAHA-Wi3AOnMtDNsYwUmM,7520
8
9
  polyapi/constants.py,sha256=i3j0-ptd7XEs6ovnYegEhiP0BRs1JSKAq1oE5CWbDVo,707
@@ -26,8 +27,8 @@ polyapi/typedefs.py,sha256=mfll-KrngOW0wzbvDNiIDaDkFMwbsT-MY5y5hzWj9RE,5642
26
27
  polyapi/utils.py,sha256=VN8n_jvphderplI5MDYjSutxVnYbJjHhJznYkwjgstw,13349
27
28
  polyapi/variables.py,sha256=hfSDPGQK6YphNCa9MqE0W88WIFfqCQWgpBDWkExMq-A,7582
28
29
  polyapi/webhook.py,sha256=0ceLwHNjNd2Yx_8MX5jOIxiQ5Lwhy2pe81ProAuKon0,5108
29
- polyapi_python-0.3.14.dev2.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
30
- polyapi_python-0.3.14.dev2.dist-info/METADATA,sha256=xOFSWEGUStR7z9kepTsvF3CuyEWqYSC9XggXEErB39Q,5928
31
- polyapi_python-0.3.14.dev2.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
32
- polyapi_python-0.3.14.dev2.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
33
- polyapi_python-0.3.14.dev2.dist-info/RECORD,,
30
+ polyapi_python-0.3.14.dev4.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
31
+ polyapi_python-0.3.14.dev4.dist-info/METADATA,sha256=_SPOiz8v0LAzfWBJQw4XwS7w0Z5-sJuPW7WghBXnT38,5928
32
+ polyapi_python-0.3.14.dev4.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
33
+ polyapi_python-0.3.14.dev4.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
34
+ polyapi_python-0.3.14.dev4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (82.0.0)
2
+ Generator: setuptools (82.0.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5