CheeseAPI 2.0.2b1__tar.gz → 2.0.4__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.2b1 → cheeseapi-2.0.4}/CheeseAPI/app.py +2 -2
- {cheeseapi-2.0.2b1 → cheeseapi-2.0.4}/CheeseAPI/printer.py +7 -7
- {cheeseapi-2.0.2b1 → cheeseapi-2.0.4}/CheeseAPI/route.py +3 -1
- {cheeseapi-2.0.2b1 → cheeseapi-2.0.4}/CheeseAPI/scheduler.py +8 -0
- {cheeseapi-2.0.2b1 → cheeseapi-2.0.4}/PKG-INFO +1 -1
- {cheeseapi-2.0.2b1 → cheeseapi-2.0.4}/pyproject.toml +1 -1
- {cheeseapi-2.0.2b1 → cheeseapi-2.0.4}/.gitignore +0 -0
- {cheeseapi-2.0.2b1 → cheeseapi-2.0.4}/CheeseAPI/__init__.py +0 -0
- {cheeseapi-2.0.2b1 → cheeseapi-2.0.4}/CheeseAPI/cors.py +0 -0
- {cheeseapi-2.0.2b1 → cheeseapi-2.0.4}/CheeseAPI/file.py +0 -0
- {cheeseapi-2.0.2b1 → cheeseapi-2.0.4}/CheeseAPI/request.py +0 -0
- {cheeseapi-2.0.2b1 → cheeseapi-2.0.4}/CheeseAPI/response.py +0 -0
- {cheeseapi-2.0.2b1 → cheeseapi-2.0.4}/CheeseAPI/signal.py +0 -0
- {cheeseapi-2.0.2b1 → cheeseapi-2.0.4}/CheeseAPI/validator.py +0 -0
- {cheeseapi-2.0.2b1 → cheeseapi-2.0.4}/CheeseAPI/websocket.py +0 -0
- {cheeseapi-2.0.2b1 → cheeseapi-2.0.4}/LICENSE +0 -0
- {cheeseapi-2.0.2b1 → cheeseapi-2.0.4}/README.md +0 -0
|
@@ -98,7 +98,7 @@ class AppProxy:
|
|
|
98
98
|
'modules': module
|
|
99
99
|
})
|
|
100
100
|
|
|
101
|
-
for path in pathlib.Path(module).glob('*.py'):
|
|
101
|
+
for path in pathlib.Path(module.replace('.', '/')).glob('*.py'):
|
|
102
102
|
__import__(f'{module}.{path.stem}')
|
|
103
103
|
|
|
104
104
|
self.after_load_module(i, module)
|
|
@@ -463,7 +463,7 @@ class CheeseAPI:
|
|
|
463
463
|
- compress: 支持的压缩算法,按照顺序尝试压缩
|
|
464
464
|
- compress_min_length: 启用压缩的最小响应体长度
|
|
465
465
|
- compress_level: 压缩等级,每个算法的压缩级别可能不同,详见各算法文档
|
|
466
|
-
- manual_modules:
|
|
466
|
+
- manual_modules: 手动加载的模块列表;若想要加载多层级模块,请使用点号分隔,如 `Xxx.module`,与导入模块的方式一致
|
|
467
467
|
- exclude_modules: 排除加载的模块列表
|
|
468
468
|
- priority_modules: 优先加载的模块列表
|
|
469
469
|
- sync_server_data_encode: 同步服务器数据编码处理函数
|
|
@@ -45,32 +45,32 @@ class Printer:
|
|
|
45
45
|
|
|
46
46
|
def fn_error(self, e: Exception, request: 'Request'):
|
|
47
47
|
error = traceback.format_exc()[:-1].replace("\n", "\n ")
|
|
48
|
-
self.app.logger.danger(f'An error occurred causing the {request.ip} visited {request.method} {request.
|
|
48
|
+
self.app.logger.danger(f'An error occurred causing the {request.ip} visited {request.method} {request.full_path}:\n {error}', f'An error occurred causing the <cyan>{request.ip}</cyan> visited <cyan>{request.method} {self.app.logger.encode(request.full_path)}</cyan>:\n {self.app.logger.encode(error)}')
|
|
49
49
|
|
|
50
50
|
def websocket_error(self, e: Exception, websocket: 'Websocket'):
|
|
51
51
|
error = traceback.format_exc()[:-1].replace("\n", "\n ")
|
|
52
|
-
self.app.logger.danger(f'An error occurred causing the {websocket.request.ip} disconnected :\n {error}', f'An error occurred causing the <cyan>{websocket.request.ip}</cyan> disconnected <cyan>{websocket.request.method} {websocket.request.
|
|
52
|
+
self.app.logger.danger(f'An error occurred causing the {websocket.request.ip} disconnected {websocket.request.method} {websocket.request.full_path}:\n {error}', f'An error occurred causing the <cyan>{websocket.request.ip}</cyan> disconnected <cyan>{websocket.request.method} {self.app.logger.encode(websocket.request.full_path)}</cyan>:\n {self.app.logger.encode(error)}')
|
|
53
53
|
|
|
54
54
|
def response(self, request: 'Request', response: 'Response'):
|
|
55
55
|
status_color = HTTP_STATUS_COLOR[int(response.status / 100) - 1]
|
|
56
56
|
if request.path is not None:
|
|
57
|
-
self.app.logger.print('HTTP', f'The {request.ip} visited {request.method} {request.
|
|
57
|
+
self.app.logger.print('HTTP', f'The {request.ip} visited {request.method} {request.full_path} and returned {response.status}', f'The <cyan>{request.ip}</cyan> visited <cyan>{request.method} {self.app.logger.encode(request.full_path)}</cyan> returned <{status_color}>{response.status}</{status_color}>')
|
|
58
58
|
else:
|
|
59
59
|
self.app.logger.print('HTTP', f'The request from {request.ip} failed to parse and returned {response.status}', f'The request from <cyan>{request.ip}</cyan> failed to parse and returned <{status_color}>{response.status}</{status_color}>')
|
|
60
60
|
|
|
61
61
|
def websocket_connect(self, websocket: 'Websocket'):
|
|
62
|
-
self.app.logger.print('WEBSOCKET', f'The {websocket.request.ip} connected {websocket.request.method} {websocket.request.
|
|
62
|
+
self.app.logger.print('WEBSOCKET', f'The {websocket.request.ip} connected {websocket.request.method} {websocket.request.full_path}', f'The <cyan>{websocket.request.ip}</cyan> connected <cyan>{websocket.request.method} {self.app.logger.encode(websocket.request.full_path)}</cyan>')
|
|
63
63
|
|
|
64
64
|
def websocket_disconnect(self, websocket: 'Websocket'):
|
|
65
|
-
self.app.logger.print('WEBSOCKET', f'The {websocket.request.ip} disconnected {websocket.request.method} {websocket.request.
|
|
65
|
+
self.app.logger.print('WEBSOCKET', f'The {websocket.request.ip} disconnected {websocket.request.method} {websocket.request.full_path}', f'The <cyan>{websocket.request.ip}</cyan> disconnected <cyan>{websocket.request.method} {self.app.logger.encode(websocket.request.full_path)}</cyan>')
|
|
66
66
|
|
|
67
67
|
def websocket_message_error(self, e: Exception, websocket: 'Websocket'):
|
|
68
68
|
error = traceback.format_exc()[:-1].replace("\n", "\n ")
|
|
69
|
-
self.app.logger.danger(f'An error occurred causing the {websocket.request.ip} received a message to {websocket.request.method} {websocket.request.
|
|
69
|
+
self.app.logger.danger(f'An error occurred causing the {websocket.request.ip} received a message to {websocket.request.method} {websocket.request.full_path}:\n {error}', f'An error occurred causing the <cyan>{websocket.request.ip}</cyan> receive a message to <cyan>{websocket.request.method} {self.app.logger.encode(websocket.request.full_path)}</cyan>:\n {self.app.logger.encode(error)}')
|
|
70
70
|
|
|
71
71
|
def scheduler_error(self, e: Exception, task: 'Task'):
|
|
72
72
|
error = traceback.format_exc()[:-1].replace("\n", "\n ")
|
|
73
|
-
self.app.logger.danger(f'An error occurred in the scheduled task {task.key} running:\n {error}', f'An error occurred in the scheduled task running <green>{task.key}</green>:\n {self.app.logger.encode(error)}')
|
|
73
|
+
self.app.logger.danger(f'An error occurred in the scheduled task {task.key} running:\n {error}', f'An error occurred in the scheduled task running <green>{self.app.logger.encode(task.key)}</green>:\n {self.app.logger.encode(error)}')
|
|
74
74
|
|
|
75
75
|
@property
|
|
76
76
|
def app(self) -> 'CheeseAPI':
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import re, uuid
|
|
2
2
|
from typing import Literal, TypedDict, Callable, TYPE_CHECKING, AsyncIterable, Union
|
|
3
3
|
|
|
4
|
+
from urllib.parse import unquote
|
|
5
|
+
|
|
4
6
|
from CheeseAPI.cors import CORS
|
|
5
7
|
|
|
6
8
|
if TYPE_CHECKING:
|
|
@@ -252,7 +254,7 @@ class RouteProxy:
|
|
|
252
254
|
i = 1
|
|
253
255
|
for key, type in self.app.route._proxy.dynamic_routes[_path][method]['params'].items():
|
|
254
256
|
value = match.group(i)
|
|
255
|
-
_params[key] = type(value)
|
|
257
|
+
_params[key] = type(unquote(value))
|
|
256
258
|
i += 1
|
|
257
259
|
return self.app.route._proxy.dynamic_routes[_path][method], _params
|
|
258
260
|
else:
|
|
@@ -158,6 +158,14 @@ class SchedulerProxy:
|
|
|
158
158
|
|
|
159
159
|
self._tasks: dict[str, Task] = {}
|
|
160
160
|
|
|
161
|
+
def __getstate__(self):
|
|
162
|
+
return {
|
|
163
|
+
'app': self.app
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
def __setstate__(self, state):
|
|
167
|
+
self.app = state['app']
|
|
168
|
+
|
|
161
169
|
def add(self, fn: Callable | None = None, *, interval_time: float | None = None, first_run_timer: datetime.datetime | None = None, expected_run_num: int | None = None, key: str | None = None, run_type: Literal['THREAD', 'PROCESS'] = 'THREAD', args: tuple = (), kwargs: dict = {}, auto_remove: bool = False):
|
|
162
170
|
if fn is not None:
|
|
163
171
|
task = Task(fn, interval_time = interval_time, first_run_timer = first_run_timer, expected_run_num = expected_run_num, key = key, run_type = run_type, args = args, kwargs = kwargs, auto_remove = auto_remove)
|
|
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
|