tzafon 0.1.4__py3-none-any.whl → 1.3.2__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.

Potentially problematic release.


This version of tzafon might be problematic. Click here for more details.

Files changed (52) hide show
  1. tzafon/__init__.py +114 -2
  2. tzafon/_base_client.py +1995 -0
  3. tzafon/_client.py +403 -0
  4. tzafon/_compat.py +219 -0
  5. tzafon/_constants.py +14 -0
  6. tzafon/_exceptions.py +108 -0
  7. tzafon/_files.py +123 -0
  8. tzafon/_models.py +835 -0
  9. tzafon/_qs.py +150 -0
  10. tzafon/_resource.py +43 -0
  11. tzafon/_response.py +830 -0
  12. tzafon/_streaming.py +333 -0
  13. tzafon/_types.py +260 -0
  14. tzafon/_utils/__init__.py +64 -0
  15. tzafon/_utils/_compat.py +45 -0
  16. tzafon/_utils/_datetime_parse.py +136 -0
  17. tzafon/_utils/_logs.py +25 -0
  18. tzafon/_utils/_proxy.py +65 -0
  19. tzafon/_utils/_reflection.py +42 -0
  20. tzafon/_utils/_resources_proxy.py +24 -0
  21. tzafon/_utils/_streams.py +12 -0
  22. tzafon/_utils/_sync.py +86 -0
  23. tzafon/_utils/_transform.py +457 -0
  24. tzafon/_utils/_typing.py +156 -0
  25. tzafon/_utils/_utils.py +421 -0
  26. tzafon/_version.py +4 -0
  27. tzafon/batch_wrapper.py +102 -0
  28. tzafon/client_extensions.py +61 -0
  29. tzafon/py.typed +0 -0
  30. tzafon/resources/__init__.py +19 -0
  31. tzafon/resources/computers.py +822 -0
  32. tzafon/types/__init__.py +13 -0
  33. tzafon/types/action_result.py +17 -0
  34. tzafon/types/computer_create_params.py +30 -0
  35. tzafon/types/computer_execute_action_params.py +11 -0
  36. tzafon/types/computer_execute_batch_params.py +11 -0
  37. tzafon/types/computer_execute_batch_response.py +8 -0
  38. tzafon/types/computer_keep_alive_response.py +8 -0
  39. tzafon/types/computer_list_response.py +10 -0
  40. tzafon/types/computer_navigate_params.py +11 -0
  41. tzafon/types/computer_response.py +19 -0
  42. tzafon/wrapper.py +102 -0
  43. tzafon-1.3.2.dist-info/METADATA +429 -0
  44. tzafon-1.3.2.dist-info/RECORD +46 -0
  45. {tzafon-0.1.4.dist-info → tzafon-1.3.2.dist-info}/WHEEL +1 -1
  46. tzafon-1.3.2.dist-info/licenses/LICENSE +7 -0
  47. tzafon/_connection.py +0 -49
  48. tzafon/client.py +0 -116
  49. tzafon/exceptions.py +0 -6
  50. tzafon/models.py +0 -99
  51. tzafon-0.1.4.dist-info/METADATA +0 -62
  52. tzafon-0.1.4.dist-info/RECORD +0 -8
