GNServer 0.0.0.0.27__py3-none-any.whl → 0.0.0.0.29__py3-none-any.whl

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/_app.py CHANGED
@@ -45,105 +45,115 @@ console = logging.StreamHandler()
45
45
  console.setLevel(logging.INFO)
46
46
  console.setFormatter(logging.Formatter("[GNServer] %(name)s: %(levelname)s: %(message)s"))
47
47
 
48
-
48
+ PayloadType = Optional[Union[int, str, list, tuple, dict]]
49
49
 
50
50
  class _BaseEXception(Exception):
51
- def __init__(self, code: str, message=""):
51
+ def __init__(self, code: str, name="", message: Optional[str] = None, payload: PayloadType = None):
52
52
  self._code = code
53
+ self._name = name
53
54
  self._message = message
55
+ self._payload = payload
54
56
 
55
57
  def assembly(self):
56
58
  """
57
59
  Собирает ошибку в ответ типа `GNResponse`
58
60
  """
59
- return gn.GNResponse(f'gn:error:{self._code}', payload={'msg': self._message})
61
+ payload: dict = {'name': self._name}
62
+
63
+ if self._message is not None:
64
+ payload['message'] = self._message
65
+
66
+ if self._payload is not None:
67
+ payload['payload'] = self._payload
68
+
69
+ return gn.GNResponse(f'gn:error:{self._code}', payload=payload)
60
70
 
61
71
 
62
72
  class GNExceptions:
63
73
  class UnprocessableEntity(_BaseEXception):
64
- def __init__(self):
74
+ def __init__(self, message: Optional[str] = None, payload: PayloadType = None):
65
75
  """
66
76
  # Некорректные данные
67
77
  """
68
- super().__init__('422', "Unprocessable Entity")
78
+ super().__init__('422', "Unprocessable Entity", message=message, payload=payload)
69
79
 
70
80
  class BadRequest(_BaseEXception):
71
- def __init__(self):
81
+ def __init__(self, message: Optional[str] = None, payload: PayloadType = None):
72
82
  """
73
83
  # неправильного синтаксис url или параметров
74
84
  """
75
- super().__init__('400', "Bad Request")
85
+ super().__init__('400', "Bad Request", message=message, payload=payload)
76
86
 
77
87
  class Forbidden(_BaseEXception):
78
- def __init__(self):
88
+ def __init__(self, message: Optional[str] = None, payload: PayloadType = None):
79
89
  """
80
90
  # Доступ запрещён, даже при наличии авторизации
81
91
  """
82
- super().__init__('403', "Forbidden")
92
+ super().__init__('403', "Forbidden", message=message, payload=payload)
83
93
 
84
94
 
85
95
  class NotFound(_BaseEXception):
86
- def __init__(self):
96
+ def __init__(self, message: Optional[str] = None, payload: PayloadType = None):
87
97
  """
88
98
  # Ресурс не найден
89
99
  """
90
- super().__init__('404', "Not Found")
100
+ super().__init__('404', "Not Found", message=message, payload=payload)
91
101
 
92
102
 
93
103
  class MethodNotAllowed(_BaseEXception):
94
- def __init__(self):
104
+ def __init__(self, message: Optional[str] = None, payload: PayloadType = None):
95
105
  """
96
106
  # Метод запроса не поддерживается данным ресурсом
97
107
  """
98
- super().__init__('405', "Method Not Allowed")
108
+ super().__init__('405', "Method Not Allowed", message=message, payload=payload)
99
109
 
100
110
 
101
111
  class Conflict(_BaseEXception):
102
- def __init__(self):
112
+ def __init__(self, message: Optional[str] = None, payload: PayloadType = None):
103
113
  """
104
114
  # Конфликт состояния ресурса (например, дубликат)
105
115
  """
106
- super().__init__('409', "Conflict")
116
+ super().__init__('409', "Conflict", message=message, payload=payload)
107
117
 
108
118
 
109
119
  class InternalServerError(_BaseEXception):
110
- def __init__(self):
120
+ def __init__(self, message: Optional[str] = None, payload: PayloadType = None):
111
121
  """
112
122
  # Внутренняя ошибка сервера
113
123
  """
114
- super().__init__('500', "Internal Server Error")
124
+ super().__init__('500', "Internal Server Error", message=message, payload=payload)
115
125
 
116
126
 
117
127
  class NotImplemented(_BaseEXception):
118
- def __init__(self):
128
+ def __init__(self, message: Optional[str] = None, payload: PayloadType = None):
119
129
  """
120
130
  # Метод или функционал ещё не реализован
121
131
  """
122
- super().__init__('501', "Not Implemented")
132
+ super().__init__('501', "Not Implemented", message=message, payload=payload)
123
133
 
124
134
 
125
135
  class BadGateway(_BaseEXception):
126
- def __init__(self):
136
+ def __init__(self, message: Optional[str] = None, payload: PayloadType = None):
127
137
  """
128
138
  # Ошибка шлюза или прокси при обращении к апстриму
129
139
  """
