prefect-client 2.19.3__py3-none-any.whl → 3.0.0rc1__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.
- prefect/__init__.py +8 -56
- prefect/_internal/compatibility/deprecated.py +6 -115
- prefect/_internal/compatibility/experimental.py +4 -79
- prefect/_internal/concurrency/api.py +0 -34
- prefect/_internal/concurrency/calls.py +0 -6
- prefect/_internal/concurrency/cancellation.py +0 -3
- prefect/_internal/concurrency/event_loop.py +0 -20
- prefect/_internal/concurrency/inspection.py +3 -3
- prefect/_internal/concurrency/threads.py +35 -0
- prefect/_internal/concurrency/waiters.py +0 -28
- prefect/_internal/pydantic/__init__.py +0 -45
- prefect/_internal/pydantic/v1_schema.py +21 -22
- prefect/_internal/pydantic/v2_schema.py +0 -2
- prefect/_internal/pydantic/v2_validated_func.py +18 -23
- prefect/_internal/schemas/bases.py +44 -177
- prefect/_internal/schemas/fields.py +1 -43
- prefect/_internal/schemas/validators.py +60 -158
- prefect/artifacts.py +161 -14
- prefect/automations.py +39 -4
- prefect/blocks/abstract.py +1 -1
- prefect/blocks/core.py +268 -148
- prefect/blocks/fields.py +2 -57
- prefect/blocks/kubernetes.py +8 -12
- prefect/blocks/notifications.py +40 -20
- prefect/blocks/system.py +22 -11
- prefect/blocks/webhook.py +2 -9
- prefect/client/base.py +4 -4
- prefect/client/cloud.py +8 -13
- prefect/client/orchestration.py +347 -341
- prefect/client/schemas/actions.py +92 -86
- prefect/client/schemas/filters.py +20 -40
- prefect/client/schemas/objects.py +147 -145
- prefect/client/schemas/responses.py +16 -24
- prefect/client/schemas/schedules.py +47 -35
- prefect/client/subscriptions.py +2 -2
- prefect/client/utilities.py +5 -2
- prefect/concurrency/asyncio.py +3 -1
- prefect/concurrency/events.py +1 -1
- prefect/concurrency/services.py +6 -3
- prefect/context.py +195 -27
- prefect/deployments/__init__.py +5 -6
- prefect/deployments/base.py +7 -5
- prefect/deployments/flow_runs.py +185 -0
- prefect/deployments/runner.py +50 -45
- prefect/deployments/schedules.py +28 -23
- prefect/deployments/steps/__init__.py +0 -1
- prefect/deployments/steps/core.py +1 -0
- prefect/deployments/steps/pull.py +7 -21
- prefect/engine.py +12 -2422
- prefect/events/actions.py +17 -23
- prefect/events/cli/automations.py +19 -6
- prefect/events/clients.py +14 -37
- prefect/events/filters.py +14 -18
- prefect/events/related.py +2 -2
- prefect/events/schemas/__init__.py +0 -5
- prefect/events/schemas/automations.py +55 -46
- prefect/events/schemas/deployment_triggers.py +7 -197
- prefect/events/schemas/events.py +34 -65
- prefect/events/schemas/labelling.py +10 -14
- prefect/events/utilities.py +2 -3
- prefect/events/worker.py +2 -3
- prefect/filesystems.py +6 -517
- prefect/{new_flow_engine.py → flow_engine.py} +313 -72
- prefect/flow_runs.py +377 -5
- prefect/flows.py +248 -165
- prefect/futures.py +186 -345
- prefect/infrastructure/__init__.py +0 -27
- prefect/infrastructure/provisioners/__init__.py +5 -3
- prefect/infrastructure/provisioners/cloud_run.py +11 -6
- prefect/infrastructure/provisioners/container_instance.py +11 -7
- prefect/infrastructure/provisioners/ecs.py +6 -4
- prefect/infrastructure/provisioners/modal.py +8 -5
- prefect/input/actions.py +2 -4
- prefect/input/run_input.py +5 -7
- prefect/logging/formatters.py +0 -2
- prefect/logging/handlers.py +3 -11
- prefect/logging/loggers.py +2 -2
- prefect/manifests.py +2 -1
- prefect/records/__init__.py +1 -0
- prefect/records/result_store.py +42 -0
- prefect/records/store.py +9 -0
- prefect/results.py +43 -39
- prefect/runner/runner.py +9 -9
- prefect/runner/server.py +6 -10
- prefect/runner/storage.py +3 -8
- prefect/runner/submit.py +2 -2
- prefect/runner/utils.py +2 -2
- prefect/serializers.py +24 -35
- prefect/server/api/collections_data/views/aggregate-worker-metadata.json +5 -14
- prefect/settings.py +70 -133
- prefect/states.py +17 -47
- prefect/task_engine.py +697 -58
- prefect/task_runners.py +269 -301
- prefect/task_server.py +53 -34
- prefect/tasks.py +327 -337
- prefect/transactions.py +220 -0
- prefect/types/__init__.py +61 -82
- prefect/utilities/asyncutils.py +195 -136
- prefect/utilities/callables.py +121 -41
- prefect/utilities/collections.py +23 -38
- prefect/utilities/dispatch.py +11 -3
- prefect/utilities/dockerutils.py +4 -0
- prefect/utilities/engine.py +140 -20
- prefect/utilities/importtools.py +26 -27
- prefect/utilities/pydantic.py +128 -38
- prefect/utilities/schema_tools/hydration.py +5 -1
- prefect/utilities/templating.py +12 -2
- prefect/variables.py +78 -61
- prefect/workers/__init__.py +0 -1
- prefect/workers/base.py +15 -17
- prefect/workers/process.py +3 -8
- prefect/workers/server.py +2 -2
- {prefect_client-2.19.3.dist-info → prefect_client-3.0.0rc1.dist-info}/METADATA +22 -21
- prefect_client-3.0.0rc1.dist-info/RECORD +176 -0
- prefect/_internal/pydantic/_base_model.py +0 -51
- prefect/_internal/pydantic/_compat.py +0 -82
- prefect/_internal/pydantic/_flags.py +0 -20
- prefect/_internal/pydantic/_types.py +0 -8
- prefect/_internal/pydantic/utilities/__init__.py +0 -0
- prefect/_internal/pydantic/utilities/config_dict.py +0 -72
- prefect/_internal/pydantic/utilities/field_validator.py +0 -150
- prefect/_internal/pydantic/utilities/model_construct.py +0 -56
- prefect/_internal/pydantic/utilities/model_copy.py +0 -55
- prefect/_internal/pydantic/utilities/model_dump.py +0 -136
- prefect/_internal/pydantic/utilities/model_dump_json.py +0 -112
- prefect/_internal/pydantic/utilities/model_fields.py +0 -50
- prefect/_internal/pydantic/utilities/model_fields_set.py +0 -29
- prefect/_internal/pydantic/utilities/model_json_schema.py +0 -82
- prefect/_internal/pydantic/utilities/model_rebuild.py +0 -80
- prefect/_internal/pydantic/utilities/model_validate.py +0 -75
- prefect/_internal/pydantic/utilities/model_validate_json.py +0 -68
- prefect/_internal/pydantic/utilities/model_validator.py +0 -87
- prefect/_internal/pydantic/utilities/type_adapter.py +0 -71
- prefect/_vendor/__init__.py +0 -0
- prefect/_vendor/fastapi/__init__.py +0 -25
- prefect/_vendor/fastapi/applications.py +0 -946
- prefect/_vendor/fastapi/background.py +0 -3
- prefect/_vendor/fastapi/concurrency.py +0 -44
- prefect/_vendor/fastapi/datastructures.py +0 -58
- prefect/_vendor/fastapi/dependencies/__init__.py +0 -0
- prefect/_vendor/fastapi/dependencies/models.py +0 -64
- prefect/_vendor/fastapi/dependencies/utils.py +0 -877
- prefect/_vendor/fastapi/encoders.py +0 -177
- prefect/_vendor/fastapi/exception_handlers.py +0 -40
- prefect/_vendor/fastapi/exceptions.py +0 -46
- prefect/_vendor/fastapi/logger.py +0 -3
- prefect/_vendor/fastapi/middleware/__init__.py +0 -1
- prefect/_vendor/fastapi/middleware/asyncexitstack.py +0 -25
- prefect/_vendor/fastapi/middleware/cors.py +0 -3
- prefect/_vendor/fastapi/middleware/gzip.py +0 -3
- prefect/_vendor/fastapi/middleware/httpsredirect.py +0 -3
- prefect/_vendor/fastapi/middleware/trustedhost.py +0 -3
- prefect/_vendor/fastapi/middleware/wsgi.py +0 -3
- prefect/_vendor/fastapi/openapi/__init__.py +0 -0
- prefect/_vendor/fastapi/openapi/constants.py +0 -2
- prefect/_vendor/fastapi/openapi/docs.py +0 -203
- prefect/_vendor/fastapi/openapi/models.py +0 -480
- prefect/_vendor/fastapi/openapi/utils.py +0 -485
- prefect/_vendor/fastapi/param_functions.py +0 -340
- prefect/_vendor/fastapi/params.py +0 -453
- prefect/_vendor/fastapi/requests.py +0 -4
- prefect/_vendor/fastapi/responses.py +0 -40
- prefect/_vendor/fastapi/routing.py +0 -1331
- prefect/_vendor/fastapi/security/__init__.py +0 -15
- prefect/_vendor/fastapi/security/api_key.py +0 -98
- prefect/_vendor/fastapi/security/base.py +0 -6
- prefect/_vendor/fastapi/security/http.py +0 -172
- prefect/_vendor/fastapi/security/oauth2.py +0 -227
- prefect/_vendor/fastapi/security/open_id_connect_url.py +0 -34
- prefect/_vendor/fastapi/security/utils.py +0 -10
- prefect/_vendor/fastapi/staticfiles.py +0 -1
- prefect/_vendor/fastapi/templating.py +0 -3
- prefect/_vendor/fastapi/testclient.py +0 -1
- prefect/_vendor/fastapi/types.py +0 -3
- prefect/_vendor/fastapi/utils.py +0 -235
- prefect/_vendor/fastapi/websockets.py +0 -7
- prefect/_vendor/starlette/__init__.py +0 -1
- prefect/_vendor/starlette/_compat.py +0 -28
- prefect/_vendor/starlette/_exception_handler.py +0 -80
- prefect/_vendor/starlette/_utils.py +0 -88
- prefect/_vendor/starlette/applications.py +0 -261
- prefect/_vendor/starlette/authentication.py +0 -159
- prefect/_vendor/starlette/background.py +0 -43
- prefect/_vendor/starlette/concurrency.py +0 -59
- prefect/_vendor/starlette/config.py +0 -151
- prefect/_vendor/starlette/convertors.py +0 -87
- prefect/_vendor/starlette/datastructures.py +0 -707
- prefect/_vendor/starlette/endpoints.py +0 -130
- prefect/_vendor/starlette/exceptions.py +0 -60
- prefect/_vendor/starlette/formparsers.py +0 -276
- prefect/_vendor/starlette/middleware/__init__.py +0 -17
- prefect/_vendor/starlette/middleware/authentication.py +0 -52
- prefect/_vendor/starlette/middleware/base.py +0 -220
- prefect/_vendor/starlette/middleware/cors.py +0 -176
- prefect/_vendor/starlette/middleware/errors.py +0 -265
- prefect/_vendor/starlette/middleware/exceptions.py +0 -74
- prefect/_vendor/starlette/middleware/gzip.py +0 -113
- prefect/_vendor/starlette/middleware/httpsredirect.py +0 -19
- prefect/_vendor/starlette/middleware/sessions.py +0 -82
- prefect/_vendor/starlette/middleware/trustedhost.py +0 -64
- prefect/_vendor/starlette/middleware/wsgi.py +0 -147
- prefect/_vendor/starlette/requests.py +0 -328
- prefect/_vendor/starlette/responses.py +0 -347
- prefect/_vendor/starlette/routing.py +0 -933
- prefect/_vendor/starlette/schemas.py +0 -154
- prefect/_vendor/starlette/staticfiles.py +0 -248
- prefect/_vendor/starlette/status.py +0 -199
- prefect/_vendor/starlette/templating.py +0 -231
- prefect/_vendor/starlette/testclient.py +0 -804
- prefect/_vendor/starlette/types.py +0 -30
- prefect/_vendor/starlette/websockets.py +0 -193
- prefect/agent.py +0 -698
- prefect/deployments/deployments.py +0 -1042
- prefect/deprecated/__init__.py +0 -0
- prefect/deprecated/data_documents.py +0 -350
- prefect/deprecated/packaging/__init__.py +0 -12
- prefect/deprecated/packaging/base.py +0 -96
- prefect/deprecated/packaging/docker.py +0 -146
- prefect/deprecated/packaging/file.py +0 -92
- prefect/deprecated/packaging/orion.py +0 -80
- prefect/deprecated/packaging/serializers.py +0 -171
- prefect/events/instrument.py +0 -135
- prefect/infrastructure/base.py +0 -323
- prefect/infrastructure/container.py +0 -818
- prefect/infrastructure/kubernetes.py +0 -920
- prefect/infrastructure/process.py +0 -289
- prefect/new_task_engine.py +0 -423
- prefect/pydantic/__init__.py +0 -76
- prefect/pydantic/main.py +0 -39
- prefect/software/__init__.py +0 -2
- prefect/software/base.py +0 -50
- prefect/software/conda.py +0 -199
- prefect/software/pip.py +0 -122
- prefect/software/python.py +0 -52
- prefect/workers/block.py +0 -218
- prefect_client-2.19.3.dist-info/RECORD +0 -292
- {prefect_client-2.19.3.dist-info → prefect_client-3.0.0rc1.dist-info}/LICENSE +0 -0
- {prefect_client-2.19.3.dist-info → prefect_client-3.0.0rc1.dist-info}/WHEEL +0 -0
- {prefect_client-2.19.3.dist-info → prefect_client-3.0.0rc1.dist-info}/top_level.txt +0 -0
prefect/_vendor/fastapi/utils.py
DELETED
@@ -1,235 +0,0 @@
|
|
1
|
-
import re
|
2
|
-
import warnings
|
3
|
-
from dataclasses import is_dataclass
|
4
|
-
from enum import Enum
|
5
|
-
from typing import (
|
6
|
-
TYPE_CHECKING,
|
7
|
-
Any,
|
8
|
-
Dict,
|
9
|
-
MutableMapping,
|
10
|
-
Optional,
|
11
|
-
Set,
|
12
|
-
Type,
|
13
|
-
Union,
|
14
|
-
cast,
|
15
|
-
)
|
16
|
-
from weakref import WeakKeyDictionary
|
17
|
-
|
18
|
-
from prefect._vendor.fastapi.datastructures import DefaultPlaceholder, DefaultType
|
19
|
-
from prefect._vendor.fastapi.exceptions import FastAPIError
|
20
|
-
from prefect._vendor.fastapi.openapi.constants import REF_PREFIX
|
21
|
-
|
22
|
-
from prefect._internal.pydantic import HAS_PYDANTIC_V2
|
23
|
-
|
24
|
-
if HAS_PYDANTIC_V2:
|
25
|
-
from pydantic.v1 import BaseConfig, BaseModel, create_model
|
26
|
-
from pydantic.v1.class_validators import Validator
|
27
|
-
from pydantic.v1.fields import FieldInfo, ModelField, UndefinedType
|
28
|
-
from pydantic.v1.schema import model_process_schema
|
29
|
-
from pydantic.v1.utils import lenient_issubclass
|
30
|
-
else:
|
31
|
-
from pydantic import BaseConfig, BaseModel, create_model
|
32
|
-
from pydantic.class_validators import Validator
|
33
|
-
from pydantic.fields import FieldInfo, ModelField, UndefinedType
|
34
|
-
from pydantic.schema import model_process_schema
|
35
|
-
from pydantic.utils import lenient_issubclass
|
36
|
-
|
37
|
-
|
38
|
-
if TYPE_CHECKING: # pragma: nocover
|
39
|
-
from .routing import APIRoute
|
40
|
-
|
41
|
-
# Cache for `create_cloned_field`
|
42
|
-
_CLONED_TYPES_CACHE: MutableMapping[
|
43
|
-
Type[BaseModel], Type[BaseModel]
|
44
|
-
] = WeakKeyDictionary()
|
45
|
-
|
46
|
-
|
47
|
-
def is_body_allowed_for_status_code(status_code: Union[int, str, None]) -> bool:
|
48
|
-
if status_code is None:
|
49
|
-
return True
|
50
|
-
# Ref: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#patterned-fields-1
|
51
|
-
if status_code in {
|
52
|
-
"default",
|
53
|
-
"1XX",
|
54
|
-
"2XX",
|
55
|
-
"3XX",
|
56
|
-
"4XX",
|
57
|
-
"5XX",
|
58
|
-
}:
|
59
|
-
return True
|
60
|
-
current_status_code = int(status_code)
|
61
|
-
return not (current_status_code < 200 or current_status_code in {204, 304})
|
62
|
-
|
63
|
-
|
64
|
-
def get_model_definitions(
|
65
|
-
*,
|
66
|
-
flat_models: Set[Union[Type[BaseModel], Type[Enum]]],
|
67
|
-
model_name_map: Dict[Union[Type[BaseModel], Type[Enum]], str],
|
68
|
-
) -> Dict[str, Any]:
|
69
|
-
definitions: Dict[str, Dict[str, Any]] = {}
|
70
|
-
for model in flat_models:
|
71
|
-
m_schema, m_definitions, m_nested_models = model_process_schema(
|
72
|
-
model, model_name_map=model_name_map, ref_prefix=REF_PREFIX
|
73
|
-
)
|
74
|
-
definitions.update(m_definitions)
|
75
|
-
model_name = model_name_map[model]
|
76
|
-
if "description" in m_schema:
|
77
|
-
m_schema["description"] = m_schema["description"].split("\f")[0]
|
78
|
-
definitions[model_name] = m_schema
|
79
|
-
return definitions
|
80
|
-
|
81
|
-
|
82
|
-
def get_path_param_names(path: str) -> Set[str]:
|
83
|
-
return set(re.findall("{(.*?)}", path))
|
84
|
-
|
85
|
-
|
86
|
-
def create_response_field(
|
87
|
-
name: str,
|
88
|
-
type_: Type[Any],
|
89
|
-
class_validators: Optional[Dict[str, Validator]] = None,
|
90
|
-
default: Optional[Any] = None,
|
91
|
-
required: Union[bool, UndefinedType] = True,
|
92
|
-
model_config: Type[BaseConfig] = BaseConfig,
|
93
|
-
field_info: Optional[FieldInfo] = None,
|
94
|
-
alias: Optional[str] = None,
|
95
|
-
) -> ModelField:
|
96
|
-
"""
|
97
|
-
Create a new response field. Raises if type_ is invalid.
|
98
|
-
"""
|
99
|
-
class_validators = class_validators or {}
|
100
|
-
field_info = field_info or FieldInfo()
|
101
|
-
|
102
|
-
try:
|
103
|
-
return ModelField(
|
104
|
-
name=name,
|
105
|
-
type_=type_,
|
106
|
-
class_validators=class_validators,
|
107
|
-
default=default,
|
108
|
-
required=required,
|
109
|
-
model_config=model_config,
|
110
|
-
alias=alias,
|
111
|
-
field_info=field_info,
|
112
|
-
)
|
113
|
-
except RuntimeError:
|
114
|
-
raise FastAPIError(
|
115
|
-
"Invalid args for response field! Hint: "
|
116
|
-
f"check that {type_} is a valid Pydantic field type. "
|
117
|
-
"If you are using a return type annotation that is not a valid Pydantic "
|
118
|
-
"field (e.g. Union[Response, dict, None]) you can disable generating the "
|
119
|
-
"response model from the type annotation with the path operation decorator "
|
120
|
-
"parameter response_model=None. Read more: "
|
121
|
-
"https://fastapi.tiangolo.com/tutorial/response-model/"
|
122
|
-
) from None
|
123
|
-
|
124
|
-
|
125
|
-
def create_cloned_field(
|
126
|
-
field: ModelField,
|
127
|
-
*,
|
128
|
-
cloned_types: Optional[MutableMapping[Type[BaseModel], Type[BaseModel]]] = None,
|
129
|
-
) -> ModelField:
|
130
|
-
# cloned_types caches already cloned types to support recursive models and improve
|
131
|
-
# performance by avoiding unecessary cloning
|
132
|
-
if cloned_types is None:
|
133
|
-
cloned_types = _CLONED_TYPES_CACHE
|
134
|
-
|
135
|
-
original_type = field.type_
|
136
|
-
if is_dataclass(original_type) and hasattr(original_type, "__pydantic_model__"):
|
137
|
-
original_type = original_type.__pydantic_model__
|
138
|
-
use_type = original_type
|
139
|
-
if lenient_issubclass(original_type, BaseModel):
|
140
|
-
original_type = cast(Type[BaseModel], original_type)
|
141
|
-
use_type = cloned_types.get(original_type)
|
142
|
-
if use_type is None:
|
143
|
-
use_type = create_model(original_type.__name__, __base__=original_type)
|
144
|
-
cloned_types[original_type] = use_type
|
145
|
-
for f in original_type.__fields__.values():
|
146
|
-
use_type.__fields__[f.name] = create_cloned_field(
|
147
|
-
f, cloned_types=cloned_types
|
148
|
-
)
|
149
|
-
new_field = create_response_field(name=field.name, type_=use_type)
|
150
|
-
new_field.has_alias = field.has_alias
|
151
|
-
new_field.alias = field.alias
|
152
|
-
new_field.class_validators = field.class_validators
|
153
|
-
new_field.default = field.default
|
154
|
-
new_field.required = field.required
|
155
|
-
new_field.model_config = field.model_config
|
156
|
-
new_field.field_info = field.field_info
|
157
|
-
new_field.allow_none = field.allow_none
|
158
|
-
new_field.validate_always = field.validate_always
|
159
|
-
if field.sub_fields:
|
160
|
-
new_field.sub_fields = [
|
161
|
-
create_cloned_field(sub_field, cloned_types=cloned_types)
|
162
|
-
for sub_field in field.sub_fields
|
163
|
-
]
|
164
|
-
if field.key_field:
|
165
|
-
new_field.key_field = create_cloned_field(
|
166
|
-
field.key_field, cloned_types=cloned_types
|
167
|
-
)
|
168
|
-
new_field.validators = field.validators
|
169
|
-
new_field.pre_validators = field.pre_validators
|
170
|
-
new_field.post_validators = field.post_validators
|
171
|
-
new_field.parse_json = field.parse_json
|
172
|
-
new_field.shape = field.shape
|
173
|
-
new_field.populate_validators()
|
174
|
-
return new_field
|
175
|
-
|
176
|
-
|
177
|
-
def generate_operation_id_for_path(
|
178
|
-
*, name: str, path: str, method: str
|
179
|
-
) -> str: # pragma: nocover
|
180
|
-
warnings.warn(
|
181
|
-
(
|
182
|
-
"fastapi.utils.generate_operation_id_for_path() was deprecated, "
|
183
|
-
"it is not used internally, and will be removed soon"
|
184
|
-
),
|
185
|
-
DeprecationWarning,
|
186
|
-
stacklevel=2,
|
187
|
-
)
|
188
|
-
operation_id = name + path
|
189
|
-
operation_id = re.sub(r"\W", "_", operation_id)
|
190
|
-
operation_id = operation_id + "_" + method.lower()
|
191
|
-
return operation_id
|
192
|
-
|
193
|
-
|
194
|
-
def generate_unique_id(route: "APIRoute") -> str:
|
195
|
-
operation_id = route.name + route.path_format
|
196
|
-
operation_id = re.sub(r"\W", "_", operation_id)
|
197
|
-
assert route.methods
|
198
|
-
operation_id = operation_id + "_" + list(route.methods)[0].lower()
|
199
|
-
return operation_id
|
200
|
-
|
201
|
-
|
202
|
-
def deep_dict_update(main_dict: Dict[Any, Any], update_dict: Dict[Any, Any]) -> None:
|
203
|
-
for key, value in update_dict.items():
|
204
|
-
if (
|
205
|
-
key in main_dict
|
206
|
-
and isinstance(main_dict[key], dict)
|
207
|
-
and isinstance(value, dict)
|
208
|
-
):
|
209
|
-
deep_dict_update(main_dict[key], value)
|
210
|
-
elif (
|
211
|
-
key in main_dict
|
212
|
-
and isinstance(main_dict[key], list)
|
213
|
-
and isinstance(update_dict[key], list)
|
214
|
-
):
|
215
|
-
main_dict[key] = main_dict[key] + update_dict[key]
|
216
|
-
else:
|
217
|
-
main_dict[key] = value
|
218
|
-
|
219
|
-
|
220
|
-
def get_value_or_default(
|
221
|
-
first_item: Union[DefaultPlaceholder, DefaultType],
|
222
|
-
*extra_items: Union[DefaultPlaceholder, DefaultType],
|
223
|
-
) -> Union[DefaultPlaceholder, DefaultType]:
|
224
|
-
"""
|
225
|
-
Pass items or `DefaultPlaceholder`s by descending priority.
|
226
|
-
|
227
|
-
The first one to _not_ be a `DefaultPlaceholder` will be returned.
|
228
|
-
|
229
|
-
Otherwise, the first item (a `DefaultPlaceholder`) will be returned.
|
230
|
-
"""
|
231
|
-
items = (first_item,) + extra_items
|
232
|
-
for item in items:
|
233
|
-
if not isinstance(item, DefaultPlaceholder):
|
234
|
-
return item
|
235
|
-
return first_item
|
@@ -1,7 +0,0 @@
|
|
1
|
-
from prefect._vendor.starlette.websockets import WebSocket as WebSocket # noqa
|
2
|
-
from prefect._vendor.starlette.websockets import (
|
3
|
-
WebSocketDisconnect as WebSocketDisconnect,
|
4
|
-
) # noqa
|
5
|
-
from prefect._vendor.starlette.websockets import (
|
6
|
-
WebSocketState as WebSocketState,
|
7
|
-
) # noqa
|
@@ -1 +0,0 @@
|
|
1
|
-
__version__ = "0.33.0"
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import hashlib
|
2
|
-
|
3
|
-
# Compat wrapper to always include the `usedforsecurity=...` parameter,
|
4
|
-
# which is only added from Python 3.9 onwards.
|
5
|
-
# We use this flag to indicate that we use `md5` hashes only for non-security
|
6
|
-
# cases (our ETag checksums).
|
7
|
-
# If we don't indicate that we're using MD5 for non-security related reasons,
|
8
|
-
# then attempting to use this function will raise an error when used
|
9
|
-
# environments which enable a strict "FIPs mode".
|
10
|
-
#
|
11
|
-
# See issue: https://github.com/encode/starlette/issues/1365
|
12
|
-
try:
|
13
|
-
# check if the Python version supports the parameter
|
14
|
-
# using usedforsecurity=False to avoid an exception on FIPS systems
|
15
|
-
# that reject usedforsecurity=True
|
16
|
-
hashlib.md5(b"data", usedforsecurity=False) # type: ignore[call-arg]
|
17
|
-
|
18
|
-
def md5_hexdigest(
|
19
|
-
data: bytes, *, usedforsecurity: bool = True
|
20
|
-
) -> str: # pragma: no cover
|
21
|
-
return hashlib.md5( # type: ignore[call-arg]
|
22
|
-
data, usedforsecurity=usedforsecurity
|
23
|
-
).hexdigest()
|
24
|
-
|
25
|
-
except TypeError: # pragma: no cover
|
26
|
-
|
27
|
-
def md5_hexdigest(data: bytes, *, usedforsecurity: bool = True) -> str:
|
28
|
-
return hashlib.md5(data).hexdigest()
|
@@ -1,80 +0,0 @@
|
|
1
|
-
import typing
|
2
|
-
|
3
|
-
from prefect._vendor.starlette._utils import is_async_callable
|
4
|
-
from prefect._vendor.starlette.concurrency import run_in_threadpool
|
5
|
-
from prefect._vendor.starlette.exceptions import HTTPException
|
6
|
-
from prefect._vendor.starlette.requests import Request
|
7
|
-
from prefect._vendor.starlette.types import (
|
8
|
-
ASGIApp,
|
9
|
-
ExceptionHandler,
|
10
|
-
Message,
|
11
|
-
Receive,
|
12
|
-
Scope,
|
13
|
-
Send,
|
14
|
-
)
|
15
|
-
from prefect._vendor.starlette.websockets import WebSocket
|
16
|
-
|
17
|
-
ExceptionHandlers = typing.Dict[typing.Any, ExceptionHandler]
|
18
|
-
StatusHandlers = typing.Dict[int, ExceptionHandler]
|
19
|
-
|
20
|
-
|
21
|
-
def _lookup_exception_handler(
|
22
|
-
exc_handlers: ExceptionHandlers, exc: Exception
|
23
|
-
) -> typing.Optional[ExceptionHandler]:
|
24
|
-
for cls in type(exc).__mro__:
|
25
|
-
if cls in exc_handlers:
|
26
|
-
return exc_handlers[cls]
|
27
|
-
return None
|
28
|
-
|
29
|
-
|
30
|
-
def wrap_app_handling_exceptions(
|
31
|
-
app: ASGIApp, conn: typing.Union[Request, WebSocket]
|
32
|
-
) -> ASGIApp:
|
33
|
-
exception_handlers: ExceptionHandlers
|
34
|
-
status_handlers: StatusHandlers
|
35
|
-
try:
|
36
|
-
exception_handlers, status_handlers = conn.scope["starlette.exception_handlers"]
|
37
|
-
except KeyError:
|
38
|
-
exception_handlers, status_handlers = {}, {}
|
39
|
-
|
40
|
-
async def wrapped_app(scope: Scope, receive: Receive, send: Send) -> None:
|
41
|
-
response_started = False
|
42
|
-
|
43
|
-
async def sender(message: Message) -> None:
|
44
|
-
nonlocal response_started
|
45
|
-
|
46
|
-
if message["type"] == "http.response.start":
|
47
|
-
response_started = True
|
48
|
-
await send(message)
|
49
|
-
|
50
|
-
try:
|
51
|
-
await app(scope, receive, sender)
|
52
|
-
except Exception as exc:
|
53
|
-
handler = None
|
54
|
-
|
55
|
-
if isinstance(exc, HTTPException):
|
56
|
-
handler = status_handlers.get(exc.status_code)
|
57
|
-
|
58
|
-
if handler is None:
|
59
|
-
handler = _lookup_exception_handler(exception_handlers, exc)
|
60
|
-
|
61
|
-
if handler is None:
|
62
|
-
raise exc
|
63
|
-
|
64
|
-
if response_started:
|
65
|
-
msg = "Caught handled exception, but response already started."
|
66
|
-
raise RuntimeError(msg) from exc
|
67
|
-
|
68
|
-
if scope["type"] == "http":
|
69
|
-
if is_async_callable(handler):
|
70
|
-
response = await handler(conn, exc)
|
71
|
-
else:
|
72
|
-
response = await run_in_threadpool(handler, conn, exc)
|
73
|
-
await response(scope, receive, sender)
|
74
|
-
elif scope["type"] == "websocket":
|
75
|
-
if is_async_callable(handler):
|
76
|
-
await handler(conn, exc)
|
77
|
-
else:
|
78
|
-
await run_in_threadpool(handler, conn, exc)
|
79
|
-
|
80
|
-
return wrapped_app
|
@@ -1,88 +0,0 @@
|
|
1
|
-
import asyncio
|
2
|
-
import functools
|
3
|
-
import sys
|
4
|
-
import typing
|
5
|
-
from contextlib import contextmanager
|
6
|
-
|
7
|
-
if sys.version_info >= (3, 10): # pragma: no cover
|
8
|
-
from typing import TypeGuard
|
9
|
-
else: # pragma: no cover
|
10
|
-
from typing_extensions import TypeGuard
|
11
|
-
|
12
|
-
has_exceptiongroups = True
|
13
|
-
if sys.version_info < (3, 11): # pragma: no cover
|
14
|
-
try:
|
15
|
-
from exceptiongroup import BaseExceptionGroup
|
16
|
-
except ImportError:
|
17
|
-
has_exceptiongroups = False
|
18
|
-
|
19
|
-
T = typing.TypeVar("T")
|
20
|
-
AwaitableCallable = typing.Callable[..., typing.Awaitable[T]]
|
21
|
-
|
22
|
-
|
23
|
-
@typing.overload
|
24
|
-
def is_async_callable(obj: AwaitableCallable[T]) -> TypeGuard[AwaitableCallable[T]]:
|
25
|
-
...
|
26
|
-
|
27
|
-
|
28
|
-
@typing.overload
|
29
|
-
def is_async_callable(obj: typing.Any) -> TypeGuard[AwaitableCallable[typing.Any]]:
|
30
|
-
...
|
31
|
-
|
32
|
-
|
33
|
-
def is_async_callable(obj: typing.Any) -> typing.Any:
|
34
|
-
while isinstance(obj, functools.partial):
|
35
|
-
obj = obj.func
|
36
|
-
|
37
|
-
return asyncio.iscoroutinefunction(obj) or (
|
38
|
-
callable(obj) and asyncio.iscoroutinefunction(obj.__call__)
|
39
|
-
)
|
40
|
-
|
41
|
-
|
42
|
-
T_co = typing.TypeVar("T_co", covariant=True)
|
43
|
-
|
44
|
-
|
45
|
-
class AwaitableOrContextManager(
|
46
|
-
typing.Awaitable[T_co], typing.AsyncContextManager[T_co], typing.Protocol[T_co]
|
47
|
-
):
|
48
|
-
...
|
49
|
-
|
50
|
-
|
51
|
-
class SupportsAsyncClose(typing.Protocol):
|
52
|
-
async def close(self) -> None:
|
53
|
-
... # pragma: no cover
|
54
|
-
|
55
|
-
|
56
|
-
SupportsAsyncCloseType = typing.TypeVar(
|
57
|
-
"SupportsAsyncCloseType", bound=SupportsAsyncClose, covariant=False
|
58
|
-
)
|
59
|
-
|
60
|
-
|
61
|
-
class AwaitableOrContextManagerWrapper(typing.Generic[SupportsAsyncCloseType]):
|
62
|
-
__slots__ = ("aw", "entered")
|
63
|
-
|
64
|
-
def __init__(self, aw: typing.Awaitable[SupportsAsyncCloseType]) -> None:
|
65
|
-
self.aw = aw
|
66
|
-
|
67
|
-
def __await__(self) -> typing.Generator[typing.Any, None, SupportsAsyncCloseType]:
|
68
|
-
return self.aw.__await__()
|
69
|
-
|
70
|
-
async def __aenter__(self) -> SupportsAsyncCloseType:
|
71
|
-
self.entered = await self.aw
|
72
|
-
return self.entered
|
73
|
-
|
74
|
-
async def __aexit__(self, *args: typing.Any) -> typing.Union[None, bool]:
|
75
|
-
await self.entered.close()
|
76
|
-
return None
|
77
|
-
|
78
|
-
|
79
|
-
@contextmanager
|
80
|
-
def collapse_excgroups() -> typing.Generator[None, None, None]:
|
81
|
-
try:
|
82
|
-
yield
|
83
|
-
except BaseException as exc:
|
84
|
-
if has_exceptiongroups:
|
85
|
-
while isinstance(exc, BaseExceptionGroup) and len(exc.exceptions) == 1:
|
86
|
-
exc = exc.exceptions[0] # pragma: no cover
|
87
|
-
|
88
|
-
raise exc
|