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.
- {clear_skies-2.0.7.dist-info → clear_skies-2.0.9.dist-info}/METADATA +1 -1
- clear_skies-2.0.9.dist-info/RECORD +256 -0
- clearskies/__init__.py +2 -2
- clearskies/authentication/authentication.py +1 -3
- clearskies/authentication/authorization.py +12 -5
- clearskies/authentication/authorization_pass_through.py +5 -3
- clearskies/authentication/jwks.py +25 -23
- clearskies/authentication/secret_bearer.py +15 -17
- clearskies/autodoc/schema/schema.py +1 -1
- clearskies/backends/api_backend.py +50 -56
- clearskies/backends/backend.py +14 -14
- clearskies/backends/cursor_backend.py +17 -23
- clearskies/backends/memory_backend.py +27 -30
- clearskies/backends/secrets_backend.py +13 -18
- clearskies/column.py +44 -56
- clearskies/columns/audit.py +14 -13
- clearskies/columns/belongs_to_id.py +10 -15
- clearskies/columns/belongs_to_model.py +6 -9
- clearskies/columns/belongs_to_self.py +13 -9
- clearskies/columns/boolean.py +13 -16
- clearskies/columns/category_tree.py +9 -11
- clearskies/columns/category_tree_children.py +2 -3
- clearskies/columns/category_tree_descendants.py +1 -1
- clearskies/columns/created.py +8 -11
- clearskies/columns/created_by_authorization_data.py +7 -9
- clearskies/columns/created_by_header.py +12 -8
- clearskies/columns/created_by_ip.py +6 -8
- clearskies/columns/created_by_routing_data.py +12 -7
- clearskies/columns/created_by_user_agent.py +6 -9
- clearskies/columns/date.py +12 -14
- clearskies/columns/datetime.py +19 -17
- clearskies/columns/email.py +3 -1
- clearskies/columns/float.py +10 -14
- clearskies/columns/has_many.py +8 -10
- clearskies/columns/has_many_self.py +13 -7
- clearskies/columns/has_one.py +2 -0
- clearskies/columns/integer.py +9 -11
- clearskies/columns/json.py +10 -12
- clearskies/columns/many_to_many_ids.py +14 -16
- clearskies/columns/many_to_many_ids_with_data.py +16 -16
- clearskies/columns/many_to_many_models.py +5 -7
- clearskies/columns/many_to_many_pivots.py +3 -5
- clearskies/columns/phone.py +12 -9
- clearskies/columns/select.py +12 -9
- clearskies/columns/string.py +1 -1
- clearskies/columns/timestamp.py +15 -15
- clearskies/columns/updated.py +8 -10
- clearskies/columns/uuid.py +7 -10
- clearskies/configs/__init__.py +8 -0
- clearskies/configs/any.py +2 -0
- clearskies/configs/any_dict.py +2 -0
- clearskies/configs/any_dict_or_callable.py +2 -0
- clearskies/configs/boolean.py +2 -0
- clearskies/configs/boolean_or_callable.py +2 -0
- clearskies/configs/callable_config.py +2 -0
- clearskies/configs/config.py +2 -0
- clearskies/configs/datetime.py +2 -0
- clearskies/configs/datetime_or_callable.py +2 -0
- clearskies/configs/email.py +10 -0
- clearskies/configs/email_list.py +17 -0
- clearskies/configs/email_list_or_callable.py +19 -0
- clearskies/configs/email_or_email_list_or_callable.py +59 -0
- clearskies/configs/float.py +2 -0
- clearskies/configs/float_or_callable.py +2 -0
- clearskies/configs/integer.py +2 -0
- clearskies/configs/integer_or_callable.py +2 -0
- clearskies/configs/list_any_dict.py +2 -0
- clearskies/configs/list_any_dict_or_callable.py +2 -0
- clearskies/configs/model_column.py +2 -0
- clearskies/configs/model_columns.py +2 -0
- clearskies/configs/model_destination_name.py +2 -1
- clearskies/configs/model_to_id_column.py +2 -0
- clearskies/configs/readable_model_column.py +2 -0
- clearskies/configs/readable_model_columns.py +2 -0
- clearskies/configs/searchable_model_columns.py +2 -0
- clearskies/configs/select.py +2 -0
- clearskies/configs/select_list.py +2 -0
- clearskies/configs/string.py +4 -2
- clearskies/configs/string_dict.py +2 -0
- clearskies/configs/string_list.py +17 -2
- clearskies/configs/string_list_or_callable.py +13 -0
- clearskies/configs/timedelta.py +2 -0
- clearskies/configs/timezone.py +2 -0
- clearskies/configs/url.py +2 -0
- clearskies/configs/writeable_model_column.py +2 -0
- clearskies/configs/writeable_model_columns.py +2 -0
- clearskies/configurable.py +2 -0
- clearskies/contexts/cli.py +9 -1
- clearskies/contexts/context.py +13 -14
- clearskies/contexts/wsgi.py +12 -10
- clearskies/contexts/wsgi_ref.py +12 -6
- clearskies/decorators.py +1 -1
- clearskies/decorators.pyi +10 -0
- clearskies/di/di.py +7 -6
- clearskies/di/inject/by_class.py +2 -0
- clearskies/di/inject/by_name.py +2 -0
- clearskies/di/inject/di.py +2 -0
- clearskies/di/inject/environment.py +1 -1
- clearskies/di/inject/now.py +2 -0
- clearskies/di/inject/requests.py +2 -0
- clearskies/di/inject/secrets.py +2 -2
- clearskies/di/inject/utcnow.py +2 -0
- clearskies/di/inject/uuid.py +2 -2
- clearskies/end.py +45 -7
- clearskies/endpoint.py +43 -59
- clearskies/endpoint_group.py +15 -18
- clearskies/endpoints/advanced_search.py +19 -26
- clearskies/endpoints/callable.py +10 -16
- clearskies/endpoints/create.py +6 -10
- clearskies/endpoints/delete.py +5 -11
- clearskies/endpoints/get.py +11 -15
- clearskies/endpoints/health_check.py +9 -11
- clearskies/endpoints/list.py +29 -36
- clearskies/endpoints/restful_api.py +43 -53
- clearskies/endpoints/schema.py +14 -18
- clearskies/endpoints/simple_search.py +5 -12
- clearskies/endpoints/update.py +6 -11
- clearskies/environment.py +2 -0
- clearskies/input_outputs/cli.py +2 -0
- clearskies/input_outputs/headers.py +2 -0
- clearskies/input_outputs/input_output.py +15 -15
- clearskies/input_outputs/programmatic.py +2 -2
- clearskies/input_outputs/wsgi.py +2 -2
- clearskies/model.py +120 -25
- clearskies/query/query.py +1 -4
- clearskies/secrets/__init__.py +2 -1
- clearskies/secrets/akeyless.py +16 -11
- clearskies/secrets/secrets.py +7 -2
- clearskies/security_header.py +4 -2
- clearskies/security_headers/cache_control.py +15 -14
- clearskies/security_headers/cors.py +10 -9
- clearskies/security_headers/csp.py +25 -24
- clearskies/security_headers/hsts.py +6 -5
- clearskies/typing.py +1 -1
- clearskies/validator.py +5 -6
- clearskies/validators/after_column.py +6 -7
- clearskies/validators/before_column.py +2 -0
- clearskies/validators/in_the_future.py +5 -8
- clearskies/validators/in_the_future_at_least.py +2 -0
- clearskies/validators/in_the_future_at_most.py +2 -0
- clearskies/validators/in_the_past.py +5 -8
- clearskies/validators/in_the_past_at_least.py +2 -0
- clearskies/validators/in_the_past_at_most.py +2 -0
- clearskies/validators/maximum_length.py +4 -5
- clearskies/validators/maximum_value.py +4 -4
- clearskies/validators/minimum_length.py +4 -4
- clearskies/validators/minimum_value.py +4 -4
- clearskies/validators/required.py +2 -4
- clearskies/validators/timedelta.py +8 -9
- clearskies/validators/unique.py +2 -3
- clear_skies-2.0.7.dist-info/RECORD +0 -251
- {clear_skies-2.0.7.dist-info → clear_skies-2.0.9.dist-info}/WHEEL +0 -0
- {clear_skies-2.0.7.dist-info → clear_skies-2.0.9.dist-info}/licenses/LICENSE +0 -0
clearskies/columns/uuid.py
CHANGED
|
@@ -2,14 +2,11 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from typing import TYPE_CHECKING, Any
|
|
4
4
|
|
|
5
|
-
import
|
|
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 =
|
|
63
|
+
uuid = di.inject.Uuid()
|
|
67
64
|
|
|
68
|
-
@
|
|
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:
|
|
75
|
-
on_change_post_save:
|
|
76
|
-
on_change_save_finished:
|
|
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
|
|
clearskies/configs/__init__.py
CHANGED
|
@@ -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
clearskies/configs/any_dict.py
CHANGED
clearskies/configs/boolean.py
CHANGED
clearskies/configs/config.py
CHANGED
clearskies/configs/datetime.py
CHANGED
|
@@ -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)
|
clearskies/configs/float.py
CHANGED
clearskies/configs/integer.py
CHANGED
clearskies/configs/select.py
CHANGED
clearskies/configs/string.py
CHANGED
|
@@ -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,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}.
|
|
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]]:
|
clearskies/configs/timedelta.py
CHANGED
clearskies/configs/timezone.py
CHANGED
clearskies/configs/url.py
CHANGED
clearskies/configurable.py
CHANGED
clearskies/contexts/cli.py
CHANGED
|
@@ -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,
|
clearskies/contexts/context.py
CHANGED
|
@@ -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
|
|
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
|
-
|
|
28
|
+
exceptions.
|
|
30
29
|
"""
|
|
31
|
-
application: Callable |
|
|
30
|
+
application: Callable | Endpoint | EndpointGroup = None # type: ignore
|
|
32
31
|
|
|
33
32
|
def __init__(
|
|
34
33
|
self,
|
|
35
|
-
application: Callable |
|
|
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
|
|
65
|
+
except exceptions.ClientError as e:
|
|
67
66
|
return input_output.respond(str(e), 400)
|
|
68
|
-
except
|
|
67
|
+
except exceptions.Authentication as e:
|
|
69
68
|
return input_output.respond(str(e), 401)
|
|
70
|
-
except
|
|
69
|
+
except exceptions.Authorization as e:
|
|
71
70
|
return input_output.respond(str(e), 403)
|
|
72
|
-
except
|
|
71
|
+
except exceptions.NotFound as e:
|
|
73
72
|
return input_output.respond(str(e), 404)
|
|
74
|
-
except
|
|
73
|
+
except exceptions.MovedPermanently as e:
|
|
75
74
|
return input_output.respond(str(e), 302)
|
|
76
|
-
except
|
|
75
|
+
except exceptions.MovedTemporarily as e:
|
|
77
76
|
return input_output.respond(str(e), 307)
|
|
78
77
|
|
|
79
78
|
def __call__(
|
clearskies/contexts/wsgi.py
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
from typing import
|
|
4
|
-
|
|
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
|
-
|
|
11
|
-
|
|
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)
|