polyapi-python 0.3.9.dev6__py3-none-any.whl → 0.3.9.dev7__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
@@ -2,6 +2,8 @@ import os
2
2
  import sys
3
3
  import copy
4
4
  import truststore
5
+ import logging
6
+ import builtins
5
7
  from typing import Any, Dict, Optional, overload, Literal
6
8
  from typing_extensions import TypedDict
7
9
  truststore.inject_into_ssl()
@@ -98,4 +100,19 @@ class _PolyCustom:
98
100
  return new
99
101
 
100
102
 
101
- polyCustom: PolyCustomDict = _PolyCustom()
103
+ polyCustom: PolyCustomDict = _PolyCustom()
104
+
105
+ original_print = print
106
+
107
+ logging.basicConfig(level=logging.INFO, format='%(levelname)s - %(message)s')
108
+
109
+ def log_prints(*objects, sep=' ', end='\n', file=sys.stdout, flush=False):
110
+ message = sep.join(map(str, objects)) + end
111
+ if file is sys.stdout:
112
+ logging.info(message)
113
+ elif file is sys.stderr:
114
+ logging.error(message)
115
+ else:
116
+ original_print(*objects, sep=sep, end=end, file=file, flush=flush)
117
+
118
+ builtins.print = log_prints
polyapi/execute.py CHANGED
@@ -1,12 +1,11 @@
1
1
  from typing import Dict, Optional
2
2
  import requests
3
3
  import os
4
- import logging
4
+ import sys
5
5
  from requests import Response
6
6
  from polyapi.config import get_api_key_and_url, get_mtls_config
7
7
  from polyapi.exceptions import PolyApiException
8
8
 
9
- logger = logging.getLogger("poly")
10
9
 
11
10
  def direct_execute(function_type, function_id, data) -> Response:
