clear-skies 2.0.7__py3-none-any.whl → 2.0.9__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 (153) hide show
  1. {clear_skies-2.0.7.dist-info → clear_skies-2.0.9.dist-info}/METADATA +1 -1
  2. clear_skies-2.0.9.dist-info/RECORD +256 -0
  3. clearskies/__init__.py +2 -2
  4. clearskies/authentication/authentication.py +1 -3
  5. clearskies/authentication/authorization.py +12 -5
  6. clearskies/authentication/authorization_pass_through.py +5 -3
  7. clearskies/authentication/jwks.py +25 -23
  8. clearskies/authentication/secret_bearer.py +15 -17
  9. clearskies/autodoc/schema/schema.py +1 -1
  10. clearskies/backends/api_backend.py +50 -56
  11. clearskies/backends/backend.py +14 -14
  12. clearskies/backends/cursor_backend.py +17 -23
  13. clearskies/backends/memory_backend.py +27 -30
  14. clearskies/backends/secrets_backend.py +13 -18
  15. clearskies/column.py +44 -56
  16. clearskies/columns/audit.py +14 -13
  17. clearskies/columns/belongs_to_id.py +10 -15
  18. clearskies/columns/belongs_to_model.py +6 -9
  19. clearskies/columns/belongs_to_self.py +13 -9
  20. clearskies/columns/boolean.py +13 -16
  21. clearskies/columns/category_tree.py +9 -11
  22. clearskies/columns/category_tree_children.py +2 -3
  23. clearskies/columns/category_tree_descendants.py +1 -1
  24. clearskies/columns/created.py +8 -11
  25. clearskies/columns/created_by_authorization_data.py +7 -9
  26. clearskies/columns/created_by_header.py +12 -8
  27. clearskies/columns/created_by_ip.py +6 -8
  28. clearskies/columns/created_by_routing_data.py +12 -7
  29. clearskies/columns/created_by_user_agent.py +6 -9
  30. clearskies/columns/date.py +12 -14
  31. clearskies/columns/datetime.py +19 -17
  32. clearskies/columns/email.py +3 -1
  33. clearskies/columns/float.py +10 -14
  34. clearskies/columns/has_many.py +8 -10
  35. clearskies/columns/has_many_self.py +13 -7
  36. clearskies/columns/has_one.py +2 -0
  37. clearskies/columns/integer.py +9 -11
  38. clearskies/columns/json.py +10 -12
  39. clearskies/columns/many_to_many_ids.py +14 -16
  40. clearskies/columns/many_to_many_ids_with_data.py +16 -16
  41. clearskies/columns/many_to_many_models.py +5 -7
  42. clearskies/columns/many_to_many_pivots.py +3 -5
  43. clearskies/columns/phone.py +12 -9
  44. clearskies/columns/select.py +12 -9
  45. clearskies/columns/string.py +1 -1
  46. clearskies/columns/timestamp.py +15 -15
  47. clearskies/columns/updated.py +8 -10
  48. clearskies/columns/uuid.py +7 -10
  49. clearskies/configs/__init__.py +8 -0
  50. clearskies/configs/any.py +2 -0
  51. clearskies/configs/any_dict.py +2 -0
  52. clearskies/configs/any_dict_or_callable.py +2 -0
  53. clearskies/configs/boolean.py +2 -0
  54. clearskies/configs/boolean_or_callable.py +2 -0
  55. clearskies/configs/callable_config.py +2 -0
  56. clearskies/configs/config.py +2 -0
  57. clearskies/configs/datetime.py +2 -0
  58. clearskies/configs/datetime_or_callable.py +2 -0
  59. clearskies/configs/email.py +10 -0
  60. clearskies/configs/email_list.py +17 -0
  61. clearskies/configs/email_list_or_callable.py +19 -0
  62. clearskies/configs/email_or_email_list_or_callable.py +59 -0
  63. clearskies/configs/float.py +2 -0
  64. clearskies/configs/float_or_callable.py +2 -0
  65. clearskies/configs/integer.py +2 -0
  66. clearskies/configs/integer_or_callable.py +2 -0
  67. clearskies/configs/list_any_dict.py +2 -0
  68. clearskies/configs/list_any_dict_or_callable.py +2 -0
  69. clearskies/configs/model_column.py +2 -0
  70. clearskies/configs/model_columns.py +2 -0
  71. clearskies/configs/model_destination_name.py +2 -1
  72. clearskies/configs/model_to_id_column.py +2 -0
  73. clearskies/configs/readable_model_column.py +2 -0
  74. clearskies/configs/readable_model_columns.py +2 -0
  75. clearskies/configs/searchable_model_columns.py +2 -0
  76. clearskies/configs/select.py +2 -0
  77. clearskies/configs/select_list.py +2 -0
  78. clearskies/configs/string.py +4 -2
  79. clearskies/configs/string_dict.py +2 -0
  80. clearskies/configs/string_list.py +17 -2
  81. clearskies/configs/string_list_or_callable.py +13 -0
  82. clearskies/configs/timedelta.py +2 -0
  83. clearskies/configs/timezone.py +2 -0
  84. clearskies/configs/url.py +2 -0
  85. clearskies/configs/writeable_model_column.py +2 -0
  86. clearskies/configs/writeable_model_columns.py +2 -0
  87. clearskies/configurable.py +2 -0
  88. clearskies/contexts/cli.py +9 -1
  89. clearskies/contexts/context.py +13 -14
  90. clearskies/contexts/wsgi.py +12 -10
  91. clearskies/contexts/wsgi_ref.py +12 -6
  92. clearskies/decorators.py +1 -1
  93. clearskies/decorators.pyi +10 -0
  94. clearskies/di/di.py +7 -6
  95. clearskies/di/inject/by_class.py +2 -0
  96. clearskies/di/inject/by_name.py +2 -0
  97. clearskies/di/inject/di.py +2 -0
  98. clearskies/di/inject/environment.py +1 -1
  99. clearskies/di/inject/now.py +2 -0
  100. clearskies/di/inject/requests.py +2 -0
  101. clearskies/di/inject/secrets.py +2 -2
  102. clearskies/di/inject/utcnow.py +2 -0
  103. clearskies/di/inject/uuid.py +2 -2
  104. clearskies/end.py +45 -7
  105. clearskies/endpoint.py +43 -59
  106. clearskies/endpoint_group.py +15 -18
  107. clearskies/endpoints/advanced_search.py +19 -26
  108. clearskies/endpoints/callable.py +10 -16
  109. clearskies/endpoints/create.py +6 -10
  110. clearskies/endpoints/delete.py +5 -11
  111. clearskies/endpoints/get.py +11 -15
  112. clearskies/endpoints/health_check.py +9 -11
  113. clearskies/endpoints/list.py +29 -36
  114. clearskies/endpoints/restful_api.py +43 -53
  115. clearskies/endpoints/schema.py +14 -18
  116. clearskies/endpoints/simple_search.py +5 -12
  117. clearskies/endpoints/update.py +6 -11
  118. clearskies/environment.py +2 -0
  119. clearskies/input_outputs/cli.py +2 -0
  120. clearskies/input_outputs/headers.py +2 -0
  121. clearskies/input_outputs/input_output.py +15 -15
  122. clearskies/input_outputs/programmatic.py +2 -2
  123. clearskies/input_outputs/wsgi.py +2 -2
  124. clearskies/model.py +120 -25
  125. clearskies/query/query.py +1 -4
  126. clearskies/secrets/__init__.py +2 -1
  127. clearskies/secrets/akeyless.py +16 -11
  128. clearskies/secrets/secrets.py +7 -2
  129. clearskies/security_header.py +4 -2
  130. clearskies/security_headers/cache_control.py +15 -14
  131. clearskies/security_headers/cors.py +10 -9
  132. clearskies/security_headers/csp.py +25 -24
  133. clearskies/security_headers/hsts.py +6 -5
  134. clearskies/typing.py +1 -1
  135. clearskies/validator.py +5 -6
  136. clearskies/validators/after_column.py +6 -7
  137. clearskies/validators/before_column.py +2 -0
  138. clearskies/validators/in_the_future.py +5 -8
  139. clearskies/validators/in_the_future_at_least.py +2 -0
  140. clearskies/validators/in_the_future_at_most.py +2 -0
  141. clearskies/validators/in_the_past.py +5 -8
  142. clearskies/validators/in_the_past_at_least.py +2 -0
  143. clearskies/validators/in_the_past_at_most.py +2 -0
  144. clearskies/validators/maximum_length.py +4 -5
  145. clearskies/validators/maximum_value.py +4 -4
  146. clearskies/validators/minimum_length.py +4 -4
  147. clearskies/validators/minimum_value.py +4 -4
  148. clearskies/validators/required.py +2 -4
  149. clearskies/validators/timedelta.py +8 -9
  150. clearskies/validators/unique.py +2 -3
  151. clear_skies-2.0.7.dist-info/RECORD +0 -251
  152. {clear_skies-2.0.7.dist-info → clear_skies-2.0.9.dist-info}/WHEEL +0 -0
  153. {clear_skies-2.0.7.dist-info → clear_skies-2.0.9.dist-info}/licenses/LICENSE +0 -0
