o
    ~j6h                 	   @  s  U d Z ddlmZ ddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlmZmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZm Z  ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z-m.Z.m/Z/m0Z0 ddlm1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: ddl;m<Z< ddlm=Z= ddl>m?Z? ddl@Z@ddlAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZI ddl@mJZJmKZKmLZLmMZMmNZNmOZO ddlPmQZQ ddlRmSZSmTZTmUZU ddlVmWZWmXZXmYZY ddlZm[Z[m\Z\ ddl]m^Z^m_Z_m`Z`maZa ddlbmcZcmdZdmeZe ddlfmgZgmhZhmiZimjZjmkZk ddllmmZm ddlnmoZo dd lmpZp d!d"lqmrZrmsZsmtZtmuZumvZv d!d#lwmxZxmyZy d!d$lzm{Z{m|Z| d!d%l}m~Z~mZmZmZ d!d&lrmZmZmZmZmZmZmZmZmZmZmZmZ d!d'lmZ d!d(lmZmZmZ d!d)lmZ d!d*lmZmZ d!d+lmZmZ d!d,lmZ d!d-lmZmZ d!d.lmZmZ d!d/lmZ d!d0lmZmZ e1rdd1lmZmZ dd2lmZ dd3l,mZ d!d4lmZ d!d5lmZ ejd6kZe8eeef Ze7d7ed8Ze8ee ee ee f Ze[Zd9ed:< e3e2egeHjBf Zd9ed;< d<Zd9ed=< ejegZd>ed?< ejeejjgZd>ed@< ejeejjgZd>edA< ejeejjgZd>edB< ejegZd>edC< e"e#e$e%e&e'gZd>edD< ejejjgZd>edE< ejejjejejjgZd>edF< ejegZd>edG< ejejgZd>edH< e	je
je
je
je
je
jgZd>edI< ejejejjejjeje@jejejgZejejgZejejgZd>edJ< e8e/e-e0ef ZeMeZehegejekdKZdLedM< ddTdUZdd[d\Zdd`daZddhdiZddldmZeee2 e`f ZddsdtZddwdxZG dydz dzeZG d{d| d|Zd}d~ dd~ dd~ dd~ dd~ dd~ dd~ dd~ dZded< dddZdddZdddZdddZdddZG dd deLZdddddddddZdddZdddZG dd dZG dd dZ G dd dZdS )z-Convert python types to pydantic-core schema.    )annotationsN)	GeneratorIterableIteratorMapping)contextmanagercopy)Decimal)Enum)Fraction)partial)	Parameter_ParameterKind	signature)IPv4AddressIPv4InterfaceIPv4NetworkIPv6AddressIPv6InterfaceIPv6Network)chain)
attrgetter)FunctionTypeGenericAlias
LambdaType
MethodType)
TYPE_CHECKINGAnyCallableFinal
ForwardRefLiteralTypeVarUnioncastoverload)UUID)warn)ZoneInfo)
CoreSchemaMultiHostUrlPydanticCustomError$PydanticSerializationUnexpectedValuePydanticUndefinedUrlcore_schemato_jsonable_python)	TypeAliasTypeAliasType	TypedDictget_args
get_originis_typeddict)typing_objects)AnnotationSourceget_literal_valuesis_union_origin   )AliasChoicesAliasGenerator	AliasPath)GetCoreSchemaHandlerGetJsonSchemaHandler)
ConfigDictJsonDictJsonEncoderJsonSchemaExtraCallable)PydanticSchemaGenerationErrorPydanticUndefinedAnnotationPydanticUserError)AfterValidatorBeforeValidatorFieldValidatorModesPlainValidatorWrapValidator)JsonSchemaValue)version_short)PydanticDeprecatedSince20   )_decorators_discriminated_union_known_annotated_metadata_repr_typing_extra)ConfigWrapperConfigWrapperStack)CoreMetadataupdate_core_metadata)get_refget_type_ref%is_list_like_schema_with_items_schemavalidate_core_schema)	DecoratorDecoratorInfosFieldSerializerDecoratorInfoFieldValidatorDecoratorInfoModelSerializerDecoratorInfoModelValidatorDecoratorInfoRootValidatorDecoratorInfoValidatorDecoratorInfoget_attribute_from_basesinspect_field_serializerinspect_model_serializerinspect_validator)extract_docstrings_from_cls)collect_dataclass_fieldsrebuild_model_fieldstakes_validated_data_argument)PydanticRecursiveRef)get_standard_typevars_mapreplace_types)import_cached_base_modelimport_cached_field_info)MockCoreSchema)NamespacesTuple
NsResolver)MissingDefinitionErrorgather_schemas_for_cleaning)CallbackGetCoreSchemaHandler)lenient_issubclasssmart_deepcopy)ComputedFieldInfo	FieldInfo	BaseModel)Discriminator)StandardDataclass)GetJsonSchemaFunction)      FieldDecoratorInfoType)boundr2   ModifyCoreSchemaWrapHandlerGetCoreSchemaFunctionz1Callable[[int, str, Any], Literal['skip'] | None]ParametersCallbackz
list[type]TUPLE_TYPES
LIST_TYPES	SET_TYPESFROZEN_SET_TYPES
DICT_TYPESIP_TYPESSEQUENCE_TYPESITERABLE_TYPES
TYPE_TYPESPATTERN_TYPES
PATH_TYPESDEQUE_TYPES)beforeafterplainwrapzbdict[FieldValidatorModes, type[BeforeValidator | AfterValidator | PlainValidator | WrapValidator]]_mode_to_validatorinfoFieldDecoratorInfofieldstrreturnboolc                 C  s   | j }d|v p
||v S )zCheck if field name is in validator fields.

    Args:
        info: The field info.
        field: The field name to check.

    Returns:
        `True` if field name is in validator fields, `False` otherwise.
    *)fields)r   r   r    r   r/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py)check_validator_fields_against_field_name   s   r   
decoratorsIterable[AnyFieldDecorator]r   Iterable[str]Nonec                 C  sf   t |}| D ]*}d|jjv rq|jjdu rq|jjD ]}||vr/td|j d|j dddqqdS )	av  Check if the defined fields in decorators exist in `fields` param.

    It ignores the check for a decorator if the decorator has `*` as field or `check_fields=False`.

    Args:
        decorators: An iterable of decorators.
        fields: An iterable of fields name.

    Raises:
        PydanticUserError: If one of the field names does not exist in `fields` param.
    r   Fz*Decorators defined with incorrect fields: .zO (use check_fields=False if you're inheriting from the model and intended this)zdecorator-missing-fieldcodeN)setr   r   check_fieldsrH   cls_refcls_var_name)r   r   decr   r   r   r   check_decorator_fields_exist   s   r   validator_functions+Iterable[Decorator[FieldDecoratorInfoType]]'list[Decorator[FieldDecoratorInfoType]]c                   s    fdd| D S )Nc                   s   g | ]
}t |j r|qS r   )r   r   ).0r   r   r   r   
<listcomp>       z8filter_field_decorator_info_by_field.<locals>.<listcomp>r   )r   r   r   r   r   $filter_field_decorator_info_by_field   s   r   schemacore_schema.CoreSchemaeach_item_validators'list[Decorator[ValidatorDecoratorInfo]]
field_name
str | Nonec                 C  s   |s| S | d dkrt | d ||| d< | S | d dkr5| d }d ur3t| d | ||| d |< | S t| rK| dt }t|||| d< | S | d dkrc| dt }t|||| d< | S td	| d  )
Ntypenullabler   tuplevariadic_item_indexitems_schemadictvalues_schemazO`@validator(..., each_item=True)` cannot be applied to fields with a schema of )apply_each_item_validatorsgetapply_validatorsr]   r0   
any_schema	TypeError)r   r   r   r   inner_schemar   r   r   r      s0   
r   FieldInfo | ComputedFieldInfoAtuple[JsonDict | None, JsonDict | JsonSchemaExtraCallable | None]c                 C  sL   | j | jt| jp| jdkpd t| jd}dd | D }|p"d | jfS )N )titledescription
deprecatedexamplesc                 S     i | ]\}}|d ur||qS Nr   r   kvr   r   r   
<dictcomp>      z=_extract_json_schema_info_from_field_info.<locals>.<dictcomp>)r   r   r   r   r1   r   itemsjson_schema_extra)r   json_schema_updatesr   r   r   )_extract_json_schema_info_from_field_info   s   r   json_encodersJsonEncoders | Nonetpr   r*   c                 C  s   | s|S d|v r
|S |gt |d|jjdd R D ]#}| |}|du r&qtdt  dt tj	|dd|d< |  S |S )	a  Iterate over the json_encoders and add the first matching encoder to the schema.

    Args:
        json_encoders: A dictionary of types and their encoder functions.
        tp: The type to check for a matching encoder.
        schema: The schema to add the encoder to.
    serialization__mro__Nz=`json_encoders` is deprecated. See https://docs.pydantic.dev/z</concepts/serialization/#custom-serializers for alternativesjson	when_used)
getattr	__class__r   r   warningsr(   rO   rP   r0   $plain_serializer_function_ser_schema)r   r   r   baseencoderr   r   r   ,_add_custom_serialization_from_json_encoders  s   
$
r   abc                 C  s   | dur| S |S )aB  Return the first argument if it is not None, otherwise return the second argument.

    Use case: serialization_alias (argument a) and alias (argument b) are both defined, and serialization_alias is ''.
    This function will return serialization_alias, which is the first argument, even though it is an empty string.
    Nr   )r   r   r   r   r   _get_first_non_null1  s   r   c                   @  s   e Zd ZdZdS )InvalidSchemaErrorzThe core schema is invalid.N)__name__
