GNServer 0.0.0.0.18__tar.gz → 0.0.0.0.20__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.
- {gnserver-0.0.0.0.18 → gnserver-0.0.0.0.20}/GNServer/GNServer/_app.py +76 -8
- {gnserver-0.0.0.0.18 → gnserver-0.0.0.0.20}/GNServer/GNServer/_client.py +0 -1
- {gnserver-0.0.0.0.18 → gnserver-0.0.0.0.20}/GNServer/GNServer.egg-info/PKG-INFO +1 -1
- {gnserver-0.0.0.0.18 → gnserver-0.0.0.0.20}/PKG-INFO +1 -1
- {gnserver-0.0.0.0.18 → gnserver-0.0.0.0.20}/setup.py +1 -1
- {gnserver-0.0.0.0.18 → gnserver-0.0.0.0.20}/GNServer/GNServer/___client.py +0 -0
- {gnserver-0.0.0.0.18 → gnserver-0.0.0.0.20}/GNServer/GNServer/__init__.py +0 -0
- {gnserver-0.0.0.0.18 → gnserver-0.0.0.0.20}/GNServer/GNServer.egg-info/SOURCES.txt +0 -0
- {gnserver-0.0.0.0.18 → gnserver-0.0.0.0.20}/GNServer/GNServer.egg-info/dependency_links.txt +0 -0
- {gnserver-0.0.0.0.18 → gnserver-0.0.0.0.20}/GNServer/GNServer.egg-info/requires.txt +0 -0
- {gnserver-0.0.0.0.18 → gnserver-0.0.0.0.20}/GNServer/GNServer.egg-info/top_level.txt +0 -0
- {gnserver-0.0.0.0.18 → gnserver-0.0.0.0.20}/GNServer/LICENSE +0 -0
- {gnserver-0.0.0.0.18 → gnserver-0.0.0.0.20}/GNServer/mmbConfig.json +0 -0
- {gnserver-0.0.0.0.18 → gnserver-0.0.0.0.20}/LICENSE +0 -0
- {gnserver-0.0.0.0.18 → gnserver-0.0.0.0.20}/MANIFEST.in +0 -0
- {gnserver-0.0.0.0.18 → gnserver-0.0.0.0.20}/setup.cfg +0 -0
@@ -46,7 +46,23 @@ console.setFormatter(logging.Formatter("[GNServer] %(name)s: %(levelname)s: %(me
|
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
+
class _BaseEXception(Exception):
|
50
|
+
def __init__(self, code: str, message=""):
|
51
|
+
self._code = code
|
52
|
+
self._message = message
|
49
53
|
|
54
|
+
def assembly(self):
|
55
|
+
return gn.GNResponse(f'gn:error:{self._code}', payload={'msg': self._message})
|
56
|
+
|
57
|
+
|
58
|
+
class GNExceptions:
|
59
|
+
class UnprocessableEntity(_BaseEXception):
|
60
|
+
def __init__(self):
|
61
|
+
super().__init__('422', "Unprocessable Entity")
|
62
|
+
|
63
|
+
class BadRequest(_BaseEXception):
|
64
|
+
def __init__(self):
|
65
|
+
super().__init__('400', "Bad Request")
|
50
66
|
|
51
67
|
|
52
68
|
|
@@ -169,7 +185,7 @@ def resolve_cors(origin_url: str, rules: list[str]) -> bool:
|
|
169
185
|
- "*.example.com" -> wildcard (одна метка)
|
170
186
|
- "**.example.com" -> globstar (0+ меток)
|
171
187
|
- "pages.*.core.gn" -> смешанное
|
172
|
-
- "
|
188
|
+
- "gn://*.site.tld" -> с проверкой схемы
|
173
189
|
- "!<regex>" -> полное соответствие по regex к origin_url
|
174
190
|
"""
|
175
191
|
|
@@ -391,6 +407,9 @@ class App:
|
|
391
407
|
def __init__(self):
|
392
408
|
self._routes: List[Route] = []
|
393
409
|
self._cors: Optional[gn.CORSObject] = None
|
410
|
+
self._events: Dict[str, Dict[str, Union[str, Callable]]] = {}
|
411
|
+
|
412
|
+
self.domain: str = None
|
394
413
|
|
395
414
|
def route(self, method: str, path: str, cors: Optional[gn.CORSObject] = None):
|
396
415
|
if path == '/':
|
@@ -428,8 +447,42 @@ class App:
|
|
428
447
|
self._cors = cors
|
429
448
|
|
430
449
|
|
450
|
+
def addEventListener(self, name: str):
|
451
|
+
def decorator(fn: Callable[Optional[dict], Any]):
|
452
|
+
events = self._events.get(name, [])
|
453
|
+
events.append({
|
454
|
+
'func': fn,
|
455
|
+
'async': inspect.iscoroutinefunction(fn),
|
456
|
+
'parameters': inspect.signature(fn).parameters
|
457
|
+
})
|
458
|
+
|
459
|
+
return fn
|
460
|
+
return decorator
|
461
|
+
|
462
|
+
async def dispatchEvent(self, name: str, payload: Optional[str] = None) -> None:
|
463
|
+
data_list = self._events.get(name, None)
|
464
|
+
if data_list:
|
465
|
+
for data in data_list:
|
466
|
+
func: Callable = data['func']
|
467
|
+
is_async = data['async']
|
468
|
+
|
469
|
+
if not is_async:
|
470
|
+
if payload in data['parameters']:
|
471
|
+
func(payload=payload)
|
472
|
+
else:
|
473
|
+
func()
|
474
|
+
else:
|
475
|
+
if payload in data['parameters']:
|
476
|
+
await func(payload=payload)
|
477
|
+
else:
|
478
|
+
await func()
|
479
|
+
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
|
431
484
|
|
432
|
-
async def
|
485
|
+
async def dispatchRequest(
|
433
486
|
self, request: gn.GNRequest
|
434
487
|
) -> Union[gn.GNResponse, AsyncGenerator[gn.GNResponse, None]]:
|
435
488
|
path = request.url.path
|
@@ -665,12 +718,17 @@ class App:
|
|
665
718
|
logger.debug(f'Отправлен на сервер ответ -> {response.command} {response.payload if response.payload and len((response.payload)) < 200 else ''}')
|
666
719
|
self.transmit()
|
667
720
|
except Exception as e:
|
668
|
-
|
721
|
+
if e.__qualname__.startswith("GNExceptions."):
|
722
|
+
e: GNExceptions.UnprocessableEntity = e
|
723
|
+
r = e.assembly()
|
724
|
+
return r
|
725
|
+
else:
|
726
|
+
logger.error('GNServer: error\n' + traceback.format_exc())
|
669
727
|
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
728
|
+
response = gn.GNResponse('gn:backend:500')
|
729
|
+
self._quic.send_stream_data(request.stream_id, response.serialize(mode), end_stream=True)
|
730
|
+
self.transmit()
|
731
|
+
|
674
732
|
async def resolve_response(self, response: gn.GNResponse) -> gn.GNResponse:
|
675
733
|
await response.assembly()
|
676
734
|
|
@@ -683,16 +741,20 @@ class App:
|
|
683
741
|
|
684
742
|
def run(
|
685
743
|
self,
|
686
|
-
|
744
|
+
domain: str,
|
687
745
|
port: int,
|
688
746
|
cert_path: str,
|
689
747
|
key_path: str,
|
690
748
|
*,
|
749
|
+
host: Optional[str] = '0.0.0.0',
|
691
750
|
idle_timeout: float = 20.0,
|
692
751
|
wait: bool = True,
|
693
752
|
run: Optional[Callable] = None
|
694
753
|
):
|
695
754
|
|
755
|
+
self.domain = domain
|
756
|
+
|
757
|
+
|
696
758
|
self._init_sys_routes()
|
697
759
|
|
698
760
|
cfg = QuicConfiguration(
|
@@ -701,6 +763,9 @@ class App:
|
|
701
763
|
cfg.load_cert_chain(cert_path, key_path)
|
702
764
|
|
703
765
|
async def _main():
|
766
|
+
|
767
|
+
await self.dispatchEvent('before-run')
|
768
|
+
|
704
769
|
await serve(
|
705
770
|
host,
|
706
771
|
port,
|
@@ -712,6 +777,9 @@ class App:
|
|
712
777
|
if run is not None:
|
713
778
|
await run()
|
714
779
|
|
780
|
+
await self.dispatchEvent('run')
|
781
|
+
|
782
|
+
|
715
783
|
|
716
784
|
if wait:
|
717
785
|
await asyncio.Event().wait()
|
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
|