polyapi-python 0.3.14.dev4__py3-none-any.whl → 0.3.16__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/http_client.py CHANGED
@@ -3,6 +3,7 @@ import httpx
3
3
 
4
4
  _sync_client: httpx.Client | None = None
5
5
  _async_client: httpx.AsyncClient | None = None
6
+ _async_client_loop: asyncio.AbstractEventLoop | None = None
6
7
 
7
8
 
8
9
  def _get_sync_client() -> httpx.Client:
@@ -13,9 +14,11 @@ def _get_sync_client() -> httpx.Client:
13
14
 
14
15
 
15
16
  def _get_async_client() -> httpx.AsyncClient:
16
- global _async_client
17
- if _async_client is None:
17
+ global _async_client, _async_client_loop
18
+ current_loop = asyncio.get_running_loop()
19
+ if _async_client is None or _async_client_loop is not current_loop:
18
20
  _async_client = httpx.AsyncClient(timeout=None)
21
+ _async_client_loop = current_loop
19
22
  return _async_client
20
23
 
21
24
 
@@ -66,8 +69,15 @@ def close():
66
69
  _sync_client = None
67
70
 
68
71
  async def close_async():
69
- global _sync_client, _async_client
72
+ global _sync_client, _async_client, _async_client_loop
70
73
  close()
71
- if _async_client is not None:
72
- await _async_client.aclose()
73
- _async_client = None
74
+ client = _async_client
75
+ client_loop = _async_client_loop
76
+ _async_client = None
77
+ _async_client_loop = None
78
+ if client is None:
79
+ return
80
+
81
+ current_loop = asyncio.get_running_loop()
82
+ if client_loop is current_loop:
83
+ await client.aclose()
polyapi/schema.py CHANGED
@@ -101,8 +101,11 @@ def generate_schema_types(input_data: Dict, root=None):
101
101
  return output
102
102
 
103
103
 
104
- # Regex to match everything between "# example: {\n" and "^}$"
105
- MALFORMED_EXAMPLES_PATTERN = re.compile(r"# example: \{\n.*?^\}$", flags=re.DOTALL | re.MULTILINE)
104
+ # Matches commented example headers emitted by jsonschema-gentypes before a raw
105
+ # multiline JSON object/array body that is not commented out.
106
+ MALFORMED_EXAMPLE_HEADER_PATTERN = re.compile(
107
+ r"^\s*#\s*(?:\|\s*)?example:\s*([\[{])\s*$"
108
+ )
106
109
 
107
110
  # Regex to fix invalid escape sequences in docstrings
108
111
  INVALID_ESCAPE_PATTERNS = [
@@ -117,8 +120,24 @@ def clean_malformed_examples(example: str) -> str:
117
120
  """ there is a bug in the `jsonschmea_gentypes` library where if an example from a jsonchema is an object,
118
121
  it will break the code because the object won't be properly commented out. Also fixes invalid escape sequences.
119
122
  """
120
- # Remove malformed examples
121
- cleaned_example = MALFORMED_EXAMPLES_PATTERN.sub("", example)
123
+ cleaned_lines = []
124
+ balance = 0
125
+ skipping_example = False
126
+
127
+ for line in example.splitlines(keepends=True):
128
+ if not skipping_example:
129
+ if MALFORMED_EXAMPLE_HEADER_PATTERN.match(line):
130
+ skipping_example = True
131
+ balance = line.count("{") + line.count("[") - line.count("}") - line.count("]")
132
+ continue
133
+ cleaned_lines.append(line)
134
+ continue
135
+
136
+ balance += line.count("{") + line.count("[") - line.count("}") - line.count("]")
137
+ if balance <= 0:
138
+ skipping_example = False
139
+
140
+ cleaned_example = "".join(cleaned_lines)
122
141
 
123
142
  # Fix invalid escape sequences in docstrings
124
143
  for pattern, replacement in INVALID_ESCAPE_PATTERNS:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polyapi-python
3
- Version: 0.3.14.dev4
3
+ Version: 0.3.16
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
@@ -13,22 +13,22 @@ polyapi/exceptions.py,sha256=Zh7i7eCUhDuXEdUYjatkLFTeZkrx1BJ1P5ePgbJ9eIY,89
13
13
  polyapi/execute.py,sha256=MeAmc5qsMQfnQPiHJK9Khkn_wrBxMoyMYYqmuFFPsRg,8779
14
14
  polyapi/function_cli.py,sha256=kKrecKCDNMmYtcOOCVF2KKOGjFUfWD2TbiVsyYQ84y8,4323
15
15
  polyapi/generate.py,sha256=TjMlxxjWN1WnFEmOjSygFcl9RkHCZeCq79R-K_7GYRU,21059
16
- polyapi/http_client.py,sha256=dfsfFzHlhScQgYMf3zJshJJCwgJGQqM8B5peY9O4NPU,1872
16
+ polyapi/http_client.py,sha256=Pd6FYHGB6plWlBbwZD9LPP6FEicdp0wyLWHd_9jxsaY,2273
17
17
  polyapi/parser.py,sha256=pAkeuwp1Kn6bHXiIoj-DuXQ518PztQThIa8vztgsKLQ,21525
18
18
  polyapi/poly_schemas.py,sha256=fZ6AGvHcOKQJtlrzSuzeBNed5DxPMA2dJGdJvuFCHWM,9066
19
19
  polyapi/poly_tables.py,sha256=T07j4H-HdcIFP5HwUq0uljpzzYzMtJvdqYvOdC0oZ4I,19728
20
20
  polyapi/prepare.py,sha256=DBlrQu_A0PqdaQ3KlMs-C6PkV3qncatkAiBlC7j2hnk,7441
21
21
  polyapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  polyapi/rendered_spec.py,sha256=J2Num7MXnW_mKAe2MSVIL1coWopNYZ-6nNNwQRfseV0,2262
23
- polyapi/schema.py,sha256=-mtRV5iL3CV0X3phXhGYFV8sLz0KouTACOKWyGO9Pwc,5309
23
+ polyapi/schema.py,sha256=2ehUgs4IcNvqsg5cUjZReg-X83hbh4l0eStKmJhFsBY,5921
24
24
  polyapi/server.py,sha256=35l3f9d6jWaa60MfX5n7KF4UCAQR-Xg8WLc0NL9dlfY,2479
25
25
  polyapi/sync.py,sha256=t0Khh8B5GylxB7KWRP_xvkrvkuyVarSLCOvtmaz7lcc,6766
26
26
  polyapi/typedefs.py,sha256=mfll-KrngOW0wzbvDNiIDaDkFMwbsT-MY5y5hzWj9RE,5642
27
27
  polyapi/utils.py,sha256=VN8n_jvphderplI5MDYjSutxVnYbJjHhJznYkwjgstw,13349
28
28
  polyapi/variables.py,sha256=hfSDPGQK6YphNCa9MqE0W88WIFfqCQWgpBDWkExMq-A,7582
29
29
  polyapi/webhook.py,sha256=0ceLwHNjNd2Yx_8MX5jOIxiQ5Lwhy2pe81ProAuKon0,5108
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,,
30
+ polyapi_python-0.3.16.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
31
+ polyapi_python-0.3.16.dist-info/METADATA,sha256=6cpwjHGYw4FUgfcoCI_isd-JYAm52BZDzr-KrqST1qs,5923
32
+ polyapi_python-0.3.16.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
33
+ polyapi_python-0.3.16.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
34
+ polyapi_python-0.3.16.dist-info/RECORD,,