python-platform 0.1.1__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.
- python_platform/__init__.py +445 -0
- python_platform/application/__init__.py +6 -0
- python_platform/application/build_spec.py +37 -0
- python_platform/application/builder.py +260 -0
- python_platform/application/composition.py +219 -0
- python_platform/application/runtime.py +546 -0
- python_platform/application/runtime_hooks.py +327 -0
- python_platform/application/state.py +216 -0
- python_platform/application_services/__init__.py +54 -0
- python_platform/application_services/catalog.py +500 -0
- python_platform/application_services/contracts.py +188 -0
- python_platform/application_services/dispatcher.py +423 -0
- python_platform/application_services/errors.py +89 -0
- python_platform/application_services/execution.py +199 -0
- python_platform/application_services/interceptors.py +44 -0
- python_platform/application_services/invocation.py +427 -0
- python_platform/application_services/policies.py +46 -0
- python_platform/application_services/seeding.py +72 -0
- python_platform/application_services/signature.py +49 -0
- python_platform/application_services/validation.py +84 -0
- python_platform/auditing/__init__.py +12 -0
- python_platform/auditing/contracts.py +39 -0
- python_platform/auditing/control.py +48 -0
- python_platform/auditing/sqlalchemy/__init__.py +6 -0
- python_platform/auditing/sqlalchemy/migrations/0001_platform_auditing.py +45 -0
- python_platform/auditing/sqlalchemy/migrations/__init__.py +1 -0
- python_platform/auditing/sqlalchemy/models.py +31 -0
- python_platform/auditing/sqlalchemy/module.py +32 -0
- python_platform/auditing/sqlalchemy/store.py +63 -0
- python_platform/authorization/__init__.py +38 -0
- python_platform/authorization/catalog.py +63 -0
- python_platform/authorization/contracts.py +241 -0
- python_platform/authorization/definition_discovery.py +81 -0
- python_platform/authorization/definitions.py +43 -0
- python_platform/authorization/errors.py +40 -0
- python_platform/background_execution/__init__.py +15 -0
- python_platform/background_execution/application.py +41 -0
- python_platform/background_execution/child.py +123 -0
- python_platform/background_execution/contracts.py +39 -0
- python_platform/background_execution/lifecycle.py +22 -0
- python_platform/background_execution/local.py +127 -0
- python_platform/background_execution/locks.py +31 -0
- python_platform/background_execution/management.py +17 -0
- python_platform/background_execution/module.py +10 -0
- python_platform/background_execution/permissions.py +14 -0
- python_platform/background_execution/processes.py +331 -0
- python_platform/background_jobs/__init__.py +31 -0
- python_platform/background_jobs/catalog.py +287 -0
- python_platform/background_jobs/contracts.py +202 -0
- python_platform/background_jobs/errors.py +28 -0
- python_platform/background_jobs/execution.py +201 -0
- python_platform/background_jobs/pgqueuer/UPSTREAM_LICENSE.txt +21 -0
- python_platform/background_jobs/pgqueuer/__init__.py +6 -0
- python_platform/background_jobs/pgqueuer/enqueue.py +82 -0
- python_platform/background_jobs/pgqueuer/migrations/0001_pgqueuer_1_3_2.py +63 -0
- python_platform/background_jobs/pgqueuer/migrations/__init__.py +1 -0
- python_platform/background_jobs/pgqueuer/module.py +102 -0
- python_platform/background_jobs/pgqueuer/options.py +70 -0
- python_platform/background_jobs/pgqueuer/runtime.py +479 -0
- python_platform/background_jobs/pgqueuer/sql/pgqueuer_1_3_2_install.sql +118 -0
- python_platform/background_jobs/pgqueuer/supervision.py +201 -0
- python_platform/background_workers/__init__.py +22 -0
- python_platform/background_workers/catalog.py +96 -0
- python_platform/background_workers/contracts.py +124 -0
- python_platform/background_workers/errors.py +20 -0
- python_platform/background_workers/execution.py +133 -0
- python_platform/background_workers/runtime.py +203 -0
- python_platform/caching/__init__.py +11 -0
- python_platform/caching/catalog.py +73 -0
- python_platform/caching/contracts.py +73 -0
- python_platform/caching/errors.py +20 -0
- python_platform/cli/__init__.py +87 -0
- python_platform/cli/errors.py +5 -0
- python_platform/cli/project.py +69 -0
- python_platform/cli/runtime.py +68 -0
- python_platform/configuration/__init__.py +21 -0
- python_platform/configuration/composition.py +65 -0
- python_platform/configuration/contracts.py +68 -0
- python_platform/configuration/dotenv_source.py +51 -0
- python_platform/configuration/environment_source.py +38 -0
- python_platform/configuration/immutability.py +124 -0
- python_platform/configuration/input_shape.py +58 -0
- python_platform/configuration/merge.py +103 -0
- python_platform/configuration/root.py +215 -0
- python_platform/configuration/sources.py +519 -0
- python_platform/configuration/values.py +427 -0
- python_platform/configuration/yaml_source.py +51 -0
- python_platform/developer_kit/__init__.py +1 -0
- python_platform/developer_kit/generation.py +182 -0
- python_platform/developer_kit/project_metadata.py +45 -0
- python_platform/developer_kit/source.py +53 -0
- python_platform/developer_kit/templates/module/cookiecutter.json +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application/cache.py.jinja +10 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application/events.py.jinja +24 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application/integration.py.jinja +46 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application/module.py.jinja +29 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application/options.py.jinja +8 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application/orders.py.jinja +81 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application/tasks.py.jinja +86 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application_contracts/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application_contracts/module.py.jinja +10 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application_contracts/orders.py.jinja +36 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain/module.py.jinja +10 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain/orders.py.jinja +57 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain/repository.py.jinja +12 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain/seeding.py.jinja +19 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain/settings.py.jinja +16 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain_shared/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain_shared/definitions.py.jinja +24 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain_shared/module.py.jinja +7 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain_shared/permissions.py.jinja +15 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/http_api/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/http_api/files.py.jinja +74 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/http_api/module.py.jinja +58 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/http_api/realtime.py.jinja +37 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/sqlalchemy/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/sqlalchemy/migrations/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/sqlalchemy/models.py.jinja +26 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/sqlalchemy/module.py.jinja +32 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/sqlalchemy/repository.py.jinja +49 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/tests/test_domain.py.jinja +18 -0
- python_platform/developer_kit/templates/project/cookiecutter.json +6 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/.dockerignore +8 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/.env.jinja +13 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/.gitignore +6 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/.python-version +1 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/Dockerfile +22 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/README.md +86 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/app.yaml.jinja +16 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/compose.dev.yaml.jinja +24 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/compose.production.yaml.jinja +13 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/pyproject.toml.jinja +28 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/src/host/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/src/host/main.py.jinja +52 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/src/host/module.py.jinja +38 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/tests/conftest.py.jinja +8 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/tests/host/test_http.py.jinja +101 -0
- python_platform/developer_kit/wiring.py +85 -0
- python_platform/diagnostics/__init__.py +23 -0
- python_platform/diagnostics/journal.py +174 -0
- python_platform/diagnostics/model.py +83 -0
- python_platform/diagnostics/source.py +25 -0
- python_platform/distributed_lock/__init__.py +6 -0
- python_platform/distributed_lock/contracts.py +20 -0
- python_platform/distributed_lock/options.py +19 -0
- python_platform/domain/__init__.py +13 -0
- python_platform/domain/aggregates.py +64 -0
- python_platform/domain/entities.py +33 -0
- python_platform/domain/errors.py +12 -0
- python_platform/domain/value_objects.py +31 -0
- python_platform/errors/__init__.py +75 -0
- python_platform/errors/base.py +13 -0
- python_platform/errors/business.py +53 -0
- python_platform/errors/configuration.py +119 -0
- python_platform/errors/diagnostics.py +12 -0
- python_platform/errors/lifecycle.py +164 -0
- python_platform/errors/modularity.py +100 -0
- python_platform/errors/services.py +100 -0
- python_platform/events/__init__.py +25 -0
- python_platform/events/aggregate.py +39 -0
- python_platform/events/catalog.py +136 -0
- python_platform/events/contracts.py +39 -0
- python_platform/events/contribution.py +128 -0
- python_platform/events/discovery.py +105 -0
- python_platform/events/errors.py +48 -0
- python_platform/events/runtime.py +192 -0
- python_platform/fastapi/__init__.py +49 -0
- python_platform/fastapi/action.py +175 -0
- python_platform/fastapi/adapter.py +381 -0
- python_platform/fastapi/application_services.py +647 -0
- python_platform/fastapi/background.py +42 -0
- python_platform/fastapi/contracts.py +278 -0
- python_platform/fastapi/errors.py +32 -0
- python_platform/fastapi/filters.py +111 -0
- python_platform/fastapi/health.py +44 -0
- python_platform/fastapi/http.py +55 -0
- python_platform/fastapi/http_router.py +212 -0
- python_platform/fastapi/manual_action.py +105 -0
- python_platform/fastapi/middleware.py +93 -0
- python_platform/fastapi/parameters.py +97 -0
- python_platform/fastapi/realtime/__init__.py +13 -0
- python_platform/fastapi/realtime/authentication.py +181 -0
- python_platform/fastapi/realtime/connection.py +166 -0
- python_platform/fastapi/realtime/module.py +41 -0
- python_platform/fastapi/realtime/options.py +50 -0
- python_platform/fastapi/realtime/runtime.py +423 -0
- python_platform/fastapi/request_context.py +244 -0
- python_platform/fastapi/route_integrity.py +88 -0
- python_platform/fastapi/routing.py +410 -0
- python_platform/fastapi/server.py +181 -0
- python_platform/fastapi/settings.py +40 -0
- python_platform/fastapi/tracing.py +62 -0
- python_platform/fastapi/transfer.py +128 -0
- python_platform/fastapi/upload_limits.py +63 -0
- python_platform/fastapi/uploads.py +94 -0
- python_platform/hosted_services/__init__.py +29 -0
- python_platform/hosted_services/bridge.py +420 -0
- python_platform/hosted_services/catalog.py +259 -0
- python_platform/hosted_services/contracts.py +55 -0
- python_platform/hosted_services/errors.py +53 -0
- python_platform/hosted_services/options.py +17 -0
- python_platform/hosted_services/runtime.py +267 -0
- python_platform/hosted_services/state.py +40 -0
- python_platform/hosting/__init__.py +4 -0
- python_platform/hosting/instance.py +40 -0
- python_platform/identity/__init__.py +73 -0
- python_platform/identity/application.py +287 -0
- python_platform/identity/contracts.py +283 -0
- python_platform/identity/errors.py +28 -0
- python_platform/identity/http_api.py +90 -0
- python_platform/identity/module.py +46 -0
- python_platform/identity/passwords.py +34 -0
- python_platform/identity/permissions.py +14 -0
- python_platform/identity/services.py +108 -0
- python_platform/identity/sqlalchemy/__init__.py +5 -0
- python_platform/identity/sqlalchemy/migrations/0001_platform_identity.py +151 -0
- python_platform/identity/sqlalchemy/migrations/0002_physical_delete.py +42 -0
- python_platform/identity/sqlalchemy/migrations/__init__.py +1 -0
- python_platform/identity/sqlalchemy/models.py +85 -0
- python_platform/identity/sqlalchemy/module.py +62 -0
- python_platform/identity/sqlalchemy/stores.py +526 -0
- python_platform/identity/tokens.py +106 -0
- python_platform/invocation/__init__.py +3 -0
- python_platform/invocation/callables.py +171 -0
- python_platform/invocation/contracts.py +33 -0
- python_platform/invocation/entries.py +54 -0
- python_platform/invocation/function_runtime.py +48 -0
- python_platform/invocation/interception.py +184 -0
- python_platform/lifecycle/__init__.py +25 -0
- python_platform/lifecycle/composition.py +35 -0
- python_platform/lifecycle/context.py +31 -0
- python_platform/lifecycle/runtime.py +43 -0
- python_platform/lifecycle/state.py +20 -0
- python_platform/modularity/__init__.py +15 -0
- python_platform/modularity/contracts.py +90 -0
- python_platform/modularity/discovery.py +143 -0
- python_platform/modularity/graph.py +334 -0
- python_platform/modularity/registry.py +100 -0
- python_platform/modularity/selection.py +16 -0
- python_platform/notifications/__init__.py +19 -0
- python_platform/notifications/catalog.py +46 -0
- python_platform/notifications/contracts.py +107 -0
- python_platform/observability/__init__.py +5 -0
- python_platform/observability/context.py +43 -0
- python_platform/observability/export.py +73 -0
- python_platform/observability/formatting.py +89 -0
- python_platform/observability/logging.py +118 -0
- python_platform/observability/options.py +45 -0
- python_platform/observability/tracing.py +80 -0
- python_platform/options/__init__.py +19 -0
- python_platform/options/aliases.py +331 -0
- python_platform/options/contribution.py +62 -0
- python_platform/options/immutability.py +48 -0
- python_platform/options/input_keys.py +214 -0
- python_platform/options/issues.py +335 -0
- python_platform/options/models.py +114 -0
- python_platform/options/registry.py +280 -0
- python_platform/options/schema.py +488 -0
- python_platform/options/validation.py +120 -0
- python_platform/py.typed +0 -0
- python_platform/realtime/__init__.py +12 -0
- python_platform/realtime/contracts.py +28 -0
- python_platform/realtime/diagnostics.py +37 -0
- python_platform/realtime/messages.py +113 -0
- python_platform/redis/__init__.py +6 -0
- python_platform/redis/distributed_lock.py +212 -0
- python_platform/redis/lease_lock.py +36 -0
- python_platform/redis/module.py +50 -0
- python_platform/redis/notification_runtime.py +182 -0
- python_platform/redis/notifications.py +25 -0
- python_platform/redis/options.py +35 -0
- python_platform/redis/runtime.py +116 -0
- python_platform/services/__init__.py +39 -0
- python_platform/services/application_bindings.py +221 -0
- python_platform/services/arbitration.py +381 -0
- python_platform/services/binding.py +102 -0
- python_platform/services/contribution.py +438 -0
- python_platform/services/convention.py +292 -0
- python_platform/services/convention_contracts.py +94 -0
- python_platform/services/exposure.py +23 -0
- python_platform/services/framework_provider.py +178 -0
- python_platform/services/native_graph.py +172 -0
- python_platform/services/provider.py +204 -0
- python_platform/services/registration.py +101 -0
- python_platform/services/runtime.py +298 -0
- python_platform/settings/__init__.py +30 -0
- python_platform/settings/application.py +95 -0
- python_platform/settings/binding.py +33 -0
- python_platform/settings/catalog.py +121 -0
- python_platform/settings/changes.py +14 -0
- python_platform/settings/contracts.py +115 -0
- python_platform/settings/definition_discovery.py +71 -0
- python_platform/settings/definitions.py +41 -0
- python_platform/settings/errors.py +22 -0
- python_platform/settings/handlers.py +43 -0
- python_platform/settings/management.py +57 -0
- python_platform/settings/manager.py +89 -0
- python_platform/settings/module.py +7 -0
- python_platform/settings/notifications.py +39 -0
- python_platform/settings/permissions.py +14 -0
- python_platform/settings/provider.py +74 -0
- python_platform/settings/refresh.py +140 -0
- python_platform/settings/refresh_module.py +45 -0
- python_platform/settings/sqlalchemy/__init__.py +5 -0
- python_platform/settings/sqlalchemy/migrations/0001_platform_settings.py +31 -0
- python_platform/settings/sqlalchemy/migrations/0002_physical_delete.py +32 -0
- python_platform/settings/sqlalchemy/migrations/0003_version_tokens.py +39 -0
- python_platform/settings/sqlalchemy/migrations/__init__.py +1 -0
- python_platform/settings/sqlalchemy/models.py +36 -0
- python_platform/settings/sqlalchemy/module.py +36 -0
- python_platform/settings/sqlalchemy/store.py +86 -0
- python_platform/settings/store.py +16 -0
- python_platform/settings/values.py +39 -0
- python_platform/sqlalchemy/__init__.py +51 -0
- python_platform/sqlalchemy/alembic_runtime/__init__.py +1 -0
- python_platform/sqlalchemy/alembic_runtime/env.py +27 -0
- python_platform/sqlalchemy/alembic_runtime/script.py.mako +14 -0
- python_platform/sqlalchemy/auditing.py +48 -0
- python_platform/sqlalchemy/errors.py +85 -0
- python_platform/sqlalchemy/metadata.py +538 -0
- python_platform/sqlalchemy/migration.py +346 -0
- python_platform/sqlalchemy/module.py +48 -0
- python_platform/sqlalchemy/module_migration.py +148 -0
- python_platform/sqlalchemy/options.py +66 -0
- python_platform/sqlalchemy/repository.py +33 -0
- python_platform/sqlalchemy/runtime.py +85 -0
- python_platform/sqlalchemy/session_provider.py +45 -0
- python_platform/sqlalchemy/unit_of_work.py +97 -0
- python_platform/testing/__init__.py +5 -0
- python_platform/testing/runtime.py +112 -0
- python_platform/unit_of_work/__init__.py +14 -0
- python_platform/unit_of_work/contracts.py +223 -0
- python_platform/unit_of_work/errors.py +27 -0
- python_platform/unit_of_work/manager.py +210 -0
- python_platform/unit_of_work/options.py +92 -0
- python_platform-0.1.1.dist-info/METADATA +122 -0
- python_platform-0.1.1.dist-info/RECORD +344 -0
- python_platform-0.1.1.dist-info/WHEEL +4 -0
- python_platform-0.1.1.dist-info/entry_points.txt +9 -0
- python_platform-0.1.1.dist-info/licenses/LICENSE +7 -0
- python_platform-0.1.1.dist-info/licenses/src/python_platform/background_jobs/pgqueuer/UPSTREAM_LICENSE.txt +21 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"""Application-owned immutable ConfigurationRoot。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable, Iterator, Mapping
|
|
6
|
+
from dataclasses import replace
|
|
7
|
+
from types import MappingProxyType
|
|
8
|
+
from typing import cast
|
|
9
|
+
|
|
10
|
+
from .contracts import (
|
|
11
|
+
ConfigurationProvenance,
|
|
12
|
+
ConfigurationSource,
|
|
13
|
+
ConfigurationSourceDiagnostic,
|
|
14
|
+
ConfigurationValueDiagnostic,
|
|
15
|
+
_SourcePayload,
|
|
16
|
+
)
|
|
17
|
+
from .values import (
|
|
18
|
+
MISSING,
|
|
19
|
+
canonical_path,
|
|
20
|
+
canonical_segment,
|
|
21
|
+
freeze_value,
|
|
22
|
+
lookup_path,
|
|
23
|
+
normalize_mapping,
|
|
24
|
+
redact_value,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class ConfigurationRoot(Mapping[str, object]):
|
|
29
|
+
"""一次 Application build 拥有的不可变配置树和来源事实。"""
|
|
30
|
+
|
|
31
|
+
__slots__ = ("_payloads", "_provenance", "_secret_paths", "_sources", "_tree")
|
|
32
|
+
|
|
33
|
+
def __init__(
|
|
34
|
+
self,
|
|
35
|
+
*,
|
|
36
|
+
tree: Mapping[str, object],
|
|
37
|
+
provenance: Mapping[tuple[str, ...], ConfigurationProvenance],
|
|
38
|
+
secret_paths: frozenset[str],
|
|
39
|
+
sources: tuple[ConfigurationSourceDiagnostic, ...],
|
|
40
|
+
payloads: tuple[_SourcePayload, ...] = (),
|
|
41
|
+
) -> None:
|
|
42
|
+
frozen_tree = freeze_value(tree)
|
|
43
|
+
if not isinstance(frozen_tree, Mapping):
|
|
44
|
+
raise TypeError("ConfigurationRoot tree must be a mapping")
|
|
45
|
+
self._tree = cast(Mapping[str, object], frozen_tree)
|
|
46
|
+
self._provenance = MappingProxyType(dict(provenance))
|
|
47
|
+
self._secret_paths = frozenset(secret_paths)
|
|
48
|
+
self._sources = tuple(sources)
|
|
49
|
+
self._payloads = payloads
|
|
50
|
+
|
|
51
|
+
def _bind_input_keys(
|
|
52
|
+
self,
|
|
53
|
+
mapping_paths: Callable[
|
|
54
|
+
[Mapping[str, object], tuple[Mapping[str, object], ...]],
|
|
55
|
+
frozenset[tuple[str | int | None, ...]],
|
|
56
|
+
],
|
|
57
|
+
*,
|
|
58
|
+
sections: frozenset[str] | None = None,
|
|
59
|
+
) -> ConfigurationRoot:
|
|
60
|
+
from ..errors import ConfigurationSourceError
|
|
61
|
+
from .merge import _ConfigurationMerger, _source_ordinal
|
|
62
|
+
|
|
63
|
+
if not self._payloads:
|
|
64
|
+
return self
|
|
65
|
+
normalized: list[_SourcePayload] = []
|
|
66
|
+
reference = tuple(
|
|
67
|
+
payload.values
|
|
68
|
+
for payload in sorted(
|
|
69
|
+
self._payloads, key=lambda item: (_source_ordinal(item.source), item.input_depth)
|
|
70
|
+
)
|
|
71
|
+
)
|
|
72
|
+
strict_paths = frozenset(canonical_path(section) for section in sections or ())
|
|
73
|
+
for payload in self._payloads:
|
|
74
|
+
values: dict[str, object] = {}
|
|
75
|
+
rejected = False
|
|
76
|
+
try:
|
|
77
|
+
for key, value in payload.values.items():
|
|
78
|
+
values.update(
|
|
79
|
+
normalize_mapping(
|
|
80
|
+
{key: value},
|
|
81
|
+
mapping_paths=mapping_paths(payload.values, reference),
|
|
82
|
+
# PreOptions 只解释已声明的完整 section,不能提前裁决其兄弟字段。
|
|
83
|
+
pending=sections is not None,
|
|
84
|
+
strict_paths=strict_paths,
|
|
85
|
+
merge_fields=payload.source
|
|
86
|
+
in (ConfigurationSource.OS_ENVIRONMENT, ConfigurationSource.DOTENV),
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
except (TypeError, ValueError):
|
|
90
|
+
rejected = True
|
|
91
|
+
if rejected:
|
|
92
|
+
# 不保留原始键或值的异常引用;来源仍是冻结快照中的正式 provenance。
|
|
93
|
+
raise ConfigurationSourceError(
|
|
94
|
+
source_id=payload.source.value,
|
|
95
|
+
location=payload.location,
|
|
96
|
+
original_error=ValueError("configuration input keys rejected"),
|
|
97
|
+
)
|
|
98
|
+
normalized.append(replace(payload, values=values))
|
|
99
|
+
result = _ConfigurationMerger().merge(
|
|
100
|
+
payloads=tuple(normalized),
|
|
101
|
+
diagnostics=self._sources,
|
|
102
|
+
secret_paths=self._secret_paths,
|
|
103
|
+
)
|
|
104
|
+
return ConfigurationRoot(
|
|
105
|
+
tree=result._tree,
|
|
106
|
+
provenance=result._provenance,
|
|
107
|
+
secret_paths=self._secret_paths,
|
|
108
|
+
sources=self._sources,
|
|
109
|
+
payloads=tuple(
|
|
110
|
+
replace(payload, values=cast(Mapping[str, object], freeze_value(payload.values)))
|
|
111
|
+
for payload in normalized
|
|
112
|
+
),
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
def _section_inputs(self, section: str) -> tuple[tuple[object, bool], ...]:
|
|
116
|
+
from .merge import _source_ordinal
|
|
117
|
+
|
|
118
|
+
layers: list[tuple[object, bool]] = []
|
|
119
|
+
for payload in sorted(
|
|
120
|
+
self._payloads, key=lambda item: (_source_ordinal(item.source), item.input_depth)
|
|
121
|
+
):
|
|
122
|
+
try:
|
|
123
|
+
value = lookup_path(payload.values, canonical_path(section))
|
|
124
|
+
except (KeyError, TypeError):
|
|
125
|
+
continue
|
|
126
|
+
layers.append(
|
|
127
|
+
(
|
|
128
|
+
value,
|
|
129
|
+
payload.source
|
|
130
|
+
in (ConfigurationSource.OS_ENVIRONMENT, ConfigurationSource.DOTENV),
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
return tuple(layers)
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def sources(self) -> tuple[ConfigurationSourceDiagnostic, ...]:
|
|
137
|
+
return self._sources
|
|
138
|
+
|
|
139
|
+
def __getitem__(self, key: str) -> object:
|
|
140
|
+
return self._tree[canonical_segment(key)]
|
|
141
|
+
|
|
142
|
+
def __iter__(self) -> Iterator[str]:
|
|
143
|
+
return iter(self._tree)
|
|
144
|
+
|
|
145
|
+
def __len__(self) -> int:
|
|
146
|
+
return len(self._tree)
|
|
147
|
+
|
|
148
|
+
def __repr__(self) -> str:
|
|
149
|
+
return f"ConfigurationRoot(keys={len(self._tree)}, sources={len(self._sources)})"
|
|
150
|
+
|
|
151
|
+
def get_path(self, path: str, default: object = MISSING) -> object:
|
|
152
|
+
try:
|
|
153
|
+
value = lookup_path(self._tree, canonical_path(path))
|
|
154
|
+
except (KeyError, TypeError, ValueError):
|
|
155
|
+
if default is not MISSING:
|
|
156
|
+
return default
|
|
157
|
+
raise KeyError(path) from None
|
|
158
|
+
return value
|
|
159
|
+
|
|
160
|
+
def provenance(self, path: str) -> ConfigurationProvenance:
|
|
161
|
+
return self._provenance_at(canonical_path(path))
|
|
162
|
+
|
|
163
|
+
def _provenance_at(self, path: tuple[str, ...]) -> ConfigurationProvenance:
|
|
164
|
+
return self._provenance[path]
|
|
165
|
+
|
|
166
|
+
def diagnostic(self, path: str) -> ConfigurationValueDiagnostic:
|
|
167
|
+
canonical_parts = canonical_path(path)
|
|
168
|
+
canonical = ".".join(canonical_parts)
|
|
169
|
+
value, redacted = redact_value(
|
|
170
|
+
self.get_path(canonical),
|
|
171
|
+
path=canonical_parts,
|
|
172
|
+
secret_paths=self._secret_paths,
|
|
173
|
+
)
|
|
174
|
+
return ConfigurationValueDiagnostic(
|
|
175
|
+
path=canonical,
|
|
176
|
+
value=value,
|
|
177
|
+
redacted=redacted,
|
|
178
|
+
provenance=self.provenance(canonical),
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
def _finalize(
|
|
182
|
+
self,
|
|
183
|
+
*,
|
|
184
|
+
sections: frozenset[str],
|
|
185
|
+
secret_paths: frozenset[str],
|
|
186
|
+
mapping_paths: Callable[
|
|
187
|
+
[Mapping[str, object], tuple[Mapping[str, object], ...]],
|
|
188
|
+
frozenset[tuple[str | int | None, ...]],
|
|
189
|
+
],
|
|
190
|
+
) -> ConfigurationRoot:
|
|
191
|
+
from ..errors import ConfigurationSourceError
|
|
192
|
+
|
|
193
|
+
resolved = self._bind_input_keys(mapping_paths)
|
|
194
|
+
known = {canonical_path(section)[0] for section in sections}
|
|
195
|
+
external = {
|
|
196
|
+
ConfigurationSource.DOTENV,
|
|
197
|
+
ConfigurationSource.OS_ENVIRONMENT,
|
|
198
|
+
ConfigurationSource.CLI,
|
|
199
|
+
}
|
|
200
|
+
for key in self:
|
|
201
|
+
chain = self.provenance(key).chain
|
|
202
|
+
if key not in known and all(item.source_id in external for item in chain):
|
|
203
|
+
source = chain[-1]
|
|
204
|
+
raise ConfigurationSourceError(
|
|
205
|
+
source_id=source.source_id.value,
|
|
206
|
+
location=source.source_location,
|
|
207
|
+
original_error=ValueError("unknown configuration section"),
|
|
208
|
+
)
|
|
209
|
+
# 旧 context 保留保守脱敏视图;只发布新的诊断视图,不重读或改变配置值。
|
|
210
|
+
return ConfigurationRoot(
|
|
211
|
+
tree=resolved._tree,
|
|
212
|
+
provenance=resolved._provenance,
|
|
213
|
+
secret_paths=secret_paths,
|
|
214
|
+
sources=self._sources,
|
|
215
|
+
)
|