__module____qualname____doc__r   r   r   r   r   :  s    r   c                      s  e Zd ZdZdZ		ddddZd fddZedddZedddZ	edddZ
dddZd dd Zdd!d"Zdd#d$Zdd'd(Zdd*d+Zdd-d.Zdd/d0Zdd1d2Zdd3d4Zdd5d6Zdd8d9Zdd=d>Zdd?d@Zd	dDdEZd
dGdHZddKdLZddMdNZddQdRZddSdTZeddXdYZ edd[dYZ ddd]dYZ dd^d_Z!ddadbZ"d
dcddZ#d
dedfZ$ddhdiZ%djdkddsdtZ&ddvdwZ'ddydzZ(e)dd~dZ*e)dddZ+e)dddZ,dddZ-dddZ.dddZ/dddZ0dddZ1dddZ2e3j4dfd ddZ5e3j4fd!ddZ6d"ddZ7d#ddZ8d#ddZ9dddZ:d$ddZ;d%ddZ<d&ddZ=d'ddZ>d#ddZ?d(ddZ@d)ddƄZA	d*d+dd˄ZB	d*d,dd΄ZCd-dd҄ZDd.ddلZEd/dd܄ZFddބ fd0ddZGd1ddZHd1ddZId2ddZJd3ddZKd4ddZL  ZMS (5  GenerateSchemaz\Generate core schema for a Pydantic model, dataclass and types like `str`, `datetime`, ... .)_config_wrapper_stack_ns_resolver_typevars_mapfield_name_stackmodel_type_stackdefsNconfig_wrapperrW   ns_resolverNsResolver | Nonetypevars_mapMapping[TypeVar, Any] | Noner   r   c                 C  s8   t || _|p	t | _|| _t | _t | _t	 | _
d S r   )rX   r   rv   r   r   _FieldNameStackr   _ModelTypeStackr   _Definitionsr   )selfr   r   r  r   r   r   __init__J  s   
zGenerateSchema.__init__c                   s   t    tjdtdd d S )NzeSubclassing `GenerateSchema` is not supported. The API is highly subject to change in minor versions.r<   )
stacklevel)super__init_subclass__r   r(   UserWarning)clsr   r   r   r  X  s   

