clear-skies 2.0.4__py3-none-any.whl → 2.0.5__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 clear-skies might be problematic. Click here for more details.

Files changed (253) hide show
  1. clear_skies-2.0.5.dist-info/METADATA +74 -0
  2. clear_skies-2.0.5.dist-info/RECORD +4 -0
  3. {clear_skies-2.0.4.dist-info → clear_skies-2.0.5.dist-info}/WHEEL +1 -1
  4. clear_skies-2.0.4.dist-info/METADATA +0 -36
  5. clear_skies-2.0.4.dist-info/RECORD +0 -251
  6. clearskies/__init__.py +0 -61
  7. clearskies/action.py +0 -7
  8. clearskies/authentication/__init__.py +0 -15
  9. clearskies/authentication/authentication.py +0 -46
  10. clearskies/authentication/authorization.py +0 -16
  11. clearskies/authentication/authorization_pass_through.py +0 -20
  12. clearskies/authentication/jwks.py +0 -163
  13. clearskies/authentication/public.py +0 -5
  14. clearskies/authentication/secret_bearer.py +0 -553
  15. clearskies/autodoc/__init__.py +0 -8
  16. clearskies/autodoc/formats/__init__.py +0 -5
  17. clearskies/autodoc/formats/oai3_json/__init__.py +0 -7
  18. clearskies/autodoc/formats/oai3_json/oai3_json.py +0 -87
  19. clearskies/autodoc/formats/oai3_json/oai3_schema_resolver.py +0 -15
  20. clearskies/autodoc/formats/oai3_json/parameter.py +0 -35
  21. clearskies/autodoc/formats/oai3_json/request.py +0 -68
  22. clearskies/autodoc/formats/oai3_json/response.py +0 -28
  23. clearskies/autodoc/formats/oai3_json/schema/__init__.py +0 -11
  24. clearskies/autodoc/formats/oai3_json/schema/array.py +0 -9
  25. clearskies/autodoc/formats/oai3_json/schema/default.py +0 -13
  26. clearskies/autodoc/formats/oai3_json/schema/enum.py +0 -7
  27. clearskies/autodoc/formats/oai3_json/schema/object.py +0 -35
  28. clearskies/autodoc/formats/oai3_json/test.json +0 -1985
  29. clearskies/autodoc/py.typed +0 -0
  30. clearskies/autodoc/request/__init__.py +0 -15
  31. clearskies/autodoc/request/header.py +0 -6
  32. clearskies/autodoc/request/json_body.py +0 -6
  33. clearskies/autodoc/request/parameter.py +0 -8
  34. clearskies/autodoc/request/request.py +0 -47
  35. clearskies/autodoc/request/url_parameter.py +0 -6
  36. clearskies/autodoc/request/url_path.py +0 -6
  37. clearskies/autodoc/response/__init__.py +0 -5
  38. clearskies/autodoc/response/response.py +0 -9
  39. clearskies/autodoc/schema/__init__.py +0 -31
  40. clearskies/autodoc/schema/array.py +0 -10
  41. clearskies/autodoc/schema/base64.py +0 -8
  42. clearskies/autodoc/schema/boolean.py +0 -5
  43. clearskies/autodoc/schema/date.py +0 -5
  44. clearskies/autodoc/schema/datetime.py +0 -5
  45. clearskies/autodoc/schema/double.py +0 -5
  46. clearskies/autodoc/schema/enum.py +0 -17
  47. clearskies/autodoc/schema/integer.py +0 -6
  48. clearskies/autodoc/schema/long.py +0 -5
  49. clearskies/autodoc/schema/number.py +0 -6
  50. clearskies/autodoc/schema/object.py +0 -13
  51. clearskies/autodoc/schema/password.py +0 -5
  52. clearskies/autodoc/schema/schema.py +0 -11
  53. clearskies/autodoc/schema/string.py +0 -5
  54. clearskies/backends/__init__.py +0 -65
  55. clearskies/backends/api_backend.py +0 -1178
  56. clearskies/backends/backend.py +0 -136
  57. clearskies/backends/cursor_backend.py +0 -335
  58. clearskies/backends/memory_backend.py +0 -797
  59. clearskies/backends/secrets_backend.py +0 -106
  60. clearskies/column.py +0 -1233
  61. clearskies/columns/__init__.py +0 -71
  62. clearskies/columns/audit.py +0 -206
  63. clearskies/columns/belongs_to_id.py +0 -483
  64. clearskies/columns/belongs_to_model.py +0 -132
  65. clearskies/columns/belongs_to_self.py +0 -105
  66. clearskies/columns/boolean.py +0 -113
  67. clearskies/columns/category_tree.py +0 -275
  68. clearskies/columns/category_tree_ancestors.py +0 -51
  69. clearskies/columns/category_tree_children.py +0 -127
  70. clearskies/columns/category_tree_descendants.py +0 -48
  71. clearskies/columns/created.py +0 -95
  72. clearskies/columns/created_by_authorization_data.py +0 -116
  73. clearskies/columns/created_by_header.py +0 -99
  74. clearskies/columns/created_by_ip.py +0 -92
  75. clearskies/columns/created_by_routing_data.py +0 -97
  76. clearskies/columns/created_by_user_agent.py +0 -92
  77. clearskies/columns/date.py +0 -234
  78. clearskies/columns/datetime.py +0 -282
  79. clearskies/columns/email.py +0 -76
  80. clearskies/columns/float.py +0 -153
  81. clearskies/columns/has_many.py +0 -505
  82. clearskies/columns/has_many_self.py +0 -56
  83. clearskies/columns/has_one.py +0 -14
  84. clearskies/columns/integer.py +0 -160
  85. clearskies/columns/json.py +0 -126
  86. clearskies/columns/many_to_many_ids.py +0 -337
  87. clearskies/columns/many_to_many_ids_with_data.py +0 -274
  88. clearskies/columns/many_to_many_models.py +0 -158
  89. clearskies/columns/many_to_many_pivots.py +0 -134
  90. clearskies/columns/phone.py +0 -159
  91. clearskies/columns/select.py +0 -92
  92. clearskies/columns/string.py +0 -102
  93. clearskies/columns/timestamp.py +0 -164
  94. clearskies/columns/updated.py +0 -110
  95. clearskies/columns/uuid.py +0 -86
  96. clearskies/configs/README.md +0 -105
  97. clearskies/configs/__init__.py +0 -162
  98. clearskies/configs/actions.py +0 -43
  99. clearskies/configs/any.py +0 -13
  100. clearskies/configs/any_dict.py +0 -22
  101. clearskies/configs/any_dict_or_callable.py +0 -23
  102. clearskies/configs/authentication.py +0 -23
  103. clearskies/configs/authorization.py +0 -23
  104. clearskies/configs/boolean.py +0 -16
  105. clearskies/configs/boolean_or_callable.py +0 -18
  106. clearskies/configs/callable_config.py +0 -18
  107. clearskies/configs/columns.py +0 -34
  108. clearskies/configs/conditions.py +0 -30
  109. clearskies/configs/config.py +0 -24
  110. clearskies/configs/datetime.py +0 -18
  111. clearskies/configs/datetime_or_callable.py +0 -19
  112. clearskies/configs/endpoint.py +0 -23
  113. clearskies/configs/endpoint_list.py +0 -28
  114. clearskies/configs/float.py +0 -16
  115. clearskies/configs/float_or_callable.py +0 -18
  116. clearskies/configs/integer.py +0 -16
  117. clearskies/configs/integer_or_callable.py +0 -18
  118. clearskies/configs/joins.py +0 -30
  119. clearskies/configs/list_any_dict.py +0 -30
  120. clearskies/configs/list_any_dict_or_callable.py +0 -31
  121. clearskies/configs/model_class.py +0 -35
  122. clearskies/configs/model_column.py +0 -65
  123. clearskies/configs/model_columns.py +0 -56
  124. clearskies/configs/model_destination_name.py +0 -25
  125. clearskies/configs/model_to_id_column.py +0 -43
  126. clearskies/configs/readable_model_column.py +0 -9
  127. clearskies/configs/readable_model_columns.py +0 -9
  128. clearskies/configs/schema.py +0 -23
  129. clearskies/configs/searchable_model_columns.py +0 -9
  130. clearskies/configs/security_headers.py +0 -39
  131. clearskies/configs/select.py +0 -26
  132. clearskies/configs/select_list.py +0 -47
  133. clearskies/configs/string.py +0 -29
  134. clearskies/configs/string_dict.py +0 -32
  135. clearskies/configs/string_list.py +0 -32
  136. clearskies/configs/string_list_or_callable.py +0 -35
  137. clearskies/configs/string_or_callable.py +0 -18
  138. clearskies/configs/timedelta.py +0 -18
  139. clearskies/configs/timezone.py +0 -18
  140. clearskies/configs/url.py +0 -23
  141. clearskies/configs/validators.py +0 -45
  142. clearskies/configs/writeable_model_column.py +0 -9
  143. clearskies/configs/writeable_model_columns.py +0 -9
  144. clearskies/configurable.py +0 -76
  145. clearskies/contexts/__init__.py +0 -11
  146. clearskies/contexts/cli.py +0 -117
  147. clearskies/contexts/context.py +0 -98
  148. clearskies/contexts/wsgi.py +0 -76
  149. clearskies/contexts/wsgi_ref.py +0 -82
  150. clearskies/decorators.py +0 -33
  151. clearskies/di/__init__.py +0 -14
  152. clearskies/di/additional_config.py +0 -130
  153. clearskies/di/additional_config_auto_import.py +0 -17
  154. clearskies/di/di.py +0 -973
  155. clearskies/di/inject/__init__.py +0 -23
  156. clearskies/di/inject/by_class.py +0 -21
  157. clearskies/di/inject/by_name.py +0 -18
  158. clearskies/di/inject/di.py +0 -13
  159. clearskies/di/inject/environment.py +0 -14
  160. clearskies/di/inject/input_output.py +0 -20
  161. clearskies/di/inject/now.py +0 -13
  162. clearskies/di/inject/requests.py +0 -13
  163. clearskies/di/inject/secrets.py +0 -14
  164. clearskies/di/inject/utcnow.py +0 -13
  165. clearskies/di/inject/uuid.py +0 -15
  166. clearskies/di/injectable.py +0 -29
  167. clearskies/di/injectable_properties.py +0 -131
  168. clearskies/di/test_module/__init__.py +0 -6
  169. clearskies/di/test_module/another_module/__init__.py +0 -2
  170. clearskies/di/test_module/module_class.py +0 -5
  171. clearskies/end.py +0 -183
  172. clearskies/endpoint.py +0 -1314
  173. clearskies/endpoint_group.py +0 -338
  174. clearskies/endpoints/__init__.py +0 -25
  175. clearskies/endpoints/advanced_search.py +0 -526
  176. clearskies/endpoints/callable.py +0 -388
  177. clearskies/endpoints/create.py +0 -205
  178. clearskies/endpoints/delete.py +0 -139
  179. clearskies/endpoints/get.py +0 -271
  180. clearskies/endpoints/health_check.py +0 -183
  181. clearskies/endpoints/list.py +0 -574
  182. clearskies/endpoints/restful_api.py +0 -427
  183. clearskies/endpoints/schema.py +0 -189
  184. clearskies/endpoints/simple_search.py +0 -286
  185. clearskies/endpoints/update.py +0 -193
  186. clearskies/environment.py +0 -104
  187. clearskies/exceptions/__init__.py +0 -19
  188. clearskies/exceptions/authentication.py +0 -2
  189. clearskies/exceptions/authorization.py +0 -2
  190. clearskies/exceptions/client_error.py +0 -2
  191. clearskies/exceptions/input_errors.py +0 -4
  192. clearskies/exceptions/missing_dependency.py +0 -2
  193. clearskies/exceptions/moved_permanently.py +0 -3
  194. clearskies/exceptions/moved_temporarily.py +0 -3
  195. clearskies/exceptions/not_found.py +0 -2
  196. clearskies/functional/__init__.py +0 -7
  197. clearskies/functional/routing.py +0 -92
  198. clearskies/functional/string.py +0 -112
  199. clearskies/functional/validations.py +0 -76
  200. clearskies/input_outputs/__init__.py +0 -13
  201. clearskies/input_outputs/cli.py +0 -171
  202. clearskies/input_outputs/exceptions/__init__.py +0 -2
  203. clearskies/input_outputs/exceptions/cli_input_error.py +0 -2
  204. clearskies/input_outputs/exceptions/cli_not_found.py +0 -2
  205. clearskies/input_outputs/headers.py +0 -45
  206. clearskies/input_outputs/input_output.py +0 -138
  207. clearskies/input_outputs/programmatic.py +0 -69
  208. clearskies/input_outputs/py.typed +0 -0
  209. clearskies/input_outputs/wsgi.py +0 -77
  210. clearskies/model.py +0 -1922
  211. clearskies/py.typed +0 -0
  212. clearskies/query/__init__.py +0 -12
  213. clearskies/query/condition.py +0 -223
  214. clearskies/query/join.py +0 -136
  215. clearskies/query/query.py +0 -196
  216. clearskies/query/sort.py +0 -27
  217. clearskies/schema.py +0 -82
  218. clearskies/secrets/__init__.py +0 -6
  219. clearskies/secrets/additional_configs/__init__.py +0 -32
  220. clearskies/secrets/additional_configs/mysql_connection_dynamic_producer.py +0 -61
  221. clearskies/secrets/additional_configs/mysql_connection_dynamic_producer_via_ssh_cert_bastion.py +0 -160
  222. clearskies/secrets/akeyless.py +0 -182
  223. clearskies/secrets/exceptions/__init__.py +0 -1
  224. clearskies/secrets/exceptions/not_found.py +0 -2
  225. clearskies/secrets/secrets.py +0 -38
  226. clearskies/security_header.py +0 -15
  227. clearskies/security_headers/__init__.py +0 -11
  228. clearskies/security_headers/cache_control.py +0 -67
  229. clearskies/security_headers/cors.py +0 -50
  230. clearskies/security_headers/csp.py +0 -94
  231. clearskies/security_headers/hsts.py +0 -22
  232. clearskies/security_headers/x_content_type_options.py +0 -0
  233. clearskies/security_headers/x_frame_options.py +0 -0
  234. clearskies/test_base.py +0 -8
  235. clearskies/typing.py +0 -11
  236. clearskies/validator.py +0 -37
  237. clearskies/validators/__init__.py +0 -33
  238. clearskies/validators/after_column.py +0 -62
  239. clearskies/validators/before_column.py +0 -13
  240. clearskies/validators/in_the_future.py +0 -32
  241. clearskies/validators/in_the_future_at_least.py +0 -11
  242. clearskies/validators/in_the_future_at_most.py +0 -10
  243. clearskies/validators/in_the_past.py +0 -32
  244. clearskies/validators/in_the_past_at_least.py +0 -10
  245. clearskies/validators/in_the_past_at_most.py +0 -10
  246. clearskies/validators/maximum_length.py +0 -26
  247. clearskies/validators/maximum_value.py +0 -29
  248. clearskies/validators/minimum_length.py +0 -26
  249. clearskies/validators/minimum_value.py +0 -29
  250. clearskies/validators/required.py +0 -34
  251. clearskies/validators/timedelta.py +0 -59
  252. clearskies/validators/unique.py +0 -30
  253. {clear_skies-2.0.4.dist-info → clear_skies-2.0.5.dist-info/licenses}/LICENSE +0 -0