@@ -2,14 +2,11 @@ from __future__ import annotations
2
2
 
3
3
  from typing import TYPE_CHECKING, Any
4
4
 
5
- import clearskies.decorators
6
- import clearskies.di
7
- import clearskies.typing
8
- from clearskies import configs
5
+ from clearskies import configs, decorators, di
9
6
  from clearskies.columns.string import String
10
7
 
11
8
  if TYPE_CHECKING:
12
- from clearskies import Model
9
+ from clearskies import Model, typing
13
10
 
14
11
 
15
12
  class Uuid(String):
@@ -63,17 +60,17 @@ class Uuid(String):
63
60
  is_writeable = configs.Boolean(default=False)
64
61
  _descriptor_config_map = None
65
62
 
66
- uuid = clearskies.di.inject.Uuid()
63
+ uuid = di.inject.Uuid()
67
64
 
68
- @clearskies.decorators.parameters_to_properties
65
+ @decorators.parameters_to_properties
69
66
  def __init__(
70
67
  self,
71
68
  is_readable: bool = True,
72
69
  is_searchable: bool = True,
73
70
  is_temporary: bool = False,
74
- on_change_pre_save: clearskies.typing.action | list[clearskies.typing.action] = [],
75
- on_change_post_save: clearskies.typing.action | list[clearskies.typing.action] = [],
76
- on_change_save_finished: clearskies.typing.action | list[clearskies.typing.action] = [],
71
+ on_change_pre_save: typing.action | list[typing.action] = [],
72
+ on_change_post_save: typing.action | list[typing.action] = [],
73
+ on_change_save_finished: typing.action | list[typing.action] = [],
77
74
  ):
