本文整理汇总了Python中pydantic.error_wrappers.ErrorWrapper方法的典型用法代码示例。如果您正苦于以下问题:Python error_wrappers.ErrorWrapper方法的具体用法?Python error_wrappers.ErrorWrapper怎么用?Python error_wrappers.ErrorWrapper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pydantic.error_wrappers
的用法示例。
在下文中一共展示了error_wrappers.ErrorWrapper方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: purchase_domain
# 需要导入模块: from pydantic import error_wrappers [as 别名]
# 或者: from pydantic.error_wrappers import ErrorWrapper [as 别名]
def purchase_domain(
db: Session = Depends(get_db),
*,
domain_profile: PurchaseDomainSchema
):
domain_isp = crud_isp.get(
db_session=db,
id=domain_profile.isp_id,
)
if domain_isp and domain_isp.provider_name != domain_profile.provider_name:
raise ValidationError(
[ErrorWrapper(Exception('provider_name is not matched'), loc="provider_name")],
model=PurchaseDomainSchema,
)
purchase_task = celery_app.send_task(
"purchase_domain", kwargs=domain_profile.dict()
)
purchase_result = purchase_task.get()
return dict(result=purchase_result)
示例2: get_missing_field_error
# 需要导入模块: from pydantic import error_wrappers [as 别名]
# 或者: from pydantic.error_wrappers import ErrorWrapper [as 别名]
def get_missing_field_error(loc: Tuple[str, ...]) -> ErrorWrapper:
if PYDANTIC_1:
missing_field_error = ErrorWrapper(MissingError(), loc=loc)
else: # pragma: no cover
missing_field_error = ErrorWrapper( # type: ignore
MissingError(), loc=loc, config=BaseConfig,
)
return missing_field_error
示例3: create_vps_server
# 需要导入模块: from pydantic import error_wrappers [as 别名]
# 或者: from pydantic.error_wrappers import ErrorWrapper [as 别名]
def create_vps_server(db: Session = Depends(get_db), *, vps_profile: VpsCreateSchema):
# validate
vps_isp_obj = crud_isp.get(db_session=db, id=vps_profile.isp_id)
if not vps_isp_obj:
raise ValidationError(
[ErrorWrapper(Exception('provider_name is not matched'), loc="isp_id")],
model=VpsCreateSchema,
)
# create base vps data
rp = RedisPool()
vps_spec_data = rp.get_vps_spec_value(
db_session=db,
isp_id=vps_profile.isp_id,
os_code=vps_profile.os_code,
plan_code=vps_profile.plan_code,
region_code=vps_profile.region_code
)
vps_config = dict(
hostname=vps_profile.hostname,
isp_id=vps_profile.isp_id,
ssh_keys=vps_profile.ssh_keys,
remark=vps_profile.remark,
status=vps_profile.status,
**vps_spec_data
)
vps_obj = crud_vps.create(db_session=db, obj_in=vps_config, serializer=None)
task = celery_app.send_task(
"create_vps", args=[vps_profile.dict(), vps_obj.id]
)
return dict(result=task)
示例4: create_domain
# 需要导入模块: from pydantic import error_wrappers [as 别名]
# 或者: from pydantic.error_wrappers import ErrorWrapper [as 别名]
def create_domain(
db: Session = Depends(get_db),
*,
domain_config: DomainCreate
):
if crud_domain.exists(db_session=db, domain=domain_config.domain):
raise ValidationError(
[ErrorWrapper(Exception('domain already exists'), loc="domain")],
model=DomainCreate,
)
domain_data = crud_domain.create(db, obj_in=domain_config, serializer=None)
celery_app.send_task("load_domain_extra_data", args=[domain_data.id])
return dict(result=domain_data)
示例5: create_domain_monitor_task
# 需要导入模块: from pydantic import error_wrappers [as 别名]
# 或者: from pydantic.error_wrappers import ErrorWrapper [as 别名]
def create_domain_monitor_task(
db: Session = Depends(get_db),
*,
monitor_profile: DomainMonitorSchema
):
if crud_domain_task.exists(db_session=db, domain_id=monitor_profile.domain_id):
raise ValidationError(
[ErrorWrapper(Exception('domain is already under monitor'), loc="domain_id")],
model=DomainMonitorSchema,
)
monitor_task_obj = crud_domain_task.create(db_session=db, obj_in=monitor_profile, serializer=None)
return dict(result=monitor_task_obj)
示例6: _add_filenames
# 需要导入模块: from pydantic import error_wrappers [as 别名]
# 或者: from pydantic.error_wrappers import ErrorWrapper [as 别名]
def _add_filenames(e: ValidationError, filename):
def _recursively_add_filenames(l):
processed = False
if isinstance(l, Sequence):
for e in l:
_recursively_add_filenames(e)
processed = True
elif isinstance(l, ErrorWrapper):
l._loc = (filename, l._loc)
processed = True
assert processed, f"Should have processed by now {l}, {repr(l)}"
_recursively_add_filenames(e.raw_errors)
示例7: serialize_response
# 需要导入模块: from pydantic import error_wrappers [as 别名]
# 或者: from pydantic.error_wrappers import ErrorWrapper [as 别名]
def serialize_response(
*,
field: ModelField = None,
response_content: Any,
include: Union[SetIntStr, DictIntStrAny] = None,
exclude: Union[SetIntStr, DictIntStrAny] = set(),
by_alias: bool = True,
exclude_unset: bool = False,
exclude_defaults: bool = False,
exclude_none: bool = False,
is_coroutine: bool = True,
) -> Any:
if field:
errors = []
response_content = _prepare_response_content(
response_content,
exclude_unset=exclude_unset,
exclude_defaults=exclude_defaults,
exclude_none=exclude_none,
)
if is_coroutine:
value, errors_ = field.validate(response_content, {}, loc=("response",))
else:
value, errors_ = await run_in_threadpool(
field.validate, response_content, {}, loc=("response",)
)
if isinstance(errors_, ErrorWrapper):
errors.append(errors_)
elif isinstance(errors_, list):
errors.extend(errors_)
if errors:
raise ValidationError(errors, field.type_)
return jsonable_encoder(
value,
include=include,
exclude=exclude,
by_alias=by_alias,
exclude_unset=exclude_unset,
exclude_defaults=exclude_defaults,
exclude_none=exclude_none,
)
else:
return jsonable_encoder(response_content)
示例8: request_params_to_args
# 需要导入模块: from pydantic import error_wrappers [as 别名]
# 或者: from pydantic.error_wrappers import ErrorWrapper [as 别名]
def request_params_to_args(
required_params: Sequence[ModelField],
received_params: Union[Mapping[str, Any], QueryParams, Headers],
) -> Tuple[Dict[str, Any], List[ErrorWrapper]]:
values = {}
errors = []
for field in required_params:
if is_scalar_sequence_field(field) and isinstance(
received_params, (QueryParams, Headers)
):
value = received_params.getlist(field.alias) or field.default
else:
value = received_params.get(field.alias)
field_info = get_field_info(field)
assert isinstance(
field_info, params.Param
), "Params must be subclasses of Param"
if value is None:
if field.required:
if PYDANTIC_1:
errors.append(
ErrorWrapper(
MissingError(), loc=(field_info.in_.value, field.alias)
)
)
else: # pragma: nocover
errors.append(
ErrorWrapper( # type: ignore
MissingError(),
loc=(field_info.in_.value, field.alias),
config=BaseConfig,
)
)
else:
values[field.name] = deepcopy(field.default)
continue
v_, errors_ = field.validate(
value, values, loc=(field_info.in_.value, field.alias)
)
if isinstance(errors_, ErrorWrapper):
errors.append(errors_)
elif isinstance(errors_, list):
errors.extend(errors_)
else:
values[field.name] = v_
return values, errors