12
11
  """ execute a specific function id/type
@@ -49,7 +48,7 @@ def direct_execute(function_type, function_id, data) -> Response:
49
48
  if (resp.status_code < 200 or resp.status_code >= 300):
50
49
  error_content = resp.content.decode("utf-8", errors="ignore")
51
50
  if function_type == 'api' and os.getenv("LOGS_ENABLED"):
52
- logger.error(f"Error executing api function with id: {function_id}. Status code: {resp.status_code}. Request data: {data}, Response: {error_content}")
51
+ print(f"Error executing api function with id: {function_id}. Status code: {resp.status_code}. Request data: {data}, Response: {error_content}", file=sys.stderr)
53
52
  elif function_type != 'api':
54
53
  raise PolyApiException(f"{resp.status_code}: {error_content}")
55
54
 
@@ -73,7 +72,7 @@ def execute(function_type, function_id, data) -> Response:
73
72
  if (resp.status_code < 200 or resp.status_code >= 300) and os.getenv("LOGS_ENABLED"):
74
73
  error_content = resp.content.decode("utf-8", errors="ignore")
75
74
  if function_type == 'api' and os.getenv("LOGS_ENABLED"):
76
- logger.error(f"Error executing api function with id: {function_id}. Status code: {resp.status_code}. Request data: {data}, Response: {error_content}")
75
+ print(f"Error executing api function with id: {function_id}. Status code: {resp.status_code}. Request data: {data}, Response: {error_content}", file=sys.stderr)
77
76
  elif function_type != 'api':
78
77
  raise PolyApiException(f"{resp.status_code}: {error_content}")
79
78
 
polyapi/schema.py CHANGED
@@ -3,6 +3,8 @@
3
3
  import logging
4
4
  import contextlib
5
5
  import re
6
+ import polyapi
7
+ import builtins
6
8
  from typing import Dict
7
9
  from jsonschema_gentypes.cli import process_config
8
10
  from jsonschema_gentypes import configuration
@@ -89,9 +91,12 @@ def generate_schema_types(input_data: Dict, root=None):
89
91
  }
90
92
 
91
93
  # jsonschema_gentypes prints source to stdout
92
- # no option to surpress so we do this
94
+ # no option to suppress so we do this
95
+ # Not reverting the print monkeypatch causes print to bypass redirect
96
+ builtins.print = polyapi.original_print
93
97
  with contextlib.redirect_stdout(None):
94
98
  process_config(config, [tmp_input])
99
+ builtins.print = polyapi.log_prints
95
100
 
96
101
  with open(tmp_output, encoding='utf-8') as f:
97
102
  output = f.read()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polyapi-python
3
- Version: 0.3.9.dev6
3
+ Version: 0.3.9.dev7
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,4 +1,4 @@
1
- polyapi/__init__.py,sha256=hw7x4j9JNJfPdkIOZqV0X9pbYcw3_5AH1iQFdSogH-c,3235
1
+ polyapi/__init__.py,sha256=y-NBe7eopIdiqvJOD9KRjz90AgTR-zziBovF9h-CNzo,3725
2
2
  polyapi/__main__.py,sha256=V4zhAh_YGxno5f_KSrlkELxcuDh9bR3WSd0n-2r-qQQ,93
3
3
  polyapi/api.py,sha256=2nds6ZdNe9OHvCba4IjOPga0CAYIsib2SbhEyDDCmd8,2188
4
4
  polyapi/auth.py,sha256=zrIGatjba5GwUTNjKj1GHQWTEDP9B-HrSzCKbLFoqvc,5336
@@ -9,7 +9,7 @@ polyapi/constants.py,sha256=sc-FnS0SngBLvSu1ZWMs0UCf9EYD1u1Yhfr-sZXGLns,607
9
9
  polyapi/deployables.py,sha256=vaZvdkPpwgjVtRXD4IxFsJ90Qmgs-AOIB3ygy4QCG78,12100
10
10
  polyapi/error_handler.py,sha256=I_e0iz6VM23FLVQWJljxs2NGcl_OODbi43OcbnqBlp8,2398
11
11
  polyapi/exceptions.py,sha256=Zh7i7eCUhDuXEdUYjatkLFTeZkrx1BJ1P5ePgbJ9eIY,89
12
- polyapi/execute.py,sha256=q4xtV6rYO8f-8hULlFTlVgoTVQSahvlMu3FHkFzYpMs,4423
12
+ polyapi/execute.py,sha256=WQH5bLG3zLpb5_21y9dUvhCLJy9kiryWcTvr9glCji0,4404
13
13
  polyapi/function_cli.py,sha256=H0sVrbvRBXw_xeApe2MvQw8p_xE7jVTTOU-07Dg041A,4220
14
14
  polyapi/generate.py,sha256=slCw9AOvQHQ8UtEaumFI1NoRvjH2Dj3Y33u7imQqi8c,19521
15
15
  polyapi/parser.py,sha256=20ZE7kSXx3UL7QVSIYYxzsnJlygVbsaDAg9q7c41WxQ,20695
@@ -17,15 +17,15 @@ polyapi/poly_schemas.py,sha256=fZ6AGvHcOKQJtlrzSuzeBNed5DxPMA2dJGdJvuFCHWM,9066
17
17
  polyapi/prepare.py,sha256=NQzpMIoakNovStvOGOmqSYIpTwiWXaweNSE9se10A2E,7420
18
18
  polyapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  polyapi/rendered_spec.py,sha256=nJEj2vRgG3N20fU4s-ThRtOIwAuTzXwXuOBIkXljDVc,2240
20
- polyapi/schema.py,sha256=-mtRV5iL3CV0X3phXhGYFV8sLz0KouTACOKWyGO9Pwc,5309
20
+ polyapi/schema.py,sha256=NyS9OgQJM0YAuZ8CLIM_9QitfpZf4lU5MFHlyFZKHCM,5498
21
21
  polyapi/server.py,sha256=YXWxhYBx-hluwDQ8Jvfpy2s8ogz0GsNTMcZVNcP5ca8,2147
22
22
  polyapi/sync.py,sha256=PGdC0feBBjEVrF3d9EluW_OAxbWuzSrfh84czma8kWg,6476
23
23
  polyapi/typedefs.py,sha256=vJLZYBNmR3i8yQEDYlu1UfvtJyg6E1R1QyGlgFUm2rU,2362
24
24
  polyapi/utils.py,sha256=1F7Dwst_PbPuUBUSxx5r8d2DHDgqHtu07QW92T_YSdw,12454
25
25
  polyapi/variables.py,sha256=VAp2d5I-4WLYHCPF1w3pqU4-z8_XRQpYW-ddOw6G5S4,7268
26
26
  polyapi/webhook.py,sha256=gWYXHz0PnB_uY_lnHeUlg3EIHfTGwF-Tc6UaatldZBw,5333
27
- polyapi_python-0.3.9.dev6.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
28
- polyapi_python-0.3.9.dev6.dist-info/METADATA,sha256=nWRTmjCS4ioIpVJZC5-U6Xg_4CbdPV_oELg1e1DOLTk,5784
29
- polyapi_python-0.3.9.dev6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
30
- polyapi_python-0.3.9.dev6.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
31
- polyapi_python-0.3.9.dev6.dist-info/RECORD,,
27
+ polyapi_python-0.3.9.dev7.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
28
+ polyapi_python-0.3.9.dev7.dist-info/METADATA,sha256=Mje5ZcoFfJXuVDl88OhagGsuicmndwVkzYMvWNy2ZA0,5784
29
+ polyapi_python-0.3.9.dev7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
30
+ polyapi_python-0.3.9.dev7.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
31
+ polyapi_python-0.3.9.dev7.dist-info/RECORD,,