clear-skies 2.0.3__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.
- clear_skies-2.0.5.dist-info/METADATA +74 -0
- clear_skies-2.0.5.dist-info/RECORD +4 -0
- {clear_skies-2.0.3.dist-info → clear_skies-2.0.5.dist-info}/WHEEL +1 -1
- clear_skies-2.0.3.dist-info/METADATA +0 -46
- clear_skies-2.0.3.dist-info/RECORD +0 -249
- clearskies/__init__.py +0 -59
- clearskies/action.py +0 -7
- clearskies/authentication/__init__.py +0 -15
- clearskies/authentication/authentication.py +0 -46
- clearskies/authentication/authorization.py +0 -16
- clearskies/authentication/authorization_pass_through.py +0 -20
- clearskies/authentication/jwks.py +0 -163
- clearskies/authentication/public.py +0 -5
- clearskies/authentication/secret_bearer.py +0 -553
- clearskies/autodoc/__init__.py +0 -8
- clearskies/autodoc/formats/__init__.py +0 -5
- clearskies/autodoc/formats/oai3_json/__init__.py +0 -7
- clearskies/autodoc/formats/oai3_json/oai3_json.py +0 -87
- clearskies/autodoc/formats/oai3_json/oai3_schema_resolver.py +0 -15
- clearskies/autodoc/formats/oai3_json/parameter.py +0 -35
- clearskies/autodoc/formats/oai3_json/request.py +0 -68
- clearskies/autodoc/formats/oai3_json/response.py +0 -28
- clearskies/autodoc/formats/oai3_json/schema/__init__.py +0 -11
- clearskies/autodoc/formats/oai3_json/schema/array.py +0 -9
- clearskies/autodoc/formats/oai3_json/schema/default.py +0 -13
- clearskies/autodoc/formats/oai3_json/schema/enum.py +0 -7
- clearskies/autodoc/formats/oai3_json/schema/object.py +0 -29
- clearskies/autodoc/formats/oai3_json/test.json +0 -1985
- clearskies/autodoc/py.typed +0 -0
- clearskies/autodoc/request/__init__.py +0 -15
- clearskies/autodoc/request/header.py +0 -6
- clearskies/autodoc/request/json_body.py +0 -6
- clearskies/autodoc/request/parameter.py +0 -8
- clearskies/autodoc/request/request.py +0 -38
- clearskies/autodoc/request/url_parameter.py +0 -6
- clearskies/autodoc/request/url_path.py +0 -6
- clearskies/autodoc/response/__init__.py +0 -5
- clearskies/autodoc/response/response.py +0 -9
- clearskies/autodoc/schema/__init__.py +0 -31
- clearskies/autodoc/schema/array.py +0 -10
- clearskies/autodoc/schema/base64.py +0 -8
- clearskies/autodoc/schema/boolean.py +0 -5
- clearskies/autodoc/schema/date.py +0 -5
- clearskies/autodoc/schema/datetime.py +0 -5
- clearskies/autodoc/schema/double.py +0 -5
- clearskies/autodoc/schema/enum.py +0 -17
- clearskies/autodoc/schema/integer.py +0 -6
- clearskies/autodoc/schema/long.py +0 -5
- clearskies/autodoc/schema/number.py +0 -6
- clearskies/autodoc/schema/object.py +0 -13
- clearskies/autodoc/schema/password.py +0 -5
- clearskies/autodoc/schema/schema.py +0 -11
- clearskies/autodoc/schema/string.py +0 -5
- clearskies/backends/__init__.py +0 -65
- clearskies/backends/api_backend.py +0 -1178
- clearskies/backends/backend.py +0 -136
- clearskies/backends/cursor_backend.py +0 -335
- clearskies/backends/memory_backend.py +0 -797
- clearskies/backends/secrets_backend.py +0 -106
- clearskies/column.py +0 -1233
- clearskies/columns/__init__.py +0 -71
- clearskies/columns/audit.py +0 -206
- clearskies/columns/belongs_to_id.py +0 -483
- clearskies/columns/belongs_to_model.py +0 -132
- clearskies/columns/belongs_to_self.py +0 -105
- clearskies/columns/boolean.py +0 -113
- clearskies/columns/category_tree.py +0 -275
- clearskies/columns/category_tree_ancestors.py +0 -51
- clearskies/columns/category_tree_children.py +0 -127
- clearskies/columns/category_tree_descendants.py +0 -48
- clearskies/columns/created.py +0 -95
- clearskies/columns/created_by_authorization_data.py +0 -116
- clearskies/columns/created_by_header.py +0 -99
- clearskies/columns/created_by_ip.py +0 -92
- clearskies/columns/created_by_routing_data.py +0 -97
- clearskies/columns/created_by_user_agent.py +0 -92
- clearskies/columns/date.py +0 -234
- clearskies/columns/datetime.py +0 -282
- clearskies/columns/email.py +0 -76
- clearskies/columns/float.py +0 -153
- clearskies/columns/has_many.py +0 -505
- clearskies/columns/has_many_self.py +0 -56
- clearskies/columns/has_one.py +0 -14
- clearskies/columns/integer.py +0 -160
- clearskies/columns/json.py +0 -126
- clearskies/columns/many_to_many_ids.py +0 -337
- clearskies/columns/many_to_many_ids_with_data.py +0 -274
- clearskies/columns/many_to_many_models.py +0 -158
- clearskies/columns/many_to_many_pivots.py +0 -134
- clearskies/columns/phone.py +0 -159
- clearskies/columns/select.py +0 -92
- clearskies/columns/string.py +0 -102
- clearskies/columns/timestamp.py +0 -164
- clearskies/columns/updated.py +0 -110
- clearskies/columns/uuid.py +0 -86
- clearskies/configs/README.md +0 -105
- clearskies/configs/__init__.py +0 -162
- clearskies/configs/actions.py +0 -43
- clearskies/configs/any.py +0 -13
- clearskies/configs/any_dict.py +0 -22
- clearskies/configs/any_dict_or_callable.py +0 -23
- clearskies/configs/authentication.py +0 -23
- clearskies/configs/authorization.py +0 -23
- clearskies/configs/boolean.py +0 -16
- clearskies/configs/boolean_or_callable.py +0 -18
- clearskies/configs/callable_config.py +0 -18
- clearskies/configs/columns.py +0 -34
- clearskies/configs/conditions.py +0 -30
- clearskies/configs/config.py +0 -24
- clearskies/configs/datetime.py +0 -18
- clearskies/configs/datetime_or_callable.py +0 -19
- clearskies/configs/endpoint.py +0 -23
- clearskies/configs/endpoint_list.py +0 -28
- clearskies/configs/float.py +0 -16
- clearskies/configs/float_or_callable.py +0 -18
- clearskies/configs/integer.py +0 -16
- clearskies/configs/integer_or_callable.py +0 -18
- clearskies/configs/joins.py +0 -30
- clearskies/configs/list_any_dict.py +0 -30
- clearskies/configs/list_any_dict_or_callable.py +0 -31
- clearskies/configs/model_class.py +0 -35
- clearskies/configs/model_column.py +0 -65
- clearskies/configs/model_columns.py +0 -56
- clearskies/configs/model_destination_name.py +0 -25
- clearskies/configs/model_to_id_column.py +0 -43
- clearskies/configs/readable_model_column.py +0 -9
- clearskies/configs/readable_model_columns.py +0 -9
- clearskies/configs/schema.py +0 -23
- clearskies/configs/searchable_model_columns.py +0 -9
- clearskies/configs/security_headers.py +0 -39
- clearskies/configs/select.py +0 -26
- clearskies/configs/select_list.py +0 -47
- clearskies/configs/string.py +0 -29
- clearskies/configs/string_dict.py +0 -32
- clearskies/configs/string_list.py +0 -32
- clearskies/configs/string_list_or_callable.py +0 -35
- clearskies/configs/string_or_callable.py +0 -18
- clearskies/configs/timedelta.py +0 -18
- clearskies/configs/timezone.py +0 -18
- clearskies/configs/url.py +0 -23
- clearskies/configs/validators.py +0 -45
- clearskies/configs/writeable_model_column.py +0 -9
- clearskies/configs/writeable_model_columns.py +0 -9
- clearskies/configurable.py +0 -76
- clearskies/contexts/__init__.py +0 -11
- clearskies/contexts/cli.py +0 -117
- clearskies/contexts/context.py +0 -98
- clearskies/contexts/wsgi.py +0 -76
- clearskies/contexts/wsgi_ref.py +0 -82
- clearskies/decorators.py +0 -33
- clearskies/di/__init__.py +0 -14
- clearskies/di/additional_config.py +0 -130
- clearskies/di/additional_config_auto_import.py +0 -17
- clearskies/di/di.py +0 -968
- clearskies/di/inject/__init__.py +0 -23
- clearskies/di/inject/by_class.py +0 -21
- clearskies/di/inject/by_name.py +0 -18
- clearskies/di/inject/di.py +0 -13
- clearskies/di/inject/environment.py +0 -14
- clearskies/di/inject/input_output.py +0 -20
- clearskies/di/inject/now.py +0 -13
- clearskies/di/inject/requests.py +0 -13
- clearskies/di/inject/secrets.py +0 -14
- clearskies/di/inject/utcnow.py +0 -13
- clearskies/di/inject/uuid.py +0 -15
- clearskies/di/injectable.py +0 -29
- clearskies/di/injectable_properties.py +0 -131
- clearskies/di/test_module/__init__.py +0 -6
- clearskies/di/test_module/another_module/__init__.py +0 -2
- clearskies/di/test_module/module_class.py +0 -5
- clearskies/end.py +0 -183
- clearskies/endpoint.py +0 -1310
- clearskies/endpoint_group.py +0 -310
- clearskies/endpoints/__init__.py +0 -23
- clearskies/endpoints/advanced_search.py +0 -526
- clearskies/endpoints/callable.py +0 -388
- clearskies/endpoints/create.py +0 -202
- clearskies/endpoints/delete.py +0 -139
- clearskies/endpoints/get.py +0 -275
- clearskies/endpoints/health_check.py +0 -181
- clearskies/endpoints/list.py +0 -573
- clearskies/endpoints/restful_api.py +0 -427
- clearskies/endpoints/simple_search.py +0 -286
- clearskies/endpoints/update.py +0 -190
- clearskies/environment.py +0 -104
- clearskies/exceptions/__init__.py +0 -17
- clearskies/exceptions/authentication.py +0 -2
- clearskies/exceptions/authorization.py +0 -2
- clearskies/exceptions/client_error.py +0 -2
- clearskies/exceptions/input_errors.py +0 -4
- clearskies/exceptions/moved_permanently.py +0 -3
- clearskies/exceptions/moved_temporarily.py +0 -3
- clearskies/exceptions/not_found.py +0 -2
- clearskies/functional/__init__.py +0 -7
- clearskies/functional/routing.py +0 -92
- clearskies/functional/string.py +0 -112
- clearskies/functional/validations.py +0 -76
- clearskies/input_outputs/__init__.py +0 -13
- clearskies/input_outputs/cli.py +0 -171
- clearskies/input_outputs/exceptions/__init__.py +0 -2
- clearskies/input_outputs/exceptions/cli_input_error.py +0 -2
- clearskies/input_outputs/exceptions/cli_not_found.py +0 -2
- clearskies/input_outputs/headers.py +0 -45
- clearskies/input_outputs/input_output.py +0 -138
- clearskies/input_outputs/programmatic.py +0 -69
- clearskies/input_outputs/py.typed +0 -0
- clearskies/input_outputs/wsgi.py +0 -77
- clearskies/model.py +0 -1922
- clearskies/py.typed +0 -0
- clearskies/query/__init__.py +0 -12
- clearskies/query/condition.py +0 -223
- clearskies/query/join.py +0 -136
- clearskies/query/query.py +0 -196
- clearskies/query/sort.py +0 -27
- clearskies/schema.py +0 -82
- clearskies/secrets/__init__.py +0 -6
- clearskies/secrets/additional_configs/__init__.py +0 -32
- clearskies/secrets/additional_configs/mysql_connection_dynamic_producer.py +0 -61
- clearskies/secrets/additional_configs/mysql_connection_dynamic_producer_via_ssh_cert_bastion.py +0 -160
- clearskies/secrets/akeyless.py +0 -182
- clearskies/secrets/exceptions/__init__.py +0 -1
- clearskies/secrets/exceptions/not_found.py +0 -2
- clearskies/secrets/secrets.py +0 -38
- clearskies/security_header.py +0 -15
- clearskies/security_headers/__init__.py +0 -11
- clearskies/security_headers/cache_control.py +0 -67
- clearskies/security_headers/cors.py +0 -50
- clearskies/security_headers/csp.py +0 -94
- clearskies/security_headers/hsts.py +0 -22
- clearskies/security_headers/x_content_type_options.py +0 -0
- clearskies/security_headers/x_frame_options.py +0 -0
- clearskies/test_base.py +0 -8
- clearskies/typing.py +0 -11
- clearskies/validator.py +0 -37
- clearskies/validators/__init__.py +0 -33
- clearskies/validators/after_column.py +0 -62
- clearskies/validators/before_column.py +0 -13
- clearskies/validators/in_the_future.py +0 -32
- clearskies/validators/in_the_future_at_least.py +0 -11
- clearskies/validators/in_the_future_at_most.py +0 -10
- clearskies/validators/in_the_past.py +0 -32
- clearskies/validators/in_the_past_at_least.py +0 -10
- clearskies/validators/in_the_past_at_most.py +0 -10
- clearskies/validators/maximum_length.py +0 -26
- clearskies/validators/maximum_value.py +0 -29
- clearskies/validators/minimum_length.py +0 -26
- clearskies/validators/minimum_value.py +0 -29
- clearskies/validators/required.py +0 -34
- clearskies/validators/timedelta.py +0 -59
- clearskies/validators/unique.py +0 -30
- {clear_skies-2.0.3.dist-info → clear_skies-2.0.5.dist-info/licenses}/LICENSE +0 -0
clearskies/contexts/wsgi_ref.py
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
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
|
|
9
|
-
from clearskies.contexts.context import Context
|
|
10
|
-
from clearskies.di import AdditionalConfig
|
|
11
|
-
from clearskies.input_outputs import Wsgi as WsgiInputOutput
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class WsgiRef(Context):
|
|
15
|
-
"""
|
|
16
|
-
Use a built in WSGI server (for development purposes only).
|
|
17
|
-
|
|
18
|
-
This context will launch a built-in HTTP server for you, so you can run applications locally
|
|
19
|
-
without having to install extra dependencies. Note that this server is not intended for production
|
|
20
|
-
usage, so this is best used for simple tests/demonstration purposes. Unlike the WSGI context, where
|
|
21
|
-
you define the application handler and invoke the context from inside of it (passing along the
|
|
22
|
-
environment and start_response variables), in this case you simply directly invoke the context to
|
|
23
|
-
launch the server. The default port is 8080:
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
#!/usr/bin/env python
|
|
27
|
-
import clearskies
|
|
28
|
-
|
|
29
|
-
def hello_world(name):
|
|
30
|
-
return f"Hello {name}!"
|
|
31
|
-
|
|
32
|
-
wsgi = clearskies.contexts.WsgiRef(
|
|
33
|
-
clearskies.endpoints.Callable(
|
|
34
|
-
hello_world,
|
|
35
|
-
url="/hello/:name",
|
|
36
|
-
)
|
|
37
|
-
)
|
|
38
|
-
wsgi()
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
And to invoke it:
|
|
42
|
-
|
|
43
|
-
```
|
|
44
|
-
curl 'http://localhost:8080/hello/Friend'
|
|
45
|
-
```
|
|
46
|
-
"""
|
|
47
|
-
|
|
48
|
-
port: int = 8080
|
|
49
|
-
|
|
50
|
-
def __init__(
|
|
51
|
-
self,
|
|
52
|
-
application: Callable | clearskies.endpoint.Endpoint | clearskies.endpoint_group.EndpointGroup,
|
|
53
|
-
port: int = 8080,
|
|
54
|
-
classes: type | list[type] = [],
|
|
55
|
-
modules: ModuleType | list[ModuleType] = [],
|
|
56
|
-
bindings: dict[str, Any] = {},
|
|
57
|
-
additional_configs: AdditionalConfig | list[AdditionalConfig] = [],
|
|
58
|
-
class_overrides: dict[type, type] = {},
|
|
59
|
-
overrides: dict[str, type] = {},
|
|
60
|
-
now: datetime.datetime | None = None,
|
|
61
|
-
utcnow: datetime.datetime | None = None,
|
|
62
|
-
):
|
|
63
|
-
super().__init__(
|
|
64
|
-
application,
|
|
65
|
-
classes=classes,
|
|
66
|
-
modules=modules,
|
|
67
|
-
bindings=bindings,
|
|
68
|
-
additional_configs=additional_configs,
|
|
69
|
-
class_overrides=class_overrides,
|
|
70
|
-
overrides=overrides,
|
|
71
|
-
now=now,
|
|
72
|
-
utcnow=utcnow,
|
|
73
|
-
)
|
|
74
|
-
self.port = port
|
|
75
|
-
|
|
76
|
-
def __call__(self): # type: ignore
|
|
77
|
-
with make_server("", self.port, self.handler) as httpd:
|
|
78
|
-
print(f"Starting WSGI server on port {self.port}. This is NOT intended for production usage.")
|
|
79
|
-
httpd.serve_forever()
|
|
80
|
-
|
|
81
|
-
def handler(self, environment, start_response):
|
|
82
|
-
return self.execute_application(WsgiInputOutput(environment, start_response))
|
clearskies/decorators.py
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import inspect
|
|
4
|
-
|
|
5
|
-
import wrapt # type: ignore
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@wrapt.decorator
|
|
9
|
-
def parameters_to_properties(wrapped, instance, args, kwargs):
|
|
10
|
-
if not instance:
|
|
11
|
-
raise ValueError(
|
|
12
|
-
"The parameters_to_properties decorator only works for methods in classes, not plain functions"
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
if args:
|
|
16
|
-
wrapped_args = inspect.getfullargspec(wrapped)
|
|
17
|
-
for key, value in zip(wrapped_args.args[1:], args):
|
|
18
|
-
# if it's a dictionary or a list then copy it to avoid linking data
|
|
19
|
-
if isinstance(value, dict):
|
|
20
|
-
value = {**value}
|
|
21
|
-
if isinstance(value, list):
|
|
22
|
-
value = [*value]
|
|
23
|
-
setattr(instance, key, value)
|
|
24
|
-
|
|
25
|
-
for key, value in kwargs.items():
|
|
26
|
-
# if it's a dictionary or a list then copy it to avoid linking data
|
|
27
|
-
if isinstance(value, dict):
|
|
28
|
-
value = {**value}
|
|
29
|
-
if isinstance(value, list):
|
|
30
|
-
value = [*value]
|
|
31
|
-
setattr(instance, key, value)
|
|
32
|
-
|
|
33
|
-
wrapped(*args, **kwargs)
|
clearskies/di/__init__.py
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import clearskies.di.inject as inject
|
|
2
|
-
from clearskies.di.additional_config import AdditionalConfig
|
|
3
|
-
from clearskies.di.additional_config_auto_import import AdditionalConfigAutoImport
|
|
4
|
-
from clearskies.di.di import Di
|
|
5
|
-
from clearskies.di.injectable import Injectable
|
|
6
|
-
from clearskies.di.injectable_properties import InjectableProperties
|
|
7
|
-
|
|
8
|
-
__all__ = [
|
|
9
|
-
"AdditionalConfig",
|
|
10
|
-
"AdditionalConfigAutoImport",
|
|
11
|
-
"Di",
|
|
12
|
-
"InjectableProperties",
|
|
13
|
-
"injectInjectable",
|
|
14
|
-
]
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class AdditionalConfig:
|
|
5
|
-
"""
|
|
6
|
-
This class allows you to add additional names to the Di container.
|
|
7
|
-
|
|
8
|
-
The idea here is that you extend the AdditonalConfig class and attach as many
|
|
9
|
-
`provide_*` methods to the class as you want. This allows the developer to declare a number of
|
|
10
|
-
dependencies and easily attach them to the Di container in one go - helpful for modules that
|
|
11
|
-
come with a variety of things that they want to make available to developers.
|
|
12
|
-
|
|
13
|
-
When an AdditionalConfig instance is attached to the Di container, the container (in essence) finds all the
|
|
14
|
-
`provide_*` methods in the class and registers the corresponding name in the Di container - e.g. if you have
|
|
15
|
-
a method called `provide_widget` then when a class or function requests an argument named `widget`
|
|
16
|
-
from the Di container, the container will call the `provide_widget` method on your instance and pass along
|
|
17
|
-
the return value to the thing that requested a `widget`. The `provide_*` methods can declare their own
|
|
18
|
-
dependencies, including ones declared in the same `AdditionalConfig` class (they just can't be circular, of course).
|
|
19
|
-
|
|
20
|
-
As always, keep in mind the priority of dependency injection names (see the `clearskies.di.Di` class for full
|
|
21
|
-
details). If two `AdditionalConfig` objects declare a `provide_*` method with the same name, then the Di
|
|
22
|
-
system will call the method for the `AdditionalConfig` object that was added last.
|
|
23
|
-
|
|
24
|
-
By default the Di system caches all values. If you have a dependency that shouldn't be cached, you can
|
|
25
|
-
extend the `can_cache` method and have it return True/False depending on the name and context.
|
|
26
|
-
|
|
27
|
-
Example:
|
|
28
|
-
```python
|
|
29
|
-
from clearskies.di import Di, AdditionalConfig
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class MyAdditionalConfig(AdditionalConfig):
|
|
33
|
-
def provide_inner_dependency(self):
|
|
34
|
-
return 5
|
|
35
|
-
|
|
36
|
-
def provide_important_thing(self, inner_dependency):
|
|
37
|
-
return inner_dependency * 10
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class AnotherAdditionalConfig(AdditionalConfig):
|
|
41
|
-
def provide_inner_dependency(self):
|
|
42
|
-
return 10
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
di = Di(additional_configs=[MyAdditionalConfig(), AnotherAdditionalConfig()])
|
|
46
|
-
# Equivalent:
|
|
47
|
-
# di = Di()
|
|
48
|
-
# di.add_addtional_configs([MyAdditionalConfig(), AnotherAdditionalConfig()])
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def my_function(important_thing):
|
|
52
|
-
print(important_thing) # prints 100
|
|
53
|
-
```
|
|
54
|
-
"""
|
|
55
|
-
|
|
56
|
-
def can_cache(self, name: str, di, context: str) -> bool:
|
|
57
|
-
"""
|
|
58
|
-
Cache control.
|
|
59
|
-
|
|
60
|
-
The Di container caches values by default, but this method allows you to override that.
|
|
61
|
-
After fetching an object from the AdditionalConfig class, the Di container will call this method to
|
|
62
|
-
determine whether or not to cache it. `name` will be the name of the Di value that was built, and
|
|
63
|
-
context will be the name of the class that the value was built for. You then return True/False.
|
|
64
|
-
|
|
65
|
-
Note that this controls whether or not to cache the returned value, not whether or not to check the
|
|
66
|
-
cache for a value. The importance is that, once there is a value in the cache, that will be reused
|
|
67
|
-
for all future requests for that name. Example:
|
|
68
|
-
|
|
69
|
-
```python
|
|
70
|
-
from clearskies.di import Di, AdditionalConfig
|
|
71
|
-
import secrets
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
class MyAdditionalConfig(AdditionalConfig):
|
|
75
|
-
def provide_random_number_not_cached(self):
|
|
76
|
-
return secrets.randbelow(100)
|
|
77
|
-
|
|
78
|
-
def provide_random_number_cached(self):
|
|
79
|
-
return secrets.randbelow(100)
|
|
80
|
-
|
|
81
|
-
def can_cache(self, name, context=None):
|
|
82
|
-
return name == "random_number_not_cached"
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
di = Di(additional_configs=MyAdditionalConfig())
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
def my_function(random_number_cached, random_number_not_cached):
|
|
89
|
-
print(random_number_cached)
|
|
90
|
-
print(random_number_not_cached)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
di.call_function(my_function)
|
|
94
|
-
di.call_function(my_function)
|
|
95
|
-
di.call_function(my_function)
|
|
96
|
-
di.call_function(my_function)
|
|
97
|
-
|
|
98
|
-
# This prints something like:
|
|
99
|
-
# 58
|
|
100
|
-
# 12
|
|
101
|
-
# 58
|
|
102
|
-
# 14
|
|
103
|
-
# 58
|
|
104
|
-
# 41
|
|
105
|
-
```
|
|
106
|
-
"""
|
|
107
|
-
return True
|
|
108
|
-
|
|
109
|
-
def can_build(self, name):
|
|
110
|
-
return hasattr(self, f"provide_{name}")
|
|
111
|
-
|
|
112
|
-
def build(self, name, di, context=None):
|
|
113
|
-
if not hasattr(self, f"provide_{name}"):
|
|
114
|
-
raise KeyError(
|
|
115
|
-
f"AdditionalConfig class '{self.__class__.__name__}' cannot build requested dependency, '{name}'"
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
return di.call_function(getattr(self, f"provide_{name}"))
|
|
119
|
-
|
|
120
|
-
def can_build_class(self, class_to_check: type) -> bool:
|
|
121
|
-
"""Return True/False to denote if this AdditionalConfig class can provide a given class."""
|
|
122
|
-
return False
|
|
123
|
-
|
|
124
|
-
def build_class(self, class_to_provide: type, argument_name: str, di, context: str = "") -> Any:
|
|
125
|
-
"""Return the desired instance of a given class."""
|
|
126
|
-
pass
|
|
127
|
-
|
|
128
|
-
def can_cache_class(self, class_to_build: type, di, context: str) -> bool:
|
|
129
|
-
"""Control whether or not the Di container caches the instance after building a class."""
|
|
130
|
-
return False
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
from .additional_config import AdditionalConfig
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class AdditionalConfigAutoImport(AdditionalConfig):
|
|
5
|
-
"""
|
|
6
|
-
AdditionalConfig, but now with auto import.
|
|
7
|
-
|
|
8
|
-
This works exactly like the AdditionalConfig class, but will be automatically imported into the Di
|
|
9
|
-
container if found in a module being imported into the Di container. This just provides a way for
|
|
10
|
-
modules to easily inject names into the Di system. In order to be found, an imported module
|
|
11
|
-
just needs to make sure that it imports the class that extends the AdditionalConfigAutoImport class.
|
|
12
|
-
|
|
13
|
-
Note that automatically-imported AdditionalConfig classes automatically have lower priority than
|
|
14
|
-
any AdditionalConfig classes added explicitly to the Di container.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
pass
|