123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- from flask_marshmallow import Marshmallow
- from marshmallow import fields, post_load
- ma = Marshmallow()
- class GenLabelForm:
- """
- 生成密码标签请求体
- """
- def __init__(self, info):
- self.info = info
- class GenLabelResp:
- """
- 生成密码标签响应体
- """
- def __init__(self, code, msg, label, cert):
- self.code = code
- self.msg = msg
- self.label = label
- self.cert = cert
- class VerifyLabelForm:
- """
- 验证密码标签请求体
- """
- def __init__(self, label, info, cert):
- self.label = label
- self.info = info
- self.cert = cert
- class VerifyLabelResp:
- """
- 验证密码标签响应体
- """
- def __init__(self, code, msg):
- self.msg = msg
- self.code = code
- # 定义 Owner 类
- class Owner:
- def __init__(self, name, id):
- self.name = name
- self.id = id
- # 定义 Info 类
- class Info:
- def __init__(self, owner, model):
- self.owner = owner
- self.model = model
- # 定义 Model 类
- class Model:
- def __init__(self, name, id, version, date):
- self.name = name
- self.id = id
- self.version = version
- self.date = date
- # 定义 OwnerSchema
- class OwnerSchema(ma.Schema):
- name = fields.String()
- id = fields.String()
- @post_load
- def make_owner(self, object, **kwargs):
- return Owner(**object)
- # 定义 ModelSchema
- class ModelSchema(ma.Schema):
- name = fields.String()
- id = fields.String()
- version = fields.String()
- date = fields.String()
- @post_load
- def make_model(self, object, **kwargs):
- return Model(**object)
- # 定义 InfoSchema
- class InfoSchema(ma.Schema):
- owner = fields.Nested(OwnerSchema)
- model = fields.Nested(ModelSchema)
- @post_load
- def make_info(self, object, **kwargs):
- return Info(**object)
- class GenLabelFormSchema(ma.Schema):
- info = fields.Nested(InfoSchema)
- @post_load
- def make_label(self, object, **kwargs):
- return GenLabelForm(**object)
- class GenLabelRespSchema(ma.Schema):
- code = fields.Integer()
- msg = fields.String()
- label = fields.String()
- cert = fields.String()
- @post_load
- def make_label_resp(self, object, **kwargs):
- return GenLabelResp(**object)
- class VerifyLabelFormSchema(ma.Schema):
- label = fields.String()
- info = fields.String()
- cert = fields.String()
- @post_load
- def make_verify_label(self, object, **kwargs):
- return VerifyLabelForm(**object)
- class VerifyLabelRespSchema(ma.Schema):
- code = fields.Integer()
- msg = fields.String()
- @post_load
- def make_verify_label_resp(self, object, **kwargs):
- return VerifyLabelResp(**object)
|