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.
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/app.py +2 -3
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/handle.py +27 -31
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/protocol.py +1 -1
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/route.py +23 -12
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI.egg-info/PKG-INFO +1 -1
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/PKG-INFO +1 -1
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/setup.py +1 -1
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/__init__.py +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/cors.py +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/exception.py +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/file.py +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/module.py +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/request.py +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/response.py +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/server.py +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/signal.py +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/websocket.py +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/worker.py +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI/workspace.py +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI.egg-info/SOURCES.txt +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI.egg-info/dependency_links.txt +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI.egg-info/requires.txt +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/CheeseAPI.egg-info/top_level.txt +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/LICENSE +0 -0
- {CheeseAPI-0.2.17 → CheeseAPI-0.2.19}/README.md +0 -0
- {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
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
55
|
-
await
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
kwargs['request'] = protocol.request
|
|
53
|
+
response = await func(**kwargs)
|
|
54
|
+
if await self._http_responseHandle(protocol, app, response):
|
|
55
|
+
return
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
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
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
return
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
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,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
|
|
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
|
-
|
|
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:],
|
|
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
|
-
|
|
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] =
|
|
93
|
+
results[key] = value
|
|
83
94
|
return results
|
|
84
95
|
|
|
85
96
|
paths: Path = Path()
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|