z GenerateSchema.__init_subclass__c                 C     | j jS r   )r   tailr  r   r   r   _config_wrapper`     zGenerateSchema._config_wrapperru   c                 C  r  r   )r   types_namespacer  r   r   r   _types_namespaced  r  zGenerateSchema._types_namespacer   c                 C  r  r   )r  arbitrary_types_allowedr  r   r   r   _arbitrary_typesh  r  zGenerateSchema._arbitrary_types
items_typer   r*   c                 C     t | |S r   )r0   list_schemagenerate_schemar  r  r   r   r   _list_scheman     zGenerateSchema._list_schema	keys_typevalues_typec                 C  s   t | || |S r   )r0   dict_schemar  )r  r  r   r   r   r   _dict_schemaq  s   zGenerateSchema._dict_schemac                 C  r  r   )r0   
set_schemar  r  r   r   r   _set_schemat  r  zGenerateSchema._set_schemac                 C  r  r   )r0   frozenset_schemar  r  r   r   r   _frozenset_schemaw  r  z GenerateSchema._frozenset_schema	enum_type
type[Enum]c                   sN  t j  tjsd ntj}|dkrd }j|ddd  D d t	t
r:dtd}n!t	trGdtd}nt	trTdtd}ntdd	 } rdfdd}tjdd tjju }tj |rxd njd|gid}| jjrtjtd||d}|S d fdd}tjd|gidS )NzAn enumeration.)r   r   c                 S  r   r   r   r   r   r   r   r     r   z/GenerateSchema._enum_schema.<locals>.<dictcomp>intr   floatc                 S     | S r   r   xr   r   r   <lambda>      z-GenerateSchema._enum_schema.<locals>.<lambda>r   r*   handlerrA   r   rN   c                   s    || }| |}|  |S r   )resolve_ref_schemaupdate)r   r0  json_schemaoriginal_schema)
js_updatesr   r   get_json_schema  s   

z4GenerateSchema._enum_schema.<locals>.get_json_schema__func__pydantic_js_functions)sub_typemissingrefmetadatavalue)r   c                   s.   |t j d}||}| |S )N)r9  r;  )r0   enum_schemar1  r2  )_r0  r3  r4  casesenum_refr'  r5  r9  r   r   get_json_schema_no_cases  s   

z=GenerateSchema._enum_schema.<locals>.get_json_schema_no_casesr<  )r   r*   r0  rA   r   rN   )r0  rA   r   rN   )list__members__valuesr\   r   inspectcleandocr   r   
issubclassr)  r0   simple_ser_schemar   r*  r   r   	_missing_r   r7  r>  r  use_enum_values no_info_after_validator_functionr   is_instance_schema)r  r'  r   value_ser_typer6  default_missingr>  rC  r   r@  r   _enum_schemaz  sN   


	
zGenerateSchema._enum_schemar   c                   s   ddl m}m} tdtdtdtdtdtdi dfdd}t	j
t	| t	jt	t	 t	dt	j|dddd fddgidS )NrQ   )IP_VALIDATOR_LOOKUPIpTypeipv4ipv4networkipv4interfaceipv6ipv6networkipv6interfaceipr   r   core_schema.SerializationInfor   str | IpTypec                   D   t |  tfstd  dt|  d|  d|jdkr| S t| S Nz
Expected `z` but got `z` with value `'z-'` - serialized value may not be as expected.python
isinstancer   r-   r   mode)r[  r   r   r   r   ser_ip     
z)GenerateSchema._ip_schema.<locals>.ser_ipr3  python_schemaTalwaysinfo_argr   r8  c                   s   d  dS )Nstringr   formatr   _1_2ip_type_json_schema_formatr   r   r   r.        z+GenerateSchema._ip_schema.<locals>.<lambda>
lax_schemastrict_schemar   r<  )r[  r   r   r\  r   r]  )_validatorsrS  rT  r   r   r   r   r   r   r0   lax_or_strict_schema no_info_plain_validator_functionjson_or_python_schemarN  
str_schemarO  r   )r  r   rS  rT  re  r   rr  r   
_ip_schema  s&   		zGenerateSchema._ip_schema	path_typec           	        s   t ju rtthvrtstdddt ju rtjn tu r*t	j
ddnt	jdd}tu r8t	
 nt	 }d fd
d}dfdd}t	jt	||t	d}t	jt	j|t	||gdd d|t	j|dddddd gid}|S )Nz;`os.PathLike` can only be used with `str`, `bytes` or `Any`zschema-for-unknown-typer   Tstrictinput_valuestr | bytesr   os.PathLike[Any]c              
     s   z6t u r(t| t r#z|  } W n! ty" } ztdd|d }~ww tddt| ts2tdd | W S  tyH } ztdd|d }~ww )N
bytes_typezInput must be valid byteszInput must be bytesr~  zInput is not a valid path)bytesrb  decodeUnicodeDecodeErrorr,   r   r   )r  e)path_constructorr~  r   r   path_validator  s"   




z3GenerateSchema._path_schema.<locals>.path_validatorpathr   r   r\  str | os.PathLike[Any]c                   r^  r_  ra  )r  r   rd  r   r   ser_path   rf  z-GenerateSchema._path_schema.<locals>.ser_pathrg  r~  zInput is not a valid path for custom_error_typecustom_error_messageri  rj  r8  c                 S  s   i || ddiS )Nrn  r  r   )sourcer0  r   r   r   r.        z-GenerateSchema._path_schema.<locals>.<lambda>ru  )r  r  r   r  )r  r   r   r\  r   r  )osPathLiker   r  r8   is_anyrH   pathlibPurePathr0   bytes_schemar|  r{  rN  rO  ry  union_schemar   )	r  r   r~  strict_inner_schemalax_inner_schemar  r  instance_schemar   r   )r  r~  r   r   _path_schema  s6    	

zGenerateSchema._path_schemac                 C  s|   ddl m} ddlm} | |}tj|dd}tj|tjt	j
ddd}t||}tj|t||gtj||d	d
dS )NrQ   serialize_sequence_via_list)deque_validatorFr  Dequecls_reprrg  Tr   rk  rv  rw  r   )_serializersr  rx  r  r  r0   r  r{  rO  collectionsdequeno_info_wrap_validator_functionry  chain_schema#wrap_serializer_function_ser_schema)r  r  r  r  item_type_schemar  check_instancerv  r   r   r   _deque_schema  s    
zGenerateSchema._deque_schemac                 C  s   ddl m}m}m} || }| |}| |}	tj||	dd}
|tu r(|
}|S tj|
t	|d}|t
ju rF||}ttjt||d}nttj|}||
}t||g}tj||tjdd |
dd	d
}|S )NrQ   )MAPPING_ORIGIN_MAPdefaultdict_validator'get_defaultdict_default_default_factoryFr  rg  )default_default_factoryc                 S     || S r   r   )r   hr   r   r   r.  V      z0GenerateSchema._mapping_schema.<locals>.<lambda>r  r  )rx  r  r  r  r  r0   r!  r   r{  rO  r  defaultdictr   r  rN  r  ry  r  )r  r   r  r   r  r  r  mapped_originkeys_schemar   r!  r   r  r  coerce_instance_wraprv  rw  r   r   r   _mapping_schema6  s:   




zGenerateSchema._mapping_schemac                 C  sL   ddl m} tjt|tjt|ttdtjddddd gid	S )
z7Support for [`fractions.Fraction`][fractions.Fraction].rQ   )fraction_validatorrg  ri  r   r8  c                 S  
   dddS )Nrl  fractionrm  r   ro  r   r   r   r.  j     
 z1GenerateSchema._fraction_schema.<locals>.<lambda>ru  )	rx  r  r0   ry  rz  r{  rO  r   to_string_ser_schema)r  r  r   r   r   _fraction_schema\  s   
zGenerateSchema._fraction_schemac                 C  s,   t |tst|dt t S t|S )Na   is not a Python type (it may be an instance of an object), Pydantic will allow any object with no validation since we cannot even enforce that the input is an instance of the given type. To get rid of this error wrap the type with `pydantic.SkipValidation`.)rb  r   r(   r  r0   r   rO  )r  r   r   r   r   _arbitrary_type_schemam  s   

z%GenerateSchema._arbitrary_type_schemaobjc                 C  s   t d|d)N,Unable to generate pydantic-core schema for a  . Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.

If you got this error by calling handler(<some type>) within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema(<some type>)` since we do not call `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.)rF   r  r  r   r   r   _unknown_type_schemay  s   
z#GenerateSchema._unknown_type_schemar   discriminatorstr | Discriminator | Nonec                 C  sF   |d u r|S z
t ||| jjW S  t jy"   t || | Y S w r   )rS   apply_discriminatorr   _definitionsMissingDefinitionForUnionRefset_discriminator_in_metadata)r  r   r  r   r   r   _apply_discriminator_to_union  s   z,GenerateSchema._apply_discriminator_to_unionc                 C  s   | j |}t|}|S r   )r   finalize_schemar^   )r  r   r   r   r   clean_schema  s   zGenerateSchema.clean_schemametadata_schemajs_functionCallable[..., Any]c                 C  s6   | di }|dg }||vr|| ||d< d S )Nr<  r8  )r   
setdefaultappend)r  r  r  r<  r8  r   r   r   _add_js_function  s
   
zGenerateSchema._add_js_functionr   c                 C  s^   |  ||}|du r| |}t|}|dur%t|| j}|r%| || t| jj||}|S )aX  Generate core schema.

        Args:
            obj: The object to generate core schema for.

        Returns:
            The generated core schema.

        Raises:
            PydanticUndefinedAnnotation:
                If it is not possible to evaluate forward reference.
            PydanticSchemaGenerationError:
                If it is not possible to generate pydantic-core schema.
            TypeError:
                - If `alias_generator` returns a disallowed type (must be str, AliasPath or AliasChoices).
                - If V1 style validator with `each_item=True` applied on a wrong field.
            PydanticUserError:
                - If `typing.TypedDict` is used instead of `typing_extensions.TypedDict` on Python < 3.12.
                - If `__modify_schema__` method is used instead of `__get_pydantic_json_schema__`.
        N)	'_generate_schema_from_get_schema_method_generate_schema_inner!_extract_get_pydantic_json_schemaresolve_original_schemar   r  r   r  r   )r  r  r   metadata_js_functionr  r   r   r   r    s   
zGenerateSchema.generate_schemar  type[BaseModel]c                   s^  t  }j|\}}|dur|W  d   S |jd}|durQt|tsQ|d dkr5j|}t|}|rHj	|W  d   S |W  d   S t
|jdd}j| j| jj|jd}|jsw||u r~t|di }	n1t|dst|jd	|jd
dzt|jjpi d}	W n ty }
 zt|
|
d}
~
ww |j  j}tt j  j   j! h |	" |"   j# }d}d}|ddkrX|j$d |u sJ |j$d t%u sJ |j$dd D ]^}t|di dd}|durWt|t&r t'j(t'j)|dddgj*R  }t+|}|t,vr-t-dj.|dd\}}|t&ur@/|}t01|sK/|}|dusU|durW nqt|di d}|j2r3d|	d  }|d }t4||d}t5j6|||t|dddt|dd||d}nCt5j7 fdd |	8 D  fd!d"| D |||jd#}t9| j: d}t4||d}t5j6|||t|dddt|dd||d};| j< }t4||d$}j	|W  d   W  d   W  d   S 1 sw   Y  W d   n1 sw   Y  W d   dS W d   dS 1 s(w   Y  dS )%z%Generate schema for a Pydantic model.N__pydantic_core_schema__r   definitionsF)checkr   __pydantic_fields__zClass z is not defined)namemessage)r   r  extra_fields_behaviorallowr   r   __annotations____pydantic_extra__T)is_argumentis_classzEThe type annotation for `__pydantic_extra__` must be `dict[str, ...]`required__pydantic_generic_metadata__originrootr   inner__pydantic_custom_init____pydantic_post_init__)generic_origincustom_init
root_model	post_initconfigr;  c                   s    i | ]\}}| || qS r   )_generate_md_field_schemar   r   r  r   r   r   @  s     z0GenerateSchema._model_schema.<locals>.<dictcomp>c                      g | ]	} | jqS r   _computed_field_schemafield_serializersr   dr  r   r   r   A      z0GenerateSchema._model_schema.<locals>.<listcomp>)computed_fieldsextras_schemaextras_keys_schema
model_nameouter)=rr   r   get_schema_or_ref__dict__r   rb  rt   unpack_definitionsr[   "create_definition_reference_schemarW   model_configr   pushr   r  core_configr   __pydantic_fields_complete__r   hasattrrG   rm   r   	NameErrorfrom_name_error__pydantic_decorators__r  r   r   field_validatorsrG  r  
validatorskeysmodel_validatorsr   objectr   rV   eval_type_backport_make_forward_refr  r6   r   rF    _get_args_resolving_forward_refsr  r8   r  __pydantic_root_model___common_field_schemaapply_model_validatorsr0   model_schemamodel_fields_schemar   r   root_validators_apply_model_serializersmodel_serializers)r  r  
BaseModel_	model_refmaybe_schemar   r;  r   r	  r   r  r  r  r  r   candidate_clsextras_annotationr   extra_keys_typeextra_items_typer  
root_fieldr   r  fields_schemar   r  r   _model_schema  s   
 


	











4$zGenerateSchema._model_schemac                 C  s"   | j  }|d u rtddd|S )Nz(`typing.Self` is invalid in this contextzinvalid-self-typer   )r   r   rH   r  r   r   r   _resolve_self_type[  s   
z!GenerateSchema._resolve_self_typer  core_schema.CoreSchema | Nonec                 C  sH  t  }t|dd }t|dd |jju }|d url|sl| j|\}}|d ur/|W  d    S W d    n1 s9w   Y  ||u rEd}nd}||t| j| |d}	|	d dkr^| j|	}	t	|	}
|
rj| j
|	S |	S |d u rt|dd  }d urd	d
lm} t||rtd|j dt ntdt tdd | D S d S d S )N__get_pydantic_core_schema__r7  unpackzto-def)ref_moder   r  __get_validators__r   r~   zeMixing V1 models and V2 models (or constructs, like `TypeAdapter`) is not supported. Please upgrade `z` to V2.zc`__get_validators__` is deprecated and will be removed, use `__get_pydantic_core_schema__` instead.c                 S  s   g | ]}t |qS r   r0   "with_info_plain_validator_functionr   r   r   r   r   r         zJGenerateSchema._generate_schema_from_get_schema_method.<locals>.<listcomp>)rr   r   r+  r7  r   r  ry   r  r  r[   r  pydantic.v1r   rJ  r(   r   r  rP   r0   r  )r  r  r  r  
get_schemais_base_model_get_schemar?  r!  r-  r   r;  r  BaseModelV1r   r   r   r  a  sL   
z6GenerateSchema._generate_schema_from_get_schema_methodc              
   C  sp   zt j|g| jR  }W n ty } zt||d }~ww t|tr-t|jd| | j	r6t
|| j	}|S )Nz%Unable to evaluate forward reference )rV   r  r  r  rG   r  rb  r!   __forward_arg__r   rq   )r  r  r  r   r   r   _resolve_forward_ref  s   
z#GenerateSchema._resolve_forward_refr  Literal[True]tuple[Any, ...]c                 C     d S r   r   )r  r  r  r   r   r   r       z/GenerateSchema._get_args_resolving_forward_refstuple[Any, ...] | Nonec                 C  r;  r   r   r  r   r   r   r    r<  Fc                   sV   t |}|rt|trdd |D }t fdd|D }|S |r)td| d|S )Nc                 s  s(    | ]}t |trt|n|V  qd S r   )rb  r   rV   r  r   r   r   r   r   	<genexpr>     & zBGenerateSchema._get_args_resolving_forward_refs.<locals>.<genexpr>c                 3  s(    | ]}t |tr |n|V  qd S r   )rb  r!   r8  r>  r  r   r   r?    r@  z	Expected z+ to have generic parameters but it had none)r5   rb  r   r   r   )r  r  r  argsr   r  r   r    s   
c                 C  s   |  |}|s	tS |d S )Nr   )r  r   )r  r  rA  r   r   r   _get_first_arg_or_any  s   
z$GenerateSchema._get_first_arg_or_anytuple[Any, Any]c                 C  sJ   |  |}|sttfS t|dk rt|}td| d|d |d fS )Nr<   z Expected two type arguments for z, got 1r   rQ   )r  r   lenr6   r   )r  r  rA  r  r   r   r   _get_first_two_args_or_any  s   
z)GenerateSchema._get_first_two_args_or_anyc                 C  s   t |r
| |}t t|r| |S t|tr|S t|tr&t	|}t|t	r3| 
| |S t }t||rV| j| | |W  d    S 1 sQw   Y  t|trbtj|jdS | |S )N)
schema_ref)r8   is_selfr)  is_annotatedr6   _annotated_schemarb  r   r   r!   r  r8  rr   rz   r   r  r(  ro   r0   definition_reference_schematype_ref
match_type)r  r  r   r   r   r   r    s$   






 

z%GenerateSchema._generate_schema_innerc                 C  s  |t u rt S |tu rt S |tu rt S |tu r t S |t	u r(t
 S |tu r0t S t|s9|tu r=t S |tju rFt S |tju rOt S |tju rXt S |tju rat S |tu rit S |tu rqt S |tu ryt S |tu r|   S |t!u rt" S |du s|t#j$u rt% S |t&v r| '|S |t(v r| )|S |t*v r| +t,S |t-v r| .t,S |t/v r| 0t,S |t1v r| 2t,S |t3v r| 4|S |t5v r| 6t,t,S |t7v r| 8|t,S |t9v r| :t,S |t;v r| <|t,t,S |t=v r	| <|t,tS t>|r| ?|S |t@u r| A S t#B|r'tC S tDtE|r4| F|S tG|r?| H|dS t#I|rK| J|dS tK|rW| L|jMS |tNv ra| O|S t#P|rk| Q S tR|tSjTrw| U|S t#V|r|tWu rt S | L| X|S tR|tYr| Z|S t[\|rt]|t^r| _|S |t`u r| a S tbc|r| d|dS tE|}|dur| e||S | jfr| g|S | h|S )a  Main mapping of types to schemas.

        The general structure is a series of if statements starting with the simple cases
        (non-generic primitive types) and then handling generics and other more complex cases.

        Each case either generates a schema directly, calls into a public user-overridable method
        (like `GenerateSchema.tuple_variable_schema`) or calls into a private method that handles some
        boilerplate before calling into the user-facing method (e.g. `GenerateSchema._tuple_schema`).

        The idea is that we'll evolve this into adding more and more user facing methods over time
        as they get requested and we figure out what the right API for them is.
        N)ir   r0   r|  r  r  r)  
