45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
|
|
from dataclasses import dataclass
|
||
|
|
import json as JSON
|
||
|
|
from flask import request
|
||
|
|
from ResponseCode import RequestMethod
|
||
|
|
from abc import abstractmethod
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass
|
||
|
|
class RequestHandler(object):
|
||
|
|
"""
|
||
|
|
基本数据请求体
|
||
|
|
login_username: str
|
||
|
|
login_password: str
|
||
|
|
self.login_username = self.check_string(self.json_data.get("login_username"))
|
||
|
|
self.login_password = self.check_string(self.json_data.get("login_token"))
|
||
|
|
|
||
|
|
"""
|
||
|
|
|
||
|
|
def __init__(self, methods: RequestMethod, json_data: bytes | str | dict):
|
||
|
|
"""
|
||
|
|
:param methods: 请求方式, 需要传入枚举类型的数据
|
||
|
|
:param json_data: 请求的数据, 如果是POST请求, 则为bytes|str类型
|
||
|
|
如果是GET请求, 则为dict类型
|
||
|
|
if request.method == "GET":
|
||
|
|
super(OverrideSampleRequestParams, self).__init__(json_data=request.args, methods=RequestMethods.GET)
|
||
|
|
if request.method == "POST":
|
||
|
|
super(OverrideSampleRequestParams, self).__init__(json_data=request.get_data(), methods=RequestMethods.POST)
|
||
|
|
"""
|
||
|
|
super().__init__()
|
||
|
|
if methods == RequestMethod.POST:
|
||
|
|
self.json_data: dict = JSON.loads(json_data)
|
||
|
|
elif methods == RequestMethod.GET:
|
||
|
|
self.json_data = json_data
|
||
|
|
|
||
|
|
@abstractmethod
|
||
|
|
def check_params(self) -> bool:
|
||
|
|
return False or True
|
||
|
|
|
||
|
|
def repr(self):
|
||
|
|
print(self.__repr__())
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def return_headers():
|
||
|
|
return request.headers
|