pboot 4.0.0__tar.gz → 4.0.1__tar.gz
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.
- {pboot-4.0.0 → pboot-4.0.1}/CHANGES.rst +28 -0
- {pboot-4.0.0 → pboot-4.0.1}/PKG-INFO +1 -1
- {pboot-4.0.0 → pboot-4.0.1}/examples/api/app.py +3 -1
- {pboot-4.0.0 → pboot-4.0.1}/examples/templates/app.py +8 -1
- {pboot-4.0.0 → pboot-4.0.1}/pyproject.toml +53 -5
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/__init__.py +1 -1
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/_body_limit.py +2 -1
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/_compat/__init__.py +1 -3
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/_compat/shared.py +3 -10
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/_compat/v2.py +5 -12
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/_datastructures.py +12 -10
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/_local.py +21 -14
- pboot-4.0.1/src/pboot/app.py +63 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/applications.py +14 -14
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/background.py +2 -1
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/blueprints.py +25 -21
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/cli.py +79 -6
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/compat.py +75 -60
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/concurrency.py +2 -2
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/config.py +3 -1
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/ctx.py +8 -5
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/datastructures.py +1 -7
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/debughelpers.py +2 -2
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/dependencies/utils.py +30 -31
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/encoders.py +4 -6
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/exception_handlers.py +5 -4
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/globals.py +14 -8
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/helpers.py +29 -23
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/json/__init__.py +2 -2
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/json/provider.py +3 -4
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/json/tag.py +3 -6
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/logging.py +2 -4
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/openapi/docs.py +2 -1
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/openapi/models.py +4 -8
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/openapi/utils.py +3 -2
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/param_functions.py +3 -2
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/params.py +5 -6
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/responses.py +3 -2
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/routing.py +28 -50
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/security/api_key.py +3 -2
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/security/http.py +4 -3
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/security/oauth2.py +3 -2
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/security/open_id_connect_url.py +3 -2
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/sessions.py +12 -17
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/telemetry/_api.py +3 -4
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/telemetry/_asgi.py +9 -8
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/telemetry/_runtime.py +3 -2
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/templating.py +3 -4
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/testing.py +5 -5
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/utils.py +3 -6
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/views.py +1 -1
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/wrappers.py +27 -14
- {pboot-4.0.0 → pboot-4.0.1}/tests/conftest.py +3 -3
- {pboot-4.0.0 → pboot-4.0.1}/tests/test_appctx.py +3 -5
- {pboot-4.0.0 → pboot-4.0.1}/tests/test_basic.py +49 -6
- {pboot-4.0.0 → pboot-4.0.1}/tests/test_blueprints.py +0 -2
- {pboot-4.0.0 → pboot-4.0.1}/tests/test_cli.py +42 -11
- {pboot-4.0.0 → pboot-4.0.1}/tests/test_compat_api.py +3 -9
- {pboot-4.0.0 → pboot-4.0.1}/tests/test_config.py +0 -2
- {pboot-4.0.0 → pboot-4.0.1}/tests/test_error_handlers.py +0 -2
- {pboot-4.0.0 → pboot-4.0.1}/tests/test_fastapi.py +2 -9
- {pboot-4.0.0 → pboot-4.0.1}/tests/test_helpers.py +13 -9
- {pboot-4.0.0 → pboot-4.0.1}/tests/test_json.py +1 -2
- {pboot-4.0.0 → pboot-4.0.1}/tests/test_reqctx.py +1 -3
- {pboot-4.0.0 → pboot-4.0.1}/tests/test_session.py +5 -3
- {pboot-4.0.0 → pboot-4.0.1}/tests/test_signals.py +2 -4
- {pboot-4.0.0 → pboot-4.0.1}/tests/test_templating.py +3 -5
- {pboot-4.0.0 → pboot-4.0.1}/tests/test_testing.py +2 -4
- {pboot-4.0.0 → pboot-4.0.1}/tests/test_views.py +1 -4
- pboot-4.0.0/src/pboot/app.py +0 -11
- {pboot-4.0.0 → pboot-4.0.1}/LICENSE.txt +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/README.md +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/docs/_static/pboot-logo.svg +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/docs/migration-from-flask.md +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/examples/basic/app.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/examples/templates/templates/index.html +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/__main__.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/_form_limits.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/_import.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/dependencies/__init__.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/dependencies/models.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/exceptions.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/logger.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/middleware/__init__.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/middleware/asyncexitstack.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/middleware/cors.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/middleware/gzip.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/middleware/httpsredirect.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/middleware/trustedhost.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/middleware/wsgi.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/openapi/__init__.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/openapi/constants.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/py.typed +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/requests.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/sansio/__init__.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/sansio/app.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/sansio/blueprints.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/sansio/scaffold.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/security/__init__.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/security/base.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/security/utils.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/signals.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/sse.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/staticfiles.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/telemetry/__init__.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/testclient.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/types.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/typing.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/src/pboot/websockets.py +0 -0
- {pboot-4.0.0 → pboot-4.0.1}/tests/templates/hello.html +0 -0
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
Version 4.0.1
|
|
2
|
+
-------------
|
|
3
|
+
|
|
4
|
+
Released 2026-12-02
|
|
5
|
+
|
|
6
|
+
- Fix ``Response.status`` raising ``AttributeError``. Starlette's response
|
|
7
|
+
has no ``reason_phrase``, the standard HTTP reason phrase is used
|
|
8
|
+
instead.
|
|
9
|
+
|
|
10
|
+
- Fix ``Blueprint.url_defaults`` being shadowed by the instance attribute
|
|
11
|
+
of the same name, which made calling it raise ``TypeError``.
|
|
12
|
+
|
|
13
|
+
- Fix JSON serialization of ``datetime.date`` values, which raised
|
|
14
|
+
``AttributeError`` in ``http_date``.
|
|
15
|
+
|
|
16
|
+
- Fix the default logging handler, which was given the error stream
|
|
17
|
+
function instead of the stream itself, so every log record failed.
|
|
18
|
+
|
|
19
|
+
- Fix ``pboot run --reload``, which required the ``--app`` value to be
|
|
20
|
+
given as ``module:attribute``. A plain module name is resolved
|
|
21
|
+
automatically now, and application factories are supported.
|
|
22
|
+
|
|
23
|
+
- Add ``pboot --version``.
|
|
24
|
+
|
|
25
|
+
- Type check the Pboot specific code with mypy in strict mode, and keep
|
|
26
|
+
the public API of Pboot 3.x importable from ``pboot.app``,
|
|
27
|
+
``pboot.typing``, ``pboot.debughelpers`` and ``pboot.sansio``.
|
|
28
|
+
|
|
1
29
|
Version 4.0.0
|
|
2
30
|
-------------
|
|
3
31
|
|
|
@@ -27,7 +27,9 @@ class ItemIn(Item):
|
|
|
27
27
|
items: dict[int, Item] = {}
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
def get_item_id(
|
|
30
|
+
def get_item_id(
|
|
31
|
+
q: Annotated[int | None, Query(description="可选的物品编号")] = None,
|
|
32
|
+
) -> int:
|
|
31
33
|
"""一个简单的依赖,用来演示依赖注入。"""
|
|
32
34
|
return q or 1
|
|
33
35
|
|
|
@@ -7,7 +7,14 @@
|
|
|
7
7
|
|
|
8
8
|
import os
|
|
9
9
|
|
|
10
|
-
from pboot import
|
|
10
|
+
from pboot import (
|
|
11
|
+
Blueprint,
|
|
12
|
+
Pboot,
|
|
13
|
+
flash,
|
|
14
|
+
get_flashed_messages,
|
|
15
|
+
render_template,
|
|
16
|
+
session,
|
|
17
|
+
)
|
|
11
18
|
|
|
12
19
|
app = Pboot(__name__)
|
|
13
20
|
app.config["SECRET_KEY"] = os.environ.get("PBOOT_SECRET_KEY", "change-me")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pboot"
|
|
3
|
-
version = "4.0.
|
|
3
|
+
version = "4.0.1"
|
|
4
4
|
description = "A Pydantic/FastAPI-based framework for building complex web applications."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "BSD-3-Clause"
|
|
@@ -109,6 +109,10 @@ typing = [
|
|
|
109
109
|
"types-contextvars",
|
|
110
110
|
"types-dataclasses",
|
|
111
111
|
]
|
|
112
|
+
pre-commit = [
|
|
113
|
+
"pre-commit",
|
|
114
|
+
"pre-commit-uv",
|
|
115
|
+
]
|
|
112
116
|
|
|
113
117
|
[tool.uv]
|
|
114
118
|
default-groups = ["dev", "tests", "typing"]
|
|
@@ -136,7 +140,29 @@ exclude_also = [
|
|
|
136
140
|
|
|
137
141
|
[tool.mypy]
|
|
138
142
|
python_version = "3.11"
|
|
139
|
-
|
|
143
|
+
# 只检查 Pboot 自己维护的代码, FastAPI 派生的部分由上游保证
|
|
144
|
+
files = [
|
|
145
|
+
"src/pboot/_datastructures.py",
|
|
146
|
+
"src/pboot/_import.py",
|
|
147
|
+
"src/pboot/_local.py",
|
|
148
|
+
"src/pboot/blueprints.py",
|
|
149
|
+
"src/pboot/cli.py",
|
|
150
|
+
"src/pboot/compat.py",
|
|
151
|
+
"src/pboot/config.py",
|
|
152
|
+
"src/pboot/ctx.py",
|
|
153
|
+
"src/pboot/debughelpers.py",
|
|
154
|
+
"src/pboot/globals.py",
|
|
155
|
+
"src/pboot/helpers.py",
|
|
156
|
+
"src/pboot/json",
|
|
157
|
+
"src/pboot/logging.py",
|
|
158
|
+
"src/pboot/sessions.py",
|
|
159
|
+
"src/pboot/signals.py",
|
|
160
|
+
"src/pboot/templating.py",
|
|
161
|
+
"src/pboot/testing.py",
|
|
162
|
+
"src/pboot/typing.py",
|
|
163
|
+
"src/pboot/views.py",
|
|
164
|
+
"src/pboot/wrappers.py",
|
|
165
|
+
]
|
|
140
166
|
show_error_codes = true
|
|
141
167
|
pretty = true
|
|
142
168
|
strict = true
|
|
@@ -145,25 +171,47 @@ strict = true
|
|
|
145
171
|
module = [
|
|
146
172
|
"dotenv.*",
|
|
147
173
|
"importlib_metadata",
|
|
174
|
+
"uvicorn.*",
|
|
148
175
|
]
|
|
149
176
|
ignore_missing_imports = true
|
|
150
177
|
|
|
151
178
|
[tool.ruff]
|
|
152
179
|
src = ["src"]
|
|
153
|
-
fix = true
|
|
154
180
|
show-fixes = true
|
|
155
181
|
output-format = "full"
|
|
156
182
|
|
|
157
183
|
[tool.ruff.lint]
|
|
158
184
|
select = [
|
|
159
185
|
"B", # flake8-bugbear
|
|
186
|
+
"C4", # flake8-comprehensions
|
|
160
187
|
"E", # pycodestyle error
|
|
161
188
|
"F", # pyflakes
|
|
162
189
|
"I", # isort
|
|
163
190
|
"UP", # pyupgrade
|
|
164
191
|
"W", # pycodestyle warning
|
|
165
192
|
]
|
|
193
|
+
ignore = [
|
|
194
|
+
"E501", # 行长由 formatter 处理
|
|
195
|
+
"B008", # FastAPI 依赖默认值里用 Depends()/Query() 作为参数
|
|
196
|
+
"C901", # 复杂度
|
|
197
|
+
]
|
|
198
|
+
|
|
199
|
+
[tool.ruff.lint.per-file-ignores]
|
|
200
|
+
"__init__.py" = ["F401"]
|
|
201
|
+
# 类型别名里用了前向引用, 不能改成 X | Y
|
|
202
|
+
"src/pboot/typing.py" = ["UP007"]
|
|
203
|
+
"tests/*" = ["F401"]
|
|
204
|
+
"examples/*" = ["F401"]
|
|
166
205
|
|
|
167
206
|
[tool.ruff.lint.isort]
|
|
168
|
-
|
|
169
|
-
|
|
207
|
+
known-third-party = [
|
|
208
|
+
"pydantic",
|
|
209
|
+
"starlette",
|
|
210
|
+
]
|
|
211
|
+
|
|
212
|
+
[tool.ruff.lint.pyupgrade]
|
|
213
|
+
keep-runtime-typing = true
|
|
214
|
+
|
|
215
|
+
[tool.codespell]
|
|
216
|
+
# te 是 typing_extensions 的别名; dependant 是上游沿用的英式拼写
|
|
217
|
+
ignore-words-list = "te,dependant,re-used"
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
from pboot.exception_handlers import http_exception_handler
|
|
2
1
|
from starlette.exceptions import HTTPException
|
|
3
2
|
from starlette.middleware import body_limit
|
|
4
3
|
from starlette.middleware.body_limit import (
|
|
@@ -8,6 +7,8 @@ from starlette.middleware.body_limit import (
|
|
|
8
7
|
from starlette.requests import Request
|
|
9
8
|
from starlette.types import ASGIApp, Message, Receive, Scope, Send
|
|
10
9
|
|
|
10
|
+
from pboot.exception_handlers import http_exception_handler
|
|
11
|
+
|
|
11
12
|
# Starlette has no public exception types for these two middleware signals.
|
|
12
13
|
# Unknown exceptions must keep their normal handling.
|
|
13
14
|
_response_sent = getattr(body_limit, "_RequestBodyLimitResponseSent", ())
|
|
@@ -35,6 +35,4 @@ from .v2 import get_model_name_map as get_model_name_map
|
|
|
35
35
|
from .v2 import get_schema_from_model_field as get_schema_from_model_field
|
|
36
36
|
from .v2 import is_scalar_field as is_scalar_field
|
|
37
37
|
from .v2 import serialize_sequence_value as serialize_sequence_value
|
|
38
|
-
from .v2 import
|
|
39
|
-
with_info_plain_validator_function as with_info_plain_validator_function,
|
|
40
|
-
)
|
|
38
|
+
from .v2 import with_info_plain_validator_function as with_info_plain_validator_function
|
|
@@ -4,21 +4,14 @@ import warnings
|
|
|
4
4
|
from collections import deque
|
|
5
5
|
from collections.abc import Mapping, Sequence
|
|
6
6
|
from dataclasses import is_dataclass
|
|
7
|
-
from typing import
|
|
8
|
-
Annotated,
|
|
9
|
-
Any,
|
|
10
|
-
TypeGuard,
|
|
11
|
-
TypeVar,
|
|
12
|
-
Union,
|
|
13
|
-
get_args,
|
|
14
|
-
get_origin,
|
|
15
|
-
)
|
|
7
|
+
from typing import Annotated, Any, TypeGuard, TypeVar, Union, get_args, get_origin
|
|
16
8
|
|
|
17
|
-
from pboot.types import UnionType
|
|
18
9
|
from pydantic import BaseModel
|
|
19
10
|
from pydantic.version import VERSION as PYDANTIC_VERSION
|
|
20
11
|
from starlette.datastructures import UploadFile
|
|
21
12
|
|
|
13
|
+
from pboot.types import UnionType
|
|
14
|
+
|
|
22
15
|
_T = TypeVar("_T")
|
|
23
16
|
|
|
24
17
|
# Copy from Pydantic: pydantic/_internal/_typing_extra.py
|
|
@@ -5,19 +5,8 @@ from copy import copy
|
|
|
5
5
|
from dataclasses import dataclass, is_dataclass
|
|
6
6
|
from enum import Enum
|
|
7
7
|
from functools import lru_cache
|
|
8
|
-
from typing import
|
|
9
|
-
Annotated,
|
|
10
|
-
Any,
|
|
11
|
-
Literal,
|
|
12
|
-
Union,
|
|
13
|
-
cast,
|
|
14
|
-
get_args,
|
|
15
|
-
get_origin,
|
|
16
|
-
)
|
|
8
|
+
from typing import Annotated, Any, Literal, Union, cast, get_args, get_origin
|
|
17
9
|
|
|
18
|
-
from pboot._compat import lenient_issubclass, shared
|
|
19
|
-
from pboot.openapi.constants import REF_TEMPLATE
|
|
20
|
-
from pboot.types import IncEx, ModelNameMap, UnionType
|
|
21
10
|
from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, create_model
|
|
22
11
|
from pydantic import PydanticSchemaGenerationError as PydanticSchemaGenerationError
|
|
23
12
|
from pydantic import PydanticUndefinedAnnotation as PydanticUndefinedAnnotation
|
|
@@ -36,6 +25,10 @@ from pydantic_core.core_schema import (
|
|
|
36
25
|
with_info_plain_validator_function as with_info_plain_validator_function,
|
|
37
26
|
)
|
|
38
27
|
|
|
28
|
+
from pboot._compat import lenient_issubclass, shared
|
|
29
|
+
from pboot.openapi.constants import REF_TEMPLATE
|
|
30
|
+
from pboot.types import IncEx, ModelNameMap, UnionType
|
|
31
|
+
|
|
39
32
|
RequiredParam = PydanticUndefined
|
|
40
33
|
Undefined = PydanticUndefined
|
|
41
34
|
|
|
@@ -7,12 +7,11 @@ WSGI-oriented Werkzeug package.
|
|
|
7
7
|
from __future__ import annotations
|
|
8
8
|
|
|
9
9
|
import typing as t
|
|
10
|
-
from datetime import datetime
|
|
11
|
-
from datetime import timezone
|
|
10
|
+
from datetime import UTC, date, datetime
|
|
12
11
|
from email.utils import format_datetime
|
|
13
12
|
|
|
14
13
|
|
|
15
|
-
class CallbackDict(dict):
|
|
14
|
+
class CallbackDict(dict[str, t.Any]):
|
|
16
15
|
"""A dict that calls a function passed every time it is modified.
|
|
17
16
|
|
|
18
17
|
:param initial: The initial value for the dict.
|
|
@@ -22,7 +21,7 @@ class CallbackDict(dict): # type: ignore[type-arg]
|
|
|
22
21
|
def __init__(
|
|
23
22
|
self,
|
|
24
23
|
initial: t.Mapping[str, t.Any] | None = None,
|
|
25
|
-
on_update: t.Callable[[
|
|
24
|
+
on_update: t.Callable[[t.Any], t.Any] | None = None,
|
|
26
25
|
) -> None:
|
|
27
26
|
super().__init__(initial or ())
|
|
28
27
|
self.on_update = on_update
|
|
@@ -35,7 +34,7 @@ class CallbackDict(dict): # type: ignore[type-arg]
|
|
|
35
34
|
super().__delitem__(key)
|
|
36
35
|
self._on_update()
|
|
37
36
|
|
|
38
|
-
def update(self, *args: t.Any, **kwargs: t.Any) -> None:
|
|
37
|
+
def update(self, *args: t.Any, **kwargs: t.Any) -> None:
|
|
39
38
|
super().update(*args, **kwargs)
|
|
40
39
|
self._on_update()
|
|
41
40
|
|
|
@@ -63,12 +62,15 @@ class CallbackDict(dict): # type: ignore[type-arg]
|
|
|
63
62
|
self.on_update(self)
|
|
64
63
|
|
|
65
64
|
|
|
66
|
-
def http_date(dt: datetime | None = None) -> str:
|
|
67
|
-
"""Format a datetime as an HTTP date string."""
|
|
65
|
+
def http_date(dt: datetime | date | None = None) -> str:
|
|
66
|
+
"""Format a datetime or a date as an HTTP date string."""
|
|
68
67
|
if dt is None:
|
|
69
|
-
dt = datetime.now(
|
|
68
|
+
dt = datetime.now(UTC)
|
|
69
|
+
elif not isinstance(dt, datetime):
|
|
70
|
+
# 只有日期没有时间, 按当天零点处理。
|
|
71
|
+
dt = datetime(dt.year, dt.month, dt.day, tzinfo=UTC)
|
|
70
72
|
elif dt.tzinfo is None:
|
|
71
|
-
dt = dt.replace(tzinfo=
|
|
73
|
+
dt = dt.replace(tzinfo=UTC)
|
|
72
74
|
return format_datetime(dt, usegmt=True)
|
|
73
75
|
|
|
74
76
|
|
|
@@ -85,6 +87,6 @@ def parse_date(value: str | None) -> datetime | None:
|
|
|
85
87
|
return None
|
|
86
88
|
|
|
87
89
|
if dt.tzinfo is None:
|
|
88
|
-
dt = dt.replace(tzinfo=
|
|
90
|
+
dt = dt.replace(tzinfo=UTC)
|
|
89
91
|
|
|
90
92
|
return dt
|
|
@@ -12,7 +12,7 @@ from contextvars import ContextVar
|
|
|
12
12
|
T = t.TypeVar("T")
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
class LocalProxy:
|
|
15
|
+
class LocalProxy(t.Generic[T]):
|
|
16
16
|
"""Proxy to an object held in a :class:`~contextvars.ContextVar`.
|
|
17
17
|
|
|
18
18
|
The proxy forwards attribute access, item access and the common
|
|
@@ -41,7 +41,7 @@ class LocalProxy:
|
|
|
41
41
|
message = object.__getattribute__(self, "_unbound_message")
|
|
42
42
|
raise RuntimeError(message)
|
|
43
43
|
|
|
44
|
-
return obj
|
|
44
|
+
return t.cast("T", obj)
|
|
45
45
|
|
|
46
46
|
def __getattr__(self, name: str) -> t.Any:
|
|
47
47
|
if name in {"_getter", "_unbound_message"}: # pragma: no cover
|
|
@@ -55,22 +55,26 @@ class LocalProxy:
|
|
|
55
55
|
delattr(self._get_current_object(), name)
|
|
56
56
|
|
|
57
57
|
def __getitem__(self, key: t.Any) -> t.Any:
|
|
58
|
-
|
|
58
|
+
obj = t.cast("t.Any", self._get_current_object())
|
|
59
|
+
return obj[key]
|
|
59
60
|
|
|
60
61
|
def __setitem__(self, key: t.Any, value: t.Any) -> None:
|
|
61
|
-
self._get_current_object()
|
|
62
|
+
obj = t.cast("t.Any", self._get_current_object())
|
|
63
|
+
obj[key] = value
|
|
62
64
|
|
|
63
65
|
def __delitem__(self, key: t.Any) -> None:
|
|
64
|
-
|
|
66
|
+
obj = t.cast("t.Any", self._get_current_object())
|
|
67
|
+
del obj[key]
|
|
65
68
|
|
|
66
69
|
def __contains__(self, key: t.Any) -> bool:
|
|
67
|
-
|
|
70
|
+
obj = t.cast("t.Any", self._get_current_object())
|
|
71
|
+
return bool(key in obj)
|
|
68
72
|
|
|
69
73
|
def __iter__(self) -> t.Iterator[t.Any]:
|
|
70
|
-
return iter(self._get_current_object())
|
|
74
|
+
return iter(t.cast("t.Iterable[t.Any]", self._get_current_object()))
|
|
71
75
|
|
|
72
76
|
def __len__(self) -> int:
|
|
73
|
-
return len(self._get_current_object())
|
|
77
|
+
return len(t.cast("t.Sized", self._get_current_object()))
|
|
74
78
|
|
|
75
79
|
def __bool__(self) -> bool:
|
|
76
80
|
try:
|
|
@@ -79,10 +83,10 @@ class LocalProxy:
|
|
|
79
83
|
return False
|
|
80
84
|
|
|
81
85
|
def __eq__(self, other: t.Any) -> bool:
|
|
82
|
-
return self._get_current_object() == other
|
|
86
|
+
return bool(self._get_current_object() == other)
|
|
83
87
|
|
|
84
88
|
def __ne__(self, other: t.Any) -> bool:
|
|
85
|
-
return self._get_current_object() != other
|
|
89
|
+
return bool(self._get_current_object() != other)
|
|
86
90
|
|
|
87
91
|
def __hash__(self) -> int:
|
|
88
92
|
return hash(self._get_current_object())
|
|
@@ -98,18 +102,21 @@ class LocalProxy:
|
|
|
98
102
|
return repr(obj)
|
|
99
103
|
|
|
100
104
|
def __call__(self, *args: t.Any, **kwargs: t.Any) -> t.Any:
|
|
101
|
-
|
|
105
|
+
func = t.cast("t.Callable[..., t.Any]", self._get_current_object())
|
|
106
|
+
return func(*args, **kwargs)
|
|
102
107
|
|
|
103
108
|
def __await__(self) -> t.Any:
|
|
104
|
-
|
|
109
|
+
obj = t.cast("t.Any", self._get_current_object())
|
|
110
|
+
return obj.__await__()
|
|
105
111
|
|
|
106
112
|
def __aiter__(self) -> t.Any:
|
|
107
|
-
|
|
113
|
+
obj = t.cast("t.Any", self._get_current_object())
|
|
114
|
+
return obj.__aiter__()
|
|
108
115
|
|
|
109
116
|
|
|
110
117
|
def make_proxy(
|
|
111
118
|
var: ContextVar[t.Any], name: str, unbound_message: str | None = None
|
|
112
|
-
) -> LocalProxy:
|
|
119
|
+
) -> LocalProxy[t.Any]:
|
|
113
120
|
"""Build a :class:`LocalProxy` bound to ``var``."""
|
|
114
121
|
|
|
115
122
|
def _getter() -> t.Any:
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""The application object.
|
|
2
|
+
|
|
3
|
+
This module re-exports the names that Pboot 3.x exposed from
|
|
4
|
+
``pboot.app``, so that ``from pboot.app import Pboot`` keeps working.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from .applications import Pboot as Pboot
|
|
10
|
+
from .blueprints import Blueprint as Blueprint
|
|
11
|
+
from .config import Config as Config
|
|
12
|
+
from .config import ConfigAttribute as ConfigAttribute
|
|
13
|
+
from .ctx import AppContext as AppContext
|
|
14
|
+
from .globals import current_app as current_app
|
|
15
|
+
from .globals import g as g
|
|
16
|
+
from .globals import request as request
|
|
17
|
+
from .globals import session as session
|
|
18
|
+
from .helpers import BuildError as BuildError
|
|
19
|
+
from .helpers import make_response as make_response
|
|
20
|
+
from .helpers import redirect as redirect
|
|
21
|
+
from .helpers import url_for as url_for
|
|
22
|
+
from .json.provider import DefaultJSONProvider as DefaultJSONProvider
|
|
23
|
+
from .json.provider import JSONProvider as JSONProvider
|
|
24
|
+
from .sessions import SecureCookieSession as SecureCookieSession
|
|
25
|
+
from .sessions import SecureCookieSessionInterface as SecureCookieSessionInterface
|
|
26
|
+
from .sessions import SessionInterface as SessionInterface
|
|
27
|
+
from .templating import DispatchingJinjaLoader as DispatchingJinjaLoader
|
|
28
|
+
from .templating import Environment as Environment
|
|
29
|
+
from .views import MethodView as MethodView
|
|
30
|
+
from .views import View as View
|
|
31
|
+
from .wrappers import Request as Request
|
|
32
|
+
from .wrappers import Response as Response
|
|
33
|
+
|
|
34
|
+
#: The sans-IO application base class of Pboot 3.x.
|
|
35
|
+
App = Pboot
|
|
36
|
+
|
|
37
|
+
__all__ = [
|
|
38
|
+
"App",
|
|
39
|
+
"AppContext",
|
|
40
|
+
"Blueprint",
|
|
41
|
+
"BuildError",
|
|
42
|
+
"Config",
|
|
43
|
+
"ConfigAttribute",
|
|
44
|
+
"DefaultJSONProvider",
|
|
45
|
+
"DispatchingJinjaLoader",
|
|
46
|
+
"Environment",
|
|
47
|
+
"JSONProvider",
|
|
48
|
+
"MethodView",
|
|
49
|
+
"Pboot",
|
|
50
|
+
"Request",
|
|
51
|
+
"Response",
|
|
52
|
+
"SecureCookieSession",
|
|
53
|
+
"SecureCookieSessionInterface",
|
|
54
|
+
"SessionInterface",
|
|
55
|
+
"View",
|
|
56
|
+
"current_app",
|
|
57
|
+
"g",
|
|
58
|
+
"make_response",
|
|
59
|
+
"redirect",
|
|
60
|
+
"request",
|
|
61
|
+
"session",
|
|
62
|
+
"url_for",
|
|
63
|
+
]
|
|
@@ -5,11 +5,23 @@ from enum import Enum
|
|
|
5
5
|
from typing import Annotated, Any, Literal, TypeVar
|
|
6
6
|
|
|
7
7
|
from annotated_doc import Doc
|
|
8
|
+
from starlette.applications import Starlette
|
|
9
|
+
from starlette.datastructures import State
|
|
10
|
+
from starlette.exceptions import HTTPException
|
|
11
|
+
from starlette.middleware import Middleware
|
|
12
|
+
from starlette.middleware.base import BaseHTTPMiddleware
|
|
13
|
+
from starlette.middleware.errors import ServerErrorMiddleware
|
|
14
|
+
from starlette.middleware.exceptions import ExceptionMiddleware
|
|
15
|
+
from starlette.requests import Request
|
|
16
|
+
from starlette.responses import HTMLResponse, JSONResponse, Response
|
|
17
|
+
from starlette.routing import BaseRoute
|
|
18
|
+
from starlette.types import ASGIApp, ExceptionHandler, Lifespan, Receive, Scope, Send
|
|
19
|
+
from typing_extensions import deprecated
|
|
20
|
+
|
|
8
21
|
from pboot import routing
|
|
9
22
|
from pboot._body_limit import AppBodyLimitMiddleware
|
|
10
|
-
from pboot.compat import PbootCompatMixin
|
|
11
|
-
from pboot.compat import PbootRouter
|
|
12
23
|
from pboot._form_limits import _FormLimits
|
|
24
|
+
from pboot.compat import PbootCompatMixin, PbootRouter
|
|
13
25
|
from pboot.datastructures import Default, DefaultPlaceholder
|
|
14
26
|
from pboot.exception_handlers import (
|
|
15
27
|
http_exception_handler,
|
|
@@ -37,18 +49,6 @@ from pboot.telemetry._asgi import (
|
|
|
37
49
|
)
|
|
38
50
|
from pboot.types import DecoratedCallable, IncEx
|
|
39
51
|
from pboot.utils import generate_unique_id
|
|
40
|
-
from starlette.applications import Starlette
|
|
41
|
-
from starlette.datastructures import State
|
|
42
|
-
from starlette.exceptions import HTTPException
|
|
43
|
-
from starlette.middleware import Middleware
|
|
44
|
-
from starlette.middleware.base import BaseHTTPMiddleware
|
|
45
|
-
from starlette.middleware.errors import ServerErrorMiddleware
|
|
46
|
-
from starlette.middleware.exceptions import ExceptionMiddleware
|
|
47
|
-
from starlette.requests import Request
|
|
48
|
-
from starlette.responses import HTMLResponse, JSONResponse, Response
|
|
49
|
-
from starlette.routing import BaseRoute
|
|
50
|
-
from starlette.types import ASGIApp, ExceptionHandler, Lifespan, Receive, Scope, Send
|
|
51
|
-
from typing_extensions import deprecated
|
|
52
52
|
|
|
53
53
|
AppType = TypeVar("AppType", bound="Pboot")
|
|
54
54
|
|
|
@@ -2,10 +2,11 @@ from collections.abc import Callable
|
|
|
2
2
|
from typing import Annotated, Any
|
|
3
3
|
|
|
4
4
|
from annotated_doc import Doc
|
|
5
|
-
from pboot.telemetry._api import _operation
|
|
6
5
|
from starlette.background import BackgroundTasks as StarletteBackgroundTasks
|
|
7
6
|
from typing_extensions import ParamSpec
|
|
8
7
|
|
|
8
|
+
from pboot.telemetry._api import _operation
|
|
9
|
+
|
|
9
10
|
P = ParamSpec("P")
|
|
10
11
|
|
|
11
12
|
|
|
@@ -96,14 +96,14 @@ class Blueprint:
|
|
|
96
96
|
self.teardown_appcontext_funcs: list[t.Callable[..., t.Any]] = []
|
|
97
97
|
self.template_context_processors: list[t.Callable[[], dict[str, t.Any]]] = []
|
|
98
98
|
self.url_value_preprocessors: list[t.Callable[..., t.Any]] = []
|
|
99
|
-
self.
|
|
100
|
-
self.error_handlers: dict[
|
|
101
|
-
int | type[Exception], t.Callable[..., t.Any]
|
|
102
|
-
] = {}
|
|
99
|
+
self.url_defaults_funcs: list[t.Callable[..., t.Any]] = []
|
|
100
|
+
self.error_handlers: dict[int | type[Exception], t.Callable[..., t.Any]] = {}
|
|
103
101
|
|
|
104
|
-
self.app_template_context_processors: list[
|
|
102
|
+
self.app_template_context_processors: list[
|
|
103
|
+
t.Callable[[], dict[str, t.Any]]
|
|
104
|
+
] = []
|
|
105
105
|
self.app_url_value_preprocessors: list[t.Callable[..., t.Any]] = []
|
|
106
|
-
self.
|
|
106
|
+
self.app_url_defaults_funcs: list[t.Callable[..., t.Any]] = []
|
|
107
107
|
self.app_error_handlers: dict[
|
|
108
108
|
int | type[Exception], t.Callable[..., t.Any]
|
|
109
109
|
] = {}
|
|
@@ -218,9 +218,7 @@ class Blueprint:
|
|
|
218
218
|
self.teardown_request_funcs.append(f)
|
|
219
219
|
return f
|
|
220
220
|
|
|
221
|
-
def teardown_appcontext(
|
|
222
|
-
self, f: t.Callable[..., t.Any]
|
|
223
|
-
) -> t.Callable[..., t.Any]:
|
|
221
|
+
def teardown_appcontext(self, f: t.Callable[..., t.Any]) -> t.Callable[..., t.Any]:
|
|
224
222
|
"""Register a function to run when the app context ends."""
|
|
225
223
|
self.teardown_appcontext_funcs.append(f)
|
|
226
224
|
return f
|
|
@@ -239,7 +237,7 @@ class Blueprint:
|
|
|
239
237
|
|
|
240
238
|
def url_defaults(self, f: t.Callable[..., t.Any]) -> t.Callable[..., t.Any]:
|
|
241
239
|
"""Register a URL defaults provider."""
|
|
242
|
-
self.
|
|
240
|
+
self.url_defaults_funcs.append(f)
|
|
243
241
|
return f
|
|
244
242
|
|
|
245
243
|
def errorhandler(
|
|
@@ -255,24 +253,26 @@ class Blueprint:
|
|
|
255
253
|
|
|
256
254
|
# -- app wide hooks --------------------------------------------------
|
|
257
255
|
|
|
258
|
-
def before_app_request(
|
|
259
|
-
self, f: t.Callable[..., t.Any]
|
|
260
|
-
) -> t.Callable[..., t.Any]:
|
|
256
|
+
def before_app_request(self, f: t.Callable[..., t.Any]) -> t.Callable[..., t.Any]:
|
|
261
257
|
"""Register a function to run before every request."""
|
|
262
|
-
self.record(
|
|
258
|
+
self.record(
|
|
259
|
+
lambda state: state.app.before_request_funcs.setdefault(None, []).append(f)
|
|
260
|
+
)
|
|
263
261
|
return f
|
|
264
262
|
|
|
265
263
|
def after_app_request(self, f: t.Callable[..., t.Any]) -> t.Callable[..., t.Any]:
|
|
266
264
|
"""Register a function to run after every request."""
|
|
267
|
-
self.record(
|
|
265
|
+
self.record(
|
|
266
|
+
lambda state: state.app.after_request_funcs.setdefault(None, []).append(f)
|
|
267
|
+
)
|
|
268
268
|
return f
|
|
269
269
|
|
|
270
|
-
def teardown_app_request(
|
|
271
|
-
self, f: t.Callable[..., t.Any]
|
|
272
|
-
) -> t.Callable[..., t.Any]:
|
|
270
|
+
def teardown_app_request(self, f: t.Callable[..., t.Any]) -> t.Callable[..., t.Any]:
|
|
273
271
|
"""Register a function to run when every request ends."""
|
|
274
272
|
self.record(
|
|
275
|
-
lambda state: state.app.teardown_request_funcs.setdefault(None, []).append(
|
|
273
|
+
lambda state: state.app.teardown_request_funcs.setdefault(None, []).append(
|
|
274
|
+
f
|
|
275
|
+
)
|
|
276
276
|
)
|
|
277
277
|
return f
|
|
278
278
|
|
|
@@ -288,7 +288,9 @@ class Blueprint:
|
|
|
288
288
|
) -> t.Callable[..., t.Any]:
|
|
289
289
|
"""Register an app-wide URL value preprocessor."""
|
|
290
290
|
self.record(
|
|
291
|
-
lambda state: state.app.url_value_preprocessors.setdefault(None, []).append(
|
|
291
|
+
lambda state: state.app.url_value_preprocessors.setdefault(None, []).append(
|
|
292
|
+
f
|
|
293
|
+
)
|
|
292
294
|
)
|
|
293
295
|
return f
|
|
294
296
|
|
|
@@ -391,7 +393,9 @@ class Blueprint:
|
|
|
391
393
|
app.url_value_preprocessors.setdefault(full_name, []).extend(
|
|
392
394
|
self.url_value_preprocessors
|
|
393
395
|
)
|
|
394
|
-
app.url_default_functions.setdefault(full_name, []).extend(
|
|
396
|
+
app.url_default_functions.setdefault(full_name, []).extend(
|
|
397
|
+
self.url_defaults_funcs
|
|
398
|
+
)
|
|
395
399
|
|
|
396
400
|
for code_or_exception, f in self.error_handlers.items():
|
|
397
401
|
app.register_error_handler(code_or_exception, f)
|