int_schemar*  float_schemar   bool_schemacomplexcomplex_schemar8   r  r  r   datetimedatedate_schemadatetime_schematimetime_schema	timedeltatimedelta_schemar
   decimal_schemar'   uuid_schemar/   
url_schemar   r  r+   multi_host_url_schemarV   NoneTypenone_schemar   r}  r   _tuple_schemar   r  r   r   r$  r   r&  r   _sequence_schemar   _iterable_schemar   r"  r   r  r   r  MAPPING_TYPESr  COUNTER_TYPESis_typealiastype_type_alias_type_schemar   _type_schemais_callablecallable_schema
is_literalr6   _literal_schemar7   _typed_dict_schemais_namedtuple_namedtuple_schema
is_newtyper  __supertype__r   _pattern_schemais_hashable_hashable_schemarb  typingr#   _unsubstituted_typevar_schemais_finalvarr    rB  VALIDATE_CALL_SUPPORTED_TYPES_call_schemarH  isclassrJ  r   rR  r)   _zoneinfo_schemadataclassesis_dataclass_dataclass_schema_match_generic_typer  r  r  )r  r  r  r   r   r   rL    s   


























zGenerateSchema.match_typer  c                 C  s  t |r| ||S t|r| ||S | ||}|d ur"|S t|r,| 	|S t
|r5| |S |tv r>| |S |tv rJ| | |S |tv rV| | |S |tv rb| | |S |tv rn| j| | S |tv r{| || |S |tv r| | |S |tv r| j|g| |R  S |tv r| || |tS t |r| !||S |t"v r| #|S |t$v r| %| |S |t&v r| '|S |t(v r| )|S | j*r| +|S | ,|S r   )-r{  r|  r}  rV   rm  rn  r  r8   re  rf  r;   _union_schemar   r`  r   r  rB  r   r$  r   r&  r   r"  rE  r   r  r   r  rc  r  rd  r)  r7   rl  r   _subclass_schemar   ra  r   rb  r   rq  r  r  r  )r  r  r  r   r   r   r   r~  d  sT   










z"GenerateSchema._match_generic_typeTr  r  r   
field_infor}   r   r`   core_schema.TypedDictFieldc                C  sD   |  |||}tj|d | sdn||d |d |d |d dS )zAPrepare a TypedDictField to represent a model or typeddict field.r   Fserialization_excludevalidation_aliasserialization_aliasr<  )r  r  r  r  r<  )r  r0   typed_dict_fieldis_required)r  r  r  r   r  common_fieldr   r   r   _generate_td_field_schema  s   	z(GenerateSchema._generate_td_field_schemacore_schema.ModelFieldc                 C  s<   |  |||}tj|d |d |d |d |d |d dS )z0Prepare a ModelField to represent a model field.r   r  r  r  frozenr<  r  r  r  r  r<  )r  r0   model_fieldr  r  r  r   r  r   r   r   r    s   z(GenerateSchema._generate_md_field_schemacore_schema.DataclassFieldc                 C  sV   |  |||}tj||d |j|jpd|jrdnd|d |d |d |d |d d	
S )
zJPrepare a DataclassField to represent the parameter/field, of a dataclass.r   NFr  r  r  r  r<  )init	init_onlykw_onlyr  r  r  r  r<  )r  r0   dataclass_fieldr  init_varr  r  r   r   r   _generate_dc_field_schema  s   z(GenerateSchema._generate_dc_field_schemaalias_generator%Callable[[str], str] | AliasGeneratorr   c                 C  s  |j du s|j dks|jdu s|jdu s|jdu rd\}}}t| tr,| |\}}}nt| trE| |}t|tsEt	d|  d|j
 |j du sO|j dkrRd|_ |j dkrft|||_t|||_||_|jdu rn||_|jdu ryt|||_|jdu rt|||_dS dS dS )a  Apply an alias_generator to aliases on a FieldInfo instance if appropriate.

        Args:
            alias_generator: A callable that takes a string and returns a string, or an AliasGenerator instance.
            field_info: The FieldInfo instance to which the alias_generator is (maybe) applied.
            field_name: The name of the field from which to generate the alias.
        NrQ   NNNalias_generator  must return str, not )alias_priorityaliasr  r  rb  r>   generate_aliasesr   r   r   r   r   )r  r  r   r  r  r  r   r   r   $_apply_alias_generator_to_field_info  s4   












z3GenerateSchema._apply_alias_generator_to_field_infocomputed_field_infor|   computed_field_namec                 C  s   |j du s|j dks|jdu rUd\}}}t| tr"| |\}}}nt| tr;| |}t|ts;td|  d|j |j du sE|j dkrHd|_ |j dkrWt	|||_dS dS dS )a  Apply an alias_generator to alias on a ComputedFieldInfo instance if appropriate.

        Args:
            alias_generator: A callable that takes a string and returns a string, or an AliasGenerator instance.
            computed_field_info: The ComputedFieldInfo instance to which the alias_generator is (maybe) applied.
            computed_field_name: The name of the computed field from which to generate the alias.
        NrQ   r  r  r  )
r  r  rb  r>   r  r   r   r   r   r   )r  r  r  r  r  r  r   r   r   -_apply_alias_generator_to_computed_field_info  s    







z<GenerateSchema._apply_alias_generator_to_computed_field_infor   c                 C  sZ   |j p| j }|du rdS |jdu r+|||}t|ts&td| d|j ||_dS dS )ae  Apply a field_title_generator on a FieldInfo or ComputedFieldInfo instance if appropriate
        Args:
            config_wrapper: The config of the model
            field_info: The FieldInfo or ComputedField instance to which the title_generator is (maybe) applied.
            field_name: The name of the field from which to generate the title.
        Nzfield_title_generator r  )field_title_generatorr   rb  r   r   r   )r   r  r   r  r   r   r   r   *_apply_field_title_generator_to_field_info-  s   




z9GenerateSchema._apply_field_title_generator_to_field_info_CommonFieldc                   s  j j}}dfdd}g }t|j |D ]}|t|jj 	| qj
|  jd ur?j||| |d}	n||| }	W d    n1 sQw   Y  t|j |}
t|
red_dd	 |
D   fd
d	|
D }
t|	 |}	t|	|
|}	 st|	}	|	t|j |}	j| t\}}i }t|||d jj}|d ur|| tjtt frʈj! }nj}t"|	j#rdnd |j$j%|dS )Nr   r*   r   c                   s    |  j} | S r   )r  r  r   )r  r  r   r   set_discriminatorH  s   z>GenerateSchema._common_field_schema.<locals>.set_discriminator)transform_inner_schemaTc                 S  s   g | ]
}|j jd u r|qS )T)r   	each_itemr1  r   r   r   r   c  r   z7GenerateSchema._common_field_schema.<locals>.<listcomp>c                   s   g | ]}| vr|qS r   r   r1  )r   r   r   r   d  s    pydantic_js_updatespydantic_js_extrar  r   r*   r   r*   )&
annotationr<  r   r  rG  r  r   r   rc  _from_decoratorr   r  r  _apply_annotationsr  $_validators_require_validate_defaultvalidate_defaultr   r   r  wrap_default_apply_field_serializersr  r  r  r   rZ   r  r  rb  r  r=   r?   convert_to_aliases_common_fieldexcluder  r  )r  r  r  r   source_typer   r  validators_from_decorators	decoratorr   this_field_validatorsr  r  core_metadatar  r  r   )r   r  r  r   r  C  s`   


z#GenerateSchema._common_field_schema
union_typec           
      C  s   | j |dd}g }d}|D ]}|du s|tju rd}q|| | qt|dkr/|d }n)g }|D ]}tt|di d}	|	durM|||	f q3|| q3t	
|}|r_t	|}|S )	zGenerate schema for a Union.Tr  FNrQ   r   r<  pydantic_internal_union_tag_key)r  rV   r^  r  r  rD  r%   rY   r   r0   r  nullable_schema)
r  r  rA  choicesr   argschoices_with_tagschoicetagr   r   r   r    s&   


zGenerateSchema._union_schemar3   c           	      C  s  | j |s\}}|d ur|W  d    S t|p|}t|}| j|> ztj|jg| j	R  }W n t
yF } zt||d }~ww t||}| |}|d dksYJ ||d< W d    n1 sgw   Y  | j |W  d    S 1 s|w   Y  d S )Nr   r  r;  )r   r  r6   rp   r   r  rV   	eval_type	__value__r  r  rG   r  rq   r  r  )	r  r  r;  r!  r  r  r  r  r   r   r   r   rf    s(   



	$z&GenerateSchema._type_alias_type_schemaliteral_typec                 C  s\   t t|ddd}|sJ d| t|}| jjr,tdd |D r,tdd |}|S )	zGenerate schema for a Literal.Feager)
