unitycatalog-client 0.2.1__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.
Files changed (82) hide show
  1. unitycatalog/client/__init__.py +102 -0
  2. unitycatalog/client/api/__init__.py +13 -0
  3. unitycatalog/client/api/catalogs_api.py +1404 -0
  4. unitycatalog/client/api/functions_api.py +1135 -0
  5. unitycatalog/client/api/grants_api.py +630 -0
  6. unitycatalog/client/api/model_versions_api.py +1748 -0
  7. unitycatalog/client/api/registered_models_api.py +1438 -0
  8. unitycatalog/client/api/schemas_api.py +1421 -0
  9. unitycatalog/client/api/tables_api.py +1135 -0
  10. unitycatalog/client/api/temporary_credentials_api.py +1109 -0
  11. unitycatalog/client/api/volumes_api.py +1421 -0
  12. unitycatalog/client/api_client.py +773 -0
  13. unitycatalog/client/api_response.py +21 -0
  14. unitycatalog/client/configuration.py +432 -0
  15. unitycatalog/client/exceptions.py +199 -0
  16. unitycatalog/client/models/__init__.py +77 -0
  17. unitycatalog/client/models/aws_credentials.py +91 -0
  18. unitycatalog/client/models/azure_user_delegation_sas.py +87 -0
  19. unitycatalog/client/models/catalog_info.py +103 -0
  20. unitycatalog/client/models/column_info.py +108 -0
  21. unitycatalog/client/models/column_type_name.py +56 -0
  22. unitycatalog/client/models/create_catalog.py +91 -0
  23. unitycatalog/client/models/create_function.py +163 -0
  24. unitycatalog/client/models/create_function_request.py +91 -0
  25. unitycatalog/client/models/create_model_version.py +97 -0
  26. unitycatalog/client/models/create_registered_model.py +93 -0
  27. unitycatalog/client/models/create_schema.py +93 -0
  28. unitycatalog/client/models/create_table.py +113 -0
  29. unitycatalog/client/models/create_volume_request_content.py +99 -0
  30. unitycatalog/client/models/data_source_format.py +42 -0
  31. unitycatalog/client/models/dependency.py +97 -0
  32. unitycatalog/client/models/dependency_list.py +95 -0
  33. unitycatalog/client/models/finalize_model_version.py +89 -0
  34. unitycatalog/client/models/function_dependency.py +87 -0
  35. unitycatalog/client/models/function_info.py +189 -0
  36. unitycatalog/client/models/function_parameter_info.py +112 -0
  37. unitycatalog/client/models/function_parameter_infos.py +95 -0
  38. unitycatalog/client/models/function_parameter_mode.py +36 -0
  39. unitycatalog/client/models/function_parameter_type.py +37 -0
  40. unitycatalog/client/models/gcp_oauth_token.py +87 -0
  41. unitycatalog/client/models/generate_temporary_model_version_credential.py +96 -0
  42. unitycatalog/client/models/generate_temporary_path_credential.py +90 -0
  43. unitycatalog/client/models/generate_temporary_table_credential.py +90 -0
  44. unitycatalog/client/models/generate_temporary_volume_credential.py +90 -0
  45. unitycatalog/client/models/list_catalogs_response.py +97 -0
  46. unitycatalog/client/models/list_functions_response.py +97 -0
  47. unitycatalog/client/models/list_model_versions_response.py +97 -0
  48. unitycatalog/client/models/list_registered_models_response.py +97 -0
  49. unitycatalog/client/models/list_schemas_response.py +97 -0
  50. unitycatalog/client/models/list_tables_response.py +97 -0
  51. unitycatalog/client/models/list_volumes_response_content.py +97 -0
  52. unitycatalog/client/models/model_version_info.py +114 -0
  53. unitycatalog/client/models/model_version_operation.py +38 -0
  54. unitycatalog/client/models/model_version_status.py +39 -0
  55. unitycatalog/client/models/path_operation.py +39 -0
  56. unitycatalog/client/models/permissions_change.py +92 -0
  57. unitycatalog/client/models/permissions_list.py +95 -0
  58. unitycatalog/client/models/principal_type.py +37 -0
  59. unitycatalog/client/models/privilege.py +47 -0
  60. unitycatalog/client/models/privilege_assignment.py +90 -0
  61. unitycatalog/client/models/registered_model_info.py +109 -0
  62. unitycatalog/client/models/schema_info.py +107 -0
  63. unitycatalog/client/models/securable_type.py +42 -0
  64. unitycatalog/client/models/table_dependency.py +87 -0
  65. unitycatalog/client/models/table_info.py +125 -0
  66. unitycatalog/client/models/table_operation.py +38 -0
  67. unitycatalog/client/models/table_type.py +37 -0
  68. unitycatalog/client/models/temporary_credentials.py +105 -0
  69. unitycatalog/client/models/update_catalog.py +91 -0
  70. unitycatalog/client/models/update_model_version.py +87 -0
  71. unitycatalog/client/models/update_permissions.py +95 -0
  72. unitycatalog/client/models/update_registered_model.py +89 -0
  73. unitycatalog/client/models/update_schema.py +91 -0
  74. unitycatalog/client/models/update_volume_request_content.py +90 -0
  75. unitycatalog/client/models/volume_info.py +113 -0
  76. unitycatalog/client/models/volume_operation.py +38 -0
  77. unitycatalog/client/models/volume_type.py +37 -0
  78. unitycatalog/client/py.typed +0 -0
  79. unitycatalog/client/rest.py +215 -0
  80. unitycatalog_client-0.2.1.dist-info/METADATA +199 -0
  81. unitycatalog_client-0.2.1.dist-info/RECORD +82 -0
  82. unitycatalog_client-0.2.1.dist-info/WHEEL +4 -0
