def to_python(value):
try:
return ObjectId(base64_decode(value))
except (InvalidId, ValueError, TypeError):
raise ValidationError()
python类ValidationError()的实例源码
def to_python(self, value):
try:
return date(*(int(_) for _ in value.split('-')))
except ValueError:
raise ValidationError('invalid date format')
def to_python(self, value):
try:
return ObjectId(value)
except InvalidId:
raise ValidationError('invalid id')
def to_python(self, value):
if not is_address(value):
raise ValidationError()
value = add_0x_prefix(value)
return value
def to_python(self, value):
tmp = [None, None, None]
for k,v in enumerate(value.split('-')):
if k == 3: raise ValidationError()
tmp[k]=v
try:
tmp[1]=int(tmp[1])
except:
raise ValidationError()
return tmp
def to_python(self, value):
try:
return from_client_participant_id(value)
except BadRequest as ex:
raise ValidationError(ex.description)
def to_python(self, value):
intval = int(value)
if not 0 < intval <= 2 ** 32:
raise ValidationError()
model = self.resolve_id(intval)
if not model:
raise ValidationError()
return model
def to_python(self, value):
if not validation.check_board_name_validity(value):
raise ValidationError()
model = board_service.find_board(value)
if not model:
raise ValidationError()
return model
def to_python(self, value):
if len(str(value)) != 2 or not str(value).isalpha():
raise ValidationError("State must be a valid two-character code.")
return str(value).upper()
flask_variables.py 文件源码
项目:Python-Microservices-Development
作者: PacktPublishing
项目源码
文件源码
阅读 17
收藏 0
点赞 0
评论 0
def to_python(self, value):
if value in _USERS:
return _USERS[value]
raise ValidationError()