type_checkunpack_type_aliasesz(literal "expected" cannot be empty, obj=c                 s  s    | ]}t |tV  qd S r   )rb  r   r1  r   r   r   r?        z1GenerateSchema._literal_schema.<locals>.<genexpr>c                 S  s   t | tr| jS | S r   )rb  r   r=  )r   r   r   r   r.    r  z0GenerateSchema._literal_schema.<locals>.<lambda>)rE  r:   r0   literal_schemar  rM  anyrN  )r  r  expectedr   r   r   r   rk    s   
zGenerateSchema._literal_schematyped_dict_clsc                   s.  t  }j| j|a\}}|dur)|W  d   W  d   S t|}|dur3|}tsBt|jdkrBt	dddzt
|d}W n tyT   d}Y nw j| jj|jd}|j}	i }
t| jjrzt|dd	}nd}z
tj|jd
}W n ty } zt||d}~ww g }| D ]P\}}|j|tjd}t|j ||_ ||	v pd|j!v od|j!v}d|j!v r|"| |dur|j#du r||v r|| |_#$j|| j%|| |d|
|< q|r!d&dd |D }t'|dk}t()d|rdnd d| d|jd|rdnd d	t* t+j,|
| fdd j-. D ||d}/| j0. }t1| j2. d}j3|W  d   W  d   W  d   S 1 sgw   Y  W d   n1 sww   Y  W d   dS W d   dS 1 sw   Y  dS ) a,  Generate a core schema for a `TypedDict` class.

        To be able to build a `DecoratorInfos` instance for the `TypedDict` class (which will include
        validators, serializers, etc.), we need to have access to the original bases of the class
        (see https://docs.python.org/3/library/types.html#types.get_original_bases).
        However, the `__orig_bases__` attribute was only added in 3.12 (https://github.com/python/cpython/pull/103698).

        For this reason, we require Python 3.12 (or using the `typing_extensions` backport).
        Nrt  zXPlease use `typing_extensions.TypedDict` instead of `typing.TypedDict` on Python < 3.12.ztyped-dict-versionr   __pydantic_config__r  T)use_inspectr   _sourcer  not_required	read_onlyr  , c                 s      | ]}t |V  qd S r   repr)r   fr   r   r   r?        z4GenerateSchema._typed_dict_schema.<locals>.<genexpr>r<   Itemr  r    z on TypedDict class areiszk using the `ReadOnly` qualifier. Pydantic will not protect items from any mutation on dictionary instances.c                   r  r   r  r  r  r   r   r   %  r  z5GenerateSchema._typed_dict_schema.<locals>.<listcomp>)r  r  r;  r  all)4rs   r   r  r   r  rp   _SUPPORTS_TYPEDDICTr   r   rH   rg   AttributeErrorr   r  r	  r   __required_keys__r`   builduse_attribute_docstringsrk   rV   get_cls_type_hintsr   r  rG   r  r   from_annotationr9   
TYPED_DICTrq   r  _qualifiersr  r   r  r  joinrD  r   r(   r  r0   typed_dict_schemar  rG  r  r  r  r  r  )r  r  r  r}   typed_dict_refr!  r  r  r	  required_keysr   field_docstringsr   r  readonly_fieldsr   r  r  r  fields_reprplural	td_schemar   r   r  r   rl    s   








 
Tz!GenerateSchema._typed_dict_schemanamedtuple_clsc           	        sV  j   j \}}|dur$|W  d   W  d   S t |dur.| z
tj jd}W n tyJ } zt	
||d}~ww |sUdd  jD }rbfdd| D }tj fdd| D dd	id
}tj| |d}j|W  d   W  d   S 1 sw   Y  W d   dS 1 sw   Y  dS )z!Generate schema for a NamedTuple.Nr  c                 S  s   i | ]}|t qS r   )r   )r   r   r   r   r   r   F      z5GenerateSchema._namedtuple_schema.<locals>.<dictcomp>c                   s   i | ]
\}}|t | qS r   rq   r   r   r  r  r   r   r   I  s    
c              
     s0   g | ]\}}j ||tj j|tjd qS ))r  default)_generate_parameter_schemar9   NAMED_TUPLE_field_defaultsr   r   emptyr  )r  r  r   r   r   O  s    z5GenerateSchema._namedtuple_schema.<locals>.<listcomp>'pydantic_js_prefer_positional_argumentsTrD  )r;  )r   r  r   r  rp   rV   r  r   r  rG   r  _fieldsr   r0   arguments_schemacall_schemar  )	r  r  r  namedtuple_refr!  r   r  r   r   r   )r  r  r  r   rn  1  sD   

	
	
Rz!GenerateSchema._namedtuple_schemar  	type[Any]r9   r  rc  JLiteral['positional_only', 'positional_or_keyword', 'keyword_only'] | Nonecore_schema.ArgumentsParameterc                 C  s
  t  }|tju r|j||d}n|j|||d}|jdus!J d| j| | |j|g}W d   n1 s:w   Y  |	 sHt
||}t||}	|durV||	d< |jdurb|j|	d< |	S | jj}
t|
try|
jdury|
||	d< |	S t|
r|
||	d< |	S )zGenerate the definition of a field in a namedtuple or a parameter in a function signature.

        This definition is meant to be used for the `'arguments'` core schema, which will be replaced
        in V3 by the `'arguments-v3`'.
        r  Nz<field.annotation should not be None when generating a schemarc  r  )rs   r   r  r  from_annotated_attributer  r   r  r  r  r  r0   arguments_parameterr  r  r  rb  r>   callable)r  r  r  r  r  rc  r}   r   r   parameter_schemar  r   r   r   r  ]  s.   



z)GenerateSchema._generate_parameter_schemaLiteral['positional_only', 'positional_or_keyword', 'keyword_only', 'var_args', 'var_kwargs_uniform', 'var_kwargs_unpacked_typed_dict'] core_schema.ArgumentsV3Parameterc                 C  s   t  }|tju r|j||d}n|j|||d}| j| | |j|g}W d   n1 s1w   Y  |	 s?t
||}tj|||d}	|jdurS|j|	d< |	S | jj}
t|
trj|
jdurj|
||	d< |	S t|
rt|
||	d< |	S )zGenerate the definition of a parameter in a function signature.

        This definition is meant to be used for the `'arguments-v3'` core schema, which will replace
        the `'arguments`' schema in V3.
        r  N)r  r   rc  r  )rs   r   r  r  r  r   r  r  r  r  r  r0   arguments_v3_parameterr  r  r  rb  r>   r  )r  r  r  r  rc  r  r}   r   r   r	  r  r   r   r   _generate_parameter_v3_schema  s0   



z,GenerateSchema._generate_parameter_v3_schema
tuple_typec                   s   t | |}r|rtfdd|D }|s-|tv r(tjt gddS tg S |d tu rJt|dkrFtj 	|d gddS t
dt|dkr[|d d	kr[tg S t fd
d|D S )zIGenerate schema for a Tuple, e.g. `tuple[int, str]` or `tuple[int, ...]`.c                 3  s    | ]}t | V  qd S r   r  r   paramr  r   r   r?    r  z/GenerateSchema._tuple_schema.<locals>.<genexpr>r   )r   r   r<   z&Variable tuples can only have one typerQ   r   c                   s   g | ]}  |qS r   )r  r  r  r   r   r     r2  z0GenerateSchema._tuple_schema.<locals>.<listcomp>)rp   r  r   r   r0   tuple_schemar   EllipsisrD  r  
ValueError)r  r  paramsr   )r  r  r   r`    s   


zGenerateSchema._tuple_schemac                 C  s   t jt tdddS )Nis_typezInput should be a typer  )r0   custom_error_schemarO  r   r  r   r   r   rg    s
   zGenerateSchema._type_schemac                 C  s.   ddl m} ddd gi}tj|t |dS )z/Generate schema for a zone_info.ZoneInfo objectrQ   )validate_str_is_valid_iana_tzr8  c                 S  r  )Nrl  zoneinform  r   ro  r   r   r   r.    r  z1GenerateSchema._zoneinfo_schema.<locals>.<lambda>r   r<  )rx  r  r0   rz  r  )r  r  r<  r   r   r   rz    s   zGenerateSchema._zoneinfo_schemac                   s&    j |dd}t fdd|D S )z*Generate schema for `type[Union[X, ...]]`.Tr  c                      g | ]	}  t| qS r   r  r   )r   rA  r  r   r   r         z<GenerateSchema._union_is_subclass_schema.<locals>.<listcomp>)r  r0   r  )r  r  rA  r   r  r   _union_is_subclass_schema  s   z(GenerateSchema._union_is_subclass_schematype_c                   s0    |}t|p|}t|r  S t|r" t|j	 S t
|rQ|jr=tt|jr7 |jS t|jS |jrMt fdd|jD S   S tt|r\ |S t|rf |}t|r}td|dtt| dddt|s|du rttjS td|t|S )	z-Generate schema for a type, e.g. `type[int]`.c                   r  r   r  )r   cr  r   r   r     r  z3GenerateSchema._subclass_schema.<locals>.<listcomp>z`Subscripting `type[]` with an already parametrized type is not supported. Instead of using type[z], use type[z].Nr   zExpected a class, got )rB  rV   annotated_typer8   r  rg  re  r  r   r  
is_typevar	__bound__r;   r6   r  r0   is_subclass_schema__constraints__r  rG  r)  is_generic_aliasrH   rU   display_as_typerH  ry  r^  r   )r  r  
type_paramr   r  r   r    s@   









zGenerateSchema._subclass_schemac           	      C  s   ddl m} | |}t|}t|}tjtjdd}t	
|s2ddlm} t|t||g}tj||dd}tj|||dS )	z5Generate schema for a Sequence, e.g. `Sequence[int]`.rQ   r  Sequencer  )sequence_validatorTr  )r3  rh  r   )r  r  r  r0   r  r{   rO  rt  r(  r8   r  rx  r)  r  r  r  r{  )	r  r  r  r  r  r3  rh  r)  r   r   r   r   ra    s    


zGenerateSchema._sequence_schemacore_schema.GeneratorSchemac                 C  s   |  |}t| |S )z$Generate a schema for an `Iterable`.)rB  r0   generator_schemar  )r  r  	item_typer   r   r   rb  (  s   
zGenerateSchema._iterable_schemapattern_typec                 C  s   ddl m} ddd gi}tjtddt d}|tju s#|tju r,tj	|j
||d	S | j|d
dd }|tu rBtj	|j||d	S |tu rOtj	|j||d	S td|d)NrQ   )rx  r8  c                 S  r  )Nrl  regexrm  r   ro  r   r   r   r.  1  r  z0GenerateSchema._pattern_schema.<locals>.<lambda>patternr   )r   return_schemar  Tr  r   r  r   )r   rx  r0   r   r   r|  rt  Patternrerz  pattern_either_validatorr  r   pattern_str_validatorr  pattern_bytes_validatorrF   )r  r-  rx  r<  serr  r   r   r   rq  .  s0   zGenerateSchema._pattern_schemac                 C  s<   t jt jt t  t tjjgt tjjddddS )Nrg  rr  zInput should be hashable)r   r  r  )	r0   r  r{  r  r   rO  r  abcHashabler  r   r   r   rs  J  s   zGenerateSchema._hashable_schema	dataclasstype[StandardDataclass]type[StandardDataclass] | Nonec                   s|  j | j|\}}|dur&|W  d   W  d   S |jd}|durkt|tsk|d dkrAj|}t	|}|r[j
|W  d   W  d   S |W  d   W  d   S t|}|duru|}t|dd}ddlm}	 j| j| |	|rdd	 |j D }
|r|
 D ]}|j|gjR   qnt||jd
}
jjdkr|
 D ]\}}|jdu rtd| dddq|jdpt| t fdd|
 D dd d}t|d}t|d}tj |j!| fdd j" D |d}t#| j$ d} j% }t&||d}jj'|j!d}tj(|||||dd t)|D ||jj*j+d	},| j- }t&||d }j
|W  d   W  d   W  d   W  d   S 1 s~w   Y  W d   n	1 sw   Y  W d   n1 sw   Y  W d   dS W d   dS 1 sw   Y  dS )!z Generate schema for a dataclass.Nr  r   r  r  r<   )is_pydantic_dataclassc                 S  s   i | ]	\}}|t |qS r   r   )r   f_namer  r   r   r   r     r  z4GenerateSchema._dataclass_schema.<locals>.<dictcomp>)r  r   r  FzField zd has `init=False` and dataclass has config setting `extra="allow"`. This combination is not allowed.z dataclass-init-false-extra-allowr   r  c                 3  s"    | ]\}} || V  qd S r   )r  r   r  r   r   r?    s     z3GenerateSchema._dataclass_schema.<locals>.<genexpr>c                 S  s   |  dduS )Nr  F)r   )r   r   r   r   r.    rt  z2GenerateSchema._dataclass_schema.<locals>.<lambda>)key__post_init__	__slots__c                   r  r   r  r  r  r   r   r     r  z4GenerateSchema._dataclass_schema.<locals>.<listcomp>)r  collect_init_onlyr  r  c                 S  s   g | ]}|j qS r   )r  )r   r   r   r   r   r     r  )r  r  r;  r   slotsr  r  r  ).r   r  r   r  r  r   rb  rt   r  r[   r  rp   r   r{  r<  r   r   r  r   rG  apply_typevars_mapr  rl   r  extrar  rH   r`   r  sortedr  r0   dataclass_args_schemar   r  r   r  r  r  r	  dataclass_schemar   r  r  r  r  )r  r9  r  dataclass_refr!  r   r;  r  r  r<  r   r   r   rA  has_post_init	has_slotsargs_schemar   r  r	  	dc_schemar   r  r   r}  V  s   










2Tz GenerateSchema._dataclass_schemafunctionValidateCallSupportedTypescore_schema.CallSchemac           
      C  sn   |  |}d}| j}|jr/t|}|j}||jur/| j\}}tj|||dhd}	| 	|	d }t
j|||dS )zsGenerate schema for a Callable.

        TODO support functional validators once we support them in Config
        Nr   )globalnslocalnsinclude_keys)r0  )_arguments_schemar  validate_returnr   return_annotationr  r  rV   get_function_type_hintsr  r0   r  )
r  rM  r   r0  r   sigreturn_hintrP  rQ  
type_hintsr   r   r   rx    s"   



zGenerateSchema._call_schemaparameters_callbackParametersCallback | Nonecore_schema.ArgumentsSchemac                 C  s  t jdt jdt jdi}t|}| j\}}tj|||d}g }d}	d}
d}t|j	
 D ]\}\}}|j|ju r>ttt}n|| }|durQ||||}|dkrQq+||j}|durl| ||tj|j|}|| q+|jt jkrx| |}	q+|jt jksJ |jt|}|durt|p|}t|std|dd	d
d |j	
 D }||j}|rtd|j dt!|dkrdnd dd"dd t#|D  dd	d}| $|t|}
q+d}| |}
q+t%j&||	||
| j'j(dS )z Generate schema for a Signature.positional_onlypositional_or_keywordkeyword_onlyrP  rQ  Nskip7Expected a `TypedDict` class inside `Unpack[...]`, got unpack-typed-dictr   c                 S      h | ]\}}|j tjkr|qS r   kindr   POSITIONAL_ONLYr   r  pr   r   r   	<setcomp>
      z3GenerateSchema._arguments_schema.<locals>.<setcomp>Typed dictionary  overlaps with parameterr<   r  r   r  r  c                 s  r  r   r  r   ri  r   r   r   r?    r  z3GenerateSchema._arguments_schema.<locals>.<genexpr>overlapping-unpack-typed-dictzunpacked-typed-dictuniform)var_args_schemavar_kwargs_modevar_kwargs_schemavalidate_by_name))r   rg  POSITIONAL_OR_KEYWORDKEYWORD_ONLYr   r  rV   rV  	enumerate
parametersr   r  r  rt  r%   r   r   rf  r  r9   FUNCTIONr  r  VAR_POSITIONALr  VAR_KEYWORDunpack_typer6   r7   rH   intersectionr  r   rD  r  rE  rl  r0   r   r  rt  )r  rM  rZ  mode_lookuprW  rP  rQ  rY  arguments_listrq  rs  rr  ir  ri  r  resultparameter_mode
arg_schemar|  r  non_pos_only_param_namesoverlapping_paramsr   r   r   rS    sx   


z GenerateSchema._arguments_schemacore_schema.ArgumentsV3Schemac                 C  s  t jdt jdt jdt jdi}t|}| j\}}tj|||d}g }t	|j
 D ]\}	\}
}|d ur>||	|
|j}|dkr>q(|jt ju rKttt}n||
 }||j}|d u r|jt jksdJ |jt|}|d urt|pr|}t|std|dd	d
d |j
 D }||j}|rtd|jdt|dkrdnd dddd t|D  dd	d}|}nd}|| j|
|t j!||j"d q(t#j$|| j%j&dS )Nr]  r^  var_argsr_  r`  ra  rb  rc  r   c                 S  rd  r   re  rh  r   r   r   rj  M  rk  z6GenerateSchema._arguments_v3_schema.<locals>.<setcomp>rl  rm  r<   r  r   r  r  c                 s  r  r   r  rn  r   r   r   r?  U  r  z6GenerateSchema._arguments_v3_schema.<locals>.<genexpr>ro  var_kwargs_unpacked_typed_dictvar_kwargs_uniform)r  )rt  )'r   rg  ru  rz  rv  r   r  rV   rV  rw  rx  r   r  r  rt  r%   r   r   rf  r{  r|  r6   r7   rH   r}  r  r   rD  r  rE  r  r  r9   ry  r  r0   arguments_v3_schemar  rt  )r  rM  rZ  r~  rW  rP  rQ  rY  parameters_listr  r  ri  r  r  r  r|  r  r  r  r   r   r   _arguments_v3_schema$  sl   	


z#GenerateSchema._arguments_v3_schematypevartyping.TypeVarc                 C  s   z|  }W n	 ty   Y n	w |r| |jS |j }r%| tj| S |j }r>| |}t	j
dd t	 d|d< |S t	 S )Nc                 S  r  r   r   )r-  r  r   r   r   r.  x  r  z>GenerateSchema._unsubstituted_typevar_schema.<locals>.<lambda>r  r   )has_defaultr  r  __default__r$  r  rt  r$   r"  r0   r  r   )r  r  r  constraintsr   r   r   r   r   ru  h  s"   



z,GenerateSchema._unsubstituted_typevar_schemar  Decorator[ComputedFieldInfo]r  2dict[str, Decorator[FieldSerializerDecoratorInfo]]core_schema.ComputedFieldc           
   
   C  s(  |j jtur|j j}nztj|j| jjd}W n ty) } zt	
||d }~ww |tu r4tdddt|| j}tj|j |d|_ | |}| |t| |j}| jj}|d urf| j||j |jd | | j|j |j t|j \}}i }	t|	ddi|r|ni |d	 tj|j||j j|	d
S )NrQ  zComputed field is missing return type annotation or specifying `return_type` to the `@computed_field` decorator (e.g. `@computed_field(return_type=int | str)`)zmodel-field-missing-annotationr   )return_type)r  r  r  readOnlyTr  )r0  r  r<  )r   r  r.   rR   get_callable_return_typefuncr  localsr  rG   r  rH   rq   r   r{  replacer  r  r   rG  r   r  r  r  r  r   rZ   r0   computed_fieldr  )
r  r  r  r  r  return_type_schemar  r  r  r  r   r   r   r    sH   


z%GenerateSchema._computed_field_schemar   c                 C  sF   t  }| j|dd^}}| ||}|D ]}t||r t||}q|S )zdGenerate schema for an Annotated type, e.g. `Annotated[int, Field(...)]` or `Annotated[int, Gt(0)]`.Tr  )rs   r  r  rb  r  )r  r   r}   r  r   r   r  r   r   r   rI    s   