tzafon/_client.py ADDED
@@ -0,0 +1,403 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from typing import Any, Mapping
7
+ from typing_extensions import Self, override
8
+
9
+ import httpx
10
+
11
+ from . import _exceptions
12
+ from ._qs import Querystring
13
+ from ._types import (
14
+ Omit,
15
+ Timeout,
16
+ NotGiven,
17
+ Transport,
18
+ ProxiesTypes,
19
+ RequestOptions,
20
+ not_given,
21
+ )
22
+ from ._utils import is_given, get_async_library
23
+ from ._version import __version__
24
+ from .resources import computers
25
+ from ._streaming import Stream as Stream, AsyncStream as AsyncStream
26
+ from ._exceptions import ComputerError, APIStatusError
27
+ from ._base_client import (
28
+ DEFAULT_MAX_RETRIES,
29
+ SyncAPIClient,
30
+ AsyncAPIClient,
31
+ )
32
+
33
+ __all__ = [
34
+ "Timeout",
35
+ "Transport",
36
+ "ProxiesTypes",
37
+ "RequestOptions",
38
+ "Computer",
39
+ "AsyncComputer",
40
+ "Client",
41
+ "AsyncClient",
42
+ ]
43
+
44
+
45
+ class Computer(SyncAPIClient):
46
+ computers: computers.ComputersResource
47
+ with_raw_response: ComputerWithRawResponse
48
+ with_streaming_response: ComputerWithStreamedResponse
49
+
50
+ # client options
51
+ api_key: str
52
+
53
+ def __init__(
54
+ self,
55
+ *,
56
+ api_key: str | None = None,
57
+ base_url: str | httpx.URL | None = None,
58
+ timeout: float | Timeout | None | NotGiven = not_given,
59
+ max_retries: int = DEFAULT_MAX_RETRIES,
60
+ default_headers: Mapping[str, str] | None = None,
61
+ default_query: Mapping[str, object] | None = None,
62
+ # Configure a custom httpx client.
63
+ # We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
64
+ # See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
65
+ http_client: httpx.Client | None = None,
66
+ # Enable or disable schema validation for data returned by the API.
67
+ # When enabled an error APIResponseValidationError is raised
68
+ # if the API responds with invalid data for the expected schema.
69
+ #
70
+ # This parameter may be removed or changed in the future.
71
+ # If you rely on this feature, please open a GitHub issue
72
+ # outlining your use-case to help us decide if it should be
73
+ # part of our public interface in the future.
74
+ _strict_response_validation: bool = False,
75
+ ) -> None:
76
+ """Construct a new synchronous Computer client instance.
77
+
78
+ This automatically infers the `api_key` argument from the `COMPUTER_API_KEY` environment variable if it is not provided.
79
+ """
80
+ if api_key is None:
81
+ api_key = os.environ.get("COMPUTER_API_KEY")
82
+ if api_key is None:
83
+ raise ComputerError(
84
+ "The api_key client option must be set either by passing api_key to the client or by setting the COMPUTER_API_KEY environment variable"
85
+ )
86
+ self.api_key = api_key
87
+
88
+ if base_url is None:
89
+ base_url = os.environ.get("COMPUTER_BASE_URL")
90
+ if base_url is None:
91
+ base_url = f"https://v2.tzafon.ai/v1"
92
+
93
+ super().__init__(
94
+ version=__version__,
95
+ base_url=base_url,
96
+ max_retries=max_retries,
97
+ timeout=timeout,
98
+ http_client=http_client,
99
+ custom_headers=default_headers,
100
+ custom_query=default_query,
101
+ _strict_response_validation=_strict_response_validation,
102
+ )
103
+
104
+ self.computers = computers.ComputersResource(self)
105
+ self.with_raw_response = ComputerWithRawResponse(self)
106
+ self.with_streaming_response = ComputerWithStreamedResponse(self)
107
+
108
+ @property
109
+ @override
110
+ def qs(self) -> Querystring:
111
+ return Querystring(array_format="comma")
112
+
113
+ @property
114
+ @override
115
+ def auth_headers(self) -> dict[str, str]:
116
+ api_key = self.api_key
117
+ return {"Authorization": f"Bearer {api_key}"}
118
+
119
+ @property
120
+ @override
121
+ def default_headers(self) -> dict[str, str | Omit]:
122
+ return {
123
+ **super().default_headers,
124
+ "X-Stainless-Async": "false",
125
+ **self._custom_headers,
126
+ }
127
+
128
+ def copy(
129
+ self,
130
+ *,
131
+ api_key: str | None = None,
132
+ base_url: str | httpx.URL | None = None,
133
+ timeout: float | Timeout | None | NotGiven = not_given,
134
+ http_client: httpx.Client | None = None,
135
+ max_retries: int | NotGiven = not_given,
136
+ default_headers: Mapping[str, str] | None = None,
137
+ set_default_headers: Mapping[str, str] | None = None,
138
+ default_query: Mapping[str, object] | None = None,
139
+ set_default_query: Mapping[str, object] | None = None,
140
+ _extra_kwargs: Mapping[str, Any] = {},
141
+ ) -> Self:
142
+ """
143
+ Create a new client instance re-using the same options given to the current client with optional overriding.
144
+ """
145
+ if default_headers is not None and set_default_headers is not None:
146
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
147
+
148
+ if default_query is not None and set_default_query is not None:
149
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
150
+
151
+ headers = self._custom_headers
152
+ if default_headers is not None:
153
+ headers = {**headers, **default_headers}
154
+ elif set_default_headers is not None:
155
+ headers = set_default_headers
156
+
157
+ params = self._custom_query
158
+ if default_query is not None:
159
+ params = {**params, **default_query}
160
+ elif set_default_query is not None:
161
+ params = set_default_query
162
+
163
+ http_client = http_client or self._client
164
+ return self.__class__(
165
+ api_key=api_key or self.api_key,
166
+ base_url=base_url or self.base_url,
167
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
168
+ http_client=http_client,
169
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
170
+ default_headers=headers,
171
+ default_query=params,
172
+ **_extra_kwargs,
173
+ )
174
+
175
+ # Alias for `copy` for nicer inline usage, e.g.
176
+ # client.with_options(timeout=10).foo.create(...)
177
+ with_options = copy
178
+
179
+ @override
180
+ def _make_status_error(
181
+ self,
182
+ err_msg: str,
183
+ *,
184
+ body: object,
185
+ response: httpx.Response,
186
+ ) -> APIStatusError:
187
+ if response.status_code == 400:
188
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
189
+
190
+ if response.status_code == 401:
191
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
192
+
193
+ if response.status_code == 403:
194
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
195
+
196
+ if response.status_code == 404:
197
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
198
+
199
+ if response.status_code == 409:
200
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
201
+
202
+ if response.status_code == 422:
203
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
204
+
205
+ if response.status_code == 429:
206
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
207
+
208
+ if response.status_code >= 500:
209
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
210
+ return APIStatusError(err_msg, response=response, body=body)
211
+
212
+
213
+ class AsyncComputer(AsyncAPIClient):
214
+ computers: computers.AsyncComputersResource
215
+ with_raw_response: AsyncComputerWithRawResponse
216
+ with_streaming_response: AsyncComputerWithStreamedResponse
217
+
218
+ # client options
219
+ api_key: str
220
+
221
+ def __init__(
222
+ self,
223
+ *,
224
+ api_key: str | None = None,
225
+ base_url: str | httpx.URL | None = None,
226
+ timeout: float | Timeout | None | NotGiven = not_given,
227
+ max_retries: int = DEFAULT_MAX_RETRIES,
228
+ default_headers: Mapping[str, str] | None = None,
229
+ default_query: Mapping[str, object] | None = None,
230
+ # Configure a custom httpx client.
231
+ # We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
232
+ # See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
233
+ http_client: httpx.AsyncClient | None = None,
234
+ # Enable or disable schema validation for data returned by the API.
235
+ # When enabled an error APIResponseValidationError is raised
236
+ # if the API responds with invalid data for the expected schema.
237
+ #
238
+ # This parameter may be removed or changed in the future.
239
+ # If you rely on this feature, please open a GitHub issue
240
+ # outlining your use-case to help us decide if it should be
241
+ # part of our public interface in the future.
242
+ _strict_response_validation: bool = False,
243
+ ) -> None:
244
+ """Construct a new async AsyncComputer client instance.
245
+
246
+ This automatically infers the `api_key` argument from the `COMPUTER_API_KEY` environment variable if it is not provided.
247
+ """
248
+ if api_key is None:
249
+ api_key = os.environ.get("COMPUTER_API_KEY")
250
+ if api_key is None:
251
+ raise ComputerError(
252
+ "The api_key client option must be set either by passing api_key to the client or by setting the COMPUTER_API_KEY environment variable"
253
+ )
254
+ self.api_key = api_key
255
+
256
+ if base_url is None:
257
+ base_url = os.environ.get("COMPUTER_BASE_URL")
258
+ if base_url is None:
259
+ base_url = f"https://v2.tzafon.ai/v1"
260
+
261
+ super().__init__(
262
+ version=__version__,
263
+ base_url=base_url,
264
+ max_retries=max_retries,
265
+ timeout=timeout,
266
+ http_client=http_client,
267
+ custom_headers=default_headers,
268
+ custom_query=default_query,
269
+ _strict_response_validation=_strict_response_validation,
270
+ )
271
+
272
+ self.computers = computers.AsyncComputersResource(self)
273
+ self.with_raw_response = AsyncComputerWithRawResponse(self)
274
+ self.with_streaming_response = AsyncComputerWithStreamedResponse(self)
275
+
276
+ @property
277
+ @override
278
+ def qs(self) -> Querystring:
279
+ return Querystring(array_format="comma")
280
+
281
+ @property
282
+ @override
283
+ def auth_headers(self) -> dict[str, str]:
284
+ api_key = self.api_key
285
+ return {"Authorization": f"Bearer {api_key}"}
286
+
287
+ @property
288
+ @override
289
+ def default_headers(self) -> dict[str, str | Omit]:
290
+ return {
291
+ **super().default_headers,
292
+ "X-Stainless-Async": f"async:{get_async_library()}",
293
+ **self._custom_headers,
294
+ }
295
+
296
+ def copy(
297
+ self,
298
+ *,
299
+ api_key: str | None = None,
300
+ base_url: str | httpx.URL | None = None,
301
+ timeout: float | Timeout | None | NotGiven = not_given,
302
+ http_client: httpx.AsyncClient | None = None,
303
+ max_retries: int | NotGiven = not_given,
304
+ default_headers: Mapping[str, str] | None = None,
305
+ set_default_headers: Mapping[str, str] | None = None,
306
+ default_query: Mapping[str, object] | None = None,
307
+ set_default_query: Mapping[str, object] | None = None,
308
+ _extra_kwargs: Mapping[str, Any] = {},
309
+ ) -> Self:
310
+ """
311
+ Create a new client instance re-using the same options given to the current client with optional overriding.
312
+ """
313
+ if default_headers is not None and set_default_headers is not None:
314
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
315
+
316
+ if default_query is not None and set_default_query is not None:
317
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
318
+
319
+ headers = self._custom_headers
320
+ if default_headers is not None:
321
+ headers = {**headers, **default_headers}
322
+ elif set_default_headers is not None:
323
+ headers = set_default_headers
324
+
325
+ params = self._custom_query
326
+ if default_query is not None:
327
+ params = {**params, **default_query}
328
+ elif set_default_query is not None:
329
+ params = set_default_query
330
+
331
+ http_client = http_client or self._client
332
+ return self.__class__(
333
+ api_key=api_key or self.api_key,
334
+ base_url=base_url or self.base_url,
335
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
336
+ http_client=http_client,
337
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
338
+ default_headers=headers,
339
+ default_query=params,
340
+ **_extra_kwargs,
341
+ )
342
+
343
+ # Alias for `copy` for nicer inline usage, e.g.
344
+ # client.with_options(timeout=10).foo.create(...)
345
+ with_options = copy
346
+
347
+ @override
348
+ def _make_status_error(
349
+ self,
350
+ err_msg: str,
351
+ *,
352
+ body: object,
353
+ response: httpx.Response,
354
+ ) -> APIStatusError:
355
+ if response.status_code == 400:
356
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
357
+
358
+ if response.status_code == 401:
359
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
360
+
361
+ if response.status_code == 403:
362
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
363
+
364
+ if response.status_code == 404:
365
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
366
+
367
+ if response.status_code == 409:
368
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
369
+
370
+ if response.status_code == 422:
371
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
372
+
373
+ if response.status_code == 429:
374
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
375
+
376
+ if response.status_code >= 500:
377
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
378
+ return APIStatusError(err_msg, response=response, body=body)
379
+
380
+
381
+ class ComputerWithRawResponse:
382
+ def __init__(self, client: Computer) -> None:
383
+ self.computers = computers.ComputersResourceWithRawResponse(client.computers)
384
+
385
+
386
+ class AsyncComputerWithRawResponse:
387
+ def __init__(self, client: AsyncComputer) -> None:
388
+ self.computers = computers.AsyncComputersResourceWithRawResponse(client.computers)
389
+
390
+
391
+ class ComputerWithStreamedResponse:
392
+ def __init__(self, client: Computer) -> None:
393
+ self.computers = computers.ComputersResourceWithStreamingResponse(client.computers)
394
+
395
+
396
+ class AsyncComputerWithStreamedResponse:
397
+ def __init__(self, client: AsyncComputer) -> None:
398
+ self.computers = computers.AsyncComputersResourceWithStreamingResponse(client.computers)
399
+
400
+
401
+ Client = Computer
402
+
403
+ AsyncClient = AsyncComputer
tzafon/_compat.py ADDED
@@ -0,0 +1,219 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Any, Union, Generic, TypeVar, Callable, cast, overload
4
+ from datetime import date, datetime
5
+ from typing_extensions import Self, Literal
6
+
7
+ import pydantic
8
+ from pydantic.fields import FieldInfo
9
+
10
+ from ._types import IncEx, StrBytesIntFloat
11
+
12
+ _T = TypeVar("_T")
13
+ _ModelT = TypeVar("_ModelT", bound=pydantic.BaseModel)
14
+
15
+ # --------------- Pydantic v2, v3 compatibility ---------------
16
+
17
+ # Pyright incorrectly reports some of our functions as overriding a method when they don't
18
+ # pyright: reportIncompatibleMethodOverride=false
19
+
20
+ PYDANTIC_V1 = pydantic.VERSION.startswith("1.")
21
+
22
+ if TYPE_CHECKING:
23
+
24
+ def parse_date(value: date | StrBytesIntFloat) -> date: # noqa: ARG001
25
+ ...
26
+
27
+ def parse_datetime(value: Union[datetime, StrBytesIntFloat]) -> datetime: # noqa: ARG001
28
+ ...
29
+
30
+ def get_args(t: type[Any]) -> tuple[Any, ...]: # noqa: ARG001
31
+ ...
32
+
33
+ def is_union(tp: type[Any] | None) -> bool: # noqa: ARG001
34
+ ...
35
+
36
+ def get_origin(t: type[Any]) -> type[Any] | None: # noqa: ARG001
37
+ ...
38
+
39
+ def is_literal_type(type_: type[Any]) -> bool: # noqa: ARG001
40
+ ...
41
+
42
+ def is_typeddict(type_: type[Any]) -> bool: # noqa: ARG001
43
+ ...
44
+
45
+ else:
46
+ # v1 re-exports
47
+ if PYDANTIC_V1:
48
+ from pydantic.typing import (
49
+ get_args as get_args,
50
+ is_union as is_union,
51
+ get_origin as get_origin,
52
+ is_typeddict as is_typeddict,
53
+ is_literal_type as is_literal_type,
54
+ )
55
+ from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
56
+ else:
57
+ from ._utils import (
58
+ get_args as get_args,
59
+ is_union as is_union,
60
+ get_origin as get_origin,
61
+ parse_date as parse_date,
62
+ is_typeddict as is_typeddict,
63
+ parse_datetime as parse_datetime,
64
+ is_literal_type as is_literal_type,
65
+ )
66
+
67
+
68
+ # refactored config
69
+ if TYPE_CHECKING:
70
+ from pydantic import ConfigDict as ConfigDict
71
+ else:
72
+ if PYDANTIC_V1:
73
+ # TODO: provide an error message here?
74
+ ConfigDict = None
75
+ else:
76
+ from pydantic import ConfigDict as ConfigDict
77
+
78
+
79
+ # renamed methods / properties
80
+ def parse_obj(model: type[_ModelT], value: object) -> _ModelT:
81
+ if PYDANTIC_V1:
82
+ return cast(_ModelT, model.parse_obj(value)) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
83
+ else:
84
+ return model.model_validate(value)
85
+
86
+
87
+ def field_is_required(field: FieldInfo) -> bool:
88
+ if PYDANTIC_V1:
89
+ return field.required # type: ignore
90
+ return field.is_required()
91
+
92
+
93
+ def field_get_default(field: FieldInfo) -> Any:
94
+ value = field.get_default()
95
+ if PYDANTIC_V1:
96
+ return value
97
+ from pydantic_core import PydanticUndefined
98
+
99
+ if value == PydanticUndefined:
100
+ return None
101
+ return value
102
+
103
+
104
+ def field_outer_type(field: FieldInfo) -> Any:
105
+ if PYDANTIC_V1:
106
+ return field.outer_type_ # type: ignore
107
+ return field.annotation
108
+
109
+
110
+ def get_model_config(model: type[pydantic.BaseModel]) -> Any:
111
+ if PYDANTIC_V1:
112
+ return model.__config__ # type: ignore
113
+ return model.model_config
114
+
115
+
116
+ def get_model_fields(model: type[pydantic.BaseModel]) -> dict[str, FieldInfo]:
117
+ if PYDANTIC_V1:
118
+ return model.__fields__ # type: ignore
119
+ return model.model_fields
120
+
121
+
122
+ def model_copy(model: _ModelT, *, deep: bool = False) -> _ModelT:
123
+ if PYDANTIC_V1:
124
+ return model.copy(deep=deep) # type: ignore
125
+ return model.model_copy(deep=deep)
126
+
127
+
128
+ def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
129
+ if PYDANTIC_V1:
130
+ return model.json(indent=indent) # type: ignore
131
+ return model.model_dump_json(indent=indent)
132
+
133
+
134
+ def model_dump(
135
+ model: pydantic.BaseModel,
136
+ *,
137
+ exclude: IncEx | None = None,
138
+ exclude_unset: bool = False,
139
+ exclude_defaults: bool = False,
140
+ warnings: bool = True,
141
+ mode: Literal["json", "python"] = "python",
142
+ ) -> dict[str, Any]:
143
+ if (not PYDANTIC_V1) or hasattr(model, "model_dump"):
144
+ return model.model_dump(
145
+ mode=mode,
146
+ exclude=exclude,
147
+ exclude_unset=exclude_unset,
148
+ exclude_defaults=exclude_defaults,
149
+ # warnings are not supported in Pydantic v1
150
+ warnings=True if PYDANTIC_V1 else warnings,
151
+ )
152
+ return cast(
153
+ "dict[str, Any]",
154
+ model.dict( # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
155
+ exclude=exclude,
156
+ exclude_unset=exclude_unset,
157
+ exclude_defaults=exclude_defaults,
158
+ ),
159
+ )
160
+
161
+
162
+ def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
163
+ if PYDANTIC_V1:
164
+ return model.parse_obj(data) # pyright: ignore[reportDeprecated]
165
+ return model.model_validate(data)
166
+
167
+
168
+ # generic models
169
+ if TYPE_CHECKING:
170
+
171
+ class GenericModel(pydantic.BaseModel): ...
172
+
173
+ else:
174
+ if PYDANTIC_V1:
175
+ import pydantic.generics
176
+
177
+ class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...
178
+ else:
179
+ # there no longer needs to be a distinction in v2 but
180
+ # we still have to create our own subclass to avoid
181
+ # inconsistent MRO ordering errors
182
+ class GenericModel(pydantic.BaseModel): ...
183
+
184
+
185
+ # cached properties
186
+ if TYPE_CHECKING:
187
+ cached_property = property
188
+
189
+ # we define a separate type (copied from typeshed)
190
+ # that represents that `cached_property` is `set`able
191
+ # at runtime, which differs from `@property`.
192
+ #
193
+ # this is a separate type as editors likely special case
194
+ # `@property` and we don't want to cause issues just to have
195
+ # more helpful internal types.
196
+
197
+ class typed_cached_property(Generic[_T]):
198
+ func: Callable[[Any], _T]
199
+ attrname: str | None
200
+
201
+ def __init__(self, func: Callable[[Any], _T]) -> None: ...
202
+
203
+ @overload
204
+ def __get__(self, instance: None, owner: type[Any] | None = None) -> Self: ...
205
+
206
+ @overload
207
+ def __get__(self, instance: object, owner: type[Any] | None = None) -> _T: ...
208
+
209
+ def __get__(self, instance: object, owner: type[Any] | None = None) -> _T | Self:
210
+ raise NotImplementedError()
211
+
212
+ def __set_name__(self, owner: type[Any], name: str) -> None: ...
213
+
214
+ # __set__ is not defined at runtime, but @cached_property is designed to be settable
215
+ def __set__(self, instance: object, value: _T) -> None: ...
216
+ else:
217
+ from functools import cached_property as cached_property
218
+
219
+ typed_cached_property = cached_property
tzafon/_constants.py ADDED
@@ -0,0 +1,14 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import httpx
4
+
5
+ RAW_RESPONSE_HEADER = "X-Stainless-Raw-Response"
6
+ OVERRIDE_CAST_TO_HEADER = "____stainless_override_cast_to"
7
+
8
+ # default timeout is 1 minute
9
+ DEFAULT_TIMEOUT = httpx.Timeout(timeout=60, connect=5.0)
10
+ DEFAULT_MAX_RETRIES = 2
11
+ DEFAULT_CONNECTION_LIMITS = httpx.Limits(max_connections=100, max_keepalive_connections=20)
12
+
13
+ INITIAL_RETRY_DELAY = 0.5
14
+ MAX_RETRY_DELAY = 8.0