28 lines
951 B
Python
28 lines
951 B
Python
|
|
"""离线测试使用的 HTTP 装饰器替身;路由函数本体仍执行 api.py 的实现。"""
|
||
|
|
import sys
|
||
|
|
import types
|
||
|
|
|
||
|
|
try:
|
||
|
|
import fastapi
|
||
|
|
except ImportError:
|
||
|
|
class Router:
|
||
|
|
def __init__(self, *a, **kw): pass
|
||
|
|
def get(self, *a, **kw): return lambda fn: fn
|
||
|
|
post = api_route = get
|
||
|
|
def include_router(self, *a, **kw): pass
|
||
|
|
|
||
|
|
class HTTPException(Exception):
|
||
|
|
def __init__(self, status_code, detail):
|
||
|
|
self.status_code, self.detail = status_code, detail
|
||
|
|
super().__init__(detail)
|
||
|
|
|
||
|
|
fa = types.ModuleType('fastapi')
|
||
|
|
fa.FastAPI = fa.APIRouter = Router
|
||
|
|
fa.Request = type('Request', (), {})
|
||
|
|
fa.HTTPException = HTTPException
|
||
|
|
fa.Header = fa.Query = lambda default=None, **kw: default
|
||
|
|
sys.modules['fastapi'] = fa
|
||
|
|
resp = types.ModuleType('fastapi.responses')
|
||
|
|
resp.PlainTextResponse = lambda content, **kw: content
|
||
|
|
sys.modules['fastapi.responses'] = resp
|