CheeseAPI 2.0.2__tar.gz → 2.0.3__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.
@@ -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.path}:\n {error}', f'An error occurred causing the <cyan>{request.ip}</cyan> visited <cyan>{request.method} {request.path}</cyan>:\n {self.app.logger.encode(error)}')
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.path}</cyan>:\n {self.app.logger.encode(error)}')
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.path} and returned {response.status}', f'The <cyan>{request.ip}</cyan> visited <cyan>{request.method} {request.path}</cyan> returned <{status_color}>{response.status}</{status_color}>')
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.path}', f'The <cyan>{websocket.request.ip}</cyan> connected <cyan>{websocket.request.method} {websocket.request.path}</cyan>')
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.path}', f'The <cyan>{websocket.request.ip}</cyan> disconnected <cyan>{websocket.request.method} {websocket.request.path}</cyan>')
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.path}:\n {error}', f'An error occurred causing the <cyan>{websocket.request.ip}</cyan> receive a message to <cyan>{websocket.request.method} {websocket.request.path}</cyan>:\n {self.app.logger.encode(error)}')
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':
@@ -26,31 +26,31 @@ def validator(*, json_model: pydantic.BaseModel | None = None, form_model: pydan
26
26
 
27
27
  json_data = None
28
28
  if json_model is not None:
29
- json_data = json_model.model_validate(request.json, by_alias = True)
29
+ json_data = json_model.model_validate(request.json or {}, by_alias = True)
30
30
  if kwargs.get('json_data') is None:
31
31
  kwargs['json_data'] = json_data
32
32
 
33
33
  form_data = None
34
34
  if form_model is not None:
35
- form_data = form_model.model_validate(request.form, by_alias = True)
35
+ form_data = form_model.model_validate(request.form or {}, by_alias = True)
36
36
  if kwargs.get('form_data') is None:
37
37
  kwargs['form_data'] = form_data
38
38
 
39
39
  params_data = None
40
40
  if params_model is not None:
41
- params_data = params_model.model_validate(request.params, by_alias = True)
41
+ params_data = params_model.model_validate(request.params or {}, by_alias = True)
42
42
  if kwargs.get('params_data') is None:
43
43
  kwargs['params_data'] = params_data
44
44
 
45
45
  headers_data = None
46
46
  if headers_model is not None:
47
- headers_data = headers_model.model_validate(request.headers, by_alias = True)
47
+ headers_data = headers_model.model_validate(request.headers or {}, by_alias = True)
48
48
  if kwargs.get('headers_data') is None:
49
49
  kwargs['headers_data'] = headers_data
50
50
 
51
51
  query_data = None
52
52
  if query_model is not None:
53
- query_data = query_model.model_validate(request.query, by_alias = True)
53
+ query_data = query_model.model_validate(request.query or {}, by_alias = True)
54
54
  if kwargs.get('query_data') is None:
55
55
  kwargs['query_data'] = query_data
56
56
  except Exception as e:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: CheeseAPI
3
- Version: 2.0.2
3
+ Version: 2.0.3
4
4
  Summary: 一款web协程框架
5
5
  Project-URL: Source, https://github.com/CheeseUnknown/CheeseAPI
6
6
  Author-email: Cheese Unknown <cheese@cheese.ren>
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "CheeseAPI"
7
- version = "2.0.2"
7
+ version = "2.0.3"
8
8
  description = "一款web协程框架"
9
9
  readme = "README.md"
10
10
  license-files = { paths = [ "LICENSE" ] }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes