mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Проверка 09.02.2025
This commit is contained in:
@@ -10,7 +10,13 @@ from importlib.metadata import version
|
||||
from ipaddress import IPv4Address, IPv4Interface, IPv4Network, IPv6Address, IPv6Interface, IPv6Network
|
||||
from typing import TYPE_CHECKING, Any, ClassVar
|
||||
|
||||
from pydantic_core import MultiHostHost, PydanticCustomError, SchemaSerializer, core_schema
|
||||
from pydantic_core import (
|
||||
MultiHostHost,
|
||||
PydanticCustomError,
|
||||
PydanticSerializationUnexpectedValue,
|
||||
SchemaSerializer,
|
||||
core_schema,
|
||||
)
|
||||
from pydantic_core import MultiHostUrl as _CoreMultiHostUrl
|
||||
from pydantic_core import Url as _CoreUrl
|
||||
from typing_extensions import Annotated, Self, TypeAlias
|
||||
@@ -283,6 +289,16 @@ class _BaseUrl:
|
||||
)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def serialize_url(cls, url: Any, info: core_schema.SerializationInfo) -> str | Self:
|
||||
if not isinstance(url, cls):
|
||||
raise PydanticSerializationUnexpectedValue(
|
||||
f"Expected `{cls}` but got `{type(url)}` with value `'{url}'` - serialized value may not be as expected."
|
||||
)
|
||||
if info.mode == 'json':
|
||||
return str(url)
|
||||
return url
|
||||
|
||||
@classmethod
|
||||
def __get_pydantic_core_schema__(
|
||||
cls, source: type[_BaseUrl], handler: GetCoreSchemaHandler
|
||||
@@ -300,7 +316,9 @@ class _BaseUrl:
|
||||
return core_schema.no_info_wrap_validator_function(
|
||||
wrap_val,
|
||||
schema=core_schema.url_schema(**cls._constraints.defined_constraints),
|
||||
serialization=core_schema.to_string_ser_schema(),
|
||||
serialization=core_schema.plain_serializer_function_ser_schema(
|
||||
cls.serialize_url, info_arg=True, when_used='always'
|
||||
),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -450,6 +468,16 @@ class _BaseMultiHostUrl:
|
||||
)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def serialize_url(cls, url: Any, info: core_schema.SerializationInfo) -> str | Self:
|
||||
if not isinstance(url, cls):
|
||||
raise PydanticSerializationUnexpectedValue(
|
||||
f"Expected `{cls}` but got `{type(url)}` with value `'{url}'` - serialized value may not be as expected."
|
||||
)
|
||||
if info.mode == 'json':
|
||||
return str(url)
|
||||
return url
|
||||
|
||||
@classmethod
|
||||
def __get_pydantic_core_schema__(
|
||||
cls, source: type[_BaseMultiHostUrl], handler: GetCoreSchemaHandler
|
||||
@@ -467,7 +495,9 @@ class _BaseMultiHostUrl:
|
||||
return core_schema.no_info_wrap_validator_function(
|
||||
wrap_val,
|
||||
schema=core_schema.multi_host_url_schema(**cls._constraints.defined_constraints),
|
||||
serialization=core_schema.to_string_ser_schema(),
|
||||
serialization=core_schema.plain_serializer_function_ser_schema(
|
||||
cls.serialize_url, info_arg=True, when_used='always'
|
||||
),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
|
Reference in New Issue
Block a user