qena-shared-lib 0.1.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.
@@ -0,0 +1,319 @@
1
+ from enum import Enum
2
+ from typing import Any
3
+
4
+ __all__ = [
5
+ "Severity",
6
+ "ServiceException",
7
+ "ClientError",
8
+ "BadRequest",
9
+ "Unauthorized",
10
+ "PaymentRequired",
11
+ "Forbidden",
12
+ "NotFound",
13
+ "MethodNotAllowed",
14
+ "NotAcceptable",
15
+ "ProxyAuthenticationRequired",
16
+ "RequestTimeout",
17
+ "Conflict",
18
+ "Gone",
19
+ "LengthRequired",
20
+ "PreconditionFailed",
21
+ "PayloadTooLarge",
22
+ "URITooLong",
23
+ "UnsupportedMediaType",
24
+ "RangeNotSatisfiable",
25
+ "ExpectationFailed",
26
+ "IAmATeapot",
27
+ "MisdirectedRequest",
28
+ "UnprocessableEntity",
29
+ "Locked",
30
+ "FailedDependency",
31
+ "TooEarly",
32
+ "UpgradeRequired",
33
+ "PreconditionRequired",
34
+ "TooManyRequests",
35
+ "RequestHeaderFieldsTooLarge",
36
+ "UnavailableForLegalReasons",
37
+ "ServerError",
38
+ "InternalServerError",
39
+ "NotImplemented",
40
+ "BadGateway",
41
+ "ServiceUnavailable",
42
+ "GatewayTimeout",
43
+ "HTTPVersionNotSupported",
44
+ "VariantAlsoNegotiates",
45
+ "InsufficientStorage",
46
+ "LoopDetected",
47
+ "NotExtended",
48
+ "NetworkAuthenticationRequired",
49
+ ]
50
+
51
+
52
+ class Severity(Enum):
53
+ LOW = 1
54
+ MEDIUM = 2
55
+ HIGH = 3
56
+
57
+
58
+ class ServiceException(Exception):
59
+ _GENERAL_EXTRACT_EXC_INFO = None
60
+ _GENERAL_SEVERITY = None
61
+ _GENERAL_STATUS_CODE = None
62
+
63
+ def __init__(
64
+ self,
65
+ message: str,
66
+ body: Any | None = None,
67
+ corrective_action: str | None = None,
68
+ severity: Severity | None = None,
69
+ status_code: int | None = None,
70
+ response_code: int | None = None,
71
+ tags: list[str] | None = None,
72
+ extra: dict[str, str] | None = None,
73
+ headers: dict[str, str] | None = None,
74
+ logstash_logging: bool = True,
75
+ extract_exc_info: bool = True,
76
+ ):
77
+ self._message = message
78
+ self._body = body
79
+ self._corrective_action = corrective_action
80
+ self._response_code = response_code
81
+ self._tags = tags
82
+ self._extra = extra
83
+ self._headers = headers
84
+ self._logstash_logging = (
85
+ logstash_logging if logstash_logging is not None else True
86
+ )
87
+ self._extract_exc_info = (
88
+ extract_exc_info
89
+ if extract_exc_info is not None
90
+ else self._GENERAL_EXTRACT_EXC_INFO
91
+ )
92
+ self._severity = (
93
+ severity if severity is not None else self._GENERAL_SEVERITY
94
+ )
95
+ self._status_code = (
96
+ status_code
97
+ if status_code is not None
98
+ else self._GENERAL_STATUS_CODE
99
+ )
100
+
101
+ @property
102
+ def message(self) -> str:
103
+ return self._message
104
+
105
+ @property
106
+ def body(self) -> Any | None:
107
+ return self._body
108
+
109
+ @property
110
+ def corrective_action(self) -> str | None:
111
+ return self._corrective_action
112
+
113
+ @property
114
+ def severity(self) -> Severity | None:
115
+ return self._severity
116
+
117
+ @property
118
+ def status_code(self) -> int | None:
119
+ return self._status_code
120
+
121
+ @property
122
+ def response_code(self) -> int | None:
123
+ return self._response_code
124
+
125
+ @property
126
+ def tags(self) -> list[str] | None:
127
+ return self._tags
128
+
129
+ @property
130
+ def extra(self) -> dict[str, str] | None:
131
+ return self._extra
132
+
133
+ @property
134
+ def headers(self) -> dict[str, str] | None:
135
+ return self._headers
136
+
137
+ @property
138
+ def logstash_logging(self) -> bool | None:
139
+ return self._logstash_logging
140
+
141
+ @property
142
+ def extract_exc_info(self) -> bool | None:
143
+ return self._extract_exc_info
144
+
145
+ def __str__(self) -> str:
146
+ return f"message `{self._message}`, tags `{self._tags or []}`"
147
+
148
+ def __repr__(self) -> str:
149
+ return f"{self.__class__.__name__} ( message = `{self._message}`, tags = `{self._tags or []}`, extra = `{self._extra or {}}` )"
150
+
151
+
152
+ class ClientError(ServiceException):
153
+ _GENERAL_EXTRACT_EXC_INFO = False
154
+ _GENERAL_SEVERITY = Severity.MEDIUM
155
+
156
+
157
+ class BadRequest(ClientError):
158
+ _GENERAL_STATUS_CODE = 400
159
+
160
+
161
+ class Unauthorized(ClientError):
162
+ _GENERAL_STATUS_CODE = 401
163
+
164
+
165
+ class PaymentRequired(ClientError):
166
+ _GENERAL_STATUS_CODE = 402
167
+
168
+
169
+ class Forbidden(ClientError):
170
+ _GENERAL_STATUS_CODE = 403
171
+
172
+
173
+ class NotFound(ClientError):
174
+ _GENERAL_STATUS_CODE = 404
175
+
176
+
177
+ class MethodNotAllowed(ClientError):
178
+ _GENERAL_STATUS_CODE = 405
179
+
180
+
181
+ class NotAcceptable(ClientError):
182
+ _GENERAL_STATUS_CODE = 406
183
+
184
+
185
+ class ProxyAuthenticationRequired(ClientError):
186
+ _GENERAL_STATUS_CODE = 407
187
+
188
+
189
+ class RequestTimeout(ClientError):
190
+ _GENERAL_STATUS_CODE = 408
191
+
192
+
193
+ class Conflict(ClientError):
194
+ _GENERAL_STATUS_CODE = 409
195
+
196
+
197
+ class Gone(ClientError):
198
+ _GENERAL_STATUS_CODE = 410
199
+
200
+
201
+ class LengthRequired(ClientError):
202
+ _GENERAL_STATUS_CODE = 411
203
+
204
+
205
+ class PreconditionFailed(ClientError):
206
+ _GENERAL_STATUS_CODE = 412
207
+
208
+
209
+ class PayloadTooLarge(ClientError):
210
+ _GENERAL_STATUS_CODE = 413
211
+
212
+
213
+ class URITooLong(ClientError):
214
+ _GENERAL_STATUS_CODE = 414
215
+
216
+
217
+ class UnsupportedMediaType(ClientError):
218
+ _GENERAL_STATUS_CODE = 415
219
+
220
+
221
+ class RangeNotSatisfiable(ClientError):
222
+ _GENERAL_STATUS_CODE = 416
223
+
224
+
225
+ class ExpectationFailed(ClientError):
226
+ _GENERAL_STATUS_CODE = 417
227
+
228
+
229
+ class IAmATeapot(ClientError):
230
+ _GENERAL_STATUS_CODE = 418
231
+
232
+
233
+ class MisdirectedRequest(ClientError):
234
+ _GENERAL_STATUS_CODE = 421
235
+
236
+
237
+ class UnprocessableEntity(ClientError):
238
+ _GENERAL_STATUS_CODE = 422
239
+
240
+
241
+ class Locked(ClientError):
242
+ _GENERAL_STATUS_CODE = 423
243
+
244
+
245
+ class FailedDependency(ClientError):
246
+ _GENERAL_STATUS_CODE = 424
247
+
248
+
249
+ class TooEarly(ClientError):
250
+ _GENERAL_STATUS_CODE = 425
251
+
252
+
253
+ class UpgradeRequired(ClientError):
254
+ _GENERAL_STATUS_CODE = 426
255
+
256
+
257
+ class PreconditionRequired(ClientError):
258
+ _GENERAL_STATUS_CODE = 428
259
+
260
+
261
+ class TooManyRequests(ClientError):
262
+ _GENERAL_STATUS_CODE = 429
263
+
264
+
265
+ class RequestHeaderFieldsTooLarge(ClientError):
266
+ _GENERAL_STATUS_CODE = 431
267
+
268
+
269
+ class UnavailableForLegalReasons(ClientError):
270
+ _GENERAL_STATUS_CODE = 451
271
+
272
+
273
+ class ServerError(ServiceException):
274
+ _GENERAL_EXTRACT_EXC_INFO = True
275
+ _GENERAL_SEVERITY = Severity.HIGH
276
+
277
+
278
+ class InternalServerError(ServerError):
279
+ _GENERAL_STATUS_CODE = 500
280
+
281
+
282
+ class NotImplemented(ServerError):
283
+ _GENERAL_STATUS_CODE = 501
284
+
285
+
286
+ class BadGateway(ServerError):
287
+ _GENERAL_STATUS_CODE = 502
288
+
289
+
290
+ class ServiceUnavailable(ServerError):
291
+ _GENERAL_STATUS_CODE = 503
292
+
293
+
294
+ class GatewayTimeout(ServerError):
295
+ _GENERAL_STATUS_CODE = 504
296
+
297
+
298
+ class HTTPVersionNotSupported(ServerError):
299
+ _GENERAL_STATUS_CODE = 505
300
+
301
+
302
+ class VariantAlsoNegotiates(ServerError):
303
+ _GENERAL_STATUS_CODE = 506
304
+
305
+
306
+ class InsufficientStorage(ServerError):
307
+ _GENERAL_STATUS_CODE = 507
308
+
309
+
310
+ class LoopDetected(ServerError):
311
+ _GENERAL_STATUS_CODE = 508
312
+
313
+
314
+ class NotExtended(ServerError):
315
+ _GENERAL_STATUS_CODE = 510
316
+
317
+
318
+ class NetworkAuthenticationRequired(ServerError):
319
+ _GENERAL_STATUS_CODE = 511