@@ -0,0 +1,21 @@
1
+ """API response object."""
2
+
3
+ from __future__ import annotations
4
+ from typing import Optional, Generic, Mapping, TypeVar
5
+ from pydantic import Field, StrictInt, StrictBytes, BaseModel
6
+
7
+ T = TypeVar("T")
8
+
9
+ class ApiResponse(BaseModel, Generic[T]):
10
+ """
11
+ API response object
12
+ """
13
+
14
+ status_code: StrictInt = Field(description="HTTP status code")
15
+ headers: Optional[Mapping[str, str]] = Field(None, description="HTTP headers")
16
+ data: T = Field(description="Deserialized data given the data type")
17
+ raw_data: StrictBytes = Field(description="Raw data (HTTP response body)")
18
+
19
+ model_config = {
20
+ "arbitrary_types_allowed": True
21
+ }
@@ -0,0 +1,432 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Unity Catalog API
5
+
6
+ No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
+
8
+ The version of the OpenAPI document: 0.1
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ import copy
16
+ import logging
17
+ from logging import FileHandler
18
+ import sys
19
+ from typing import Optional
20
+ import urllib3
21
+
22
+ import http.client as httplib
23
+
24
+ JSON_SCHEMA_VALIDATION_KEYWORDS = {
25
+ 'multipleOf', 'maximum', 'exclusiveMaximum',
26
+ 'minimum', 'exclusiveMinimum', 'maxLength',
27
+ 'minLength', 'pattern', 'maxItems', 'minItems'
28
+ }
29
+
30
+ class Configuration:
31
+ """This class contains various settings of the API client.
32
+
33
+ :param host: Base url.
34
+ :param api_key: Dict to store API key(s).
35
+ Each entry in the dict specifies an API key.
36
+ The dict key is the name of the security scheme in the OAS specification.
37
+ The dict value is the API key secret.
38
+ :param api_key_prefix: Dict to store API prefix (e.g. Bearer).
39
+ The dict key is the name of the security scheme in the OAS specification.
40
+ The dict value is an API key prefix when generating the auth data.
41
+ :param username: Username for HTTP basic authentication.
42
+ :param password: Password for HTTP basic authentication.
43
+ :param access_token: Access token.
44
+ :param server_index: Index to servers configuration.
45
+ :param server_variables: Mapping with string values to replace variables in
46
+ templated server configuration. The validation of enums is performed for
47
+ variables with defined enum values before.
48
+ :param server_operation_index: Mapping from operation ID to an index to server
49
+ configuration.
50
+ :param server_operation_variables: Mapping from operation ID to a mapping with
51
+ string values to replace variables in templated server configuration.
52
+ The validation of enums is performed for variables with defined enum
53
+ values before.
54
+ :param ssl_ca_cert: str - the path to a file of concatenated CA certificates
55
+ in PEM format.
56
+
57
+ """
58
+
59
+ _default = None
60
+
61
+ def __init__(self, host=None,
62
+ api_key=None, api_key_prefix=None,
63
+ username=None, password=None,
64
+ access_token=None,
65
+ server_index=None, server_variables=None,
66
+ server_operation_index=None, server_operation_variables=None,
67
+ ssl_ca_cert=None,
68
+ ) -> None:
69
+ """Constructor
70
+ """
71
+ self._base_path = "http://localhost:8080/api/2.1/unity-catalog" if host is None else host
72
+ """Default Base url
73
+ """
74
+ self.server_index = 0 if server_index is None and host is None else server_index
75
+ self.server_operation_index = server_operation_index or {}
76
+ """Default server index
77
+ """
78
+ self.server_variables = server_variables or {}
79
+ self.server_operation_variables = server_operation_variables or {}
80
+ """Default server variables
81
+ """
82
+ self.temp_folder_path = None
83
+ """Temp file folder for downloading files
84
+ """
85
+ # Authentication Settings
86
+ self.api_key = {}
87
+ if api_key:
88
+ self.api_key = api_key
89
+ """dict to store API key(s)
90
+ """
91
+ self.api_key_prefix = {}
92
+ if api_key_prefix:
93
+ self.api_key_prefix = api_key_prefix
94
+ """dict to store API prefix (e.g. Bearer)
95
+ """
96
+ self.refresh_api_key_hook = None
97
+ """function hook to refresh API key if expired
98
+ """
99
+ self.username = username
100
+ """Username for HTTP basic authentication
101
+ """
102
+ self.password = password
103
+ """Password for HTTP basic authentication
104
+ """
105
+ self.access_token = access_token
106
+ """Access token
107
+ """
108
+ self.logger = {}
109
+ """Logging Settings
110
+ """
111
+ self.logger["package_logger"] = logging.getLogger("unitycatalog.client")
112
+ self.logger["urllib3_logger"] = logging.getLogger("urllib3")
113
+ self.logger_format = '%(asctime)s %(levelname)s %(message)s'
114
+ """Log format
115
+ """
116
+ self.logger_stream_handler = None
117
+ """Log stream handler
118
+ """
119
+ self.logger_file_handler: Optional[FileHandler] = None
120
+ """Log file handler
121
+ """
122
+ self.logger_file = None
123
+ """Debug file location
124
+ """
125
+ self.debug = False
126
+ """Debug switch
127
+ """
128
+
129
+ self.verify_ssl = True
130
+ """SSL/TLS verification
131
+ Set this to false to skip verifying SSL certificate when calling API
132
+ from https server.
133
+ """
134
+ self.ssl_ca_cert = ssl_ca_cert
135
+ """Set this to customize the certificate file to verify the peer.
136
+ """
137
+ self.cert_file = None
138
+ """client certificate file
139
+ """
140
+ self.key_file = None
141
+ """client key file
142
+ """
143
+ self.assert_hostname = None
144
+ """Set this to True/False to enable/disable SSL hostname verification.
145
+ """
146
+ self.tls_server_name = None
147
+ """SSL/TLS Server Name Indication (SNI)
148
+ Set this to the SNI value expected by the server.
149
+ """
150
+
151
+ self.connection_pool_maxsize = 100
152
+ """This value is passed to the aiohttp to limit simultaneous connections.
153
+ Default values is 100, None means no-limit.
154
+ """
155
+
156
+ self.proxy: Optional[str] = None
157
+ """Proxy URL
158
+ """
159
+ self.proxy_headers = None
160
+ """Proxy headers
161
+ """
162
+ self.safe_chars_for_path_param = ''
163
+ """Safe chars for path_param
164
+ """
165
+ self.retries = None
166
+ """Adding retries to override urllib3 default value 3
167
+ """
168
+ # Enable client side validation
169
+ self.client_side_validation = True
170
+
171
+ self.socket_options = None
172
+ """Options to pass down to the underlying urllib3 socket
173
+ """
174
+
175
+ self.datetime_format = "%Y-%m-%dT%H:%M:%S.%f%z"
176
+ """datetime format
177
+ """
178
+
179
+ self.date_format = "%Y-%m-%d"
180
+ """date format
181
+ """
182
+
183
+ def __deepcopy__(self, memo):
184
+ cls = self.__class__
185
+ result = cls.__new__(cls)
186
+ memo[id(self)] = result
187
+ for k, v in self.__dict__.items():
188
+ if k not in ('logger', 'logger_file_handler'):
189
+ setattr(result, k, copy.deepcopy(v, memo))
190
+ # shallow copy of loggers
191
+ result.logger = copy.copy(self.logger)
192
+ # use setters to configure loggers
193
+ result.logger_file = self.logger_file
194
+ result.debug = self.debug
195
+ return result
196
+
197
+ def __setattr__(self, name, value):
198
+ object.__setattr__(self, name, value)
199
+
200
+ @classmethod
201
+ def set_default(cls, default):
202
+ """Set default instance of configuration.
203
+
204
+ It stores default configuration, which can be
205
+ returned by get_default_copy method.
206
+
207
+ :param default: object of Configuration
208
+ """
209
+ cls._default = default
210
+
211
+ @classmethod
212
+ def get_default_copy(cls):
213
+ """Deprecated. Please use `get_default` instead.
214
+
215
+ Deprecated. Please use `get_default` instead.
216
+
217
+ :return: The configuration object.
218
+ """
219
+ return cls.get_default()
220
+
221
+ @classmethod
222
+ def get_default(cls):
223
+ """Return the default configuration.
224
+
225
+ This method returns newly created, based on default constructor,
226
+ object of Configuration class or returns a copy of default
227
+ configuration.
228
+
229
+ :return: The configuration object.
230
+ """
231
+ if cls._default is None:
232
+ cls._default = Configuration()
233
+ return cls._default
234
+
235
+ @property
236
+ def logger_file(self):
237
+ """The logger file.
238
+
239
+ If the logger_file is None, then add stream handler and remove file
240
+ handler. Otherwise, add file handler and remove stream handler.
241
+
242
+ :param value: The logger_file path.
243
+ :type: str
244
+ """
245
+ return self.__logger_file
246
+
247
+ @logger_file.setter
248
+ def logger_file(self, value):
249
+ """The logger file.
250
+
251
+ If the logger_file is None, then add stream handler and remove file
252
+ handler. Otherwise, add file handler and remove stream handler.
253
+
254
+ :param value: The logger_file path.
255
+ :type: str
256
+ """
257
+ self.__logger_file = value
258
+ if self.__logger_file:
259
+ # If set logging file,
260
+ # then add file handler and remove stream handler.
261
+ self.logger_file_handler = logging.FileHandler(self.__logger_file)
262
+ self.logger_file_handler.setFormatter(self.logger_formatter)
263
+ for _, logger in self.logger.items():
264
+ logger.addHandler(self.logger_file_handler)
265
+
266
+ @property
267
+ def debug(self):
268
+ """Debug status
269
+
270
+ :param value: The debug status, True or False.
271
+ :type: bool
272
+ """
273
+ return self.__debug
274
+
275
+ @debug.setter
276
+ def debug(self, value):
277
+ """Debug status
278
+
279
+ :param value: The debug status, True or False.
280
+ :type: bool
281
+ """
282
+ self.__debug = value
283
+ if self.__debug:
284
+ # if debug status is True, turn on debug logging
285
+ for _, logger in self.logger.items():
286
+ logger.setLevel(logging.DEBUG)
287
+ # turn on httplib debug
288
+ httplib.HTTPConnection.debuglevel = 1
289
+ else:
290
+ # if debug status is False, turn off debug logging,
291
+ # setting log level to default `logging.WARNING`
292
+ for _, logger in self.logger.items():
293
+ logger.setLevel(logging.WARNING)
294
+ # turn off httplib debug
295
+ httplib.HTTPConnection.debuglevel = 0
296
+
297
+ @property
298
+ def logger_format(self):
299
+ """The logger format.
300
+
301
+ The logger_formatter will be updated when sets logger_format.
302
+
303
+ :param value: The format string.
304
+ :type: str
305
+ """
306
+ return self.__logger_format
307
+
308
+ @logger_format.setter
309
+ def logger_format(self, value):
310
+ """The logger format.
311
+
312
+ The logger_formatter will be updated when sets logger_format.
313
+
314
+ :param value: The format string.
315
+ :type: str
316
+ """
317
+ self.__logger_format = value
318
+ self.logger_formatter = logging.Formatter(self.__logger_format)
319
+
320
+ def get_api_key_with_prefix(self, identifier, alias=None):
321
+ """Gets API key (with prefix if set).
322
+
323
+ :param identifier: The identifier of apiKey.
324
+ :param alias: The alternative identifier of apiKey.
325
+ :return: The token for api key authentication.
326
+ """
327
+ if self.refresh_api_key_hook is not None:
328
+ self.refresh_api_key_hook(self)
329
+ key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
330
+ if key:
331
+ prefix = self.api_key_prefix.get(identifier)
332
+ if prefix:
333
+ return "%s %s" % (prefix, key)
334
+ else:
335
+ return key
336
+
337
+ def get_basic_auth_token(self):
338
+ """Gets HTTP basic authentication header (string).
339
+
340
+ :return: The token for basic HTTP authentication.
341
+ """
342
+ username = ""
343
+ if self.username is not None:
344
+ username = self.username
345
+ password = ""
346
+ if self.password is not None:
347
+ password = self.password
348
+ return urllib3.util.make_headers(
349
+ basic_auth=username + ':' + password
350
+ ).get('authorization')
351
+
352
+ def auth_settings(self):
353
+ """Gets Auth Settings dict for api client.
354
+
355
+ :return: The Auth Settings information dict.
356
+ """
357
+ auth = {}
358
+ return auth
359
+
360
+ def to_debug_report(self):
361
+ """Gets the essential information for debugging.
362
+
363
+ :return: The report for debugging.
364
+ """
365
+ return "Python SDK Debug Report:\n"\
366
+ "OS: {env}\n"\
367
+ "Python Version: {pyversion}\n"\
368
+ "Version of the API: 0.1\n"\
369
+ "SDK Package Version: 0.2.1".\
370
+ format(env=sys.platform, pyversion=sys.version)
371
+
372
+ def get_host_settings(self):
373
+ """Gets an array of host settings
374
+
375
+ :return: An array of host settings
376
+ """
377
+ return [
378
+ {
379
+ 'url': "http://localhost:8080/api/2.1/unity-catalog",
380
+ 'description': "Localhost reference server",
381
+ }
382
+ ]
383
+
384
+ def get_host_from_settings(self, index, variables=None, servers=None):
385
+ """Gets host URL based on the index and variables
386
+ :param index: array index of the host settings
387
+ :param variables: hash of variable and the corresponding value
388
+ :param servers: an array of host settings or None
389
+ :return: URL based on host settings
390
+ """
391
+ if index is None:
392
+ return self._base_path
393
+
394
+ variables = {} if variables is None else variables
395
+ servers = self.get_host_settings() if servers is None else servers
396
+
397
+ try:
398
+ server = servers[index]
399
+ except IndexError:
400
+ raise ValueError(
401
+ "Invalid index {0} when selecting the host settings. "
402
+ "Must be less than {1}".format(index, len(servers)))
403
+
404
+ url = server['url']
405
+
406
+ # go through variables and replace placeholders
407
+ for variable_name, variable in server.get('variables', {}).items():
408
+ used_value = variables.get(
409
+ variable_name, variable['default_value'])
410
+
411
+ if 'enum_values' in variable \
412
+ and used_value not in variable['enum_values']:
413
+ raise ValueError(
414
+ "The variable `{0}` in the host URL has invalid value "
415
+ "{1}. Must be {2}.".format(
416
+ variable_name, variables[variable_name],
417
+ variable['enum_values']))
418
+
419
+ url = url.replace("{" + variable_name + "}", used_value)
420
+
421
+ return url
422
+
423
+ @property
424
+ def host(self):
425
+ """Return generated host."""
426
+ return self.get_host_from_settings(self.server_index, variables=self.server_variables)
427
+
428
+ @host.setter
429
+ def host(self, value):
430
+ """Fix base path."""
431
+ self._base_path = value
432
+ self.server_index = None
@@ -0,0 +1,199 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Unity Catalog API
5
+
6
+ No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
+
8
+ The version of the OpenAPI document: 0.1
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+ from typing import Any, Optional
15
+ from typing_extensions import Self
16
+
17
+ class OpenApiException(Exception):
18
+ """The base exception class for all OpenAPIExceptions"""
19
+
20
+
21
+ class ApiTypeError(OpenApiException, TypeError):
22
+ def __init__(self, msg, path_to_item=None, valid_classes=None,
23
+ key_type=None) -> None:
24
+ """ Raises an exception for TypeErrors
25
+
26
+ Args:
27
+ msg (str): the exception message
28
+
29
+ Keyword Args:
30
+ path_to_item (list): a list of keys an indices to get to the
31
+ current_item
32
+ None if unset
33
+ valid_classes (tuple): the primitive classes that current item
34
+ should be an instance of
35
+ None if unset
36
+ key_type (bool): False if our value is a value in a dict
37
+ True if it is a key in a dict
38
+ False if our item is an item in a list
39
+ None if unset
40
+ """
41
+ self.path_to_item = path_to_item
42
+ self.valid_classes = valid_classes
43
+ self.key_type = key_type
44
+ full_msg = msg
45
+ if path_to_item:
46
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
47
+ super(ApiTypeError, self).__init__(full_msg)
48
+
49
+
50
+ class ApiValueError(OpenApiException, ValueError):
51
+ def __init__(self, msg, path_to_item=None) -> None:
52
+ """
53
+ Args:
54
+ msg (str): the exception message
55
+
56
+ Keyword Args:
57
+ path_to_item (list) the path to the exception in the
58
+ received_data dict. None if unset
59
+ """
60
+
61
+ self.path_to_item = path_to_item
62
+ full_msg = msg
63
+ if path_to_item:
64
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
65
+ super(ApiValueError, self).__init__(full_msg)
66
+
67
+
68
+ class ApiAttributeError(OpenApiException, AttributeError):
69
+ def __init__(self, msg, path_to_item=None) -> None:
70
+ """
71
+ Raised when an attribute reference or assignment fails.
72
+
73
+ Args:
74
+ msg (str): the exception message
75
+
76
+ Keyword Args:
77
+ path_to_item (None/list) the path to the exception in the
78
+ received_data dict
79
+ """
80
+ self.path_to_item = path_to_item
81
+ full_msg = msg
82
+ if path_to_item:
83
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
84
+ super(ApiAttributeError, self).__init__(full_msg)
85
+
86
+
87
+ class ApiKeyError(OpenApiException, KeyError):
88
+ def __init__(self, msg, path_to_item=None) -> None:
89
+ """
90
+ Args:
91
+ msg (str): the exception message
92
+
93
+ Keyword Args:
94
+ path_to_item (None/list) the path to the exception in the
95
+ received_data dict
96
+ """
97
+ self.path_to_item = path_to_item
98
+ full_msg = msg
99
+ if path_to_item:
100
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
101
+ super(ApiKeyError, self).__init__(full_msg)
102
+
103
+
104
+ class ApiException(OpenApiException):
105
+
106
+ def __init__(
107
+ self,
108
+ status=None,
109
+ reason=None,
110
+ http_resp=None,
111
+ *,
112
+ body: Optional[str] = None,
113
+ data: Optional[Any] = None,
114
+ ) -> None:
115
+ self.status = status
116
+ self.reason = reason
117
+ self.body = body
118
+ self.data = data
119
+ self.headers = None
120
+
121
+ if http_resp:
122
+ if self.status is None:
123
+ self.status = http_resp.status
124
+ if self.reason is None:
125
+ self.reason = http_resp.reason
126
+ if self.body is None:
127
+ try:
128
+ self.body = http_resp.data.decode('utf-8')
129
+ except Exception:
130
+ pass
131
+ self.headers = http_resp.getheaders()
132
+
133
+ @classmethod
134
+ def from_response(
135
+ cls,
136
+ *,
137
+ http_resp,
138
+ body: Optional[str],
139
+ data: Optional[Any],
140
+ ) -> Self:
141
+ if http_resp.status == 400:
142
+ raise BadRequestException(http_resp=http_resp, body=body, data=data)
143
+
144
+ if http_resp.status == 401:
145
+ raise UnauthorizedException(http_resp=http_resp, body=body, data=data)
146
+
147
+ if http_resp.status == 403:
148
+ raise ForbiddenException(http_resp=http_resp, body=body, data=data)
149
+
150
+ if http_resp.status == 404:
151
+ raise NotFoundException(http_resp=http_resp, body=body, data=data)
152
+
153
+ if 500 <= http_resp.status <= 599:
154
+ raise ServiceException(http_resp=http_resp, body=body, data=data)
155
+ raise ApiException(http_resp=http_resp, body=body, data=data)
156
+
157
+ def __str__(self):
158
+ """Custom error messages for exception"""
159
+ error_message = "({0})\n"\
160
+ "Reason: {1}\n".format(self.status, self.reason)
161
+ if self.headers:
162
+ error_message += "HTTP response headers: {0}\n".format(
163
+ self.headers)
164
+
165
+ if self.data or self.body:
166
+ error_message += "HTTP response body: {0}\n".format(self.data or self.body)
167
+
168
+ return error_message
169
+
170
+
171
+ class BadRequestException(ApiException):
172
+ pass
173
+
174
+
175
+ class NotFoundException(ApiException):
176
+ pass
177
+
178
+
179
+ class UnauthorizedException(ApiException):
180
+ pass
181
+
182
+
183
+ class ForbiddenException(ApiException):
184
+ pass
185
+
186
+
187
+ class ServiceException(ApiException):
188
+ pass
189
+
190
+
191
+ def render_path(path_to_item):
192
+ """Returns a string representation of a path"""
193
+ result = ""
194
+ for pth in path_to_item:
195
+ if isinstance(pth, int):
196
+ result += "[{0}]".format(pth)
197
+ else:
198
+ result += "['{0}']".format(pth)
199
+ return result