reyserver 1.1.77__py3-none-any.whl → 1.1.79__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.
Potentially problematic release.
This version of reyserver might be problematic. Click here for more details.
- reyserver/__init__.py +1 -0
- reyserver/rall.py +3 -1
- reyserver/rauth.py +2 -1
- reyserver/rbase.py +4 -317
- reyserver/rbind.py +331 -0
- reyserver/rfile.py +2 -1
- reyserver/rpublic.py +1 -1
- reyserver/rredirect.py +48 -0
- reyserver/rserver.py +21 -2
- reyserver/rtest.py +1 -1
- {reyserver-1.1.77.dist-info → reyserver-1.1.79.dist-info}/METADATA +1 -1
- reyserver-1.1.79.dist-info/RECORD +15 -0
- reyserver-1.1.77.dist-info/RECORD +0 -13
- {reyserver-1.1.77.dist-info → reyserver-1.1.79.dist-info}/WHEEL +0 -0
- {reyserver-1.1.77.dist-info → reyserver-1.1.79.dist-info}/licenses/LICENSE +0 -0
reyserver/__init__.py
CHANGED
reyserver/rall.py
CHANGED
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
|
|
12
12
|
from .rauth import *
|
|
13
13
|
from .rbase import *
|
|
14
|
+
from .rbind import *
|
|
14
15
|
from .rclient import *
|
|
15
16
|
from .rfile import *
|
|
16
|
-
from rpublic import *
|
|
17
|
+
from .rpublic import *
|
|
18
|
+
from .rredirect import *
|
|
17
19
|
from .rserver import *
|
|
18
20
|
from .rtest import *
|
reyserver/rauth.py
CHANGED
reyserver/rbase.py
CHANGED
|
@@ -9,39 +9,17 @@
|
|
|
9
9
|
"""
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
from typing import
|
|
12
|
+
from typing import NoReturn
|
|
13
13
|
from http import HTTPStatus
|
|
14
|
-
from fastapi import
|
|
15
|
-
from
|
|
16
|
-
Depends,
|
|
17
|
-
Path,
|
|
18
|
-
Query,
|
|
19
|
-
Header,
|
|
20
|
-
Cookie,
|
|
21
|
-
Body,
|
|
22
|
-
Form,
|
|
23
|
-
File as Forms
|
|
24
|
-
)
|
|
25
|
-
from reydb.rconn import DatabaseConnectionAsync
|
|
26
|
-
from reydb.rorm import DatabaseORMSessionAsync
|
|
27
|
-
from reykit.rbase import Base, Exit, StaticMeta, Singleton, throw
|
|
28
|
-
|
|
29
|
-
from . import rserver
|
|
14
|
+
from fastapi import HTTPException
|
|
15
|
+
from reykit.rbase import Base, Exit, throw
|
|
30
16
|
|
|
31
17
|
|
|
32
18
|
__all__ = (
|
|
33
19
|
'ServerBase',
|
|
34
20
|
'ServerExit',
|
|
35
21
|
'ServerExitAPI',
|
|
36
|
-
'exit_api'
|
|
37
|
-
'ServerBindInstanceDatabaseSuper',
|
|
38
|
-
'ServerBindInstanceDatabaseConnection',
|
|
39
|
-
'ServerBindInstanceDatabaseSession',
|
|
40
|
-
'ServerBindInstance',
|
|
41
|
-
'ServerBind',
|
|
42
|
-
'Bind',
|
|
43
|
-
'router_test',
|
|
44
|
-
'router_public'
|
|
22
|
+
'exit_api'
|
|
45
23
|
)
|
|
46
24
|
|
|
47
25
|
|
|
@@ -83,294 +61,3 @@ def exit_api(code: int = 400, text: str | None = None) -> NoReturn:
|
|
|
83
61
|
|
|
84
62
|
# Throw exception.
|
|
85
63
|
raise ServerExitAPI(code, text)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
class ServerBindInstanceDatabaseSuper(ServerBase):
|
|
89
|
-
"""
|
|
90
|
-
Server API bind parameter build database instance super type.
|
|
91
|
-
"""
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
def __getattr__(self, name: str) -> Depends:
|
|
95
|
-
"""
|
|
96
|
-
Create dependencie instance of asynchronous database.
|
|
97
|
-
|
|
98
|
-
Parameters
|
|
99
|
-
----------
|
|
100
|
-
name : Database engine name.
|
|
101
|
-
mode : Mode.
|
|
102
|
-
- `Literl['sess']`: Create ORM session instance.
|
|
103
|
-
- `Literl['conn']`: Create connection instance.
|
|
104
|
-
|
|
105
|
-
Returns
|
|
106
|
-
-------
|
|
107
|
-
Dependencie instance.
|
|
108
|
-
"""
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
async def depend_func(server: Bind.Server = Bind.server):
|
|
112
|
-
"""
|
|
113
|
-
Dependencie function of asynchronous database.
|
|
114
|
-
"""
|
|
115
|
-
|
|
116
|
-
# Parameter.
|
|
117
|
-
engine = server.db[name]
|
|
118
|
-
|
|
119
|
-
# Context.
|
|
120
|
-
match self:
|
|
121
|
-
case ServerBindInstanceDatabaseConnection():
|
|
122
|
-
async with engine.connect() as conn:
|
|
123
|
-
yield conn
|
|
124
|
-
case ServerBindInstanceDatabaseSession():
|
|
125
|
-
async with engine.orm.session() as sess:
|
|
126
|
-
yield sess
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
# Create.
|
|
130
|
-
depend = Depends(depend_func)
|
|
131
|
-
|
|
132
|
-
return depend
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
@overload
|
|
136
|
-
def __getitem__(self, engine: str) -> DatabaseConnectionAsync: ...
|
|
137
|
-
|
|
138
|
-
__getitem__ = __getattr__
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
class ServerBindInstanceDatabaseConnection(ServerBindInstanceDatabaseSuper, Singleton):
|
|
142
|
-
"""
|
|
143
|
-
Server API bind parameter build database connection instance type, singleton mode.
|
|
144
|
-
"""
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
class ServerBindInstanceDatabaseSession(ServerBindInstanceDatabaseSuper, Singleton):
|
|
148
|
-
"""
|
|
149
|
-
Server API bind parameter build database session instance type, singleton mode.
|
|
150
|
-
"""
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
class ServerBindInstance(ServerBase, Singleton):
|
|
154
|
-
"""
|
|
155
|
-
Server API bind parameter build instance type.
|
|
156
|
-
"""
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
@property
|
|
160
|
-
def path(self) -> Path:
|
|
161
|
-
"""
|
|
162
|
-
Path instance.
|
|
163
|
-
"""
|
|
164
|
-
|
|
165
|
-
# Build.
|
|
166
|
-
path = Path()
|
|
167
|
-
|
|
168
|
-
return path
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
@property
|
|
172
|
-
def query(self) -> Query:
|
|
173
|
-
"""
|
|
174
|
-
Query instance.
|
|
175
|
-
"""
|
|
176
|
-
|
|
177
|
-
# Build.
|
|
178
|
-
query = Query()
|
|
179
|
-
|
|
180
|
-
return query
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
@property
|
|
184
|
-
def header(self) -> Header:
|
|
185
|
-
"""
|
|
186
|
-
Header instance.
|
|
187
|
-
"""
|
|
188
|
-
|
|
189
|
-
# Build.
|
|
190
|
-
header = Header()
|
|
191
|
-
|
|
192
|
-
return header
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
@property
|
|
196
|
-
def cookie(self) -> Cookie:
|
|
197
|
-
"""
|
|
198
|
-
Cookie instance.
|
|
199
|
-
"""
|
|
200
|
-
|
|
201
|
-
# Build.
|
|
202
|
-
cookie = Cookie()
|
|
203
|
-
|
|
204
|
-
return cookie
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
@property
|
|
208
|
-
def body(self) -> Body:
|
|
209
|
-
"""
|
|
210
|
-
Body instance.
|
|
211
|
-
"""
|
|
212
|
-
|
|
213
|
-
# Build.
|
|
214
|
-
body = Body()
|
|
215
|
-
|
|
216
|
-
return body
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
@property
|
|
220
|
-
def form(self) -> Form:
|
|
221
|
-
"""
|
|
222
|
-
Form instance.
|
|
223
|
-
"""
|
|
224
|
-
|
|
225
|
-
# Build.
|
|
226
|
-
form = Form()
|
|
227
|
-
|
|
228
|
-
return form
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
@property
|
|
232
|
-
def forms(self) -> Forms:
|
|
233
|
-
"""
|
|
234
|
-
Forms instance.
|
|
235
|
-
"""
|
|
236
|
-
|
|
237
|
-
# Build.
|
|
238
|
-
forms = Forms()
|
|
239
|
-
|
|
240
|
-
return forms
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
@property
|
|
244
|
-
def query_n(self) -> Query:
|
|
245
|
-
"""
|
|
246
|
-
Query instance, default `None`.
|
|
247
|
-
"""
|
|
248
|
-
|
|
249
|
-
# Build.
|
|
250
|
-
query = Query(None)
|
|
251
|
-
|
|
252
|
-
return query
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
@property
|
|
256
|
-
def header_n(self) -> Header:
|
|
257
|
-
"""
|
|
258
|
-
Header instance, default `None`.
|
|
259
|
-
"""
|
|
260
|
-
|
|
261
|
-
# Build.
|
|
262
|
-
header = Header(None)
|
|
263
|
-
|
|
264
|
-
return header
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
@property
|
|
268
|
-
def cookie_n(self) -> Cookie:
|
|
269
|
-
"""
|
|
270
|
-
Cookie instance, default `None`.
|
|
271
|
-
"""
|
|
272
|
-
|
|
273
|
-
# Build.
|
|
274
|
-
cookie = Cookie(None)
|
|
275
|
-
|
|
276
|
-
return cookie
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
@property
|
|
280
|
-
def body_n(self) -> Body:
|
|
281
|
-
"""
|
|
282
|
-
Body instance, default `None`.
|
|
283
|
-
"""
|
|
284
|
-
|
|
285
|
-
# Build.
|
|
286
|
-
body = Body(None)
|
|
287
|
-
|
|
288
|
-
return body
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
@property
|
|
292
|
-
def form_n(self) -> Form:
|
|
293
|
-
"""
|
|
294
|
-
Form instance, default `None`.
|
|
295
|
-
"""
|
|
296
|
-
|
|
297
|
-
# Build.
|
|
298
|
-
form = Form(None)
|
|
299
|
-
|
|
300
|
-
return form
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
@property
|
|
304
|
-
def forms_n(self) -> Forms:
|
|
305
|
-
"""
|
|
306
|
-
Forms instance, default `None`.
|
|
307
|
-
"""
|
|
308
|
-
|
|
309
|
-
# Build.
|
|
310
|
-
forms = Forms(None)
|
|
311
|
-
|
|
312
|
-
return forms
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
async def depend_server(request: Request) -> 'rserver.Server':
|
|
316
|
-
"""
|
|
317
|
-
Dependencie function of now Server instance.
|
|
318
|
-
|
|
319
|
-
Parameters
|
|
320
|
-
----------
|
|
321
|
-
request : Request.
|
|
322
|
-
|
|
323
|
-
Returns
|
|
324
|
-
-------
|
|
325
|
-
Server.
|
|
326
|
-
"""
|
|
327
|
-
|
|
328
|
-
# Get.
|
|
329
|
-
app: FastAPI = request.app
|
|
330
|
-
server: rserver.Server = app.extra['server']
|
|
331
|
-
|
|
332
|
-
return server
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
class ServerBind(ServerBase, metaclass=StaticMeta):
|
|
336
|
-
"""
|
|
337
|
-
Server API bind parameter type.
|
|
338
|
-
"""
|
|
339
|
-
|
|
340
|
-
Request = Request
|
|
341
|
-
'Reqeust instance dependency type.'
|
|
342
|
-
Path = Path
|
|
343
|
-
'URL source path dependency type.'
|
|
344
|
-
Query = Query
|
|
345
|
-
'URL query parameter dependency type.'
|
|
346
|
-
Header = Header
|
|
347
|
-
'Request header parameter dependency type.'
|
|
348
|
-
Cookie = Cookie
|
|
349
|
-
'Request header cookie parameter dependency type.'
|
|
350
|
-
Body = Body
|
|
351
|
-
'Request body JSON parameter dependency type.'
|
|
352
|
-
Form = Form
|
|
353
|
-
'Request body form parameter dependency type.'
|
|
354
|
-
Forms = Forms
|
|
355
|
-
'Request body multiple forms parameter dependency type.'
|
|
356
|
-
File = UploadFile
|
|
357
|
-
'Type hints file type.'
|
|
358
|
-
Depend = Depends
|
|
359
|
-
'Dependency type.'
|
|
360
|
-
Conn = DatabaseConnectionAsync
|
|
361
|
-
Sess = DatabaseORMSessionAsync
|
|
362
|
-
Server = Type['rserver.Server']
|
|
363
|
-
'Server type.'
|
|
364
|
-
server: Depend = Depend(depend_server)
|
|
365
|
-
'Server instance dependency type.'
|
|
366
|
-
i = ServerBindInstance()
|
|
367
|
-
'Server API bind parameter build instance.'
|
|
368
|
-
conn = ServerBindInstanceDatabaseConnection()
|
|
369
|
-
'Server API bind parameter asynchronous database connection.'
|
|
370
|
-
sess = ServerBindInstanceDatabaseSession()
|
|
371
|
-
'Server API bind parameter asynchronous database session.'
|
|
372
|
-
token: Depend
|
|
373
|
-
'Server authentication token dependency type.'
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
Bind = ServerBind
|
reyserver/rbind.py
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
# !/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
@Time : 2025-10-21
|
|
6
|
+
@Author : Rey
|
|
7
|
+
@Contact : reyxbo@163.com
|
|
8
|
+
@Explain : Dependency bind methods.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
from typing import overload, TYPE_CHECKING
|
|
13
|
+
from fastapi import FastAPI, Request, UploadFile
|
|
14
|
+
from fastapi.params import (
|
|
15
|
+
Depends,
|
|
16
|
+
Path,
|
|
17
|
+
Query,
|
|
18
|
+
Header,
|
|
19
|
+
Cookie,
|
|
20
|
+
Body,
|
|
21
|
+
Form,
|
|
22
|
+
File as Forms
|
|
23
|
+
)
|
|
24
|
+
from reydb.rconn import DatabaseConnectionAsync
|
|
25
|
+
from reydb.rorm import DatabaseORMSessionAsync
|
|
26
|
+
from reykit.rbase import StaticMeta, Singleton
|
|
27
|
+
|
|
28
|
+
from . import rserver
|
|
29
|
+
from .rbase import ServerBase
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
__all__ = (
|
|
33
|
+
'ServerBindInstanceDatabaseSuper',
|
|
34
|
+
'ServerBindInstanceDatabaseConnection',
|
|
35
|
+
'ServerBindInstanceDatabaseSession',
|
|
36
|
+
'ServerBindInstance',
|
|
37
|
+
'ServerBind',
|
|
38
|
+
'Bind'
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ServerBindInstanceDatabaseSuper(ServerBase):
|
|
43
|
+
"""
|
|
44
|
+
Server API bind parameter build database instance super type.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def __getattr__(self, name: str) -> Depends:
|
|
49
|
+
"""
|
|
50
|
+
Create dependencie instance of asynchronous database.
|
|
51
|
+
|
|
52
|
+
Parameters
|
|
53
|
+
----------
|
|
54
|
+
name : Database engine name.
|
|
55
|
+
mode : Mode.
|
|
56
|
+
- `Literl['sess']`: Create ORM session instance.
|
|
57
|
+
- `Literl['conn']`: Create connection instance.
|
|
58
|
+
|
|
59
|
+
Returns
|
|
60
|
+
-------
|
|
61
|
+
Dependencie instance.
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
async def depend_func(server: Bind.Server = Bind.server):
|
|
66
|
+
"""
|
|
67
|
+
Dependencie function of asynchronous database.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
# Parameter.
|
|
71
|
+
engine = server.db[name]
|
|
72
|
+
|
|
73
|
+
# Context.
|
|
74
|
+
match self:
|
|
75
|
+
case ServerBindInstanceDatabaseConnection():
|
|
76
|
+
async with engine.connect() as conn:
|
|
77
|
+
yield conn
|
|
78
|
+
case ServerBindInstanceDatabaseSession():
|
|
79
|
+
async with engine.orm.session() as sess:
|
|
80
|
+
yield sess
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
# Create.
|
|
84
|
+
depend = Depends(depend_func)
|
|
85
|
+
|
|
86
|
+
return depend
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@overload
|
|
90
|
+
def __getitem__(self, engine: str) -> DatabaseConnectionAsync: ...
|
|
91
|
+
|
|
92
|
+
__getitem__ = __getattr__
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class ServerBindInstanceDatabaseConnection(ServerBindInstanceDatabaseSuper, Singleton):
|
|
96
|
+
"""
|
|
97
|
+
Server API bind parameter build database connection instance type, singleton mode.
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class ServerBindInstanceDatabaseSession(ServerBindInstanceDatabaseSuper, Singleton):
|
|
102
|
+
"""
|
|
103
|
+
Server API bind parameter build database session instance type, singleton mode.
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class ServerBindInstance(ServerBase, Singleton):
|
|
108
|
+
"""
|
|
109
|
+
Server API bind parameter build instance type.
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@property
|
|
114
|
+
def path(self) -> Path:
|
|
115
|
+
"""
|
|
116
|
+
Path instance.
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
# Build.
|
|
120
|
+
path = Path()
|
|
121
|
+
|
|
122
|
+
return path
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
@property
|
|
126
|
+
def query(self) -> Query:
|
|
127
|
+
"""
|
|
128
|
+
Query instance.
|
|
129
|
+
"""
|
|
130
|
+
|
|
131
|
+
# Build.
|
|
132
|
+
query = Query()
|
|
133
|
+
|
|
134
|
+
return query
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@property
|
|
138
|
+
def header(self) -> Header:
|
|
139
|
+
"""
|
|
140
|
+
Header instance.
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
# Build.
|
|
144
|
+
header = Header()
|
|
145
|
+
|
|
146
|
+
return header
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def cookie(self) -> Cookie:
|
|
151
|
+
"""
|
|
152
|
+
Cookie instance.
|
|
153
|
+
"""
|
|
154
|
+
|
|
155
|
+
# Build.
|
|
156
|
+
cookie = Cookie()
|
|
157
|
+
|
|
158
|
+
return cookie
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@property
|
|
162
|
+
def body(self) -> Body:
|
|
163
|
+
"""
|
|
164
|
+
Body instance.
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
# Build.
|
|
168
|
+
body = Body()
|
|
169
|
+
|
|
170
|
+
return body
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
@property
|
|
174
|
+
def form(self) -> Form:
|
|
175
|
+
"""
|
|
176
|
+
Form instance.
|
|
177
|
+
"""
|
|
178
|
+
|
|
179
|
+
# Build.
|
|
180
|
+
form = Form()
|
|
181
|
+
|
|
182
|
+
return form
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
@property
|
|
186
|
+
def forms(self) -> Forms:
|
|
187
|
+
"""
|
|
188
|
+
Forms instance.
|
|
189
|
+
"""
|
|
190
|
+
|
|
191
|
+
# Build.
|
|
192
|
+
forms = Forms()
|
|
193
|
+
|
|
194
|
+
return forms
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
@property
|
|
198
|
+
def query_n(self) -> Query:
|
|
199
|
+
"""
|
|
200
|
+
Query instance, default `None`.
|
|
201
|
+
"""
|
|
202
|
+
|
|
203
|
+
# Build.
|
|
204
|
+
query = Query(None)
|
|
205
|
+
|
|
206
|
+
return query
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
@property
|
|
210
|
+
def header_n(self) -> Header:
|
|
211
|
+
"""
|
|
212
|
+
Header instance, default `None`.
|
|
213
|
+
"""
|
|
214
|
+
|
|
215
|
+
# Build.
|
|
216
|
+
header = Header(None)
|
|
217
|
+
|
|
218
|
+
return header
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
@property
|
|
222
|
+
def cookie_n(self) -> Cookie:
|
|
223
|
+
"""
|
|
224
|
+
Cookie instance, default `None`.
|
|
225
|
+
"""
|
|
226
|
+
|
|
227
|
+
# Build.
|
|
228
|
+
cookie = Cookie(None)
|
|
229
|
+
|
|
230
|
+
return cookie
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
@property
|
|
234
|
+
def body_n(self) -> Body:
|
|
235
|
+
"""
|
|
236
|
+
Body instance, default `None`.
|
|
237
|
+
"""
|
|
238
|
+
|
|
239
|
+
# Build.
|
|
240
|
+
body = Body(None)
|
|
241
|
+
|
|
242
|
+
return body
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
@property
|
|
246
|
+
def form_n(self) -> Form:
|
|
247
|
+
"""
|
|
248
|
+
Form instance, default `None`.
|
|
249
|
+
"""
|
|
250
|
+
|
|
251
|
+
# Build.
|
|
252
|
+
form = Form(None)
|
|
253
|
+
|
|
254
|
+
return form
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
@property
|
|
258
|
+
def forms_n(self) -> Forms:
|
|
259
|
+
"""
|
|
260
|
+
Forms instance, default `None`.
|
|
261
|
+
"""
|
|
262
|
+
|
|
263
|
+
# Build.
|
|
264
|
+
forms = Forms(None)
|
|
265
|
+
|
|
266
|
+
return forms
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
async def depend_server(request: Request) -> 'rserver.Server':
|
|
270
|
+
"""
|
|
271
|
+
Dependencie function of now Server instance.
|
|
272
|
+
|
|
273
|
+
Parameters
|
|
274
|
+
----------
|
|
275
|
+
request : Request.
|
|
276
|
+
|
|
277
|
+
Returns
|
|
278
|
+
-------
|
|
279
|
+
Server.
|
|
280
|
+
"""
|
|
281
|
+
|
|
282
|
+
# Get.
|
|
283
|
+
app: FastAPI = request.app
|
|
284
|
+
server: rserver.Server = app.extra['server']
|
|
285
|
+
|
|
286
|
+
return server
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
class ServerBind(ServerBase, metaclass=StaticMeta):
|
|
290
|
+
"""
|
|
291
|
+
Server API bind parameter type.
|
|
292
|
+
"""
|
|
293
|
+
|
|
294
|
+
Request = Request
|
|
295
|
+
'Reqeust instance dependency type.'
|
|
296
|
+
Path = Path
|
|
297
|
+
'URL source path dependency type.'
|
|
298
|
+
Query = Query
|
|
299
|
+
'URL query parameter dependency type.'
|
|
300
|
+
Header = Header
|
|
301
|
+
'Request header parameter dependency type.'
|
|
302
|
+
Cookie = Cookie
|
|
303
|
+
'Request header cookie parameter dependency type.'
|
|
304
|
+
Body = Body
|
|
305
|
+
'Request body JSON parameter dependency type.'
|
|
306
|
+
Form = Form
|
|
307
|
+
'Request body form parameter dependency type.'
|
|
308
|
+
Forms = Forms
|
|
309
|
+
'Request body multiple forms parameter dependency type.'
|
|
310
|
+
File = UploadFile
|
|
311
|
+
'Type hints file type.'
|
|
312
|
+
Depend = Depends
|
|
313
|
+
'Dependency type.'
|
|
314
|
+
Conn = DatabaseConnectionAsync
|
|
315
|
+
Sess = DatabaseORMSessionAsync
|
|
316
|
+
if TYPE_CHECKING:
|
|
317
|
+
Server = rserver.Server
|
|
318
|
+
'Server type.'
|
|
319
|
+
server: Depend = Depend(depend_server)
|
|
320
|
+
'Server instance dependency type.'
|
|
321
|
+
i = ServerBindInstance()
|
|
322
|
+
'Server API bind parameter build instance.'
|
|
323
|
+
conn = ServerBindInstanceDatabaseConnection()
|
|
324
|
+
'Server API bind parameter asynchronous database connection.'
|
|
325
|
+
sess = ServerBindInstanceDatabaseSession()
|
|
326
|
+
'Server API bind parameter asynchronous database session.'
|
|
327
|
+
token: Depend
|
|
328
|
+
'Server authentication token dependency type.'
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
Bind = ServerBind
|
reyserver/rfile.py
CHANGED
|
@@ -14,7 +14,8 @@ from fastapi.responses import FileResponse
|
|
|
14
14
|
from reydb import rorm, DatabaseEngine, DatabaseEngineAsync
|
|
15
15
|
from reykit.ros import get_md5
|
|
16
16
|
|
|
17
|
-
from .rbase import
|
|
17
|
+
from .rbase import exit_api
|
|
18
|
+
from .rbind import Bind
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
__all__ = (
|
reyserver/rpublic.py
CHANGED
reyserver/rredirect.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# !/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
@Time : 2025-10-21
|
|
6
|
+
@Author : Rey
|
|
7
|
+
@Contact : reyxbo@163.com
|
|
8
|
+
@Explain : Redirect methods.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
from fastapi import APIRouter
|
|
13
|
+
from fastapi.responses import RedirectResponse
|
|
14
|
+
from reykit.rnet import join_url
|
|
15
|
+
|
|
16
|
+
from .rbind import Bind
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
__all__ = (
|
|
20
|
+
'router_redirect',
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
router_redirect = APIRouter()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@router_redirect.get('/{path:path}')
|
|
28
|
+
def redirect_all(
|
|
29
|
+
path: str = Bind.i.path,
|
|
30
|
+
server: Bind.Server = Bind.server
|
|
31
|
+
) -> RedirectResponse:
|
|
32
|
+
"""
|
|
33
|
+
Redirect all requests to the target server.
|
|
34
|
+
|
|
35
|
+
Parameters
|
|
36
|
+
----------
|
|
37
|
+
path : Resource path.
|
|
38
|
+
|
|
39
|
+
Returns
|
|
40
|
+
-------
|
|
41
|
+
Redirect response.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
# Response.
|
|
45
|
+
url = join_url(server.api_redirect_server_url, path)
|
|
46
|
+
response = RedirectResponse(url, 308)
|
|
47
|
+
|
|
48
|
+
return response
|
reyserver/rserver.py
CHANGED
|
@@ -13,7 +13,6 @@ from typing import Literal
|
|
|
13
13
|
from collections.abc import Sequence, Callable, Coroutine
|
|
14
14
|
from inspect import iscoroutinefunction
|
|
15
15
|
from contextlib import asynccontextmanager, _AsyncGeneratorContextManager
|
|
16
|
-
from logging import getLogger, Filter
|
|
17
16
|
from uvicorn import run as uvicorn_run
|
|
18
17
|
from starlette.middleware.base import _StreamingResponse
|
|
19
18
|
from fastapi import FastAPI, Request
|
|
@@ -26,7 +25,8 @@ from reykit.rbase import CoroutineFunctionSimple, Singleton, throw
|
|
|
26
25
|
from reykit.ros import FileStore
|
|
27
26
|
from reykit.rrand import randchar
|
|
28
27
|
|
|
29
|
-
from .rbase import ServerBase
|
|
28
|
+
from .rbase import ServerBase
|
|
29
|
+
from .rbind import Bind
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
__all__ = (
|
|
@@ -45,6 +45,8 @@ class Server(ServerBase, Singleton):
|
|
|
45
45
|
'Whether start authentication.'
|
|
46
46
|
api_public_dir: str
|
|
47
47
|
'Public directory.'
|
|
48
|
+
api_redirect_server_url: str
|
|
49
|
+
'Target server URL of redirect all requests.'
|
|
48
50
|
api_auth_key: str
|
|
49
51
|
'Authentication API JWT encryption key.'
|
|
50
52
|
api_auth_sess_seconds: int
|
|
@@ -332,6 +334,23 @@ class Server(ServerBase, Singleton):
|
|
|
332
334
|
self.app.include_router(router_public, tags=['public'])
|
|
333
335
|
|
|
334
336
|
|
|
337
|
+
def add_api_redirect_all(self, server_url: str) -> None:
|
|
338
|
+
"""
|
|
339
|
+
Add redirect all API.
|
|
340
|
+
Redirect all requests to the target server.
|
|
341
|
+
|
|
342
|
+
Parameters
|
|
343
|
+
----------
|
|
344
|
+
server_url : Target server URL.
|
|
345
|
+
"""
|
|
346
|
+
|
|
347
|
+
from .rredirect import router_redirect
|
|
348
|
+
|
|
349
|
+
# Add.
|
|
350
|
+
self.api_redirect_server_url = server_url
|
|
351
|
+
self.app.include_router(router_redirect, tags=['redirect'])
|
|
352
|
+
|
|
353
|
+
|
|
335
354
|
def add_api_auth(self, key: str | None = None, sess_seconds: int = 28800) -> None:
|
|
336
355
|
"""
|
|
337
356
|
Add authentication API.
|
reyserver/rtest.py
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
reyserver/__init__.py,sha256=iT5IWIBDvaeYvxs0HuV6mZfN2D0G4xkb_0DhX-VpsDk,454
|
|
2
|
+
reyserver/rall.py,sha256=a3e8o1wtV_wBlR2m-df94SQ7TakC9-jPUoxNZfix1nM,364
|
|
3
|
+
reyserver/rauth.py,sha256=7mANcRcbJ3e4u0PDSMquBeCWKchHbmVeFOVv7syU7Q0,15236
|
|
4
|
+
reyserver/rbase.py,sha256=mq6ChIcxb8-RUZgYqJZ8LOa0XTr0d8VU-xVzhJ0q5AQ,1134
|
|
5
|
+
reyserver/rbind.py,sha256=QrRCT8p-2bwxxBQNZmFq4RAsVHs3_mRuobsbHo1Uc9M,6792
|
|
6
|
+
reyserver/rclient.py,sha256=w79RJEjAfIlQatCeZZIlrGLH_A5vEw9HvpHp3a5bNYw,6295
|
|
7
|
+
reyserver/rfile.py,sha256=xudSM-bVRqzCvifCUTgiZwitPzPNe1KQ2GXLgHtu2zg,8891
|
|
8
|
+
reyserver/rpublic.py,sha256=ixKDWdDihdVQ8Pqjpril7veJ9kkFK9yiRm8CTwmck4Q,1095
|
|
9
|
+
reyserver/rredirect.py,sha256=c7wgXn5UeF53irMlbJ8vctec2KEc3DuHhBOa8NBoFjA,857
|
|
10
|
+
reyserver/rserver.py,sha256=GnsGTsjTUogIqY8o1onKzYqIAoGUSVXWnpxJoW7nvSg,11329
|
|
11
|
+
reyserver/rtest.py,sha256=MPYsyRzO3mZL5LJfUeBY1cafXvDsT2BGqoXq49wmJeo,777
|
|
12
|
+
reyserver-1.1.79.dist-info/METADATA,sha256=rNMsd11WUSGw5uG_xhjC4oncl1V5Uh323zSfYrphCqs,1666
|
|
13
|
+
reyserver-1.1.79.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
14
|
+
reyserver-1.1.79.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
|
15
|
+
reyserver-1.1.79.dist-info/RECORD,,
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
reyserver/__init__.py,sha256=umEAldZYjSIpHJQHUOXlgXqMgOiRC-FRGmRZjrji7as,423
|
|
2
|
-
reyserver/rall.py,sha256=SoG4PX2YAz94EuelDNhk1wvwNkrLfzskiWoknEBZitk,315
|
|
3
|
-
reyserver/rauth.py,sha256=SGBtopM4fwn7pFjFPmrh6mD61c0iSJmqYEYUpgoCayA,15217
|
|
4
|
-
reyserver/rbase.py,sha256=hdBRiaGho12D7qoH8P8w7sZK7Jd6xTJSJXIiVoiFNFw,7654
|
|
5
|
-
reyserver/rclient.py,sha256=w79RJEjAfIlQatCeZZIlrGLH_A5vEw9HvpHp3a5bNYw,6295
|
|
6
|
-
reyserver/rfile.py,sha256=qqJrCwDr27ymXgBs1n6nFwqUrZZs-rxa97isaCOaGNY,8872
|
|
7
|
-
reyserver/rpublic.py,sha256=iZvEgIUYtXavStpTzXDB71jd7X8NaEx3yZBnBHrtmPI,1095
|
|
8
|
-
reyserver/rserver.py,sha256=Bjde4jRQdeijJSWpz0eU0Dy3sNKxsQiY2xBmWoFaiuA,10817
|
|
9
|
-
reyserver/rtest.py,sha256=z7i-tKwDzqErebLgF-M2hBg5HUKStK8b9398Yca9s-g,777
|
|
10
|
-
reyserver-1.1.77.dist-info/METADATA,sha256=0dzV3A8ROwrPWrQeHkrJT1FbLgKC3f3mJ1R36pUNpZU,1666
|
|
11
|
-
reyserver-1.1.77.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
12
|
-
reyserver-1.1.77.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
|
13
|
-
reyserver-1.1.77.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|