CheeseAPI 0.2.17__tar.gz → 0.2.19__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.
Files changed (26) hide show
  1. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/app.py +2 -3
  2. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/handle.py +27 -31
  3. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/protocol.py +1 -1
  4. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/route.py +23 -12
  5. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI.egg-info/PKG-INFO +1 -1
  6. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/PKG-INFO +1 -1
  7. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/setup.py +1 -1
  8. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/__init__.py +0 -0
  9. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/cors.py +0 -0
  10. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/exception.py +0 -0
  11. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/file.py +0 -0
  12. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/module.py +0 -0
  13. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/request.py +0 -0
  14. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/response.py +0 -0
  15. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/server.py +0 -0
  16. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/signal.py +0 -0
  17. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/websocket.py +0 -0
  18. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/worker.py +0 -0
  19. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/workspace.py +0 -0
  20. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI.egg-info/SOURCES.txt +0 -0
  21. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI.egg-info/dependency_links.txt +0 -0
  22. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI.egg-info/requires.txt +0 -0
  23. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI.egg-info/top_level.txt +0 -0
  24. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/LICENSE +0 -0
  25. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/README.md +0 -0
  26. {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/setup.cfg +0 -0
@@ -50,15 +50,14 @@ class App:
50
50
  sock.bind((self.server.host, self.server.port))
51
51
  sock.set_inheritable(True)
52
52
 
53
- asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
54
- asyncio.run(_run(app, sock, managers))
55
-
56
53
  multiprocessing.allow_connection_pickling()
57
54
  for i in range(0, self.server.workers - 1):
58
55
  process = multiprocessing.Process(target = run, args = (app, sock, managers), name = f'CheeseAPI_Subprocess<{i}>', daemon = True)
59
56
  process.start()
60
57
  os.setpgid(process.pid, os.getpid())
61
58
 
59
+ run(app, sock, managers)
60
+
62
61
  while managers['startedWorkerNum'].value != 0:
63
62
  time.sleep(0.1)
64
63
  except Exception as e:
@@ -41,29 +41,28 @@ class Handle:
41
41
  except:
42
42
  ...
43
43
 
44
- funcs = paths.match(protocol.request.path)
45
-
46
- if not funcs:
47
- await self._http_responseHandle(protocol, app, await self._http_404Handle(protocol, app))
48
- return
44
+ try:
45
+ func, kwargs = paths.match(protocol.request.path, protocol.request.method)
49
46
 
50
- if protocol.request.method not in funcs:
51
- await self._http_responseHandle(protocol, app, await self._http_405Handle(protocol, app))
52
- return
47
+ for http_beforeRequestHandle in self.http_beforeRequestHandles:
48
+ await http_beforeRequestHandle(**{ 'request': protocol.request })
49
+ if signal.receiver('http_beforeRequestHandle'):
50
+ await signal.async_send('http_beforeRequestHandle', { 'request': protocol.request })
53
51
 
54
- for http_beforeRequestHandle in self.http_beforeRequestHandles:
55
- await http_beforeRequestHandle(**{ 'request': protocol.request })
56
- if signal.receiver('http_beforeRequestHandle'):
57
- await signal.async_send('http_beforeRequestHandle', { 'request': protocol.request })
52
+ kwargs['request'] = protocol.request
53
+ response = await func(**kwargs)
54
+ if await self._http_responseHandle(protocol, app, response):
55
+ return
58
56
 
59
- func = funcs[protocol.request.method][0]
60
- kwargs = funcs[protocol.request.method][1]
61
- kwargs['request'] = protocol.request
62
- response = await func(**kwargs)
63
- if await self._http_responseHandle(protocol, app, response):
64
- return
57
+ await self._http_responseHandle(protocol, app, await self._http_noResponseHandle(protocol, app))
58
+ except KeyError as e:
59
+ if e.args[0] == 0:
60
+ await self._http_responseHandle(protocol, app, await self._http_404Handle(protocol, app))
61
+ return
65
62
 
66
- await self._http_responseHandle(protocol, app, await self._http_noResponseHandle(protocol, app))
63
+ if e.args[0] == 1:
64
+ await self._http_responseHandle(protocol, app, await self._http_405Handle(protocol, app))
65
+ return
67
66
  except BaseException as e:
68
67
  await self._http_responseHandle(protocol, app, await self._http_500Handle(protocol, app, e))
69
68
 
@@ -265,19 +264,16 @@ A usable BaseResponse is not returned''')
265
264
  self.http_afterResponseHandles.append(func)
266
265
 
267
266
  async def _websocket_requestHandle(self, protocol: 'WebsocketProtocol', app: 'App') -> Tuple[Callable, Dict[str, Any]] | HTTPResponse:
268
- funcs = paths.match(protocol.request.path)
269
-
270
- if not funcs:
271
- return await self._websocket_responseHandle(protocol, app, await self._websocket_404Handle(protocol, app))
272
-
273
- if 'WEBSOCKET' not in funcs:
274
- return await self._websocket_responseHandle(protocol, app, await self._websocket_405Handle(protocol, app))
275
-
276
- func = funcs['WEBSOCKET'][0]()
277
- kwargs = funcs['WEBSOCKET'][1]
278
- kwargs['request'] = protocol.request
267
+ try:
268
+ func, kwargs = paths.match(protocol.request.path, 'WEBSOCKET')
269
+ kwargs['request'] = protocol.request
270
+ return func(), kwargs
271
+ except KeyError as e:
272
+ if e.args[0] == 0:
273
+ return await self._websocket_responseHandle(protocol, app, await self._websocket_404Handle(protocol, app))
279
274
 
280
- return func, kwargs
275
+ if e.args[0] == 1:
276
+ return await self._websocket_responseHandle(protocol, app, await self._websocket_405Handle(protocol, app))
281
277
 
282
278
  async def _websocket_404Handle(self, protocol: 'WebsocketProtocol', app: 'App') -> Response:
283
279
  return Response(status = http.HTTPStatus.NOT_FOUND)
@@ -1,4 +1,4 @@
1
- import asyncio, http, traceback
1
+ import asyncio, http
2
2
  from typing import TYPE_CHECKING, Dict, Any, Tuple, Deque, Self
3
3
  from multiprocessing import Manager
4
4
  from collections import deque
@@ -1,5 +1,5 @@
1
1
  import re, uuid, http
2
- from typing import Callable, Dict, List, Tuple, Any
2
+ from typing import Callable, Dict, List, Tuple, Any, Literal
3
3
  from urllib.parse import unquote
4
4
 
5
5
  patterns: Dict[str, re.Pattern] = {
@@ -25,7 +25,7 @@ class PathNode:
25
25
  def __init__(self):
26
26
  self.children: Dict[str, PathNode] = None
27
27
  self.key: str | None = None
28
- self.methods: Dict[str, Callable] | None = None
28
+ self.methods: Dict[str, Tuple[str, Callable]] | None = None
29
29
 
30
30
  class Path:
31
31
  def __init__(self):
@@ -57,29 +57,40 @@ class Path:
57
57
  if not node.methods:
58
58
  node.methods = {}
59
59
  for method in methods:
60
- node.methods[method] = func
60
+ node.methods[method] = path, func
61
61
 
62
- def match(self, path: str) -> Dict[http.HTTPMethod, Tuple[Callable, Dict[str, Any]]]:
62
+ def match(self, path: str, method: http.HTTPMethod | Literal['WEBSOCKET']) -> Tuple[Callable, Dict[str, Any]]:
63
63
  paths = path.split('/')[1:]
64
64
  if paths[-1] == '' and path != '/':
65
65
  paths = paths[:-1]
66
- results = self._match(self.root, paths, {}, {})
67
- return results
68
66
 
69
- def _match(self, node: PathNode, paths: List[str], kwargs: Dict[str, Any], results: Dict[http.HTTPMethod, Tuple[Callable, Dict[str, Any]]]) -> List[Tuple[http.HTTPMethod, Callable, Dict[str, Any]]]:
67
+ results = self._match(self.root, paths, {})
68
+ if not results:
69
+ raise KeyError(0)
70
+ if method not in results:
71
+ raise KeyError(1)
72
+ results = results[method]
73
+ kwargs = {}
74
+ _paths = results[0].split('/')
75
+ for i in range(len(paths)):
76
+ if re.match(r'<.*?:.*?>', _paths[i + 1]):
77
+ kwargs[_paths[i + 1][1:].split(':')[0]] = unquote(paths[i])
78
+
79
+ return results[1], kwargs
80
+
81
+ def _match(self, node: PathNode, paths: List[str], results: Dict[http.HTTPMethod, Tuple[str, Callable]]) -> Dict[http.HTTPMethod, Tuple[str, Callable]]:
70
82
  if paths and node.children:
71
- paths[0] = unquote(paths[0])
72
83
  if paths[0] in node.children:
73
- results = self._match(node.children[paths[0]], paths[1:], kwargs, results)
84
+ results = self._match(node.children[paths[0]], paths[1:], results)
85
+ paths[0] = unquote(paths[0])
74
86
  for key, value in patterns.items():
75
87
  if re.fullmatch(value['pattern'], paths[0]) and f'<:{key}>' in node.children:
76
- kwargs[node.children[f'<:{key}>'].key] = value['type'](paths[0])
77
- results = self._match(node.children[f'<:{key}>'], paths[1:], kwargs, results)
88
+ results = self._match(node.children[f'<:{key}>'], paths[1:], results)
78
89
 
79
90
  if not paths and node.methods:
80
91
  for key, value in node.methods.items():
81
92
  if key not in results:
82
- results[key] = (value, kwargs)
93
+ results[key] = value
83
94
  return results
84
95
 
85
96
  paths: Path = Path()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CheeseAPI
3
- Version: 0.2.17
3
+ Version: 0.2.19
4
4
  Summary: 一款web协程框架
5
5
  Home-page: https://github.com/CheeseUnknown/CheeseAPI
6
6
  Author: Cheese Unknown
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CheeseAPI
3
- Version: 0.2.17
3
+ Version: 0.2.19
4
4
  Summary: 一款web协程框架
5
5
  Home-page: https://github.com/CheeseUnknown/CheeseAPI
6
6
  Author: Cheese Unknown
@@ -5,7 +5,7 @@ with open('./README.md', 'r', encoding = 'utf-8') as f:
5
5
 
6
6
  setuptools.setup(
7
7
  name = 'CheeseAPI',
8
- version = '0.2.17',
8
+ version = '0.2.19',
9
9
  author = 'Cheese Unknown',
10
10
  author_email = 'cheese@cheese.ren',
11
11
  description = '一款web协程框架',
File without changes
File without changes
File without changes
File without changes
File without changes