z GenerateSchema._annotated_schemac                 C  r+  r   r   r,  r   r   r   r.    r/  zGenerateSchema.<lambda>r  r   	list[Any]r  "Callable[[CoreSchema], CoreSchema]c           
        s   t t|}g }d
 fdd}t| }|D ]}|du r q |||}q|}|r:|di }	t|	|d	 t jj	|S )a  Apply arguments from `Annotated` or from `FieldInfo` to a schema.

        This gets called by `GenerateSchema._annotated_schema` but differs from it in that it does
        not expect `source_type` to be an `Annotated` object, it expects it to be  the first argument of that
        (in other words, `GenerateSchema._annotated_schema` just unpacks `Annotated`, this process it).
        r  r   r   r*   c                   sV     | }|d u r | }t| }|d ur't| j}|d ur' || |S r   )r  r  r  r  r   r  )r  r   r  r  r  r  r  r   r   inner_handler  s   
z8GenerateSchema._apply_annotations.<locals>.inner_handlerNr<  ) pydantic_js_annotation_functionsr  r   r   r*   )
rE  rT   expand_grouped_metadatary   _get_wrapped_inner_schemar  rZ   r   r  r   )
r  r  r   r  r  r  get_inner_schemar  r   r  r   r  r   r    s   
z!GenerateSchema._apply_annotationsr<  c                 C  sL  t  }t||r"|jD ]}| ||}q|jd ur | ||j}|S |d dkr>|dt }| ||}|r<||d< |S |}|d}|d urg|	 }|dt
|  }| j| }	d urb|	S ||d< n1|d dkr|d }| j| }
d ur|
	 }|dt
|  }| j| }	d ur|	S ||d< t||}|d ur|S |S )Nr   r   r   r;  r?  definition-refrF  )rs   rb  r<  _apply_single_annotationr  r  r   r0   r   r	   r  r   get_schema_from_refrT   apply_known_metadata)r  r   r<  r}   field_metadatar  r4  r;  new_refexistingreferenced_schemamaybe_updated_schemar   r   r   r    sB   




z'GenerateSchema._apply_single_annotationc                 C  sR   t  }t||r'|jD ]}| ||}qt|\}}|di }t|||d |S )Nr<  r  )rs   rb  r<  $_apply_single_annotation_json_schemar   r  rZ   )r  r   r<  r}   r  r  r  r  r   r   r   r  	  s   

z3GenerateSchema._apply_single_annotation_json_schemar  r@   r  list[GetJsonSchemaFunction]ry   c                   s,   t  dd d fdd}t|S )	Nr+  r  r   r   r   c                   sR   d ur
| }n| } | }| }t }|d ur'| |S r   )r  r  r  r  )r  r   r  r  annotation_get_schemar  r  r  r   r   new_handler/	  s   
z=GenerateSchema._get_wrapped_inner_schema.<locals>.new_handler)r  r   r   r   )r   ry   )r  r  r  r  r  r   r  r   r  '	  s   
z(GenerateSchema._get_wrapped_inner_schemaserializers-list[Decorator[FieldSerializerDecoratorInfo]]c           
   
   C  s0  |rt |}|d dkr|d }| |||d< |S d|v r$| j|}|d }t|j|jj\}}|jjt	ur=|jj}nzt
j|j| jjd}W n ty[ } zt||d}~ww |t	u rcd}	n| |}	|jjdkrtj|j|||	|jjd	|d
< |S |jjdksJ tj|j|||	|jjd	|d
< |S )z$Apply field serializers to a schema.r   r  r   r;  r   r  Nr   )is_field_serializerrk  r0  r   r   r   )r	   r  r   r  rh   r  r   rc  r  r.   rR   r  r  r  r  rG   r  r  r0   r  r   r   )
r  r   r  r   
serializerr  rk  r  r  r0  r   r   r   r  >	  sR   





z'GenerateSchema._apply_field_serializers1Iterable[Decorator[ModelSerializerDecoratorInfo]]c           
   
   C  s   | dd}|rot|d }t|j|jj}|jjtur!|jj}nztj	|j| j
jd}W n ty? } zt||d}~ww |tu rGd}n| |}|jjdkr_tj|j|||jjd}	ntj|j|||jjd}	|	|d< |ru||d< |S )z$Apply model serializers to a schema.r;  Nr   r  r   )rk  r0  r   r   )poprE  ri   r  r   rc  r  r.   rR   r  r  r  r  rG   r  r  r0   r  r   r   )
r  r   r  r;  r  rk  r  r  r0  
ser_schemar   r   r   r  v	  sD   



z'GenerateSchema._apply_model_serializers)NN)r   rW   r   r  r  r  r   r   r   r   )r   rW   )r   ru   )r   r   )r  r   r   r*   )r  r   r   r   r   r*   )r'  r(  r   r*   )r   r   r   r*   )r   r   r~  r   r   r*   )r   r   r  r   r   r   r   r*   )r   r*   r  )r   r*   r  r  r   r*   r  )r  r*   r  r  r   r   )r  r   r   r   )r  r  r   r   )r  r   r   r   )r  r   r  r   r   r*  )r  r   r  r9  r   r:  )r  r   r   r=  )F)r  r   r  r   r   r=  )r  r   r   rC  )r  r   r  r   r   r*   )
r  r   r  r}   r   r`   r  r   r   r  )r  r   r  r}   r   r`   r   r  )r  r   r  r}   r   r`   r   r  )r  r  r  r}   r   r   r   r   )r  r  r  r|   r  r   )r   rW   r  r   r   r   r   r   )r  r   r  r}   r   r`   r   r  )r  r   r   r   )r  r3   r   r*   )r  r   r   r*   )r  r   r  r   r   r   )r  r   r  r   r   r   )r  r   r  r  r  r9   r  r   rc  r  r   r  )r  r   r  r   r  r9   rc  r
  r  r   r   r  )r  r   r   r   )r   r   )r  r   r   r   )r  r   r   r   )r  r   r   r*  )r-  r   r   r   )r9  r:  r  r;  r   r   )rM  rN  r   rO  r   )rM  rN  rZ  r[  r   r\  )rM  rN  rZ  r[  r   r  )r  r  r   r   )r  r  r  r  r   r  )r   r   r   r   )r  r   r   r  r  r  r   r*   )r   r   r<  r   r   r   )r  r@   r  r   r  r  r   ry   )r   r   r  r  r   r   )r   r   r  r  r   r   )Nr   r   r   r   r@  r  r  propertyr  r  r  r  r"  r$  r&  rR  r}  r  r  r  r  r  r  r  r  r  r  r(  r)  r  r8  r&   r  rB  rE  r  rL  r~  r  r  r  staticmethodr  r  r  r  r  rf  rk  rl  rn  r   r  r  r  r`  rg  rz  r  r  ra  rb  rq  rs  r}  rx  rS  r  ru  r  rI  r  r  r  r  r  r  __classcell__r   r   r  r   r   >  s    


H!
:&' ;	v91*Ij141'jLD3,*8r   c                 C     t | |S r   )r0   !no_info_before_validator_functionr  r   r?  r   r   r   r.  	      r.  c                 C  r  r   )r0   rN  r  r   r   r   r.  	  r  c                 C  s
   t | S r   )r0   rz  )r  rp  rq  r   r   r   r.  	  r  c                 C  r  r   )r0   r  r  r   r   r   r.  	  r  c                 C     t j| ||dS N)r   )r0   #with_info_before_validator_functionr  r   r   r   r   r   r.  	      c                 C  r  r  )r0   "with_info_after_validator_functionr  r   r   r   r.  	  r  c                 C  s   t j| |dS r  r/  )r  r?  r   r   r   r   r.  	  s    c                 C  r  r  )r0   !with_info_wrap_validator_functionr  r   r   r   r.  	  r  ))r   no-info)r   r  )r   r  )r   r  )r   	with-info)r   r  )r   r  )r   r  zMapping[tuple[FieldValidatorModes, Literal['no-info', 'with-info']], Callable[[Callable[..., Any], core_schema.CoreSchema, str | None], core_schema.CoreSchema]]_VALIDATOR_F_MATCHr  Iterable[Decorator[RootValidatorDecoratorInfo]] | Iterable[Decorator[ValidatorDecoratorInfo]] | Iterable[Decorator[FieldValidatorDecoratorInfo]]c                 C  sD   |D ]}t |j|jj}|rdnd}t|jj|f |j| |} q| S )a  Apply validators to a schema.

    Args:
        schema: The schema to apply validators on.
        validators: An iterable of validators.
        field_name: The name of the field if validators are being applied to a model field.

    Returns:
        The updated schema.
    r  r  )rj   r  r   rc  r  )r   r  r   	validatorrk  val_typer   r   r   r   	  s
   r   +Iterable[Decorator[ValidatorDecoratorInfo]]c                 C  s   | D ]	}|j jr dS qdS )a?  In v1, if any of the validators for a field had `always=True`, the default value would be validated.

    This serves as an auxiliary function for re-implementing that logic, by looping over a provided
    collection of (v1-style) ValidatorDecoratorInfo's and checking if any of them have `always=True`.

    We should be able to drop this function and the associated logic calling it once we drop support
    for v1-style validator decorators. (Or we can extend it and keep it if we add something equivalent
    to the v1-validator `always` kwarg to `field_validator`.)
    TF)r   ri  )r  r  r   r   r   r  	  s
   