@@ -1,19 +0,0 @@
1
- import datetime
2
- from typing import Callable
3
-
4
- from clearskies.configs import config
5
-
6
-
7
- class DatetimeOrCallable(config.Config):
8
- def __set__(self, instance, value: datetime.datetime | Callable[..., datetime.datetime]):
9
- if not isinstance(value, datetime.datetime) and not callable(value):
10
- error_prefix = self._error_prefix(instance)
11
- raise TypeError(
12
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to a parameter that requries a datetime object or a callable."
13
- )
14
- instance._set_config(self, value)
15
-
16
- def __get__(self, instance, parent) -> datetime.datetime | Callable[..., datetime.datetime]:
17
- if not instance:
18
- return self # type: ignore
19
- return instance._get_config(self)
@@ -1,23 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING
4
-
5
- from clearskies.configs import config
6
-
7
- if TYPE_CHECKING:
8
- from clearskies.endpoint import Endpoint as EndpointBase
9
-
10
-
11
- class Endpoint(config.Config):
12
- def __set__(self, instance, value: EndpointBase):
13
- if not hasattr(value, "success"):
14
- error_prefix = self._error_prefix(instance)
15
- raise TypeError(
16
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to a parameter that requries an endpoint."
17
- )
18
- instance._set_config(self, value)
19
-
20
- def __get__(self, instance, parent) -> EndpointBase:
21
- if not instance:
22
- return self # type: ignore
23
- return instance._get_config(self)
@@ -1,28 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING
4
-
5
- from clearskies.configs import config
6
-
7
- if TYPE_CHECKING:
8
- from clearskies.endpoint import Endpoint as EndpointBase
9
-
10
-
11
- class EndpointList(config.Config):
12
- def __set__(self, instance, value: list[EndpointBase]):
13
- if not isinstance(value, list):
14
- raise TypeError(
15
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to a parameter that requries a list of endpoints."
16
- )
17
- for index, item in enumerate(value):
18
- if not hasattr(item, "top_level_authentication_and_authorization"):
19
- error_prefix = self._error_prefix(instance)
20
- raise TypeError(
21
- f"{error_prefix} attempt to set a value of type '{item.__class__.__name__}' for item #{index+1} when all items in the list should be instances of clearskies.End."
22
- )
23
- instance._set_config(self, value)
24
-
25
- def __get__(self, instance, parent) -> list[EndpointBase]:
26
- if not instance:
27
- return self # type: ignore
28
- return instance._get_config(self)
@@ -1,16 +0,0 @@
1
- from clearskies.configs import config
2
-
3
-
4
- class Float(config.Config):
5
- def __set__(self, instance, value: float):
6
- if not isinstance(value, float):
7
- error_prefix = self._error_prefix(instance)
8
- raise TypeError(
9
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to parameter that requires a float."
10
- )
11
- instance._set_config(self, value)
12
-
13
- def __get__(self, instance, parent) -> float:
14
- if not instance:
15
- return self # type: ignore
16
- return instance._get_config(self)
@@ -1,18 +0,0 @@
1
- from typing import Callable
2
-
3
- from clearskies.configs import config
4
-
5
-
6
- class FloatOrCallable(config.Config):
7
- def __set__(self, instance, value: float | Callable[..., float]):
8
- if not isinstance(value, float) and not callable(value):
9
- error_prefix = self._error_prefix(instance)
10
- raise TypeError(
11
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to parameter that requires a float or a callable."
12
- )
13
- instance._set_config(self, value)
14
-
15
- def __get__(self, instance, parent) -> float | Callable[..., float]:
16
- if not instance:
17
- return self # type: ignore
18
- return instance._get_config(self)
@@ -1,16 +0,0 @@
1
- from clearskies.configs import config
2
-
3
-
4
- class Integer(config.Config):
5
- def __set__(self, instance, value: int):
6
- if not isinstance(value, int):
7
- error_prefix = self._error_prefix(instance)
8
- raise TypeError(
9
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to parameter that requires an integer."
10
- )
11
- instance._set_config(self, value)
12
-
13
- def __get__(self, instance, parent) -> int:
14
- if not instance:
15
- return self # type: ignore
16
- return instance._get_config(self)
@@ -1,18 +0,0 @@
1
- from typing import Callable
2
-
3
- from clearskies.configs import config
4
-
5
-
6
- class IntegerOrCallable(config.Config):
7
- def __set__(self, instance, value: int | Callable[..., int]):
8
- if not isinstance(value, int) and not callable(value):
9
- error_prefix = self._error_prefix(instance)
10
- raise TypeError(
11
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to parameter that requires an integer or a callable."
12
- )
13
- instance._set_config(self, value)
14
-
15
- def __get__(self, instance, parent) -> int | Callable[..., int]:
16
- if not instance:
17
- return self # type: ignore
18
- return instance._get_config(self)
@@ -1,30 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING
4
-
5
- from clearskies.configs import config
6
-
7
- if TYPE_CHECKING:
8
- from clearskies import typing
9
-
10
-
11
- class Joins(config.Config):
12
- def __set__(self, instance, value: typing.join | list[typing.join]):
13
- if not isinstance(value, list):
14
- value = [value]
15
-
16
- for index, item in enumerate(value):
17
- if callable(item) or isinstance(item, str):
18
- continue
19
-
20
- error_prefix = self._error_prefix(instance)
21
- raise TypeError(
22
- f"{error_prefix} attempt to set a value of type '{item.__class__.__name__}' for item #{index + 1} when a string or callable is required" # type: ignore
23
- )
24
-
25
- instance._set_config(self, [*value])
26
-
27
- def __get__(self, instance, parent) -> list[typing.join]:
28
- if not instance:
29
- return self # type: ignore
30
- return instance._get_config(self)
@@ -1,30 +0,0 @@
1
- from typing import Any
2
-
3
- from clearskies.configs import config
4
-
5
-
6
- class ListAnyDict(config.Config):
7
- def __set__(self, instance, value: list[dict[str, Any]]):
8
- if not isinstance(value, list):
9
- error_prefix = self._error_prefix(instance)
10
- raise TypeError(
11
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to a parameter that requries a list."
12
- )
13
- for index, list_item in enumerate(value):
14
- if not isinstance(list_item, dict):
15
- error_prefix = self._error_prefix(instance)
16
- raise TypeError(
17
- f"{error_prefix} I was expecting a list of dictionaries, but item # {index + 1} has type '{list_item.__class__.__name__}."
18
- )
19
- for key, val in list_item.items():
20
- if not isinstance(key, str):
21
- error_prefix = self._error_prefix(instance)
22
- raise TypeError(
23
- f"{error_prefix} attempt to set a dictionary with a non-string key for item #{index + 1}."
24
- )
25
- instance._set_config(self, value)
26
-
27
- def __get__(self, instance, parent) -> list[dict[str, Any]]:
28
- if not instance:
29
- return self # type: ignore
30
- return instance._get_config(self)
@@ -1,31 +0,0 @@
1
- from typing import Any, Callable
2
-
3
- from clearskies.configs import config
4
-
5
-
6
- class ListAnyDictOrCallable(config.Config):
7
- def __set__(self, instance, value: list[dict[str, Any]] | Callable[..., list[dict[str, Any]]]):
8
- if not isinstance(value, list) and not callable(value):
9
- error_prefix = self._error_prefix(instance)
10
- raise TypeError(
11
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to a parameter that requries a list or a callable."
12
- )
13
- if isinstance(value, list):
14
- for index, list_item in enumerate(value):
15
- if not isinstance(list_item, dict):
16
- error_prefix = self._error_prefix(instance)
17
- raise TypeError(
18
- f"{error_prefix} I was expecting a list of dictionaries, but item # {index + 1} has type '{list_item.__class__.__name__}."
19
- )
20
- for key, val in list_item.items():
21
- if not isinstance(key, str):
22
- error_prefix = self._error_prefix(instance)
23
- raise TypeError(
24
- f"{error_prefix} attempt to set a dictionary with a non-string key for item #{index + 1}."
25
- )
26
- instance._set_config(self, value)
27
-
28
- def __get__(self, instance, parent) -> list[dict[str, Any]] | Callable[..., list[dict[str, Any]]]:
29
- if not instance:
30
- return self # type: ignore
31
- return instance._get_config(self)
@@ -1,35 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import inspect
4
- from typing import TYPE_CHECKING
5
-
6
- from clearskies.configs import config
7
- from clearskies.functional import validations
8
-
9
- if TYPE_CHECKING:
10
- from clearskies.model import Model, ModelClassReference
11
-
12
-
13
- class ModelClass(config.Config):
14
- """A config that accepts a model class."""
15
-
16
- def __set__(self, instance, value: type[Model | ModelClassReference]):
17
- try:
18
- validations.is_model_class_or_reference(value, raise_error_message=True, strict=False)
19
- except TypeError as e:
20
- error_prefix = self._error_prefix(instance)
21
- raise TypeError(f"{error_prefix} {str(e)}")
22
-
23
- # reference or model class?
24
- instance._set_config(self, value) # type: ignore
25
-
26
- def __get__(self, instance, parent) -> type[Model]:
27
- if not instance:
28
- return self # type: ignore
29
-
30
- value = instance._get_config(self)
31
- if validations.is_model_class_reference(value):
32
- class_reference = value() if inspect.isclass(value) else value
33
- instance._set_config(self, class_reference.get_model_class())
34
-
35
- return instance._get_config(self)
@@ -1,65 +0,0 @@
1
- from clearskies.configs import select
2
-
3
-
4
- class ModelColumn(select.Select):
5
- def __init__(self, model_column_config_name="", required=False, default=None):
6
- self.required = required
7
- self.default = default
8
- self.model_column_config_name = model_column_config_name
9
- self.model_class = None
10
-
11
- def __set__(self, instance, value: str):
12
- if value is None:
13
- return
14
-
15
- if not isinstance(value, str):
16
- error_prefix = self._error_prefix(instance)
17
- raise TypeError(
18
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to a string parameter"
19
- )
20
-
21
- instance._set_config(self, value)
22
- # unlike select, we won't validate the value currently because we won't be able to
23
- # do that until the finalize_and_validate_configuration phase
24
-
25
- def get_allowed_columns(self, model_class, column_configs):
26
- return [name for name in column_configs.keys()]
27
-
28
- def my_description(self):
29
- return "column"
30
-
31
- def get_model_class(self, instance):
32
- model_class = self.model_class
33
- if not model_class and self.model_column_config_name:
34
- model_class = getattr(instance, self.model_column_config_name)
35
- return model_class
36
-
37
- def set_model_class(self, model_class):
38
- self.model_class = model_class
39
-
40
- def finalize_and_validate_configuration(self, instance):
41
- super().finalize_and_validate_configuration(instance)
42
-
43
- # to check for a valid column we need to know the name of the model class.
44
- # This can be either provided to us directly or we may be given the name of a configuration
45
- # from which we fetch the model class
46
- model_class = self.get_model_class(instance)
47
-
48
- # if we don't have one though, no worries - some classes have to provide it later and
49
- # can trigger validation then.
50
- if not model_class:
51
- return
52
-
53
- allowed_columns = self.get_allowed_columns(model_class, model_class.get_columns())
54
-
55
- value = instance._get_config(self)
56
- if not value:
57
- return
58
- if value not in allowed_columns:
59
- error_prefix = self._error_prefix(instance)
60
- my_description = self.my_description()
61
- raise ValueError(
62
- f"{error_prefix} attempt to set a value of '{value}' but this is not a {my_description} in the specified model class, '{model_class.__name__}'. Expected values are: '"
63
- + "', '".join(allowed_columns)
64
- + "'"
65
- )
@@ -1,56 +0,0 @@
1
- from clearskies.configs import select_list
2
-
3
-
4
- class ModelColumns(select_list.SelectList):
5
- def __init__(self, model_column_config_name="", allow_relationship_references=False, required=False, default=None):
6
- self.required = required
7
- self.default = default
8
- self.model_column_config_name = model_column_config_name
9
- self.allow_relationship_references = allow_relationship_references
10
-
11
- def __set__(self, instance, value: list[str]):
12
- if value is None:
13
- return
14
-
15
- if not isinstance(value, list):
16
- error_prefix = self._error_prefix(instance)
17
- raise TypeError(
18
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to a list parameter"
19
- )
20
-
21
- instance._set_config(self, value)
22
- # unlike select_list, we won't validate the value currently because we won't be able to
23
- # do that until the finalize_and_validate_configuration phase
24
-
25
- def get_allowed_columns(self, model_class, column_configs):
26
- return [name for name in column_configs.keys()]
27
-
28
- def my_description(self):
29
- return "column"
30
-
31
- def finalize_and_validate_configuration(self, instance):
32
- super().finalize_and_validate_configuration(instance)
33
-
34
- # when we were created we were told the name of the config that stores
35
- # the model class we're getting readable columns from. Let's use that
36
- # and fetch the model class. Note that this is an optional feature though
37
- if not self.model_column_config_name:
38
- return
39
-
40
- model_class = getattr(instance, self.model_column_config_name)
41
- values = instance._get_config(self)
42
- if not values or not model_class:
43
- return
44
-
45
- allowed_columns = self.get_allowed_columns(model_class, model_class.get_columns())
46
- for value in values:
47
- if self.allow_relationship_references and "." in value:
48
- value = value.split(".")[0]
49
- if value not in allowed_columns:
50
- error_prefix = self._error_prefix(instance)
51
- my_description = self.my_description()
52
- raise ValueError(
53
- f"{error_prefix} attempt to set a value of '{value}' but this is not a {my_description} in the specified model class, '{model_class.__name__}. Expected values are: '"
54
- + "', '".join(allowed_columns)
55
- + "'"
56
- )
@@ -1,25 +0,0 @@
1
- from clearskies.configs.string import String
2
- from clearskies.functional import string
3
-
4
-
5
- class ModelDestinationName(String):
6
- def __init__(self, model_column_config_name, required=False, default=None):
7
- self.required = required
8
- self.default = default
9
- self.model_column_config_name = model_column_config_name
10
-
11
- def get_model_class(self, instance):
12
- if self.model_column_config_name:
13
- return getattr(instance, self.model_column_config_name)
14
- return None
15
-
16
- def finalize_and_validate_configuration(self, instance):
17
- # we use the model class itself to decide on our value. However,
18
- # if we don't have it yet, don't worry. Someone will eventually tell us
19
- # what we need to know
20
- model_class = self.get_model_class(instance)
21
- if not model_class:
22
- return
23
-
24
- instance._set_config(self, model_class.destination_name())
25
- super().finalize_and_validate_configuration(instance)
@@ -1,43 +0,0 @@
1
- from clearskies.configs import model_column
2
- from clearskies.functional import string
3
-
4
-
5
- class ModelToIdColumn(model_column.ModelColumn):
6
- def __init__(
7
- self,
8
- model_column_config_name="",
9
- source_model_class=None,
10
- source_model_class_config_name="",
11
- required=False,
12
- default=None,
13
- ):
14
- self.required = required
15
- self.default = default
16
- self.model_column_config_name = model_column_config_name
17
- self.source_model_class_config_name = source_model_class_config_name
18
- self.model_class = None
19
- self.source_model_class = source_model_class
20
-
21
- def finalize_and_validate_configuration(self, instance):
22
- # we use the model class itself to decide on our value. However,
23
- # if we don't have it yet, don't worry. Someone will eventually tell us
24
- # what we need to know
25
- model_class = self.get_model_class(instance)
26
- if not model_class:
27
- return
28
- if self.source_model_class:
29
- model_class = self.source_model_class
30
- elif self.source_model_class_config_name:
31
- model_class = getattr(instance, self.source_model_class_config_name)
32
-
33
- has_config = False
34
- try:
35
- if instance._get_config(self):
36
- has_config = True
37
- except KeyError:
38
- pass
39
-
40
- if not has_config:
41
- instance._set_config(self, string.camel_case_to_snake_case(model_class.__name__) + "_id")
42
-
43
- super().finalize_and_validate_configuration(instance)
@@ -1,9 +0,0 @@
1
- from clearskies.configs import model_column
2
-
3
-
4
- class ReadableModelColumn(model_column.ModelColumn):
5
- def get_allowed_columns(self, model_class, column_configs):
6
- return [name for (name, column) in column_configs.items() if column.is_readable]
7
-
8
- def my_description(self):
9
- return "readable column"
@@ -1,9 +0,0 @@
1
- from clearskies.configs import model_columns
2
-
3
-
4
- class ReadableModelColumns(model_columns.ModelColumns):
5
- def get_allowed_columns(self, model_class, column_configs):
6
- return [name for (name, column) in column_configs.items() if column.is_readable]
7
-
8
- def my_description(self):
9
- return "readable column"
@@ -1,23 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING
4
-
5
- from clearskies.configs import config
6
-
7
- if TYPE_CHECKING:
8
- from clearskies.schema import Schema as SchemaType
9
-
10
-
11
- class Schema(config.Config):
12
- def __set__(self, instance, value: type[SchemaType]) -> None:
13
- if not hasattr(value, "get_columns"):
14
- error_prefix = self._error_prefix(instance)
15
- raise TypeError(
16
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to parameter that requires a Schema."
17
- )
18
- instance._set_config(self, value)
19
-
20
- def __get__(self, instance, parent) -> type[SchemaType]:
21
- if not instance:
22
- return self # type: ignore
23
- return instance._get_config(self)
@@ -1,9 +0,0 @@
1
- from clearskies.configs import model_columns
2
-
3
-
4
- class SearchableModelColumns(model_columns.ModelColumns):
5
- def get_allowed_columns(self, model_class, column_configs):
6
- return [name for (name, column) in column_configs.items() if column.is_searchable]
7
-
8
- def my_description(self):
9
- return "searchable column"
@@ -1,39 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING
4
-
5
- from clearskies.configs import config
6
-
7
- if TYPE_CHECKING:
8
- from clearskies import SecurityHeader
9
-
10
-
11
- class SecurityHeaders(config.Config):
12
- """
13
- This is for a configuration that should be a list of strings.
14
-
15
- This is different than SelectList, which also accepts a list of strings, but
16
- valdiates that all of those values match against an allow list.
17
- """
18
-
19
- def __set__(self, instance, value: list[SecurityHeader]):
20
- if value is None:
21
- return
22
-
23
- if not isinstance(value, list):
24
- error_prefix = self._error_prefix(instance)
25
- raise TypeError(
26
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to a list parameter"
27
- )
28
- for index, item in enumerate(value):
29
- if not hasattr(item, "set_headers_for_input_output"):
30
- error_prefix = self._error_prefix(instance)
31
- raise TypeError(
32
- f"{error_prefix} attempt to set a value of type '{item.__class__.__name__}' for item #{index + 1}. A clearskies.SecurityHeader was expected."
33
- )
34
- instance._set_config(self, value)
35
-
36
- def __get__(self, instance, parent) -> list[SecurityHeader]:
37
- if not instance:
38
- return self # type: ignore
39
- return instance._get_config(self)
@@ -1,26 +0,0 @@
1
- from clearskies.configs import string
2
-
3
-
4
- class Select(string.String):
5
- def __init__(self, allowed_values: list[str], required=False, default=None):
6
- self.allowed_values = allowed_values
7
- self.required = required
8
- self.default = default
9
-
10
- def __set__(self, instance, value: str):
11
- if value is None:
12
- return
13
-
14
- if not isinstance(value, str):
15
- error_prefix = self._error_prefix(instance)
16
- raise TypeError(
17
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to a string parameter"
18
- )
19
- if value not in self.allowed_values:
20
- error_prefix = self._error_prefix(instance)
21
- raise ValueError(
22
- f"{error_prefix} attempt to set a value of type '{value}' which is not in the list of allowed values. It must be one of '" # type: ignore
23
- + "', '".join(self.allowed_values)
24
- + "'"
25
- )
26
- instance._set_config(self, value)
@@ -1,47 +0,0 @@
1
- from clearskies.configs import config
2
-
3
-
4
- class SelectList(config.Config):
5
- """
6
- This is for a configuration that should be a list of strings matching some list of allowed values.
7
-
8
- The allowed values are set when you create the config, and when values are set for the config
9
- they must match.
10
-
11
- This is different than StringList, which also accepts a list of any strings.
12
- """
13
-
14
- def __init__(self, allowed_values: list[str], required=False, default=None):
15
- self.allowed_values = allowed_values
16
- self.required = required
17
- self.default = default
18
-
19
- def __set__(self, instance, value: list[str]):
20
- if value is None:
21
- return
22
-
23
- if not isinstance(value, list):
24
- error_prefix = self._error_prefix(instance)
25
- raise TypeError(
26
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to a list parameter"
27
- )
28
- for index, item in enumerate(value):
29
- if not isinstance(item, str):
30
- error_prefix = self._error_prefix(instance)
31
- raise TypeError(
32
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' for item #{index + 1}. A string was expected."
33
- )
34
-
35
- if item not in self.allowed_values:
36
- error_prefix = self._error_prefix(instance)
37
- raise ValueError(
38
- f"{error_prefix} attempt to set a value of '{item}' for item #{index + 1}. This is not in the list of allowed values. It must be one of '"
39
- + "', '".join(self.allowed_values)
40
- + "'"
41
- )
42
- instance._set_config(self, [*value])
43
-
44
- def __get__(self, instance, parent) -> list[str]:
45
- if not instance:
46
- return self # type: ignore
47
- return instance._get_config(self)