alpha-python 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.
- alpha/__init__.py +0 -0
- alpha/adapters/__init__.py +0 -0
- alpha/adapters/sqla_unit_of_work.py +120 -0
- alpha/domain/__init__.py +0 -0
- alpha/domain/models/__init__.py +0 -0
- alpha/domain/models/base_model.py +25 -0
- alpha/encoder.py +62 -0
- alpha/exceptions.py +99 -0
- alpha/factories/__init__.py +0 -0
- alpha/factories/_type_conversion_matrix.py +233 -0
- alpha/factories/_type_mapping.py +29 -0
- alpha/factories/class_factories.py +496 -0
- alpha/factories/default_field_factory.py +50 -0
- alpha/factories/field_iterator.py +188 -0
- alpha/factories/logging_handler_factory.py +86 -0
- alpha/factories/model_class_factory.py +176 -0
- alpha/factories/models/__init__.py +0 -0
- alpha/factories/models/factory_classes.py +20 -0
- alpha/factories/request_factory.py +211 -0
- alpha/factories/response_factory.py +186 -0
- alpha/factories/type_factories.py +204 -0
- alpha/infra/__init__.py +0 -0
- alpha/infra/database/__init__.py +0 -0
- alpha/infra/database/sql_alchemy_database.py +159 -0
- alpha/infra/database/sql_alchemy_view.py +48 -0
- alpha/infra/models/__init__.py +0 -0
- alpha/infra/models/filter_operators.py +98 -0
- alpha/infra/models/json_patch.py +21 -0
- alpha/infra/models/order_by.py +69 -0
- alpha/infra/models/query_clause.py +45 -0
- alpha/infra/models/search_filter.py +586 -0
- alpha/interfaces/__init__.py +0 -0
- alpha/interfaces/attrs_instance.py +10 -0
- alpha/interfaces/dataclass_instance.py +11 -0
- alpha/interfaces/factories.py +102 -0
- alpha/interfaces/openapi_model.py +21 -0
- alpha/interfaces/patchable.py +8 -0
- alpha/interfaces/sql_database.py +36 -0
- alpha/interfaces/sql_mapper.py +23 -0
- alpha/interfaces/sql_repository.py +380 -0
- alpha/interfaces/token_factory.py +56 -0
- alpha/interfaces/unit_of_work.py +53 -0
- alpha/interfaces/updateable.py +7 -0
- alpha/py.typed +0 -0
- alpha/repositories/__init__.py +0 -0
- alpha/repositories/default_sql_repository.py +679 -0
- alpha/repositories/models/__init__.py +0 -0
- alpha/repositories/models/repository_model.py +16 -0
- alpha/services/__init__.py +0 -0
- alpha/services/authentication_service.py +71 -0
- alpha/utils/__init__.py +0 -0
- alpha/utils/_http_codes.py +148 -0
- alpha/utils/is_attrs.py +18 -0
- alpha/utils/logging_configurator.py +133 -0
- alpha/utils/logging_level_checker.py +26 -0
- alpha/utils/response_object.py +26 -0
- alpha/utils/version_check.py +17 -0
- alpha_python-0.1.0.dist-info/METADATA +22 -0
- alpha_python-0.1.0.dist-info/RECORD +62 -0
- alpha_python-0.1.0.dist-info/WHEEL +5 -0
- alpha_python-0.1.0.dist-info/licenses/LICENSE +21 -0
- alpha_python-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from enum import Enum, auto
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from sqlalchemy.orm.attributes import InstrumentedAttribute
|
|
6
|
+
from sqlalchemy.orm.query import Query
|
|
7
|
+
from sqlalchemy.sql.expression import BinaryExpression, ColumnOperators
|
|
8
|
+
|
|
9
|
+
from alpha.infra.models.query_clause import QueryClause
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Operator(Enum):
|
|
13
|
+
LT = auto()
|
|
14
|
+
LTE = auto()
|
|
15
|
+
EQ = auto()
|
|
16
|
+
NEQ = auto()
|
|
17
|
+
GT = auto()
|
|
18
|
+
GTE = auto()
|
|
19
|
+
IN = auto()
|
|
20
|
+
NIN = auto()
|
|
21
|
+
LIKE = auto()
|
|
22
|
+
NLIKE = auto()
|
|
23
|
+
ILIKE = auto()
|
|
24
|
+
NILIKE = auto()
|
|
25
|
+
STARTSWITH = auto()
|
|
26
|
+
ISTARTSWITH = auto()
|
|
27
|
+
NSTARTSWITH = auto()
|
|
28
|
+
NISTARTSWITH = auto()
|
|
29
|
+
ENDSWITH = auto()
|
|
30
|
+
IENDSWITH = auto()
|
|
31
|
+
NENDSWITH = auto()
|
|
32
|
+
NIENDSWITH = auto()
|
|
33
|
+
CONTAINS = auto()
|
|
34
|
+
ICONTAINS = auto()
|
|
35
|
+
NCONTAINS = auto()
|
|
36
|
+
NICONTAINS = auto()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass
|
|
40
|
+
class SearchFilter(QueryClause):
|
|
41
|
+
op: Operator = Operator.EQ
|
|
42
|
+
field: str | InstrumentedAttribute[Any] = ""
|
|
43
|
+
value: Any = ""
|
|
44
|
+
|
|
45
|
+
def __post_init__(self) -> None:
|
|
46
|
+
super().__post_init__()
|
|
47
|
+
self.__class__ = self._get_filter_class() # type: ignore
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def filter_statement(
|
|
51
|
+
self,
|
|
52
|
+
) -> BinaryExpression[Any] | ColumnOperators:
|
|
53
|
+
"""Returns the filter statement
|
|
54
|
+
|
|
55
|
+
Returns
|
|
56
|
+
-------
|
|
57
|
+
Filter statement
|
|
58
|
+
|
|
59
|
+
Raises
|
|
60
|
+
------
|
|
61
|
+
NotImplementedError
|
|
62
|
+
When called directly
|
|
63
|
+
"""
|
|
64
|
+
raise NotImplementedError
|
|
65
|
+
|
|
66
|
+
def _get_filter_class(self) -> type["SearchFilter"]:
|
|
67
|
+
match self.op:
|
|
68
|
+
case Operator.LT:
|
|
69
|
+
return LessThanFilter
|
|
70
|
+
case Operator.LTE:
|
|
71
|
+
return LessThanEqualsFilter
|
|
72
|
+
case Operator.EQ:
|
|
73
|
+
return EqualsFilter
|
|
74
|
+
case Operator.NEQ:
|
|
75
|
+
return NotEqualsFilter
|
|
76
|
+
case Operator.GT:
|
|
77
|
+
return GreaterThanFilter
|
|
78
|
+
case Operator.GTE:
|
|
79
|
+
return GreaterThanEqualsFilter
|
|
80
|
+
case Operator.IN:
|
|
81
|
+
return InFilter
|
|
82
|
+
case Operator.NIN:
|
|
83
|
+
return NotInFilter
|
|
84
|
+
case Operator.LIKE:
|
|
85
|
+
return LikeFilter
|
|
86
|
+
case Operator.NLIKE:
|
|
87
|
+
return NotLikeFilter
|
|
88
|
+
case Operator.ILIKE:
|
|
89
|
+
return InsensitiveLikeFilter
|
|
90
|
+
case Operator.NILIKE:
|
|
91
|
+
return InsensitiveNotLikeFilter
|
|
92
|
+
case Operator.STARTSWITH:
|
|
93
|
+
return StartsWithFilter
|
|
94
|
+
case Operator.NSTARTSWITH:
|
|
95
|
+
return NotStartsWithFilter
|
|
96
|
+
case Operator.ISTARTSWITH:
|
|
97
|
+
return InsensitiveStartsWithFilter
|
|
98
|
+
case Operator.NISTARTSWITH:
|
|
99
|
+
return InsensitiveNotStartsWithFilter
|
|
100
|
+
case Operator.ENDSWITH:
|
|
101
|
+
return EndsWithFilter
|
|
102
|
+
case Operator.NENDSWITH:
|
|
103
|
+
return NotEndsWithFilter
|
|
104
|
+
case Operator.IENDSWITH:
|
|
105
|
+
return InsensitiveEndsWithFilter
|
|
106
|
+
case Operator.NIENDSWITH:
|
|
107
|
+
return InsensitiveNotEndsWithFilter
|
|
108
|
+
case Operator.CONTAINS:
|
|
109
|
+
return ContainsFilter
|
|
110
|
+
case Operator.NCONTAINS:
|
|
111
|
+
return NotContainsFilter
|
|
112
|
+
case Operator.ICONTAINS:
|
|
113
|
+
return InsensitiveContainsFilter
|
|
114
|
+
case Operator.NICONTAINS:
|
|
115
|
+
return InsensitiveNotContainsFilter
|
|
116
|
+
|
|
117
|
+
def _parse_list(self, obj: str | list[str] | Any) -> list[str]:
|
|
118
|
+
if isinstance(obj, list):
|
|
119
|
+
return obj # type: ignore
|
|
120
|
+
if isinstance(obj, str):
|
|
121
|
+
return obj.split(",")
|
|
122
|
+
return [obj]
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class LessThanFilter(SearchFilter):
|
|
126
|
+
@property
|
|
127
|
+
def filter_statement(self) -> BinaryExpression[Any]:
|
|
128
|
+
"""Returns a lesser then filter statement
|
|
129
|
+
|
|
130
|
+
Returns
|
|
131
|
+
-------
|
|
132
|
+
Filter statement
|
|
133
|
+
"""
|
|
134
|
+
if self._instrumented_attr:
|
|
135
|
+
return self._instrumented_attr < self.value
|
|
136
|
+
self._raise_instrumented_attr_exception()
|
|
137
|
+
|
|
138
|
+
def query_clause(self, query: Query[Any]):
|
|
139
|
+
if self._instrumented_attr:
|
|
140
|
+
return query.filter(self._instrumented_attr < self.value)
|
|
141
|
+
self._raise_instrumented_attr_exception()
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class LessThanEqualsFilter(SearchFilter):
|
|
145
|
+
@property
|
|
146
|
+
def filter_statement(self) -> BinaryExpression[Any]:
|
|
147
|
+
"""Returns a lesser then or equals filter statement
|
|
148
|
+
|
|
149
|
+
Returns
|
|
150
|
+
-------
|
|
151
|
+
Filter statement
|
|
152
|
+
"""
|
|
153
|
+
if self._instrumented_attr:
|
|
154
|
+
return self._instrumented_attr <= self.value
|
|
155
|
+
self._raise_instrumented_attr_exception()
|
|
156
|
+
|
|
157
|
+
def query_clause(self, query: Query[Any]):
|
|
158
|
+
if self._instrumented_attr:
|
|
159
|
+
return query.filter(self._instrumented_attr <= self.value)
|
|
160
|
+
self._raise_instrumented_attr_exception()
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
class EqualsFilter(SearchFilter):
|
|
164
|
+
@property
|
|
165
|
+
def filter_statement(self) -> BinaryExpression[Any]:
|
|
166
|
+
"""Returns an equals filter statement
|
|
167
|
+
|
|
168
|
+
Returns
|
|
169
|
+
-------
|
|
170
|
+
Filter statement
|
|
171
|
+
"""
|
|
172
|
+
if self._instrumented_attr:
|
|
173
|
+
return self._instrumented_attr == self.value
|
|
174
|
+
self._raise_instrumented_attr_exception()
|
|
175
|
+
|
|
176
|
+
def query_clause(self, query: Query[Any]):
|
|
177
|
+
if self._instrumented_attr:
|
|
178
|
+
return query.filter(self._instrumented_attr == self.value)
|
|
179
|
+
return query.filter_by(**{self.field: self.value})
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
class NotEqualsFilter(SearchFilter):
|
|
183
|
+
@property
|
|
184
|
+
def filter_statement(self) -> BinaryExpression[Any]:
|
|
185
|
+
"""Returns a not equals filter statement
|
|
186
|
+
|
|
187
|
+
Returns
|
|
188
|
+
-------
|
|
189
|
+
Filter statement
|
|
190
|
+
"""
|
|
191
|
+
if self._instrumented_attr:
|
|
192
|
+
return self._instrumented_attr != self.value
|
|
193
|
+
self._raise_instrumented_attr_exception()
|
|
194
|
+
|
|
195
|
+
def query_clause(self, query: Query[Any]):
|
|
196
|
+
if self._instrumented_attr:
|
|
197
|
+
return query.filter(self._instrumented_attr != self.value)
|
|
198
|
+
self._raise_instrumented_attr_exception()
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
class GreaterThanFilter(SearchFilter):
|
|
202
|
+
@property
|
|
203
|
+
def filter_statement(self) -> BinaryExpression[Any]:
|
|
204
|
+
"""Returns a greater then filter statement
|
|
205
|
+
|
|
206
|
+
Returns
|
|
207
|
+
-------
|
|
208
|
+
Filter statement
|
|
209
|
+
"""
|
|
210
|
+
if self._instrumented_attr:
|
|
211
|
+
return self._instrumented_attr > self.value
|
|
212
|
+
self._raise_instrumented_attr_exception()
|
|
213
|
+
|
|
214
|
+
def query_clause(self, query: Query[Any]):
|
|
215
|
+
if self._instrumented_attr:
|
|
216
|
+
return query.filter(self._instrumented_attr > self.value)
|
|
217
|
+
self._raise_instrumented_attr_exception()
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
class GreaterThanEqualsFilter(SearchFilter):
|
|
221
|
+
@property
|
|
222
|
+
def filter_statement(self) -> BinaryExpression[Any]:
|
|
223
|
+
"""Returns a greater then or equals filter statement
|
|
224
|
+
|
|
225
|
+
Returns
|
|
226
|
+
-------
|
|
227
|
+
Filter statement
|
|
228
|
+
"""
|
|
229
|
+
if self._instrumented_attr:
|
|
230
|
+
return self._instrumented_attr >= self.value
|
|
231
|
+
self._raise_instrumented_attr_exception()
|
|
232
|
+
|
|
233
|
+
def query_clause(self, query: Query[Any]):
|
|
234
|
+
if self._instrumented_attr:
|
|
235
|
+
return query.filter(self._instrumented_attr >= self.value)
|
|
236
|
+
self._raise_instrumented_attr_exception()
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
class InFilter(SearchFilter):
|
|
240
|
+
@property
|
|
241
|
+
def filter_statement(self) -> ColumnOperators:
|
|
242
|
+
"""Returns an in filter statement
|
|
243
|
+
|
|
244
|
+
Returns
|
|
245
|
+
-------
|
|
246
|
+
Filter statement
|
|
247
|
+
"""
|
|
248
|
+
if self._instrumented_attr:
|
|
249
|
+
self.value = self._parse_list(self.value)
|
|
250
|
+
return self._instrumented_attr.in_(self.value)
|
|
251
|
+
self._raise_instrumented_attr_exception()
|
|
252
|
+
|
|
253
|
+
def query_clause(self, query: Query[Any]):
|
|
254
|
+
if self._instrumented_attr:
|
|
255
|
+
return query.filter(self._instrumented_attr.in_(self.value))
|
|
256
|
+
self._raise_instrumented_attr_exception()
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
class NotInFilter(SearchFilter):
|
|
260
|
+
@property
|
|
261
|
+
def filter_statement(self) -> ColumnOperators:
|
|
262
|
+
"""Returns a not in filter statement
|
|
263
|
+
|
|
264
|
+
Returns
|
|
265
|
+
-------
|
|
266
|
+
Filter statement
|
|
267
|
+
"""
|
|
268
|
+
if self._instrumented_attr:
|
|
269
|
+
self.value = self._parse_list(self.value)
|
|
270
|
+
return self._instrumented_attr.not_in(self.value)
|
|
271
|
+
self._raise_instrumented_attr_exception()
|
|
272
|
+
|
|
273
|
+
def query_clause(self, query: Query[Any]):
|
|
274
|
+
if self._instrumented_attr:
|
|
275
|
+
return query.filter(self._instrumented_attr.not_in(self.value))
|
|
276
|
+
self._raise_instrumented_attr_exception()
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
class LikeFilter(SearchFilter):
|
|
280
|
+
@property
|
|
281
|
+
def filter_statement(self) -> ColumnOperators:
|
|
282
|
+
"""Returns a like filter statement
|
|
283
|
+
|
|
284
|
+
Returns
|
|
285
|
+
-------
|
|
286
|
+
Filter statement
|
|
287
|
+
"""
|
|
288
|
+
if self._instrumented_attr:
|
|
289
|
+
return self._instrumented_attr.like(self.value)
|
|
290
|
+
self._raise_instrumented_attr_exception()
|
|
291
|
+
|
|
292
|
+
def query_clause(self, query: Query[Any]):
|
|
293
|
+
if self._instrumented_attr:
|
|
294
|
+
return query.filter(self._instrumented_attr.like(self.value))
|
|
295
|
+
self._raise_instrumented_attr_exception()
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
class InsensitiveLikeFilter(SearchFilter):
|
|
299
|
+
@property
|
|
300
|
+
def filter_statement(self) -> ColumnOperators:
|
|
301
|
+
"""Returns a case insensitive like filter statement
|
|
302
|
+
|
|
303
|
+
Returns
|
|
304
|
+
-------
|
|
305
|
+
Filter statement
|
|
306
|
+
"""
|
|
307
|
+
if self._instrumented_attr:
|
|
308
|
+
return self._instrumented_attr.ilike(self.value)
|
|
309
|
+
self._raise_instrumented_attr_exception()
|
|
310
|
+
|
|
311
|
+
def query_clause(self, query: Query[Any]):
|
|
312
|
+
if self._instrumented_attr:
|
|
313
|
+
return query.filter(self._instrumented_attr.ilike(self.value))
|
|
314
|
+
self._raise_instrumented_attr_exception()
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
class NotLikeFilter(SearchFilter):
|
|
318
|
+
@property
|
|
319
|
+
def filter_statement(self) -> ColumnOperators:
|
|
320
|
+
"""Returns a not like filter statement
|
|
321
|
+
|
|
322
|
+
Returns
|
|
323
|
+
-------
|
|
324
|
+
Filter statement
|
|
325
|
+
"""
|
|
326
|
+
if self._instrumented_attr:
|
|
327
|
+
return ~self._instrumented_attr.like(self.value)
|
|
328
|
+
self._raise_instrumented_attr_exception()
|
|
329
|
+
|
|
330
|
+
def query_clause(self, query: Query[Any]):
|
|
331
|
+
if self._instrumented_attr:
|
|
332
|
+
return query.filter(~self._instrumented_attr.like(self.value))
|
|
333
|
+
self._raise_instrumented_attr_exception()
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
class InsensitiveNotLikeFilter(SearchFilter):
|
|
337
|
+
@property
|
|
338
|
+
def filter_statement(self) -> ColumnOperators:
|
|
339
|
+
"""Returns a case insensitive not like filter statement
|
|
340
|
+
|
|
341
|
+
Returns
|
|
342
|
+
-------
|
|
343
|
+
Filter statement
|
|
344
|
+
"""
|
|
345
|
+
if self._instrumented_attr:
|
|
346
|
+
return ~self._instrumented_attr.ilike(self.value)
|
|
347
|
+
self._raise_instrumented_attr_exception()
|
|
348
|
+
|
|
349
|
+
def query_clause(self, query: Query[Any]):
|
|
350
|
+
if self._instrumented_attr:
|
|
351
|
+
return query.filter(~self._instrumented_attr.ilike(self.value))
|
|
352
|
+
self._raise_instrumented_attr_exception()
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
class StartsWithFilter(SearchFilter):
|
|
356
|
+
@property
|
|
357
|
+
def filter_statement(self) -> ColumnOperators:
|
|
358
|
+
"""Returns a starts with filter statement
|
|
359
|
+
|
|
360
|
+
Returns
|
|
361
|
+
-------
|
|
362
|
+
Filter statement
|
|
363
|
+
"""
|
|
364
|
+
if self._instrumented_attr:
|
|
365
|
+
return self._instrumented_attr.startswith(self.value)
|
|
366
|
+
self._raise_instrumented_attr_exception()
|
|
367
|
+
|
|
368
|
+
def query_clause(self, query: Query[Any]):
|
|
369
|
+
if self._instrumented_attr:
|
|
370
|
+
return query.filter(self._instrumented_attr.startswith(self.value))
|
|
371
|
+
self._raise_instrumented_attr_exception()
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
class InsensitiveStartsWithFilter(SearchFilter):
|
|
375
|
+
@property
|
|
376
|
+
def filter_statement(self) -> ColumnOperators:
|
|
377
|
+
"""Returns a case insensitive starts with filter statement
|
|
378
|
+
|
|
379
|
+
Returns
|
|
380
|
+
-------
|
|
381
|
+
Filter statement
|
|
382
|
+
"""
|
|
383
|
+
if self._instrumented_attr:
|
|
384
|
+
return self._instrumented_attr.istartswith(self.value)
|
|
385
|
+
self._raise_instrumented_attr_exception()
|
|
386
|
+
|
|
387
|
+
def query_clause(self, query: Query[Any]):
|
|
388
|
+
if self._instrumented_attr:
|
|
389
|
+
return query.filter(
|
|
390
|
+
self._instrumented_attr.istartswith(self.value)
|
|
391
|
+
)
|
|
392
|
+
self._raise_instrumented_attr_exception()
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
class NotStartsWithFilter(SearchFilter):
|
|
396
|
+
@property
|
|
397
|
+
def filter_statement(self) -> ColumnOperators:
|
|
398
|
+
"""Returns a not starts with filter statement
|
|
399
|
+
|
|
400
|
+
Returns
|
|
401
|
+
-------
|
|
402
|
+
Filter statement
|
|
403
|
+
"""
|
|
404
|
+
if self._instrumented_attr:
|
|
405
|
+
return ~self._instrumented_attr.startswith(self.value)
|
|
406
|
+
self._raise_instrumented_attr_exception()
|
|
407
|
+
|
|
408
|
+
def query_clause(self, query: Query[Any]):
|
|
409
|
+
if self._instrumented_attr:
|
|
410
|
+
return query.filter(
|
|
411
|
+
~self._instrumented_attr.startswith(self.value)
|
|
412
|
+
)
|
|
413
|
+
self._raise_instrumented_attr_exception()
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
class InsensitiveNotStartsWithFilter(SearchFilter):
|
|
417
|
+
@property
|
|
418
|
+
def filter_statement(self) -> ColumnOperators:
|
|
419
|
+
"""Returns a case insensitive not starts with filter statement
|
|
420
|
+
|
|
421
|
+
Returns
|
|
422
|
+
-------
|
|
423
|
+
Filter statement
|
|
424
|
+
"""
|
|
425
|
+
if self._instrumented_attr:
|
|
426
|
+
return ~self._instrumented_attr.istartswith(self.value)
|
|
427
|
+
self._raise_instrumented_attr_exception()
|
|
428
|
+
|
|
429
|
+
def query_clause(self, query: Query[Any]):
|
|
430
|
+
if self._instrumented_attr:
|
|
431
|
+
return query.filter(
|
|
432
|
+
~self._instrumented_attr.istartswith(self.value)
|
|
433
|
+
)
|
|
434
|
+
self._raise_instrumented_attr_exception()
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
class EndsWithFilter(SearchFilter):
|
|
438
|
+
@property
|
|
439
|
+
def filter_statement(self) -> ColumnOperators:
|
|
440
|
+
"""Returns a ends with filter statement
|
|
441
|
+
|
|
442
|
+
Returns
|
|
443
|
+
-------
|
|
444
|
+
Filter statement
|
|
445
|
+
"""
|
|
446
|
+
if self._instrumented_attr:
|
|
447
|
+
return self._instrumented_attr.endswith(self.value)
|
|
448
|
+
self._raise_instrumented_attr_exception()
|
|
449
|
+
|
|
450
|
+
def query_clause(self, query: Query[Any]):
|
|
451
|
+
if self._instrumented_attr:
|
|
452
|
+
return query.filter(self._instrumented_attr.endswith(self.value))
|
|
453
|
+
self._raise_instrumented_attr_exception()
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
class InsensitiveEndsWithFilter(SearchFilter):
|
|
457
|
+
@property
|
|
458
|
+
def filter_statement(self) -> ColumnOperators:
|
|
459
|
+
"""Returns a case insensitive ends with filter statement
|
|
460
|
+
|
|
461
|
+
Returns
|
|
462
|
+
-------
|
|
463
|
+
Filter statement
|
|
464
|
+
"""
|
|
465
|
+
if self._instrumented_attr:
|
|
466
|
+
return self._instrumented_attr.iendswith(self.value)
|
|
467
|
+
self._raise_instrumented_attr_exception()
|
|
468
|
+
|
|
469
|
+
def query_clause(self, query: Query[Any]):
|
|
470
|
+
if self._instrumented_attr:
|
|
471
|
+
return query.filter(self._instrumented_attr.iendswith(self.value))
|
|
472
|
+
self._raise_instrumented_attr_exception()
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
class NotEndsWithFilter(SearchFilter):
|
|
476
|
+
@property
|
|
477
|
+
def filter_statement(self) -> ColumnOperators:
|
|
478
|
+
"""Returns a not ends with filter statement
|
|
479
|
+
|
|
480
|
+
Returns
|
|
481
|
+
-------
|
|
482
|
+
Filter statement
|
|
483
|
+
"""
|
|
484
|
+
if self._instrumented_attr:
|
|
485
|
+
return ~self._instrumented_attr.endswith(self.value)
|
|
486
|
+
self._raise_instrumented_attr_exception()
|
|
487
|
+
|
|
488
|
+
def query_clause(self, query: Query[Any]):
|
|
489
|
+
if self._instrumented_attr:
|
|
490
|
+
return query.filter(~self._instrumented_attr.endswith(self.value))
|
|
491
|
+
self._raise_instrumented_attr_exception()
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
class InsensitiveNotEndsWithFilter(SearchFilter):
|
|
495
|
+
@property
|
|
496
|
+
def filter_statement(self) -> ColumnOperators:
|
|
497
|
+
"""Returns a case insensitive not ends with filter statement
|
|
498
|
+
|
|
499
|
+
Returns
|
|
500
|
+
-------
|
|
501
|
+
Filter statement
|
|
502
|
+
"""
|
|
503
|
+
if self._instrumented_attr:
|
|
504
|
+
return ~self._instrumented_attr.iendswith(self.value)
|
|
505
|
+
self._raise_instrumented_attr_exception()
|
|
506
|
+
|
|
507
|
+
def query_clause(self, query: Query[Any]):
|
|
508
|
+
if self._instrumented_attr:
|
|
509
|
+
return query.filter(~self._instrumented_attr.iendswith(self.value))
|
|
510
|
+
self._raise_instrumented_attr_exception()
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
class ContainsFilter(SearchFilter):
|
|
514
|
+
@property
|
|
515
|
+
def filter_statement(self) -> ColumnOperators:
|
|
516
|
+
"""Returns a contains filter statement
|
|
517
|
+
|
|
518
|
+
Returns
|
|
519
|
+
-------
|
|
520
|
+
Filter statement
|
|
521
|
+
"""
|
|
522
|
+
if self._instrumented_attr:
|
|
523
|
+
return self._instrumented_attr.contains(self.value)
|
|
524
|
+
self._raise_instrumented_attr_exception()
|
|
525
|
+
|
|
526
|
+
def query_clause(self, query: Query[Any]):
|
|
527
|
+
if self._instrumented_attr:
|
|
528
|
+
return query.filter(self._instrumented_attr.contains(self.value))
|
|
529
|
+
self._raise_instrumented_attr_exception()
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
class InsensitiveContainsFilter(SearchFilter):
|
|
533
|
+
@property
|
|
534
|
+
def filter_statement(self) -> ColumnOperators:
|
|
535
|
+
"""Returns a case insensitive contains filter statement
|
|
536
|
+
|
|
537
|
+
Returns
|
|
538
|
+
-------
|
|
539
|
+
Filter statement
|
|
540
|
+
"""
|
|
541
|
+
if self._instrumented_attr:
|
|
542
|
+
return self._instrumented_attr.icontains(self.value)
|
|
543
|
+
self._raise_instrumented_attr_exception()
|
|
544
|
+
|
|
545
|
+
def query_clause(self, query: Query[Any]):
|
|
546
|
+
if self._instrumented_attr:
|
|
547
|
+
return query.filter(self._instrumented_attr.icontains(self.value))
|
|
548
|
+
self._raise_instrumented_attr_exception()
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
class NotContainsFilter(SearchFilter):
|
|
552
|
+
@property
|
|
553
|
+
def filter_statement(self) -> ColumnOperators:
|
|
554
|
+
"""Returns a not contains filter statement
|
|
555
|
+
|
|
556
|
+
Returns
|
|
557
|
+
-------
|
|
558
|
+
Filter statement
|
|
559
|
+
"""
|
|
560
|
+
if self._instrumented_attr:
|
|
561
|
+
return ~self._instrumented_attr.contains(self.value)
|
|
562
|
+
self._raise_instrumented_attr_exception()
|
|
563
|
+
|
|
564
|
+
def query_clause(self, query: Query[Any]):
|
|
565
|
+
if self._instrumented_attr:
|
|
566
|
+
return query.filter(~self._instrumented_attr.contains(self.value))
|
|
567
|
+
self._raise_instrumented_attr_exception()
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
class InsensitiveNotContainsFilter(SearchFilter):
|
|
571
|
+
@property
|
|
572
|
+
def filter_statement(self) -> ColumnOperators:
|
|
573
|
+
"""Returns a case insensitive not contains filter statement
|
|
574
|
+
|
|
575
|
+
Returns
|
|
576
|
+
-------
|
|
577
|
+
Filter statement
|
|
578
|
+
"""
|
|
579
|
+
if self._instrumented_attr:
|
|
580
|
+
return ~self._instrumented_attr.icontains(self.value)
|
|
581
|
+
self._raise_instrumented_attr_exception()
|
|
582
|
+
|
|
583
|
+
def query_clause(self, query: Query[Any]):
|
|
584
|
+
if self._instrumented_attr:
|
|
585
|
+
return query.filter(~self._instrumented_attr.icontains(self.value))
|
|
586
|
+
self._raise_instrumented_attr_exception()
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from dataclasses import Field
|
|
2
|
+
from typing import Any, ClassVar, Protocol, runtime_checkable
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@runtime_checkable
|
|
6
|
+
class DataclassInstance(Protocol):
|
|
7
|
+
"""Dataclass instance interface"""
|
|
8
|
+
|
|
9
|
+
__dataclass_fields__: ClassVar[dict[str, Field[Any]]]
|
|
10
|
+
|
|
11
|
+
def __call__(self, *args: Any, **kwds: Any) -> Any: ...
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""This module contains the following interfaces:
|
|
2
|
+
- ClassFactory
|
|
3
|
+
- TypeFactory
|
|
4
|
+
- DefaultFactory
|
|
5
|
+
- FactoryClassesInstance
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from alpha.factories.field_iterator import Field
|
|
9
|
+
from typing import Any, Protocol
|
|
10
|
+
|
|
11
|
+
from alpha.interfaces.attrs_instance import AttrsInstance
|
|
12
|
+
from alpha.interfaces.dataclass_instance import DataclassInstance
|
|
13
|
+
from alpha.interfaces.openapi_model import OpenAPIModel
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ClassFactory(Protocol):
|
|
17
|
+
"""ClassFactory interface
|
|
18
|
+
|
|
19
|
+
A ClassFactory implementation only has a 'process' method.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def process(
|
|
23
|
+
self,
|
|
24
|
+
obj: OpenAPIModel,
|
|
25
|
+
field: Field,
|
|
26
|
+
factory_classes: "FactoryClassesInstance",
|
|
27
|
+
) -> Any:
|
|
28
|
+
"""This method handles the class operation
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
obj
|
|
33
|
+
Instance of an OpenAPIModel class
|
|
34
|
+
field
|
|
35
|
+
Dataclass field of the destination attribute
|
|
36
|
+
factory_classes
|
|
37
|
+
FactoryClasses instance which acts as a toolbox of Factory classes
|
|
38
|
+
|
|
39
|
+
Returns
|
|
40
|
+
-------
|
|
41
|
+
Any object that will be returned by one of the factory classes
|
|
42
|
+
which is called by a ClassFactory implementation
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class TypeFactory(Protocol):
|
|
47
|
+
"""TypeFactory interface
|
|
48
|
+
|
|
49
|
+
A TypeFactory implementation only has a 'process' method.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
def process(
|
|
53
|
+
self, key: str, value: Any, cls: Any, **kwargs: dict[str, Any]
|
|
54
|
+
) -> Any:
|
|
55
|
+
"""This method handles the type operation
|
|
56
|
+
|
|
57
|
+
Parameters
|
|
58
|
+
----------
|
|
59
|
+
key
|
|
60
|
+
Key name
|
|
61
|
+
value
|
|
62
|
+
Source value which corresponds to the factory implementation
|
|
63
|
+
cls
|
|
64
|
+
Class of the destination type
|
|
65
|
+
kwargs
|
|
66
|
+
Additional parameters
|
|
67
|
+
|
|
68
|
+
Returns
|
|
69
|
+
-------
|
|
70
|
+
Mapped instance of the value
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class DefaultFactory(Protocol):
|
|
75
|
+
"""DefaultFactory interface
|
|
76
|
+
|
|
77
|
+
A DefaultFactory implementation only has a 'process' method.
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
def process(
|
|
81
|
+
self,
|
|
82
|
+
field: Field,
|
|
83
|
+
) -> Any: ...
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class ModelClassFactoryInstance(Protocol):
|
|
87
|
+
"""ModelClassFactory dataclass interface"""
|
|
88
|
+
|
|
89
|
+
def process(
|
|
90
|
+
self,
|
|
91
|
+
obj: OpenAPIModel,
|
|
92
|
+
cls: DataclassInstance | AttrsInstance | Any,
|
|
93
|
+
) -> DataclassInstance | AttrsInstance | None: ...
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class FactoryClassesInstance(Protocol):
|
|
97
|
+
"""FactoryClasses dataclass interface"""
|
|
98
|
+
|
|
99
|
+
class_factories: dict[str, ClassFactory]
|
|
100
|
+
type_factories: dict[str, TypeFactory]
|
|
101
|
+
default_factory: DefaultFactory
|
|
102
|
+
model_class_factory: ModelClassFactoryInstance | None
|