130
- super().__init__('502', "Bad Gateway")
140
+ super().__init__('502', "Bad Gateway", message=message, payload=payload)
131
141
 
132
142
 
133
143
  class ServiceUnavailable(_BaseEXception):
134
- def __init__(self):
144
+ def __init__(self, message: Optional[str] = None, payload: PayloadType = None):
135
145
  """
136
146
  # Сервис временно недоступен
137
147
  """
138
- super().__init__('503', "Service Unavailable")
148
+ super().__init__('503', "Service Unavailable", message=message, payload=payload)
139
149
 
140
150
 
141
151
  class GatewayTimeout(_BaseEXception):
142
- def __init__(self):
152
+ def __init__(self, message: Optional[str] = None, payload: PayloadType = None):
143
153
  """
144
154
  # Таймаут при обращении к апстриму
145
155
  """
146
- super().__init__('504', "Gateway Timeout")
156
+ super().__init__('504', "Gateway Timeout", message=message, payload=payload)
147
157
 
148
158
  def guess_type(filename: str) -> str:
149
159
  """
@@ -605,6 +615,9 @@ class App:
605
615
 
606
616
  if "request" in sig.parameters:
607
617
  kw["request"] = request
618
+
619
+ params = set(sig.parameters.keys())
620
+ kw = {k: v for k, v in kw.items() if k in params}
608
621
 
609
622
  if inspect.isasyncgenfunction(r.handler):
610
623
  return r.handler(**kw)
@@ -671,7 +684,7 @@ class App:
671
684
  @self.post('/!gn-vm-host/ping', cors=gn.CORSObject(None))
672
685
  async def r_ping(request: gn.GNRequest):
673
686
 
674
- if request.client.remote_addr != '127.0.0.1':
687
+ if request.client.ip != '127.0.0.1':
675
688
  raise GNExceptions.Forbidden()
676
689
  return gn.GNResponse('ok', {'time': datetime.datetime.now(datetime.UTC).isoformat()})
677
690
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GNServer
3
- Version: 0.0.0.0.27
3
+ Version: 0.0.0.0.29
4
4
  Summary: GNServer
5
5
  Home-page: https://github.com/KeyisB/libs/tree/main/GNServer
6
6
  Author: KeyisB
@@ -0,0 +1,9 @@
1
+ GNServer/___client.py,sha256=hmeUL2Vqp-BnwJeRcLZAaIfRNVxBrRRB_AFk9ofkei4,25459
2
+ GNServer/__init__.py,sha256=V50sMYrrPdOGuI1iJm-SW7izhX-eggDH16AHvtIKjmM,1480
3
+ GNServer/_app.py,sha256=FygOu5nl2A7bO5yUA-dAJeczPdfst3clCyOjJ23KSPw,32188
4
+ GNServer/_client.py,sha256=uF5h5pu0noJ1uNWSdC-kxGvBUwUUmyyAQTt_altNJ_g,29861
5
+ gnserver-0.0.0.0.29.dist-info/licenses/LICENSE,sha256=WH_t7dKZyWJ5Ld07eYIkUG4Tv6zZWXtAdsUqYAUesn0,1084
6
+ gnserver-0.0.0.0.29.dist-info/METADATA,sha256=5q7zb4_0MdV4_COCwy-HiIm-SRu84GikJtjM6nauAOE,833
7
+ gnserver-0.0.0.0.29.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ gnserver-0.0.0.0.29.dist-info/top_level.txt,sha256=-UOUBuD4u7Qkb1o5PdcwyA3kx8xCH2lwy0tJHi26Wb4,9
9
+ gnserver-0.0.0.0.29.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- GNServer/___client.py,sha256=hmeUL2Vqp-BnwJeRcLZAaIfRNVxBrRRB_AFk9ofkei4,25459
2
- GNServer/__init__.py,sha256=V50sMYrrPdOGuI1iJm-SW7izhX-eggDH16AHvtIKjmM,1480
3
- GNServer/_app.py,sha256=WYK16u-G6TDEMBa3MVaJP3-HzTh4NIcmzsyOdxaSsm0,30664
4
- GNServer/_client.py,sha256=uF5h5pu0noJ1uNWSdC-kxGvBUwUUmyyAQTt_altNJ_g,29861
5
- gnserver-0.0.0.0.27.dist-info/licenses/LICENSE,sha256=WH_t7dKZyWJ5Ld07eYIkUG4Tv6zZWXtAdsUqYAUesn0,1084
6
- gnserver-0.0.0.0.27.dist-info/METADATA,sha256=8pB4A-duYiWVMfoKmSEE7zUs1rfo8gaF5fe1yszZfXE,833
7
- gnserver-0.0.0.0.27.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- gnserver-0.0.0.0.27.dist-info/top_level.txt,sha256=-UOUBuD4u7Qkb1o5PdcwyA3kx8xCH2lwy0tJHi26Wb4,9
9
- gnserver-0.0.0.0.27.dist-info/RECORD,,