r  0Iterable[Decorator[ModelValidatorDecoratorInfo]]rc   Literal['inner', 'outer', 'all']c                 C  s   |  dd}|D ]o}|dkr|jjdkrq|dkr |jjdkr qt|j|jj}|jjdkrB|r9tj|j| d} qtj|j| d} q|jjdkr\|rStj|j| d} qtj	|j| d} q|jjdksdJ |rotj
|j| d} qtj|j| d} q|r~|| d< | S )	a  Apply model validators to a schema.

    If mode == 'inner', only "before" validators are applied
    If mode == 'outer', validators other than "before" are applied
    If mode == 'all', all validators are applied

    Args:
        schema: The schema to apply validators on.
        validators: An iterable of validators.
        mode: The validator mode.

    Returns:
        The updated schema.
    r;  Nr  r   r  r   )rM  r   r   )r  r   rc  rj   r  r0   r  r  r  r  r  rN  )r   r  rc  r;  r  rk  r   r   r   r  	  s,   r  r  r}   c                 C  sD   | j rtj|| j t| j | jdS | jtur tj|| j| jdS |S )a  Wrap schema with default schema if default value or `default_factory` are available.

    Args:
        field_info: The field info object.
        schema: The schema to apply default on.

    Returns:
        Updated schema by default value or `default_factory`.
    )default_factorydefault_factory_takes_datar  )r  r  )r  r0   with_default_schemarn   r  r  r.   )r  r   r   r   r   r  
  s   


r  GetJsonSchemaFunction | Nonec                 C  s   t | dd}t| dr8t }|duo|jj|t |ddfv}|s8t | dd}td|r0d| dnd	 d
ddt|  }durDt|S |du rJdS |S )z`Extract `__get_pydantic_json_schema__` from a type, handling the deprecated `__modify_schema__`.__get_pydantic_json_schema__N__modify_schema__r7  r   zjThe `__modify_schema__` method is not supported in Pydantic v2. Use `__get_pydantic_json_schema__` insteadz in class ``r   r   zcustom-json-schemar   )r   r  rr   r  r7  rH   r6   r  )r   js_modify_functionr   has_custom_v2_modify_js_funccls_namer  r   r   r   r  0
  s*   
r  c                   @  s>   e Zd ZU ded< ded< ded< ded< ded	< d
ed< dS )r  r   r   4str | list[str | int] | list[list[str | int]] | Noner  r   r  bool | Noner  r  zdict[str, Any]r<  N)r   r   r   r  r   r   r   r   r  P
  s   
 r  )r  r  r  r  r<  r  r  r  r  r  r  r<  c                C  s   | |||||dS )Nr   r  r  r  r  r<  r   r  r   r   r   r  Y
  s   
r  r  r  CoreSchema | Nonec                 C  s2   | d dkr| | d S | d dkr| d S | S )Nr   r  rF  r  r   )r  r   r  r   r   r   r  l
  s
   r  def_ref%core_schema.DefinitionReferenceSchema.Literal['inline', 'keep', 'preserve_metadata']c                 C  s:   d| v rdS |  d}|sdS t|dkrd|v rdS dS )a  Determine the inlining behavior of the `'definition-ref'` schema.

    - If no `'serialization'` schema and no metadata is attached, the schema can safely be inlined.
    - If it has metadata but only related to the deferred discriminator application, it can be inlined
      provided that such metadata is kept.
    - Otherwise, the schema should not be inlined. Doing so would remove the `'serialization'` schema or metadata.
    r   keepr<  inlinerQ   %pydantic_internal_union_discriminatorpreserve_metadata)r   rD  )r  r<  r   r   r   _inlining_behavioru
  s   

r  c                   @  sp   e Zd ZU dZded< 	 ded< 	 d#dd	Zed$ddZd%ddZd&ddZ	d'ddZ
d(ddZd)d d!Zd"S )*r  z*Keeps track of references and definitions.zset[str]_recursively_seenz!dict[str, core_schema.CoreSchema]r  r   r   c                 C  s   t  | _i | _d S r   )r   r  r  r  r   r   r   r  
  s   
z_Definitions.__init__r   r   CGenerator[tuple[str, core_schema.DefinitionReferenceSchema | None]]c             	   c  sj    t |}|| jv s|| jv r|t|fV  dS | j| z|dfV  W | j| dS | j| w )a  Get a definition for `tp` if one exists.

        If a definition exists, a tuple of `(ref_string, CoreSchema)` is returned.
        If no definition exists yet, a tuple of `(ref_string, None)` is returned.

        Note that the returned `CoreSchema` will always be a `DefinitionReferenceSchema`,
        not the actual definition itself.

        This should be called for any type that can be identified by reference.
        This includes any recursive types.

        At present the following types can be named/recursive:

        - Pydantic model
        - Pydantic and stdlib dataclasses
        - Typed dictionaries
        - Named tuples
        - `TypeAliasType` instances
        - Enums
        N)r\   r  r  r0   rJ  adddiscard)r  r   r;  r   r   r   r  
  s   z_Definitions.get_schema_or_refr;  r   r  c                 C  s   | j |S )z,Resolve the schema from the given reference.)r  r   )r  r;  r   r   r   r  
  s   z _Definitions.get_schema_from_refr   r*   r  c                 C  s   |d }|| j |< t|S )zStore the schema as a definition and return a `'definition-reference'` schema pointing to it.

        The schema must have a reference attached to it.
        r;  )r  r0   rJ  )r  r   r;  r   r   r   r  
  s   

z/_Definitions.create_definition_reference_schemacore_schema.DefinitionsSchemac                 C  s$   |d D ]	}|| j |d < q|d S )zZStore the definitions of the `'definitions'` core schema and return the inner core schema.r  r;  r   )r  )r  r   
def_schemar   r   r   r  
  s   z_Definitions.unpack_definitionsc              
   C  s<  | j }zt||d}W n ty } zt|d}~ww i }|d  D ]E\}}|dur`t| }dkr`|dkrE|  || || q#|dkr_|	d}	|  || || |	|d< q#| ||||< q#|d D ]!}
|
d 	d	d}|du r|qmt
|
 ||}|
  |
| qm|rtj|g | d
}|S )zFinalize the core schema.

        This traverses the core schema and referenced definitions, replaces `'definition-ref'` schemas
        by the referenced definition if possible, and applies deferred discriminators.
        )r  Ncollected_referencesr  r  r  r<  deferred_discriminator_schemasr  r  )r  rx   rw   r   r   r  clearr2  _resolve_definitionr  rS   r  r	   r0   definitions_schemarG  )r  r   r  gather_resultr  remaining_defsr;  inlinable_def_refinlining_behaviormetacsr  appliedr   r   r   r  
  sB   

z_Definitions.finalize_schemar  dict[str, CoreSchema]c                 C  s   || }|d dkr|S t  }|d dkrAt|dkrA|d }||v r,t| ddd|| || }|d dkrAt|dksi |d|iS )	Nr   r  r  rF  z) contains a circular reference to itself.zcircular-reference-schemar   r;  )r   r  rH   r  )r  r;  r  
definitionvisitedrF  r   r   r   r    s   

z _Definitions._resolve_definitionNr  )r   r   r   r  )r;  r   r   r  )r   r*   r   r  )r   r  r   r*   r  )r;  r   r  r  r   r*   )r   r   r   r   r  r  r   r  r  r  r  r  r  r   r   r   r   r  
  s   
 	

 

	
:c                   @  2   e Zd ZdZdddZedd	d
ZdddZdS )r  _stackr   r   c                 C  
   g | _ d S r   r  r  r   r   r   r  &     
z_FieldNameStack.__init__r   r   Iterator[None]c                 c  "    | j | d V  | j   d S r   r  r  r  )r  r   r   r   r   r  )     z_FieldNameStack.pushr   c                 C     | j r| j d S d S Nr   r  r  r   r   r   r   /     
z_FieldNameStack.getNr  )r   r   r   r  )r   r   r   r   r   r@  r  r   r  r   r   r   r   r   r  #      
r  c                   @  r   )r  r  r   r   c                 C  r  r   r  r  r   r   r   r  9  r  z_ModelTypeStack.__init__type_objr   r  c                 c  r  r   r  )r  r  r   r   r   r  <  r  z_ModelTypeStack.pushtype | Nonec                 C  r	  r
  r  r  r   r   r   r   B  r  z_ModelTypeStack.getNr  )r  r   r   r  )r   r  r  r   r   r   r   r  6  r  r  )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   r*   r   r*   )r   r   r   r   r   r   )r   r   r  r  r   r   r   r   )r  r  r   r   )r   r   r  r  rc  r  r   r   )r  r}   r   r   r   r   )r   r   r   r  )r   r   r  r  r  r   r  r  r  r  r<  r   r   r  )r   r*   r  r  r   r  )r  r  r   r  (  r   
__future__r   _annotationscollections.abcr  r{  rR  rH  r  r  r2  sysrt  r   r   r   r   r   
contextlibr   r	   decimalr
   enumr   	fractionsr   	functoolsr   r   r   r   	ipaddressr   r   r   r   r   r   	itertoolsr   operatorr   typesr   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   uuidr'   r(   r  r)   typing_extensionspydantic_corer*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   typing_inspectionr8   typing_inspection.introspectionr9   r:   r;   aliasesr=   r>   r?   annotated_handlersr@   rA   r  rB   rC   rD   rE   errorsrF   rG   rH   functional_validatorsrI   rJ   rK   rL   rM   r3  rN   versionrO   rP   r   rR   rS   rT   rU   rV   _configrW   rX   _core_metadatarY   rZ   _core_utilsr[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   _docs_extractionrk   r  rl   rm   rn   _forward_refro   	_genericsrp   rq   _import_utilsrr   rs   _mock_val_serrt   _namespace_utilsru   rv   _schema_gatherrw   rx   _schema_generation_sharedry   _utilsrz   r{   r   r|   r}   mainr   r   _dataclassesr   r   version_infor  r   r   AnyFieldDecoratorr   r  r   r   Tupler   r   ListrE  r7  MutableSequencer   Setr   
MutableSetr   	FrozenSet	frozensetr   Dictr   r   r   r(  r   r   Typer   r   r1  r   r  Pathr  	PosixPathPurePosixPathPureWindowsPathr   MutableMappingOrderedDictDefaultDictr  rc  Counterrd  r  r  r   rN  rw  r   r   r   r   r   r   JsonEncodersr   r   	Exceptionr   r   r  r   r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   <module>   sL    0( 
8
 	






%

"	                |




/
 

	 