permitstack 1.0.0__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.
- permitstack/__init__.py +17 -0
- permitstack/_hooks/__init__.py +4 -0
- permitstack/_hooks/sdkhooks.py +74 -0
- permitstack/_hooks/types.py +112 -0
- permitstack/_version.py +15 -0
- permitstack/basesdk.py +396 -0
- permitstack/bulk_export.py +241 -0
- permitstack/contractors.py +625 -0
- permitstack/errors/__init__.py +39 -0
- permitstack/errors/httpvalidationerror.py +28 -0
- permitstack/errors/no_response_error.py +17 -0
- permitstack/errors/permitstackdefaulterror.py +40 -0
- permitstack/errors/permitstackerror.py +30 -0
- permitstack/errors/responsevalidationerror.py +27 -0
- permitstack/health.py +171 -0
- permitstack/httpclient.py +125 -0
- permitstack/models/__init__.py +158 -0
- permitstack/models/contractorprofile.py +108 -0
- permitstack/models/contractorsearchresponse.py +24 -0
- permitstack/models/contractorsummary.py +57 -0
- permitstack/models/delete_webhookop.py +16 -0
- permitstack/models/export_permits_csvop.py +98 -0
- permitstack/models/get_contractor_permitsop.py +46 -0
- permitstack/models/get_contractorop.py +16 -0
- permitstack/models/get_permitop.py +16 -0
- permitstack/models/get_permits_by_addressop.py +46 -0
- permitstack/models/get_property_historyop.py +18 -0
- permitstack/models/permitcategory.py +27 -0
- permitstack/models/permitdetail.py +164 -0
- permitstack/models/permitsearchresponse.py +24 -0
- permitstack/models/permitstatus.py +16 -0
- permitstack/models/permitsummary.py +121 -0
- permitstack/models/propertytype.py +14 -0
- permitstack/models/search_contractorsop.py +98 -0
- permitstack/models/search_permitsop.py +247 -0
- permitstack/models/security.py +42 -0
- permitstack/models/validationerror.py +57 -0
- permitstack/models/webhookcreate.py +60 -0
- permitstack/permits.py +866 -0
- permitstack/property_history.py +207 -0
- permitstack/py.typed +1 -0
- permitstack/sdk.py +218 -0
- permitstack/sdkconfiguration.py +49 -0
- permitstack/types/__init__.py +21 -0
- permitstack/types/basemodel.py +77 -0
- permitstack/utils/__init__.py +178 -0
- permitstack/utils/annotations.py +79 -0
- permitstack/utils/datetimes.py +23 -0
- permitstack/utils/dynamic_imports.py +54 -0
- permitstack/utils/enums.py +134 -0
- permitstack/utils/eventstreaming.py +309 -0
- permitstack/utils/forms.py +234 -0
- permitstack/utils/headers.py +136 -0
- permitstack/utils/logger.py +27 -0
- permitstack/utils/metadata.py +119 -0
- permitstack/utils/queryparams.py +217 -0
- permitstack/utils/requestbodies.py +66 -0
- permitstack/utils/retries.py +271 -0
- permitstack/utils/security.py +215 -0
- permitstack/utils/serializers.py +225 -0
- permitstack/utils/unmarshal_json_response.py +38 -0
- permitstack/utils/url.py +155 -0
- permitstack/utils/values.py +137 -0
- permitstack/webhooks.py +593 -0
- permitstack-1.0.0.dist-info/METADATA +541 -0
- permitstack-1.0.0.dist-info/RECORD +68 -0
- permitstack-1.0.0.dist-info/WHEEL +5 -0
- permitstack-1.0.0.dist-info/top_level.txt +1 -0
permitstack/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from ._version import (
|
|
4
|
+
__title__,
|
|
5
|
+
__version__,
|
|
6
|
+
__openapi_doc_version__,
|
|
7
|
+
__gen_version__,
|
|
8
|
+
__user_agent__,
|
|
9
|
+
)
|
|
10
|
+
from .sdk import *
|
|
11
|
+
from .sdkconfiguration import *
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
VERSION: str = __version__
|
|
15
|
+
OPENAPI_DOC_VERSION = __openapi_doc_version__
|
|
16
|
+
SPEAKEASY_GENERATOR_VERSION = __gen_version__
|
|
17
|
+
USER_AGENT = __user_agent__
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
import httpx
|
|
4
|
+
from .types import (
|
|
5
|
+
SDKInitHook,
|
|
6
|
+
BeforeRequestContext,
|
|
7
|
+
BeforeRequestHook,
|
|
8
|
+
AfterSuccessContext,
|
|
9
|
+
AfterSuccessHook,
|
|
10
|
+
AfterErrorContext,
|
|
11
|
+
AfterErrorHook,
|
|
12
|
+
Hooks,
|
|
13
|
+
)
|
|
14
|
+
from typing import List, Optional, Tuple
|
|
15
|
+
from permitstack.sdkconfiguration import SDKConfiguration
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class SDKHooks(Hooks):
|
|
19
|
+
def __init__(self) -> None:
|
|
20
|
+
self.sdk_init_hooks: List[SDKInitHook] = []
|
|
21
|
+
self.before_request_hooks: List[BeforeRequestHook] = []
|
|
22
|
+
self.after_success_hooks: List[AfterSuccessHook] = []
|
|
23
|
+
self.after_error_hooks: List[AfterErrorHook] = []
|
|
24
|
+
|
|
25
|
+
def register_sdk_init_hook(self, hook: SDKInitHook) -> None:
|
|
26
|
+
self.sdk_init_hooks.append(hook)
|
|
27
|
+
|
|
28
|
+
def register_before_request_hook(self, hook: BeforeRequestHook) -> None:
|
|
29
|
+
self.before_request_hooks.append(hook)
|
|
30
|
+
|
|
31
|
+
def register_after_success_hook(self, hook: AfterSuccessHook) -> None:
|
|
32
|
+
self.after_success_hooks.append(hook)
|
|
33
|
+
|
|
34
|
+
def register_after_error_hook(self, hook: AfterErrorHook) -> None:
|
|
35
|
+
self.after_error_hooks.append(hook)
|
|
36
|
+
|
|
37
|
+
def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
|
|
38
|
+
for hook in self.sdk_init_hooks:
|
|
39
|
+
config = hook.sdk_init(config)
|
|
40
|
+
return config
|
|
41
|
+
|
|
42
|
+
def before_request(
|
|
43
|
+
self, hook_ctx: BeforeRequestContext, request: httpx.Request
|
|
44
|
+
) -> httpx.Request:
|
|
45
|
+
for hook in self.before_request_hooks:
|
|
46
|
+
out = hook.before_request(hook_ctx, request)
|
|
47
|
+
if isinstance(out, Exception):
|
|
48
|
+
raise out
|
|
49
|
+
request = out
|
|
50
|
+
|
|
51
|
+
return request
|
|
52
|
+
|
|
53
|
+
def after_success(
|
|
54
|
+
self, hook_ctx: AfterSuccessContext, response: httpx.Response
|
|
55
|
+
) -> httpx.Response:
|
|
56
|
+
for hook in self.after_success_hooks:
|
|
57
|
+
out = hook.after_success(hook_ctx, response)
|
|
58
|
+
if isinstance(out, Exception):
|
|
59
|
+
raise out
|
|
60
|
+
response = out
|
|
61
|
+
return response
|
|
62
|
+
|
|
63
|
+
def after_error(
|
|
64
|
+
self,
|
|
65
|
+
hook_ctx: AfterErrorContext,
|
|
66
|
+
response: Optional[httpx.Response],
|
|
67
|
+
error: Optional[Exception],
|
|
68
|
+
) -> Tuple[Optional[httpx.Response], Optional[Exception]]:
|
|
69
|
+
for hook in self.after_error_hooks:
|
|
70
|
+
result = hook.after_error(hook_ctx, response, error)
|
|
71
|
+
if isinstance(result, Exception):
|
|
72
|
+
raise result
|
|
73
|
+
response, error = result
|
|
74
|
+
return response, error
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
import httpx
|
|
5
|
+
from permitstack.sdkconfiguration import SDKConfiguration
|
|
6
|
+
from typing import Any, Callable, List, Optional, Tuple, Union
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class HookContext:
|
|
10
|
+
config: SDKConfiguration
|
|
11
|
+
base_url: str
|
|
12
|
+
operation_id: str
|
|
13
|
+
oauth2_scopes: Optional[List[str]] = None
|
|
14
|
+
security_source: Optional[Union[Any, Callable[[], Any]]] = None
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
config: SDKConfiguration,
|
|
19
|
+
base_url: str,
|
|
20
|
+
operation_id: str,
|
|
21
|
+
oauth2_scopes: Optional[List[str]],
|
|
22
|
+
security_source: Optional[Union[Any, Callable[[], Any]]],
|
|
23
|
+
):
|
|
24
|
+
self.config = config
|
|
25
|
+
self.base_url = base_url
|
|
26
|
+
self.operation_id = operation_id
|
|
27
|
+
self.oauth2_scopes = oauth2_scopes
|
|
28
|
+
self.security_source = security_source
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class BeforeRequestContext(HookContext):
|
|
32
|
+
def __init__(self, hook_ctx: HookContext):
|
|
33
|
+
super().__init__(
|
|
34
|
+
hook_ctx.config,
|
|
35
|
+
hook_ctx.base_url,
|
|
36
|
+
hook_ctx.operation_id,
|
|
37
|
+
hook_ctx.oauth2_scopes,
|
|
38
|
+
hook_ctx.security_source,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class AfterSuccessContext(HookContext):
|
|
43
|
+
def __init__(self, hook_ctx: HookContext):
|
|
44
|
+
super().__init__(
|
|
45
|
+
hook_ctx.config,
|
|
46
|
+
hook_ctx.base_url,
|
|
47
|
+
hook_ctx.operation_id,
|
|
48
|
+
hook_ctx.oauth2_scopes,
|
|
49
|
+
hook_ctx.security_source,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class AfterErrorContext(HookContext):
|
|
54
|
+
def __init__(self, hook_ctx: HookContext):
|
|
55
|
+
super().__init__(
|
|
56
|
+
hook_ctx.config,
|
|
57
|
+
hook_ctx.base_url,
|
|
58
|
+
hook_ctx.operation_id,
|
|
59
|
+
hook_ctx.oauth2_scopes,
|
|
60
|
+
hook_ctx.security_source,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class SDKInitHook(ABC):
|
|
65
|
+
@abstractmethod
|
|
66
|
+
def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
|
|
67
|
+
pass
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class BeforeRequestHook(ABC):
|
|
71
|
+
@abstractmethod
|
|
72
|
+
def before_request(
|
|
73
|
+
self, hook_ctx: BeforeRequestContext, request: httpx.Request
|
|
74
|
+
) -> Union[httpx.Request, Exception]:
|
|
75
|
+
pass
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class AfterSuccessHook(ABC):
|
|
79
|
+
@abstractmethod
|
|
80
|
+
def after_success(
|
|
81
|
+
self, hook_ctx: AfterSuccessContext, response: httpx.Response
|
|
82
|
+
) -> Union[httpx.Response, Exception]:
|
|
83
|
+
pass
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class AfterErrorHook(ABC):
|
|
87
|
+
@abstractmethod
|
|
88
|
+
def after_error(
|
|
89
|
+
self,
|
|
90
|
+
hook_ctx: AfterErrorContext,
|
|
91
|
+
response: Optional[httpx.Response],
|
|
92
|
+
error: Optional[Exception],
|
|
93
|
+
) -> Union[Tuple[Optional[httpx.Response], Optional[Exception]], Exception]:
|
|
94
|
+
pass
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class Hooks(ABC):
|
|
98
|
+
@abstractmethod
|
|
99
|
+
def register_sdk_init_hook(self, hook: SDKInitHook):
|
|
100
|
+
pass
|
|
101
|
+
|
|
102
|
+
@abstractmethod
|
|
103
|
+
def register_before_request_hook(self, hook: BeforeRequestHook):
|
|
104
|
+
pass
|
|
105
|
+
|
|
106
|
+
@abstractmethod
|
|
107
|
+
def register_after_success_hook(self, hook: AfterSuccessHook):
|
|
108
|
+
pass
|
|
109
|
+
|
|
110
|
+
@abstractmethod
|
|
111
|
+
def register_after_error_hook(self, hook: AfterErrorHook):
|
|
112
|
+
pass
|
permitstack/_version.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
import importlib.metadata
|
|
4
|
+
|
|
5
|
+
__title__: str = "permitstack"
|
|
6
|
+
__version__: str = "1.0.0"
|
|
7
|
+
__openapi_doc_version__: str = "1.0.0"
|
|
8
|
+
__gen_version__: str = "2.881.2"
|
|
9
|
+
__user_agent__: str = "speakeasy-sdk/python 1.0.0 2.881.2 1.0.0 permitstack"
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
if __package__ is not None:
|
|
13
|
+
__version__ = importlib.metadata.version(__package__)
|
|
14
|
+
except importlib.metadata.PackageNotFoundError:
|
|
15
|
+
pass
|
permitstack/basesdk.py
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from .sdkconfiguration import SDKConfiguration
|
|
4
|
+
import httpx
|
|
5
|
+
from permitstack import errors, models, utils
|
|
6
|
+
from permitstack._hooks import (
|
|
7
|
+
AfterErrorContext,
|
|
8
|
+
AfterSuccessContext,
|
|
9
|
+
BeforeRequestContext,
|
|
10
|
+
HookContext,
|
|
11
|
+
)
|
|
12
|
+
from permitstack.utils import (
|
|
13
|
+
RetryConfig,
|
|
14
|
+
SerializedRequestBody,
|
|
15
|
+
get_body_content,
|
|
16
|
+
run_sync_in_thread,
|
|
17
|
+
)
|
|
18
|
+
from typing import Callable, List, Mapping, Optional, Tuple
|
|
19
|
+
from urllib.parse import parse_qs, urlparse
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class BaseSDK:
|
|
23
|
+
sdk_configuration: SDKConfiguration
|
|
24
|
+
parent_ref: Optional[object] = None
|
|
25
|
+
"""
|
|
26
|
+
Reference to the root SDK instance, if any. This will prevent it from
|
|
27
|
+
being garbage collected while there are active streams.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def __init__(
|
|
31
|
+
self,
|
|
32
|
+
sdk_config: SDKConfiguration,
|
|
33
|
+
parent_ref: Optional[object] = None,
|
|
34
|
+
) -> None:
|
|
35
|
+
self.sdk_configuration = sdk_config
|
|
36
|
+
self.parent_ref = parent_ref
|
|
37
|
+
|
|
38
|
+
def _get_url(self, base_url, url_variables):
|
|
39
|
+
sdk_url, sdk_variables = self.sdk_configuration.get_server_details()
|
|
40
|
+
|
|
41
|
+
if base_url is None:
|
|
42
|
+
base_url = sdk_url
|
|
43
|
+
|
|
44
|
+
if url_variables is None:
|
|
45
|
+
url_variables = sdk_variables
|
|
46
|
+
|
|
47
|
+
return utils.template_url(base_url, url_variables)
|
|
48
|
+
|
|
49
|
+
def _build_request_async(
|
|
50
|
+
self,
|
|
51
|
+
method,
|
|
52
|
+
path,
|
|
53
|
+
base_url,
|
|
54
|
+
url_variables,
|
|
55
|
+
request,
|
|
56
|
+
request_body_required,
|
|
57
|
+
request_has_path_params,
|
|
58
|
+
request_has_query_params,
|
|
59
|
+
user_agent_header,
|
|
60
|
+
accept_header_value,
|
|
61
|
+
_globals=None,
|
|
62
|
+
security=None,
|
|
63
|
+
timeout_ms: Optional[int] = None,
|
|
64
|
+
get_serialized_body: Optional[
|
|
65
|
+
Callable[[], Optional[SerializedRequestBody]]
|
|
66
|
+
] = None,
|
|
67
|
+
url_override: Optional[str] = None,
|
|
68
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
69
|
+
allow_empty_value: Optional[List[str]] = None,
|
|
70
|
+
allowed_fields: Optional[List[str]] = None,
|
|
71
|
+
) -> httpx.Request:
|
|
72
|
+
client = self.sdk_configuration.async_client
|
|
73
|
+
return self._build_request_with_client(
|
|
74
|
+
client,
|
|
75
|
+
method,
|
|
76
|
+
path,
|
|
77
|
+
base_url,
|
|
78
|
+
url_variables,
|
|
79
|
+
request,
|
|
80
|
+
request_body_required,
|
|
81
|
+
request_has_path_params,
|
|
82
|
+
request_has_query_params,
|
|
83
|
+
user_agent_header,
|
|
84
|
+
accept_header_value,
|
|
85
|
+
_globals,
|
|
86
|
+
security,
|
|
87
|
+
timeout_ms,
|
|
88
|
+
get_serialized_body,
|
|
89
|
+
url_override,
|
|
90
|
+
http_headers,
|
|
91
|
+
allow_empty_value,
|
|
92
|
+
allowed_fields,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
def _build_request(
|
|
96
|
+
self,
|
|
97
|
+
method,
|
|
98
|
+
path,
|
|
99
|
+
base_url,
|
|
100
|
+
url_variables,
|
|
101
|
+
request,
|
|
102
|
+
request_body_required,
|
|
103
|
+
request_has_path_params,
|
|
104
|
+
request_has_query_params,
|
|
105
|
+
user_agent_header,
|
|
106
|
+
accept_header_value,
|
|
107
|
+
_globals=None,
|
|
108
|
+
security=None,
|
|
109
|
+
timeout_ms: Optional[int] = None,
|
|
110
|
+
get_serialized_body: Optional[
|
|
111
|
+
Callable[[], Optional[SerializedRequestBody]]
|
|
112
|
+
] = None,
|
|
113
|
+
url_override: Optional[str] = None,
|
|
114
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
115
|
+
allow_empty_value: Optional[List[str]] = None,
|
|
116
|
+
allowed_fields: Optional[List[str]] = None,
|
|
117
|
+
) -> httpx.Request:
|
|
118
|
+
client = self.sdk_configuration.client
|
|
119
|
+
return self._build_request_with_client(
|
|
120
|
+
client,
|
|
121
|
+
method,
|
|
122
|
+
path,
|
|
123
|
+
base_url,
|
|
124
|
+
url_variables,
|
|
125
|
+
request,
|
|
126
|
+
request_body_required,
|
|
127
|
+
request_has_path_params,
|
|
128
|
+
request_has_query_params,
|
|
129
|
+
user_agent_header,
|
|
130
|
+
accept_header_value,
|
|
131
|
+
_globals,
|
|
132
|
+
security,
|
|
133
|
+
timeout_ms,
|
|
134
|
+
get_serialized_body,
|
|
135
|
+
url_override,
|
|
136
|
+
http_headers,
|
|
137
|
+
allow_empty_value,
|
|
138
|
+
allowed_fields,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
def _build_request_with_client(
|
|
142
|
+
self,
|
|
143
|
+
client,
|
|
144
|
+
method,
|
|
145
|
+
path,
|
|
146
|
+
base_url,
|
|
147
|
+
url_variables,
|
|
148
|
+
request,
|
|
149
|
+
request_body_required,
|
|
150
|
+
request_has_path_params,
|
|
151
|
+
request_has_query_params,
|
|
152
|
+
user_agent_header,
|
|
153
|
+
accept_header_value,
|
|
154
|
+
_globals=None,
|
|
155
|
+
security=None,
|
|
156
|
+
timeout_ms: Optional[int] = None,
|
|
157
|
+
get_serialized_body: Optional[
|
|
158
|
+
Callable[[], Optional[SerializedRequestBody]]
|
|
159
|
+
] = None,
|
|
160
|
+
url_override: Optional[str] = None,
|
|
161
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
162
|
+
allow_empty_value: Optional[List[str]] = None,
|
|
163
|
+
allowed_fields: Optional[List[str]] = None,
|
|
164
|
+
) -> httpx.Request:
|
|
165
|
+
query_params = {}
|
|
166
|
+
|
|
167
|
+
url = url_override
|
|
168
|
+
if url is None:
|
|
169
|
+
url = utils.generate_url(
|
|
170
|
+
self._get_url(base_url, url_variables),
|
|
171
|
+
path,
|
|
172
|
+
request if request_has_path_params else None,
|
|
173
|
+
_globals if request_has_path_params else None,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
query_params = utils.get_query_params(
|
|
177
|
+
request if request_has_query_params else None,
|
|
178
|
+
_globals if request_has_query_params else None,
|
|
179
|
+
allow_empty_value,
|
|
180
|
+
)
|
|
181
|
+
else:
|
|
182
|
+
# Pick up the query parameter from the override so they can be
|
|
183
|
+
# preserved when building the request later on (necessary as of
|
|
184
|
+
# httpx 0.28).
|
|
185
|
+
parsed_override = urlparse(str(url_override))
|
|
186
|
+
query_params = parse_qs(parsed_override.query, keep_blank_values=True)
|
|
187
|
+
|
|
188
|
+
headers = utils.get_headers(request, _globals)
|
|
189
|
+
headers["Accept"] = accept_header_value
|
|
190
|
+
headers[user_agent_header] = self.sdk_configuration.user_agent
|
|
191
|
+
|
|
192
|
+
if security is not None:
|
|
193
|
+
if callable(security):
|
|
194
|
+
security = security()
|
|
195
|
+
security = utils.get_security_from_env(security, models.Security)
|
|
196
|
+
if security is not None:
|
|
197
|
+
security_headers, security_query_params = utils.get_security(
|
|
198
|
+
security, allowed_fields
|
|
199
|
+
)
|
|
200
|
+
headers = {**headers, **security_headers}
|
|
201
|
+
query_params = {**query_params, **security_query_params}
|
|
202
|
+
|
|
203
|
+
serialized_request_body = SerializedRequestBody()
|
|
204
|
+
if get_serialized_body is not None:
|
|
205
|
+
rb = get_serialized_body()
|
|
206
|
+
if request_body_required and rb is None:
|
|
207
|
+
raise ValueError("request body is required")
|
|
208
|
+
|
|
209
|
+
if rb is not None:
|
|
210
|
+
serialized_request_body = rb
|
|
211
|
+
|
|
212
|
+
if (
|
|
213
|
+
serialized_request_body.media_type is not None
|
|
214
|
+
and serialized_request_body.media_type
|
|
215
|
+
not in (
|
|
216
|
+
"multipart/form-data",
|
|
217
|
+
"multipart/mixed",
|
|
218
|
+
)
|
|
219
|
+
):
|
|
220
|
+
headers["content-type"] = serialized_request_body.media_type
|
|
221
|
+
|
|
222
|
+
if http_headers is not None:
|
|
223
|
+
for header, value in http_headers.items():
|
|
224
|
+
headers[header] = value
|
|
225
|
+
|
|
226
|
+
timeout = timeout_ms / 1000 if timeout_ms is not None else None
|
|
227
|
+
|
|
228
|
+
return client.build_request(
|
|
229
|
+
method,
|
|
230
|
+
url,
|
|
231
|
+
params=query_params,
|
|
232
|
+
content=serialized_request_body.content,
|
|
233
|
+
data=serialized_request_body.data,
|
|
234
|
+
files=serialized_request_body.files,
|
|
235
|
+
headers=headers,
|
|
236
|
+
timeout=timeout if timeout is not None else httpx.USE_CLIENT_DEFAULT,
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
def do_request(
|
|
240
|
+
self,
|
|
241
|
+
hook_ctx: HookContext,
|
|
242
|
+
request: httpx.Request,
|
|
243
|
+
is_error_status_code: Callable[[int], bool],
|
|
244
|
+
stream: bool = False,
|
|
245
|
+
retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
|
|
246
|
+
) -> httpx.Response:
|
|
247
|
+
client = self.sdk_configuration.client
|
|
248
|
+
logger = self.sdk_configuration.debug_logger
|
|
249
|
+
|
|
250
|
+
hooks = self.sdk_configuration.__dict__["_hooks"]
|
|
251
|
+
|
|
252
|
+
def do():
|
|
253
|
+
http_res = None
|
|
254
|
+
try:
|
|
255
|
+
req = hooks.before_request(BeforeRequestContext(hook_ctx), request)
|
|
256
|
+
if "timeout" in request.extensions and "timeout" not in req.extensions:
|
|
257
|
+
req.extensions["timeout"] = request.extensions["timeout"]
|
|
258
|
+
logger.debug(
|
|
259
|
+
"Request:\nMethod: %s\nURL: %s\nHeaders: %s\nBody: %s",
|
|
260
|
+
req.method,
|
|
261
|
+
req.url,
|
|
262
|
+
req.headers,
|
|
263
|
+
get_body_content(req),
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
if client is None:
|
|
267
|
+
raise ValueError("client is required")
|
|
268
|
+
|
|
269
|
+
http_res = client.send(req, stream=stream)
|
|
270
|
+
except Exception as e:
|
|
271
|
+
_, e = hooks.after_error(AfterErrorContext(hook_ctx), None, e)
|
|
272
|
+
if e is not None:
|
|
273
|
+
logger.debug("Request Exception", exc_info=True)
|
|
274
|
+
raise e
|
|
275
|
+
|
|
276
|
+
if http_res is None:
|
|
277
|
+
logger.debug("Raising no response SDK error")
|
|
278
|
+
raise errors.NoResponseError("No response received")
|
|
279
|
+
|
|
280
|
+
logger.debug(
|
|
281
|
+
"Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
|
|
282
|
+
http_res.status_code,
|
|
283
|
+
http_res.url,
|
|
284
|
+
http_res.headers,
|
|
285
|
+
"<streaming response>" if stream else http_res.text,
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
return http_res
|
|
289
|
+
|
|
290
|
+
if retry_config is not None:
|
|
291
|
+
http_res = utils.retry(do, utils.Retries(retry_config[0], retry_config[1]))
|
|
292
|
+
else:
|
|
293
|
+
http_res = do()
|
|
294
|
+
|
|
295
|
+
if is_error_status_code(http_res.status_code):
|
|
296
|
+
result, err = hooks.after_error(AfterErrorContext(hook_ctx), http_res, None)
|
|
297
|
+
if err is not None:
|
|
298
|
+
logger.debug("Request Exception", exc_info=True)
|
|
299
|
+
raise err
|
|
300
|
+
if result is not None:
|
|
301
|
+
http_res = result
|
|
302
|
+
else:
|
|
303
|
+
logger.debug("Raising unexpected SDK error")
|
|
304
|
+
raise errors.PermitstackDefaultError(
|
|
305
|
+
"Unexpected error occurred", http_res
|
|
306
|
+
)
|
|
307
|
+
else:
|
|
308
|
+
http_res = hooks.after_success(AfterSuccessContext(hook_ctx), http_res)
|
|
309
|
+
|
|
310
|
+
return http_res
|
|
311
|
+
|
|
312
|
+
async def do_request_async(
|
|
313
|
+
self,
|
|
314
|
+
hook_ctx: HookContext,
|
|
315
|
+
request: httpx.Request,
|
|
316
|
+
is_error_status_code: Callable[[int], bool],
|
|
317
|
+
stream: bool = False,
|
|
318
|
+
retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
|
|
319
|
+
) -> httpx.Response:
|
|
320
|
+
client = self.sdk_configuration.async_client
|
|
321
|
+
logger = self.sdk_configuration.debug_logger
|
|
322
|
+
|
|
323
|
+
hooks = self.sdk_configuration.__dict__["_hooks"]
|
|
324
|
+
|
|
325
|
+
async def do():
|
|
326
|
+
http_res = None
|
|
327
|
+
try:
|
|
328
|
+
req = await run_sync_in_thread(
|
|
329
|
+
hooks.before_request, BeforeRequestContext(hook_ctx), request
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
if "timeout" in request.extensions and "timeout" not in req.extensions:
|
|
333
|
+
req.extensions["timeout"] = request.extensions["timeout"]
|
|
334
|
+
logger.debug(
|
|
335
|
+
"Request:\nMethod: %s\nURL: %s\nHeaders: %s\nBody: %s",
|
|
336
|
+
req.method,
|
|
337
|
+
req.url,
|
|
338
|
+
req.headers,
|
|
339
|
+
get_body_content(req),
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
if client is None:
|
|
343
|
+
raise ValueError("client is required")
|
|
344
|
+
|
|
345
|
+
http_res = await client.send(req, stream=stream)
|
|
346
|
+
except Exception as e:
|
|
347
|
+
_, e = await run_sync_in_thread(
|
|
348
|
+
hooks.after_error, AfterErrorContext(hook_ctx), None, e
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
if e is not None:
|
|
352
|
+
logger.debug("Request Exception", exc_info=True)
|
|
353
|
+
raise e
|
|
354
|
+
|
|
355
|
+
if http_res is None:
|
|
356
|
+
logger.debug("Raising no response SDK error")
|
|
357
|
+
raise errors.NoResponseError("No response received")
|
|
358
|
+
|
|
359
|
+
logger.debug(
|
|
360
|
+
"Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
|
|
361
|
+
http_res.status_code,
|
|
362
|
+
http_res.url,
|
|
363
|
+
http_res.headers,
|
|
364
|
+
"<streaming response>" if stream else http_res.text,
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
return http_res
|
|
368
|
+
|
|
369
|
+
if retry_config is not None:
|
|
370
|
+
http_res = await utils.retry_async(
|
|
371
|
+
do, utils.Retries(retry_config[0], retry_config[1])
|
|
372
|
+
)
|
|
373
|
+
else:
|
|
374
|
+
http_res = await do()
|
|
375
|
+
|
|
376
|
+
if is_error_status_code(http_res.status_code):
|
|
377
|
+
result, err = await run_sync_in_thread(
|
|
378
|
+
hooks.after_error, AfterErrorContext(hook_ctx), http_res, None
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
if err is not None:
|
|
382
|
+
logger.debug("Request Exception", exc_info=True)
|
|
383
|
+
raise err
|
|
384
|
+
if result is not None:
|
|
385
|
+
http_res = result
|
|
386
|
+
else:
|
|
387
|
+
logger.debug("Raising unexpected SDK error")
|
|
388
|
+
raise errors.PermitstackDefaultError(
|
|
389
|
+
"Unexpected error occurred", http_res
|
|
390
|
+
)
|
|
391
|
+
else:
|
|
392
|
+
http_res = await run_sync_in_thread(
|
|
393
|
+
hooks.after_success, AfterSuccessContext(hook_ctx), http_res
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
return http_res
|