78
75
  pass
79
76
 
@@ -79,6 +79,10 @@ from .conditions import Conditions
79
79
  from .config import Config
80
80
  from .datetime import Datetime
81
81
  from .datetime_or_callable import DatetimeOrCallable
82
+ from .email import Email
83
+ from .email_list import EmailList
84
+ from .email_list_or_callable import EmailListOrCallable
85
+ from .email_or_email_list_or_callable import EmailOrEmailListOrCallable
82
86
  from .endpoint import Endpoint
83
87
  from .endpoint_list import EndpointList
84
88
  from .float import Float
@@ -127,6 +131,10 @@ __all__ = [
127
131
  "Config",
128
132
  "Datetime",
129
133
  "DatetimeOrCallable",
134
+ "Email",
135
+ "EmailList",
136
+ "EmailListOrCallable",
137
+ "EmailOrEmailListOrCallable",
130
138
  "Endpoint",
131
139
  "EndpointList",
132
140
  "Float",
clearskies/configs/any.py CHANGED
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from typing import Any as AnyType
2
4
 
3
5
  from clearskies.configs import config
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from typing import Any
2
4
 
3
5
  from clearskies.configs import config
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from typing import Any, Callable
2
4
 
3
5
  from clearskies.configs import config
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from clearskies.configs import config
2
4
 
3
5
 
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from typing import Callable
2
4
 
3
5
  from clearskies.configs import config
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from typing import Callable as CallableType
2
4
 
3
5
  from clearskies.configs import config
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from typing import Any
2
4
 
3
5
 
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import datetime
2
4
 
3
5
  from clearskies.configs import config
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import datetime
2
4
  from typing import Callable
3
5
 
@@ -0,0 +1,10 @@
1
+ from __future__ import annotations
2
+
3
+ from clearskies.configs import string
4
+
5
+
6
+ class Email(string.String):
7
+ def __init__(
8
+ self, required=False, default=None, regexp: str = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
9
+ ):
10
+ super().__init__(required=required, default=default, regexp=regexp)
@@ -0,0 +1,17 @@
1
+ from __future__ import annotations
2
+
3
+ from clearskies.configs import string_list
4
+
5
+
6
+ class EmailList(string_list.StringList):
7
+ """
8
+ This is for a configuration that should be a list of strings in email format.
9
+
10
+ This is different than StringList, which also accepts a list of strings, but
11
+ validates that all of those values match the required format.
12
+ """
13
+
14
+ def __init__(
15
+ self, required=False, default=None, regexp: str = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
16
+ ):
17
+ super().__init__(required=required, default=default, regexp=regexp)
@@ -0,0 +1,19 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Callable
4
+
5
+ from clearskies.configs import string_list_or_callable
6
+
7
+
8
+ class EmailListOrCallable(string_list_or_callable.StringListOrCallable):
9
+ """
10
+ This is for a configuration that should be a list of emails or a callable that returns a list of emails.
11
+
12
+ This is different than StringList, which also accepts a list of strings, but
13
+ validates that all of those values match the email format.
14
+ """
15
+
16
+ def __init__(
17
+ self, required=False, default=None, regexp: str = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
18
+ ):
19
+ super().__init__(required=required, default=default, regexp=regexp)
@@ -0,0 +1,59 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Callable
4
+
5
+ from clearskies.configs import config
6
+
7
+
8
+ class EmailOrEmailListOrCallable(config.Config):
9
+ """
10
+ This is for a configuration that should be an email or a list of emails or a callable that returns a list of emails.
11
+
12
+ This is a combination of Email and EmailListOrCallable.
13
+ """
14
+
15
+ def __init__(
16
+ self, required=False, default=None, regexp: str = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
17
+ ):
18
+ self.required = required
19
+ self.default = default
20
+ self.regexp = regexp
21
+
22
+ def __set__(self, instance, value: str | list[str] | Callable[..., list[str]]):
23
+ if value is None:
24
+ return
25
+ if self.regexp:
26
+ import re
27
+ if isinstance(value, str):
28
+ if self.regexp and not re.match(self.regexp, value):
29
+ error_prefix = self._error_prefix(instance)
30
+ raise ValueError(
31
+ f"{error_prefix} attempt to set a value of '{value}' but this does not match the required regexp: '{self.regexp}'."
32
+ )
33
+ value = [value]
34
+ elif not isinstance(value, list) and not callable(value):
35
+ error_prefix = self._error_prefix(instance)
36
+ raise TypeError(
37
+ f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to a parameter that should be a list or a callable"
38
+ )
39
+ if isinstance(value, list):
40
+ if self.regexp:
41
+ import re
42
+
43
+ for index, item in enumerate(value):
44
+ if not isinstance(item, str):
45
+ error_prefix = self._error_prefix(instance)
46
+ raise TypeError(
47
+ f"{error_prefix} attempt to set a value of type '{item.__class__.__name__}' for item #{index + 1}. A string was expected."
48
+ )
49
+ if not re.match(self.regexp, item):
50
+ error_prefix = self._error_prefix(instance)
51
+ raise ValueError(
52
+ f"{error_prefix} attempt to set a value of '{item}' for item #{index + 1} but this does not match the required regexp: '{self.regexp}'."
53
+ )
54
+ instance._set_config(self, value)
55
+
56
+ def __get__(self, instance, parent) -> list[str] | Callable[..., list[str]]:
57
+ if not instance:
58
+ return self # type: ignore
59
+ return instance._get_config(self)
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from clearskies.configs import config
2
4
 
3
5
 
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from typing import Callable
2
4
 
3
5
  from clearskies.configs import config
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from clearskies.configs import config
2
4
 
3
5
 
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from typing import Callable
2
4
 
3
5
  from clearskies.configs import config
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from typing import Any
2
4
 
3
5
  from clearskies.configs import config
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from typing import Any, Callable
2
4
 
3
5
  from clearskies.configs import config
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from clearskies.configs import select
2
4
 
3
5
 
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from clearskies.configs import select_list
2
4
 
3
5
 
@@ -1,5 +1,6 @@
1
+ from __future__ import annotations
2
+
1
3
  from clearskies.configs.string import String
2
- from clearskies.functional import string
3
4
 
4
5
 
5
6
  class ModelDestinationName(String):
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from clearskies.configs import model_column
2
4
  from clearskies.functional import string
3
5
 
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from clearskies.configs import model_column
2
4
 
3
5
 
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from clearskies.configs import model_columns
2
4
 
3
5
 
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from clearskies.configs import model_columns
2
4
 
3
5
 
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from clearskies.configs import string
2
4
 
3
5
 
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from clearskies.configs import config
2
4
 
3
5
 
@@ -1,3 +1,7 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+
1
5
  from clearskies.configs import config
2
6
 
3
7
 
@@ -14,8 +18,6 @@ class String(config.Config):
14
18
  f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to a parameter that requires a string."
15
19
  )
