CheeseAPI 2.0.4__tar.gz → 2.0.5b1__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.
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/CheeseAPI/response.py +13 -5
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/PKG-INFO +1 -1
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/pyproject.toml +1 -1
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/.gitignore +0 -0
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/CheeseAPI/__init__.py +0 -0
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/CheeseAPI/app.py +0 -0
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/CheeseAPI/cors.py +0 -0
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/CheeseAPI/file.py +0 -0
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/CheeseAPI/printer.py +0 -0
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/CheeseAPI/request.py +0 -0
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/CheeseAPI/route.py +0 -0
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/CheeseAPI/scheduler.py +0 -0
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/CheeseAPI/signal.py +0 -0
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/CheeseAPI/validator.py +0 -0
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/CheeseAPI/websocket.py +0 -0
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/LICENSE +0 -0
- {cheeseapi-2.0.4 → cheeseapi-2.0.5b1}/README.md +0 -0
|
@@ -75,6 +75,10 @@ HTTP_STATUS = {
|
|
|
75
75
|
}
|
|
76
76
|
NO_BODY_STATUS = (100, 101, 102, 204, 304)
|
|
77
77
|
PREVIEWABLE_TYPES = ('text/plain', 'text/html', 'text/css', 'text/javascript', 'application/json', 'application/xml', 'text/xml', 'image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/svg+xml', 'image/webp', 'image/bmp', 'video/mp4', 'video/webm', 'video/ogg', 'audio/mpeg', 'audio/ogg', 'audio/wav', 'audio/webm', 'application/pdf')
|
|
78
|
+
MERGE_TYPES = {
|
|
79
|
+
'audio/x-wav': 'audio/wav',
|
|
80
|
+
'audio/vnd.wave': 'audio/wav'
|
|
81
|
+
}
|
|
78
82
|
|
|
79
83
|
class Cookie(TypedDict):
|
|
80
84
|
value: str
|
|
@@ -87,7 +91,7 @@ class Cookie(TypedDict):
|
|
|
87
91
|
class Response:
|
|
88
92
|
__slots__ = ('status', '_proxy', 'body', 'headers', 'cookies', 'high_precision_date', 'compress', 'compress_level')
|
|
89
93
|
|
|
90
|
-
def __init__(self, body: dict | list | str | bytes | AsyncIterable | None = None, status: int = 200, headers: dict[str, str] =
|
|
94
|
+
def __init__(self, body: dict | list | str | bytes | AsyncIterable | None = None, status: int = 200, headers: dict[str, str] | None = None, *, high_precision_date: bool = False, compress: Literal['gzip', 'deflate', 'br', 'zstd'] | None = None, compress_level: int | None = None):
|
|
91
95
|
'''
|
|
92
96
|
- Args
|
|
93
97
|
- body: 当为 `AsyncIterable` 时,自动使用 chunked 传输编码
|
|
@@ -99,7 +103,7 @@ class Response:
|
|
|
99
103
|
|
|
100
104
|
self.status: int = status
|
|
101
105
|
self.body: dict | list | str | bytes | AsyncIterable | None = body
|
|
102
|
-
self.headers: dict[str, str] = headers
|
|
106
|
+
self.headers: dict[str, str] = headers if headers is not None else {}
|
|
103
107
|
self.cookies: dict[str, Cookie] = {}
|
|
104
108
|
self.high_precision_date: bool = high_precision_date
|
|
105
109
|
self.compress: Literal['gzip', 'deflate', 'br', 'zstd'] | None = compress
|
|
@@ -118,7 +122,9 @@ class Response:
|
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
class RedirectResponse(Response):
|
|
121
|
-
def __init__(self, location: str, status: Literal[301, 302, 303, 307, 308] = 302, headers: dict[str, str] =
|
|
125
|
+
def __init__(self, location: str, status: Literal[301, 302, 303, 307, 308] = 302, headers: dict[str, str] | None = None, body: bytes | str | list | dict | None = None):
|
|
126
|
+
if headers is None:
|
|
127
|
+
headers = {}
|
|
122
128
|
headers['Location'] = location
|
|
123
129
|
|
|
124
130
|
super().__init__(status, body, headers)
|
|
@@ -126,7 +132,7 @@ class RedirectResponse(Response):
|
|
|
126
132
|
class FileResponse(Response):
|
|
127
133
|
__slots__ = ('file', 'preview', 'transmission_type', 'chunked_size')
|
|
128
134
|
|
|
129
|
-
def __init__(self, file_path_or_file: str | File, *, status: int = 200, headers: dict[str, str] =
|
|
135
|
+
def __init__(self, file_path_or_file: str | File, *, status: int = 200, headers: dict[str, str] | None = None , preview: bool = True, transmission_type: Literal['CONTENT_LENGTH', 'CHUNKED'] = 'CONTENT_LENGTH', chunked_size: int | None = None, compress: Literal['gzip', 'deflate', 'br', 'zstd'] | None = None, compress_level: int | None = None):
|
|
130
136
|
'''
|
|
131
137
|
- Args
|
|
132
138
|
- preview: 优先预览文件
|
|
@@ -225,6 +231,8 @@ class ResponseProxy:
|
|
|
225
231
|
|
|
226
232
|
if 'Content-Type' not in headers and 'Content-Disposition' not in headers:
|
|
227
233
|
mime_type = mimetypes.guess_type(self.response.file.name)[0] or 'application/octet-stream'
|
|
234
|
+
if mime_type in MERGE_TYPES:
|
|
235
|
+
mime_type = MERGE_TYPES[mime_type]
|
|
228
236
|
headers['Content-Type'] = f'{mime_type}; charset=utf-8'
|
|
229
237
|
headers['Content-Disposition'] = f'{"inline" if self.response.preview and mime_type in PREVIEWABLE_TYPES else "attachment"}; filename="{self.response.file.name}"'
|
|
230
238
|
|
|
@@ -398,4 +406,4 @@ class ResponseProxy:
|
|
|
398
406
|
if 'Content-Encoding' in headers:
|
|
399
407
|
del headers['Content-Encoding']
|
|
400
408
|
|
|
401
|
-
return status, headers, body
|
|
409
|
+
return status, headers, body
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|