GNServer 0.0.0.0.20__tar.gz → 0.0.0.0.21__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.
@@ -29,7 +29,7 @@ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29
29
  DEALINGS IN THE SOFTWARE.
30
30
  """
31
31
 
32
- from ._app import App
32
+ from ._app import App, GNExceptions
33
33
  from KeyisBClient.gn import GNRequest, GNResponse, CORSObject, FileObject, TemplateObject
34
34
 
35
35
 
@@ -52,19 +52,97 @@ class _BaseEXception(Exception):
52
52
  self._message = message
53
53
 
54
54
  def assembly(self):
55
+ """
56
+ Собирает ошибку в ответ типа `GNResponse`
57
+ """
55
58
  return gn.GNResponse(f'gn:error:{self._code}', payload={'msg': self._message})
56
59
 
57
60
 
58
61
  class GNExceptions:
59
62
  class UnprocessableEntity(_BaseEXception):
60
63
  def __init__(self):
64
+ """
65
+ # Некорректные данные
66
+ """
61
67
  super().__init__('422', "Unprocessable Entity")
62
68
 
63
69
  class BadRequest(_BaseEXception):
64
70
  def __init__(self):
71
+ """
72
+ # неправильного синтаксис url или параметров
73
+ """
65
74
  super().__init__('400', "Bad Request")
66
75
 
76
+ class Forbidden(_BaseEXception):
77
+ def __init__(self):
78
+ """
79
+ # Доступ запрещён, даже при наличии авторизации
80
+ """
81
+ super().__init__('403', "Forbidden")
82
+
83
+
84
+ class NotFound(_BaseEXception):
85
+ def __init__(self):
86
+ """
87
+ # Ресурс не найден
88
+ """
89
+ super().__init__('404', "Not Found")
90
+
91
+
92
+ class MethodNotAllowed(_BaseEXception):
93
+ def __init__(self):
94
+ """
95
+ # Метод запроса не поддерживается данным ресурсом
96
+ """
97
+ super().__init__('405', "Method Not Allowed")
98
+
99
+
100
+ class Conflict(_BaseEXception):
101
+ def __init__(self):
102
+ """
103
+ # Конфликт состояния ресурса (например, дубликат)
104
+ """
105
+ super().__init__('409', "Conflict")
106
+
107
+
108
+ class InternalServerError(_BaseEXception):
109
+ def __init__(self):
110
+ """
111
+ # Внутренняя ошибка сервера
112
+ """
113
+ super().__init__('500', "Internal Server Error")
114
+
115
+
116
+ class NotImplemented(_BaseEXception):
117
+ def __init__(self):
118
+ """
119
+ # Метод или функционал ещё не реализован
120
+ """
121
+ super().__init__('501', "Not Implemented")
122
+
123
+
124
+ class BadGateway(_BaseEXception):
125
+ def __init__(self):
126
+ """
127
+ # Ошибка шлюза или прокси при обращении к апстриму
128
+ """
129
+ super().__init__('502', "Bad Gateway")
130
+
131
+
132
+ class ServiceUnavailable(_BaseEXception):
133
+ def __init__(self):
134
+ """
135
+ # Сервис временно недоступен
136
+ """
137
+ super().__init__('503', "Service Unavailable")
138
+
67
139
 
140
+ class GatewayTimeout(_BaseEXception):
141
+ def __init__(self):
142
+ """
143
+ # Таймаут при обращении к апстриму
144
+ """
145
+ super().__init__('504', "Gateway Timeout")
68
146
 
69
147
  def guess_type(filename: str) -> str:
70
148
  """
@@ -552,8 +630,8 @@ class App:
552
630
  )
553
631
 
554
632
  if allowed:
555
- return gn.GNResponse("gn:backend:405", {'error': 'Method Not Allowed'})
556
- return gn.GNResponse("gn:backend:404", {'error': 'Not Found'})
633
+ raise GNExceptions.MethodNotAllowed()
634
+ raise GNExceptions.NotFound()
557
635
 
558
636
 
559
637
  def fastFile(self, path: str, file_path: str, cors: Optional[gn.CORSObject] = None, template: Optional[gn.TemplateObject] = None, payload: Optional[dict] = None):
@@ -564,7 +642,7 @@ class App:
564
642
  file_path = file_path[:-1]
565
643
 
566
644
  if not os.path.isfile(file_path):
567
- return gn.GNResponse('gn:backend:404', cors=cors)
645
+ raise GNExceptions.NotFound()
568
646
 
569
647
  fileObject = gn.FileObject(file_path, template)
570
648
  return gn.GNResponse('ok', payload=payload, files=fileObject, cors=cors)
@@ -579,7 +657,7 @@ class App:
579
657
  file_path = file_path[:-1]
580
658
 
581
659
  if not os.path.isfile(file_path):
582
- return gn.GNResponse('gn:backend:404', cors=cors)
660
+ raise GNExceptions.NotFound()
583
661
 
584
662
  fileObject = gn.FileObject(file_path, template)
585
663
  return gn.GNResponse('ok', payload=payload, files=fileObject, cors=cors)
@@ -591,8 +669,8 @@ class App:
591
669
  @self.post('/!gn-vm-host/ping', cors=gn.CORSObject(None))
592
670
  async def r_ping(request: gn.GNRequest):
593
671
 
594
- if request._client_ip != '127.0.0.1':
595
- return gn.GNResponse('gn:backend:403', {'error': 'Forbidden'})
672
+ if request.client.remote_addr != '127.0.0.1':
673
+ raise GNExceptions.Forbidden()
596
674
  return gn.GNResponse('ok', {'time': datetime.datetime.now(datetime.UTC).isoformat()})
597
675
 
598
676
 
@@ -692,7 +770,7 @@ class App:
692
770
 
693
771
  async def _handle_request(self, request: gn.GNRequest, mode: int):
694
772
 
695
- request._client_ip = self._quic._network_paths[0].addr[0]
773
+ request.client._data['remote_addr'] = self._quic._network_paths[0].addr[0]
696
774
 
697
775
  try:
698
776
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GNServer
3
- Version: 0.0.0.0.20
3
+ Version: 0.0.0.0.21
4
4
  Summary: GNServer
5
5
  Home-page: https://github.com/KeyisB/libs/tree/main/GNServer
6
6
  Author: KeyisB
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GNServer
3
- Version: 0.0.0.0.20
3
+ Version: 0.0.0.0.21
4
4
  Summary: GNServer
5
5
  Home-page: https://github.com/KeyisB/libs/tree/main/GNServer
6
6
  Author: KeyisB
@@ -5,7 +5,7 @@ filesName = 'GNServer'
5
5
 
6
6
  setup(
7
7
  name=name,
8
- version='0.0.0.0.20',
8
+ version='0.0.0.0.21',
9
9
  author="KeyisB",
10
10
  author_email="keyisb.pip@gmail.com",
11
11
  description=name,
File without changes
File without changes
File without changes