16
20
  if self.regexp:
17
- import re
18
-
19
21
  if not re.match(self.regexp, value):
20
22
  error_prefix = self._error_prefix(instance)
21
23
  raise ValueError(
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from clearskies.configs import config
2
4
 
3
5
 
@@ -1,3 +1,7 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+
1
5
  from clearskies.configs import config
2
6
 
3
7
 
@@ -9,6 +13,11 @@ class StringList(config.Config):
9
13
  valdiates that all of those values match against an allow list.
10
14
  """
11
15
 
16
+ def __init__(self, required=False, default=None, regexp: str = ""):
17
+ self.required = required
18
+ self.default = default
19
+ self.regexp = regexp
20
+
12
21
  def __set__(self, instance, value: list[str]):
13
22
  if value is None:
14
23
  return
@@ -16,13 +25,19 @@ class StringList(config.Config):
16
25
  if not isinstance(value, list):
17
26
  error_prefix = self._error_prefix(instance)
18
27
  raise TypeError(
19
- f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to a list parameter"
28
+ f"{error_prefix} attempt to set a value of type '{value.__class__.__name__}' to a list of strings parameter."
20
29
  )
30
+
21
31
  for index, item in enumerate(value):
22
32
  if not isinstance(item, str):
23
33
  error_prefix = self._error_prefix(instance)
24
34
  raise TypeError(
25
- f"{error_prefix} attempt to set a value of type '{item.__class__.__name__}' for item #{index + 1}. A string was expected."
35
+ f"{error_prefix} attempt to set a value of type '{item.__class__.__name__}' for item #{index + 1}. A string was expected."
36
+ )
37
+ if self.regexp and not re.match(self.regexp, item):
38
+ error_prefix = self._error_prefix(instance)
39
+ raise ValueError(
40
+ f"{error_prefix} attempt to set a value of '{item}' for item #{index + 1} but this does not match the required regexp: '{self.regexp}'."
26
41
  )
27
42
  instance._set_config(self, value)
28
43
 
@@ -1,3 +1,6 @@
1
+ from __future__ import annotations
2
+
3
+ import re
1
4
  from typing import Callable
2
5
 
3
6
  from clearskies.configs import config
@@ -11,6 +14,11 @@ class StringListOrCallable(config.Config):
11
14
  valdiates that all of those values match against an allow list.
12
15
  """
13
16
 
17
+ def __init__(self, required=False, default=None, regexp: str = ""):
18
+ self.required = required
19
+ self.default = default
20
+ self.regexp = regexp
21
+
14
22
  def __set__(self, instance, value: list[str] | Callable[..., list[str]]):
15
23
  if value is None:
16
24
  return
@@ -27,6 +35,11 @@ class StringListOrCallable(config.Config):
27
35
  raise TypeError(
28
36
  f"{error_prefix} attempt to set a value of type '{item.__class__.__name__}' for item #{index + 1}. A string was expected."
29
37
  )
38
+ if self.regexp and not re.match(self.regexp, item):
39
+ error_prefix = self._error_prefix(instance)
40
+ raise ValueError(
41
+ f"{error_prefix} attempt to set a value of '{item}' for item #{index + 1} but this does not match the required regexp: '{self.regexp}'."
42
+ )
30
43
  instance._set_config(self, value)
31
44
 
32
45
  def __get__(self, instance, parent) -> list[str] | Callable[..., list[str]]:
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import datetime
2
4
 
3
5
  from clearskies.configs import config
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import datetime
2
4
 
3
5
  from clearskies.configs import config
clearskies/configs/url.py CHANGED
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from clearskies.configs import string
2
4
  from clearskies.functional import routing
3
5
 
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from clearskies.configs import model_column
2
4
 
3
5
 
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from clearskies.configs import model_columns
2
4
 
3
5
 
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from typing import Any
2
4
 
3
5
  from clearskies.configs import config
@@ -4,7 +4,7 @@ from clearskies.input_outputs import Cli as CliInputOutput
4
4
 
5
5
  class Cli(Context):
6
6
  """
7
- Run an application via a CLI command
7
+ Run an application via a CLI command.
8
8
 
9
9
  This context converts a clearskies application into a CLI command. Here's a simple example:
10
10
 
@@ -12,9 +12,11 @@ class Cli(Context):
12
12
  #!/usr/bin/env python
13
13
  import clearskies
14
14
 
15
+
15
16
  def my_function():
16
17
  return "Hello World!"
17
18
 
19
+
18
20
  cli = clearskies.contexts.Cli(my_function)
19
21
  cli()
20
22
  ```
@@ -32,9 +34,11 @@ class Cli(Context):
32
34
  #!/usr/bin/env python
33
35
  import clearskies
34
36
 
37
+
35
38
  def my_function(name):
36
39
  return f"Hello {name}!"
37
40
 
41
+
38
42
  cli = clearskies.contexts.Cli(
39
43
  clearskies.endpoints.Callable(
40
44
  my_function,
@@ -59,9 +63,11 @@ class Cli(Context):
59
63
  #!/usr/bin/env python
60
64
  import clearskies
61
65
 
66
+
62
67
  def my_function(name):
63
68
  return f"Hello {name}!"
64
69
 
70
+
65
71
  cli = clearskies.contexts.Cli(
66
72
  clearskies.endpoints.Callable(
67
73
  my_function,
@@ -87,9 +93,11 @@ class Cli(Context):
87
93
  #!/usr/bin/env python
88
94
  import clearskies
89
95
 
96
+
90
97
  def my_function(request_data):
91
98
  return request_data
92
99
 
100
+
93
101
  cli = clearskies.contexts.Cli(
94
102
  clearskies.endpoints.Callable(
95
103
  my_function,
@@ -4,20 +4,19 @@ import datetime
4
4
  from types import ModuleType
5
5
  from typing import TYPE_CHECKING, Any, Callable
6
6
 
7
- import clearskies.endpoint
8
- import clearskies.endpoint_group
7
+ from clearskies import exceptions
9
8
  from clearskies.di import Di
10
9
  from clearskies.di.additional_config import AdditionalConfig
11
10
  from clearskies.input_outputs import Programmatic
12
11
 
13
12
  if TYPE_CHECKING:
13
+ from clearskies.endpoint import Endpoint
14
+ from clearskies.endpoint_group import EndpointGroup
14
15
  from clearskies.input_outputs import InputOutput
15
16
 
16
17
 
17
18
  class Context:
18
- """
19
- Context: a flexible way to connect applications to hosting strategies.
20
- """
19
+ """Context: a flexible way to connect applications to hosting strategies."""
21
20
 
22
21
  di: Di = None # type: ignore
23
22
 
@@ -26,13 +25,13 @@ class Context:
26
25
 
27
26
  This can be a callable, an endpoint, or an endpoint group. If passed a callable, the callable can request any
28
27
  standard or defined dependencies and should return the desired response. It can also raise any exception from
29
- clearskies.exceptions.
28
+ exceptions.
30
29
  """
31
- application: Callable | clearskies.endpoint.Endpoint | clearskies.endpoint_group.EndpointGroup = None # type: ignore
30
+ application: Callable | Endpoint | EndpointGroup = None # type: ignore
32
31
 
33
32
  def __init__(
34
33
  self,
35
- application: Callable | clearskies.endpoint.Endpoint | clearskies.endpoint_group.EndpointGroup,
34
+ application: Callable | Endpoint | EndpointGroup,
36
35
  classes: type | list[type] = [],
37
36
  modules: ModuleType | list[ModuleType] = [],
38
37
  bindings: dict[str, Any] = {},
@@ -63,17 +62,17 @@ class Context:
63
62
  return input_output.respond(
64
63
  self.di.call_function(self.application, **input_output.get_context_for_callables())
65
64
  )
66
- except clearskies.exceptions.ClientError as e:
65
+ except exceptions.ClientError as e:
67
66
  return input_output.respond(str(e), 400)
68
- except clearskies.exceptions.Authentication as e:
67
+ except exceptions.Authentication as e:
69
68
  return input_output.respond(str(e), 401)
70
- except clearskies.exceptions.Authorization as e:
69
+ except exceptions.Authorization as e:
71
70
  return input_output.respond(str(e), 403)
72
- except clearskies.exceptions.NotFound as e:
71
+ except exceptions.NotFound as e:
73
72
  return input_output.respond(str(e), 404)
74
- except clearskies.exceptions.MovedPermanently as e:
73
+ except exceptions.MovedPermanently as e:
75
74
  return input_output.respond(str(e), 302)
76
- except clearskies.exceptions.MovedTemporarily as e:
75
+ except exceptions.MovedTemporarily as e:
77
76
  return input_output.respond(str(e), 307)
78
77
 
79
78
  def __call__(
@@ -1,14 +1,11 @@
1
- import datetime
2
- from types import ModuleType
3
- from typing import Any, Callable
4
- from wsgiref.simple_server import make_server
5
- from wsgiref.util import setup_testing_defaults
6
-
7
- import clearskies.endpoint
8
- import clearskies.endpoint_group
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING
4
+
9
5
  from clearskies.contexts.context import Context
10
- from clearskies.di import AdditionalConfig
11
- from clearskies.input_outputs import Wsgi as WsgiInputOutput
6
+
7
+ if TYPE_CHECKING:
8
+ from clearskies.input_outputs import Wsgi as WsgiInputOutput
12
9
 
13
10
 
14
11
  class Wsgi(Context):
@@ -24,11 +21,14 @@ class Wsgi(Context):
24
21
  ```
25
22
  import clearskies
26
23
 
24
+
27
25
  def hello_world():
28
26
  return "Hello World!"
29
27
 
28
+
30
29
  wsgi = clearskies.contexts.Wsgi(hello_world)
31
30
 
31
+
32
32
  def application(environment, start_response):
33
33
  return wsgi(environment, start_response)
34
34
  ```
@@ -52,9 +52,11 @@ class Wsgi(Context):
52
52
  ```
53
53
  import clearskies
54
54
 
55
+
55
56
  def hello_world():
56
57
  return "Hello World!"
57
58
 
59
+
58
60
  def application(environment, start_response):
59
61
  wsgi = clearskies.contexts.Wsgi(hello_world)
60
62
  return wsgi(environment, start_response)