139 lines
3.6 KiB
Python
139 lines
3.6 KiB
Python
|
|
import re
|
|
from cerberus import Validator
|
|
# pattern = re.compile('^[a-zA-Z0-9]{1,36}$') # 用于匹配至少一个数字
|
|
# m = pattern.match('111aaa3213213123123213123a222')
|
|
# print(m)
|
|
#
|
|
# schema = {
|
|
# 'name': {'type': 'string', 'required': True},
|
|
# 'age': {'type': 'integer', 'required': True, 'min': 18},
|
|
# 'email': {'type': 'string', 'required': True, 'regex': r'\w+@\w+\.\w+'}
|
|
# }
|
|
# v = Validator(schema)
|
|
# print(v.validate({ 'name': '11', 'age': 20, 'email': '764784960@qq.com'}))
|
|
# aa = str({ 'name': '11', 'age': 20, 'email': '764784960@qq.com'})
|
|
# print(isinstance(aa, dict))
|
|
|
|
# schema = {'name': {'type': 'string'}}
|
|
# v = Validator(schema)
|
|
# document = {'name1': 'john doe'}
|
|
# print(v.validate(document))
|
|
# print(v.validate(document, schema))
|
|
|
|
schema = {
|
|
'request_id': {
|
|
'type': 'string',
|
|
'required': True,
|
|
'empty': False,
|
|
'regex': r'^[a-zA-Z0-9]{1,36}$'
|
|
},
|
|
'command': {
|
|
'type': 'string',
|
|
'required': True,
|
|
'allowed': ['start', 'stop']
|
|
},
|
|
'pull_url': {
|
|
'type': 'string',
|
|
'required': False,
|
|
'nullable': True,
|
|
'maxlength': 255
|
|
},
|
|
'push_url': {
|
|
'type': 'string',
|
|
'required': False,
|
|
'nullable': True,
|
|
'maxlength': 255
|
|
},
|
|
'original_url': {
|
|
'type': 'string',
|
|
'required': False,
|
|
'nullable': True,
|
|
'maxlength': 255
|
|
},
|
|
'original_type': {
|
|
'type': 'string',
|
|
'required': False,
|
|
'nullable': True,
|
|
'maxlength': 255
|
|
},
|
|
'image_urls': {
|
|
'type': 'list',
|
|
'required': False,
|
|
'schema': {
|
|
'type': 'string',
|
|
'empty': False,
|
|
'maxlength': 5000
|
|
}
|
|
},
|
|
'results_base_dir': {
|
|
'type': 'string',
|
|
'required': False,
|
|
'nullable': True,
|
|
'regex': r'^[a-zA-Z0-9]{0,36}$'
|
|
},
|
|
'models': {
|
|
'type': 'list',
|
|
'required': False,
|
|
'schema': {
|
|
'type': 'dict',
|
|
'required': False,
|
|
'schema': {
|
|
'code': {
|
|
'type': 'string',
|
|
'required': True,
|
|
'empty': False,
|
|
'dependencies': 'categories',
|
|
'regex': r'^[a-zA-Z0-9]{1,255}$'
|
|
},
|
|
'categories': {
|
|
'type': 'list',
|
|
'required': True,
|
|
'dependencies': 'code',
|
|
'schema': {
|
|
'type': 'dict',
|
|
'required': True,
|
|
'schema': {
|
|
'id': {
|
|
'type': 'string',
|
|
'required': True,
|
|
'empty': False,
|
|
'regex': r'^[a-zA-Z0-9]{0,255}$'},
|
|
'config': {
|
|
'type': 'dict',
|
|
'required': False,
|
|
'dependencies': 'id',
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
v = Validator(schema, allow_unknown=True)
|
|
aa={
|
|
'request_id': "111",
|
|
'command': 'start',
|
|
'pull_url': None,
|
|
'push_url': None,
|
|
'original_url': '',
|
|
'original_type': '',
|
|
'image_urls': ['1','1'],
|
|
'results_base_dir': '111',
|
|
'models': [
|
|
# {
|
|
# 'code': '1',
|
|
# 'categories': [
|
|
# # {
|
|
# # 'id': '1',
|
|
# # 'config': {}
|
|
# # }
|
|
# ]
|
|
# }
|
|
]
|
|
}
|
|
|
|
print(v.validate(aa))
|
|
print(v.errors) |