
    RPf             	      \   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mZmZ ddlmZ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 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%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- ddlm.Z. ddl/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; ddl<m=Z= ddl>m?Z?m@Z@ ddlAmBZBmCZCmDZD ddlEmFZFmGZGmHZH ddlImJZJ ddlKmLZL ddlmMZM ddlNmOZOmPZPmQZQmRZRmSZS ddlTmUZUmVZV ddlWmXZXmYZY ddlOmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZb ddlPmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZn ddlompZp ddlqmrZrmsZs dd ltmuZu dd!lvmwZwmxZxmyZymzZz dd"l{m|Z| dd#lSm}Z}m~Z~ dd$lmZ e r&dd%lmZmZ dd&lmZ dd'lmZ dd(lmZ dd)lmZ dd*l{mZ e	j                  d+k\  Z ee5ed,f         Ze+ejefeef   Z e*d-e.      Ze+ecej   ecef   ecee   f   Ze?Ze"e!ege2j`                  f   Zee
j.                  gZd/ed0<   ee
j6                  ej8                  j:                  gZd/ed1<   ee
j@                  ej8                  jB                  gZd/ed2<   ee
jH                  ej8                  j@                  gZd/ed3<   ee
jF                  ej8                  jN                  ej8                  jP                  gZd/ed4<   	 	 	 	 	 	 d]d5Zd^d6Z	 	 	 	 	 	 d_d7Z	 	 	 	 	 	 	 	 d`d8Z	 	 	 	 	 	 	 	 dad9Ze#e)e!   eDf   Z	 	 	 	 	 	 	 	 dbd:Ze+e#ee!f   df   Z G d; d<      Zdcd=Z G d> d?      Zd@ dA dB dC dD dE dF dG dHZdIedJ<   	 	 	 	 	 	 	 	 dddKZdedLZ	 	 	 	 	 	 	 	 dfdMZdgdNZdhdOZ	 	 	 	 	 	 didPZ	 	 	 	 djdQZ G dR dSe8      ZddddddT	 	 	 	 	 	 	 	 	 	 	 	 	 dkdUZ G dV dW      ZdldXZ G dY dZ      Z G d[ d\      Zy)mz-Convert python types to pydantic-core schema.    )annotationsN)	ExitStackcontextmanager)copydeepcopy)Enum)partial)	Parameter_ParameterKind	signature)chain)
attrgetter)FunctionType
LambdaType
MethodType)TYPE_CHECKINGAnyCallableDictFinal
ForwardRefIterableIteratorMappingTypeTypeVarUnioncastoverload)warn)
CoreSchemaPydanticUndefinedcore_schemato_jsonable_python)	AnnotatedLiteralTypeAliasType	TypedDictget_args
get_originis_typeddict   )AliasGenerator)GetCoreSchemaHandlerGetJsonSchemaHandler)
ConfigDictJsonDictJsonEncoder)PydanticSchemaGenerationErrorPydanticUndefinedAnnotationPydanticUserError)JsonSchemaValue)version_short)PydanticDeprecatedSince20   )_core_utils_decorators_discriminated_union_known_annotated_metadata_typing_extra)ConfigWrapperConfigWrapperStack)CoreMetadataHandlerbuild_metadata_dict)	CoreSchemaOrFieldcollect_invalid_schemasdefine_expected_missing_refsget_refget_type_refis_function_with_inner_schema%is_list_like_schema_with_items_schemasimplify_schema_references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get_type_hints_infer_globalns)PydanticRecursiveRef)get_standard_typevars_maphas_instance_in_typerecursively_defined_type_refsreplace_types)CallbackGetCoreSchemaHandler)is_finalvaris_self_type)lenient_issubclass)ComputedFieldInfo	FieldInfo	BaseModel)Discriminator)FieldValidatorModes)StandardDataclass)GetJsonSchemaFunction)      {   FieldDecoratorInfoType)boundz
list[type]TUPLE_TYPES
LIST_TYPES	SET_TYPESFROZEN_SET_TYPES
DICT_TYPESc                R    d| j                   v ry| j                   D ]	  }||k(  s	 y y)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.
    *TF)fields)infofieldv_field_names      ]/var/www/fastapitest/venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py)check_validator_fields_against_field_namer}   q   s6     dkk 5      c           	        t        |      }| D ]{  }d|j                  j                  v r|j                  j                  du r5|j                  j                  D ].  }||vst	        d|j
                   d|j                   dd       } y)	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.
    rw   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)setry   rx   check_fieldsr5   cls_refcls_var_name)
decoratorsrx   decrz   s       r|   check_decorator_fields_existr      s     [F #((//!88  E)XX__ 	EF"'@QsO_O_N`ef2 	r~   c                Z    | D cg c]  }t        |j                  |      s| c}S c c}w N)r}   ry   )validator_functionsrz   r   s      r|   $filter_field_decorator_info_by_fieldr      s*     /mC2[\_\d\dfk2lCmmms   ((c                   | d   dk(  rt        | d   ||      | d<   | S | d   dk(  r.| j                  d      x}t        | d   |   ||      | d   |<   | S t        |       r:| j                  dd       }|t	        j
                         }t        |||      | d<   | S | d   dk(  r:| j                  dd       }|t	        j
                         }t        |||      | d<   | S |rt        d	| d          | S )
Ntypenullableschema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_validatorsrI   r#   
any_schema	TypeError)r   each_item_validators
field_namer   inner_schemas        r|   r   r      sF    f~#5fX6FH\^hix	7	"#)::.C#DDQ:J~&':;=QS];F>"#67& M! 
/v	6zz.$7&113L!1,@TV`!a~ M 
6	! zz/48&113L"2<AUWa"b
 M	 
]^dek^l]mn
 	
 Mr~   c                  ddl m} ddlm}  ||       }|j	                  |      }d|v r|d   }|j                          d|ig|d<   d|vr|j                  |d<   ||u rdn|j                  }|rd|vrt        j                  |      |d<   |S t        ||      r5|j                  d	   j                  r|j                  d	   j                  |d<   |S )
a0  Add title and description for model-like classes' JSON schema.

    Args:
        schema_or_field: The schema data to generate a JSON schema from.
        handler: The `GetCoreSchemaHandler` instance.
        cls: The model-like class.

    Returns:
        JsonSchemaValue: The updated JSON schema.
    r,   rf   )	RootModelz$refallOftitleNdescriptionroot)mainrg   
root_modelr   resolve_ref_schemaclear__name____doc__inspectcleandoc
issubclassmodel_fieldsr   )	schema_or_fieldhandlerclsrg   r   json_schemaoriginal_schemaref	docstrings	            r|   modify_model_json_schemar      s     !&/*K00=O f%%+SM? o%#&<< y(ckkI]/9)0)9)9))D&  
C	#(8(8(@(L(L),)9)9&)A)M)M&r~   c                "   | s|S d|v r|S |gt        |d|j                  j                        dd D ]Y  }| j                  |      }|t	        j
                  dt                dt               t        j                  |d      |d<   |c 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    r7   r8   r#   $plain_serializer_function_ser_schema)json_encoderstpr   baseencoders        r|   ,_add_custom_serialization_from_json_encodersr      s     &  Hgb)R\\-A-AB3BGH ##D)?KMOK\  ]Y  Z%	
 #."R"RSZfl"m Mr~   c                  <    e Zd ZdZddZedd       Zedd       Zy)	TypesNamespaceStackzA stack of types namespaces.c                    |g| _         y r   _types_namespace_stack)selftypes_namespaces     r|   __init__zTypesNamespaceStack.__init__  s    =L<M#r~   c                     | j                   d   S Nr   r   r   s    r|   tailzTypesNamespaceStack.tail  s    **2..r~   c              #    K   i t        j                  |      | j                  xs i }| j                  j	                  |       	 d  | j                  j                          y # | j                  j                          w xY wwr   )r>   get_cls_types_namespacer   r   appendpop)r   for_typer   s      r|   pushzTypesNamespaceStack.push   sm     b]BB8LbQUQZQZQ`^`b##**?;	.''++-D''++-s   ABA% 
B%BBN)r   TypesNamespace)returnr   )r   	type[Any])	r   
__module____qualname__r   r   propertyr   r   r    r~   r|   r   r     s3    &N / / . .r~   r   c                    | | 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.
    r   )abs     r|   _get_first_non_nullr   *  s     1$1$r~   c                     e Zd ZdZdZ	 dG	 	 	 	 	 	 	 dHdZe	 	 	 	 	 	 	 	 	 	 	 	 dId       ZedJd       Z	edKd       Z
edLd       ZedMd	       ZdNd
ZdOdZdPdZdOdZdOdZdQdZdRdZ	 	 	 	 	 	 dSdZ G d de      ZdTdZdTdZdUdZ	 dV	 	 	 	 	 dWdZdXdZdTdZdYdZdZdZed[d       Z ed\d       Z d]d^dZ dZd Z!d_d!Z"d`d"Z#d`d#Z$dad$Z%dd%	 	 	 	 	 	 	 	 	 dbd&Z&	 	 	 	 	 	 	 	 dcd'Z'	 	 	 	 	 	 	 	 ddd(Z(e)	 	 	 	 	 	 	 	 ded)       Z*e)	 	 	 	 	 	 dfd*       Z+	 	 	 	 	 	 	 	 dgd+Z,dhd,Z-	 	 	 	 dRd-Z.did.Z/djd/Z0dkd0Z1e2jf                  df	 	 	 	 	 	 	 	 	 dld1Z4dmd2Z5dnd3Z6dhd4Z7dod5Z8dpd6Z9dqd7Z:drd8Z;dnd9Z<	 	 	 	 	 	 dsd:Z=dtd;Z>dud<Z?	 	 	 	 	 	 dvd=Z@dwd>ZA	 	 	 	 	 	 dxd?ZBd@ f	 	 	 	 	 	 	 dydAZCdzdBZD	 	 	 	 	 	 dzdCZE	 	 	 	 	 	 	 	 d{dDZF	 d]	 	 	 	 	 	 	 d|dEZG	 	 	 	 	 	 d}dFZHy)~GenerateSchemaz\Generate core schema for a Pydantic model, dataclass and types like `str`, `datetime`, ... .)_config_wrapper_stackr   _typevars_mapfield_name_stackmodel_type_stackdefsNc                    t        |      | _        t        |      | _        || _        t               | _        t               | _        t               | _
        y r   )r@   r   r   r   r   _FieldNameStackr   _ModelTypeStackr   _Definitionsr   )r   config_wrapperr   typevars_maps       r|   r   zGenerateSchema.__init__?  sE     &8%G"&9/&J#) / 1 / 1 N	r~   c                    | j                  |       }||_        ||_        ||_        ||_        t               |_        ||_        |S r   )__new__r   r   r   r   r   r   r   )r   config_wrapper_stacktypes_namespace_stackr   r   r   objs          r|   __from_parentzGenerateSchema.__from_parentM  sI     kk#$8!%:"/(.0
r~   c                .    | j                   j                  S r   )r   r   r   s    r|   _config_wrapperzGenerateSchema._config_wrapper_  s    ))...r~   c                .    | j                   j                  S r   )r   r   r   s    r|   _types_namespacezGenerateSchema._types_namespacec  s    **///r~   c                    | j                   j                  xs t        }|j                  | j                  | j
                  | j                  | j                  | j                        S r   )	r   schema_generatorr   _GenerateSchema__from_parentr   r   r   r   r   )r   r   s     r|   _current_generate_schemaz'GenerateSchema._current_generate_schemag  sV    ""33E~  &&''!!II
 	
r~   c                .    | j                   j                  S r   )r   arbitrary_types_allowedr   s    r|   _arbitrary_typeszGenerateSchema._arbitrary_typesr  s    ##;;;r~   c                *    t        j                         S )zGenerate a CoreSchema for `str`)r#   
str_schemar   s    r|   r  zGenerateSchema.str_schemav  s    %%''r~   c                J    t        j                  | j                  |            S r   )r#   list_schemagenerate_schemar   r   
items_types      r|   _list_schemazGenerateSchema._list_schema|  s    &&t';';J'GHHr~   c                j    t        j                  | j                  |      | j                  |            S r   )r#   dict_schemar  )r   r   	keys_typevalues_types       r|   _dict_schemazGenerateSchema._dict_schema  s,    &&t';';I'FH\H\]hHijjr~   c                J    t        j                  | j                  |            S r   )r#   
set_schemar  r  s      r|   _set_schemazGenerateSchema._set_schema  s    %%d&:&::&FGGr~   c                J    t        j                  | j                  |            S r   )r#   frozenset_schemar  r  s      r|   _frozenset_schemaz GenerateSchema._frozenset_schema  s    ++D,@,@,LMMr~   c                    t        |t              s't        |dt               t	        j
                         S t	        j                  |      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`.)
isinstancer   r    UserWarningr#   r   is_instance_schema)r   r   s     r|   _arbitrary_type_schemaz%GenerateSchema._arbitrary_type_schema  sL    "d#& Z Z  ))++--b11r~   c                     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.)r3   r   r   s     r|   _unknown_type_schemaz#GenerateSchema._unknown_type_schema  s#    +:3' Bf f
 	
r~   c                    ||S 	 t        j                  ||      S # t         j                  $ r t        j                  ||       |cY S w xY wr   )r<   apply_discriminatorMissingDefinitionForUnionRefset_discriminator_in_metadata)r   r   discriminators      r|   _apply_discriminator_to_unionz,GenerateSchema._apply_discriminator_to_union  s_      M	';;  $@@ 	 >> M	s    +A
	A
c                      e Zd Zy)GenerateSchema.CollectedInvalidN)r   r   r   r   r~   r|   CollectedInvalidr$    s    r~   r%  c                    | j                  |      }t        |      }t        |      r| j                         t	        j
                  |      }t        |      }|S r   )collect_definitionsrJ   rD   r%  r<   apply_discriminatorsrK   )r   r   s     r|   clean_schemazGenerateSchema.clean_schema  sR    ))&1+F3"6*''))%::6B%f-r~   c                *   t        d|j                  dd             }|r|| j                  j                  |<   d|v rt	        j
                  |d         }t	        j                  |t        | j                  j                  j                                     S )N
str | Noner   )	r   r   r   definitionsr#   definition_reference_schemadefinitions_schemalistvalues)r   r   r   s      r|   r'  z"GenerateSchema.collect_definitions  s|    <E4!89)/DII!!#&F? <<VE]KF--&&--/0
 	
r~   c                ~    t        |      j                  }|j                  dg       }||vr|j                  |       y y )Npydantic_js_functions)rA   metadata
setdefaultr   )r   metadata_schemajs_functionr3  r2  s        r|   _add_js_functionzGenerateSchema._add_js_function  sD    &7@@ ( 3 34KR P 33!((5 4r~   Tc                &   d}|r| j                  ||      }||}|| j                  |      }t        ||      }|4t        || j                  j
                        }|r| j                  ||       t        | j                  j                  ||      }|S )a  Generate core schema.

        Args:
            obj: The object to generate core schema for.
            from_dunder_get_core_schema: Whether to generate schema from either the
                `__get_pydantic_core_schema__` function or `__pydantic_core_schema__` property.

        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_property_generate_schema_inner!_extract_get_pydantic_json_schemaresolve_original_schemar   r,  r7  r   r   r   )r   r   from_dunder_get_core_schemar   from_propertymetadata_js_functionr5  s          r|   r  zGenerateSchema.generate_schema  s    6 %)& ??SIM(&>005F@fM+5fdii>S>STO%%o7KL=d>R>R>`>`begmnr~   c                h	   | j                   j                  |      5 \  }}||cddd       S |j                  }|j                  }|j                  }t        t        |j                  j                         |j                  j                         |j                  j                               h |j                         |j                                t        |j                  d      }|j                  |      }t        t!        t"        |      g      }	|j$                  j                         }
d}|j'                  d      dk(  r|j(                  d   |u sJ |j(                  d	   t*        u sJ |j(                  dd	 D ]  }t-        |d
i       j'                  dd      }|#t/        |t0              r6t3        j4                  t3        j6                  |dd      | j8                        }t;        |      }|t<        t>        fvrtA        d      | jC                  |d      d   }|tD        us| jG                  |      } n | jH                  jK                  |      5  | jL                  jK                  |      5  | jN                  } |jP                  r]| jS                  d|d   |      }|d   }tU        ||
d      }tW        jX                  ||t-        |dd      dt-        |dd      |||	      }n	tW        jZ                  |j]                         D ci c]  \  }}|| j_                  |||       c}}|j                         D cg c]  }| ja                  ||j                          c}||jb                        }te        ||jf                  j                         d      }ti        |tk                     }||}tU        ||
d      }tW        jX                  ||t-        |dd      dt-        |dd      |||	      }| jm                  ||jn                  j                               }tU        ||
d      }|| j                   jp                  |<   tW        jr                  |      cddd       cddd       cddd       S c c}}w c c}w # 1 sw Y   nxY wddd       n# 1 sw Y   nxY wddd       y# 1 sw Y   yxY w)z%Generate schema for a Pydantic model.NF)checkr   js_functionsextra_fields_behaviorallowr   r   __annotations____pydantic_extra__T)is_argumentis_classzEThe type annotation for `__pydantic_extra__` must be `Dict[str, ...]`requiredr9   r   r   inner__pydantic_custom_init____pydantic_post_init__)custom_initr   	post_initconfigr   r3  )computed_fieldsextras_schema
model_nameouter):r   get_schema_or_refr   __pydantic_decorators__rS  r   r   field_validatorsr0  field_serializers
validatorskeysr?   model_configcore_configrB   r	   r   model_validatorsr   r   objectr   r  strr>   eval_type_backport_make_forward_refr   r*   r   r   r3    _get_args_resolving_forward_refsr   r  r   r   r   r   __pydantic_root_model___common_field_schemaapply_model_validatorsr#   model_schemamodel_fields_schemaitems_generate_md_field_schema_computed_field_schemar   r   root_validatorsrE   r^   _apply_model_serializersmodel_serializersr,  r-  )r   r   	model_refmaybe_schemarx   r   rS  r   r^  r3  r_  rT  candidate_clsextras_annotationr   extra_items_type
root_fieldr   rh  kvdfields_schemanew_inner_schemar   s                            r|   _model_schemazGenerateSchema._model_schema  s   YY((- \	J1J)\'#\	J \	J %%F44J(88O(//66800779))002
 :&++-9/"6"6"89 +3+;+;5IN(44S9K*AY_b9c8deH)::AAC M677B{{1~,,,{{2&000%([["%5 "M(/?PRT(U(Y(YZnpt(u%(4%&7=0=0P0P - ? ?@Q_dos t $ 5 51- ((9:dD\1"? g#  ,0+P+P-%) ,Q , ,( ,36,0,@,@AQ,RM!'"* ++00@ .J$B]B]BbBbcfBg .J44..!%!:!:66&>S]!^J#-h#7L#9,HXZa#bL#.#;#;$$+C1KT$R#'")#/G"N*%!)	$L =H<[<[Y_YeYeYghQUQRTUD::1aLLh &5%;%;%=) ! !77:;W;WX) '4#&<<=M $4M:C]C]CdCdCfhl#mL'CLRoRq'r$'3'7#9,HXZa#bL#.#;#;$$+C1KT$R#(")#/G"N*%!)	$L 66|ZEaEaEhEhEjk/8H'R39		%%i0">>yI].J .J .J]\	J \	J@ i)'.J .J .J .J .J]\	J \	J \	Jst   R(E2R( BR()/R(R4BQ>Q3*Q>?#Q9"C5Q>	R 	R(3Q>>RR
	R(R	R((R1c                    dd}|d   dk(  rB| j                   j                  j                  |d   D ci c]  } ||      | c}       |d   }|S c c}w )zuUnpack all 'definitions' schemas into `GenerateSchema.defs.definitions`
        and return the inner schema.
        c                    | d   S )Nr   r   )ss    r|   rF   z1GenerateSchema._unpack_refs_defs.<locals>.get_refg  s    U8Or~   r   r,  r   )r~  r!   r   ra  )r   r,  update)r   r   rF   r~  s       r|   _unpack_refs_defsz GenerateSchema._unpack_refs_defsb  sZ    
	 &>]*II!!((AV)WA'!*a-)WXH%F *Xs   Ac                   t        |      r| j                  j                         }| j                  j	                  |      5 \  }}||cddd       S 	 ddd       ||u rd}nd}t        |dd      x}Tt        t        j                  |      j                        dk(  r	 ||      }n ||t        | j                  | |            }nt        |dd      x}|j                  dd      |k(  r|}n\t        |d	d      x}	Lt        d
t               t        j                   |	       D 
cg c]  }
t        j                   |
       c}
      }ny| j#                  |      }t%        |      r|d   j'                  dd      }|r||d<   nt)        |      }|r.|| j                  j*                  |<   t        j,                  |      S |S # 1 sw Y   oxY wc c}
w )a0  Try to generate schema from either the `__get_pydantic_core_schema__` function or
        `__pydantic_core_schema__` property.

        Note: `__get_pydantic_core_schema__` takes priority so it can
        decide whether to use a `__pydantic_core_schema__` attribute, or generate a fresh schema.
        Nunpackzto-def__get_pydantic_core_schema__r9   )ref_mode__pydantic_core_schema__r   __get_validators__zc`__get_validators__` is deprecated and will be removed, use `__get_pydantic_core_schema__` instead.r   r   )rb   r   r   r   rW  r   lenr   r   
parametersr`   r:  r    r8   r#   chain_schema"with_info_plain_validator_functionr  rH   r   rF   r,  r-  )r   r   source_rq  r  
get_schemar   existing_schemar[  rw  r   s               r|   r9  z-GenerateSchema._generate_schema_from_propertyo  s    ''++-CYY((- 	$1B!\'#	$ 	$'	$ &=HH "#'EtLLJY7$$Z0;;<A#F+#89T9TVZemn ").H$!OOo\apatat4b
b %F#C)=tDDjQu) !--jtjv.wef{/]/]^_/`.wxF ''/(0"&&ud3C #u&/C)/DII!!#&::3??_	$ 	$: /xs   G %G G
c                .   	 t        j                  || j                        }t        |t              rt	        |j                  d|       | j                  rt        || j                        }|S # t        $ r}t	        j
                  |      |d }~ww xY w)N)globalnsz%Unable to evaluate forward reference )r>   rb  r   	NameErrorr4   from_name_errorr  r   __forward_arg__r   r_   )r   r   es      r|   _resolve_forward_refz#GenerateSchema._resolve_forward_ref  s    	H223AVAVWC
 c:&-c.A.AEjknjoCpqqT%7%78C
  	H-==a@aG	Hs   !A0 0	B9BBc                     y r   r   )r   r   rL  s      r|   rd  z/GenerateSchema._get_args_resolving_forward_refs      r~   c                     y r   r   r  s     r|   rd  z/GenerateSchema._get_args_resolving_forward_refs  r  r~   c           	         t        |      }|r<t        |D cg c]%  }t        |t              r| j	                  |      n|' c}      }|S |rt        d| d      |S c c}w )Nz	Expected z+ to have generic parameters but it had none)r)   r   r  r   r  r   )r   r   rL  argsr   s        r|   rd  z/GenerateSchema._get_args_resolving_forward_refs  sk    }dhi_`*Q
:S$33A6YZZijD  iu,WXYY js   *Ac                >    | j                  |      }|st        S |d   S )Nr   )rd  r   )r   r   r  s      r|   _get_first_arg_or_anyz$GenerateSchema._get_first_arg_or_any  s#    44S9JAwr~   c                    | j                  |      }|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   r9   )rd  r   r  r*   r   )r   r   r  origins       r|   _get_first_two_args_or_anyz)GenerateSchema._get_first_two_args_or_any  s[    44S9:t9q=_F>vhgNOOAwQr~   c                (   t        |t              r| j                  |      S t        |t              r|S t        |t              rt        |      }t        |t
              r | j                  | j                  |            S ddlm	} t        ||      r6| j                  j                  |      5  | j                  |      cd d d        S t        |t              r t        j                   |j"                        S | j%                  |      S # 1 sw Y   JxY w)Nr,   rf   )
schema_ref)r  _AnnotatedType_annotated_schemar   ra  r   r  r  r   rg   rc   r   r   r{  r[   r#   r-  type_ref
match_type)r   r   rg   s      r|   r:  z%GenerateSchema._generate_schema_inner  s    c>*))#..c4 Jc3S/Cc:&''(A(A#(FGG$c9-&&++C0 /))#./ / c/0::cllSSs##/ /s   ,DDc                   |t         u r| j                         S |t        u rt        j                         S |t
        u rt        j                         S |t        u rt        j                         S |t        u rt        j                         S |t        u s|t        u rt        j                         S ||t        j                  u rt        j                          S |t"        v r| j%                  |      S |t&        v r!| j)                  || j+                  |            S |t,        v r!| j/                  || j+                  |            S |t0        v r!| j3                  || j+                  |            S |t4        v r" | j6                  |g| j9                  |       S t;        |t<              r| j?                  |      S |t@        k(  r| jC                         S t        jD                  |      rt        jF                         S t        jH                  |      r| jK                  |      S tM        |      r| jO                  |d      S t        jP                  |      r| jS                  |d      S t        jT                  |      r| jW                  |jX                        S |tZ        j\                  k(  r| j_                  |      S |t`        jb                  jd                  u s|tf        jd                  u r| ji                         S t;        |tf        jj                        r| jm                  |      S to        |      r<|tp        u rt        j                         S | jW                  | j+                  |            S t;        |tr        tt        tv        tx        f      r| j{                  |      S t}        j~                  |      r3t        |t              r#ddlBmC}  ||| j                  j                        S t        j                  |      r| j                  |d      S | j                  |d      }||\  }}| j                  ||      S t        |      }|| j                  ||      S | j                  r| j                  |      S | j                  |      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.
        Nr9   )get_enum_core_schemar   )Ora  r  bytesr#   bytes_schemaint
int_schemafloatfloat_schemaboolbool_schemar   r`  r   r>   NoneTypenone_schemarq   _tuple_schemarr   r  r  rs   r  rt   r  ru   r  r  r  r'   _type_alias_type_schemar   _type_schemais_callable_typecallable_schemais_literal_type_literal_schemar+   _typed_dict_schemais_namedtuple_namedtuple_schemais_new_typer  __supertype__rePattern_pattern_schemacollectionsabcHashabletyping_hashable_schemar   _unsubstituted_typevar_schemara   r   r   r   r   r	   _callable_schemar   isclassr   r   _std_types_schemar  r   config_dictis_dataclass_dataclass_schema0_get_prepare_pydantic_annotations_for_known_type_apply_annotationsr*   _match_generic_typer   r  r  )r   r   r  ressource_typer   r  s          r|   r  zGenerateSchema.match_type  s    #:??$$E\++--CZ))++E\++--D[**,,CZ3&=))++[C=#9#99**,,K%%c**J$$S$*D*DS*IJJI##C)C)CC)HII$$))#t/I/I#/NOOJ$4$$SP4+J+J3+OPP]+//44D[$$&&++C0..00**3/'',,#**355((-**355&&s+''(9(9::BJJ'',,KOO,,,v0F((**V^^,55c::e|"--//''**3/  lJ
GLM((--__S!jd&;?'T-A-A-M-MNN%%c*))#t44CCCL?'*$K**;DDC++C88  ..s33((--r~   c                f   t        |t              r| j                  |      S t        j                  |      r| j                  ||      S t        j                  |      r| j                  ||      S | j                  ||      }||S t        j                  |      r| j                  |      S |t        v r| j                  |      S |t        v r!| j                  || j                  |            S |t         v r!| j#                  || j                  |            S |t$        v r!| j'                  || j                  |            S |t(        v r" | j*                  |g| j-                  |       S t/        |      r| j1                  ||      S |t2        j4                  t6        fv r| j9                  |      S |t2        j:                  t<        j>                  j:                  hv r| jA                  |      S |t2        jB                  t<        j>                  jB                  t2        jD                  t<        j>                  jD                  hv r| jG                  |      S |tH        jJ                  t2        jJ                  fv r| jM                  |      S | jN                  r| jQ                  |      S | jS                  |      S r   )*r  r'   r  r>   r  r  r  r  r9  origin_is_union_union_schemarq   r  rr   r  r  rs   r  rt   r  ru   r  r  r+   r  r  r   r   _subclass_schemaSequencer  r  _sequence_schemar   	Generator_iterable_schemar  r  r  r   r  r  )r   r   r  r>  s       r|   r  z"GenerateSchema._match_generic_typeN  sR   fm,//44 %%f-))#v66&&v.**377;;FCH$  ((0%%c**{"%%c**z!$$S$*D*DS*IJJy ##C)C)CC)HII''))#t/I/I#/NOOz!$4$$SP4+J+J3+OPP&!**377T**((--)A)ABB((--)A)A6CSCSU`UdUdUnUnoo((--

FNN33'',,  ..v66((--r~   rK  c          	         | j                  |||      }t        j                  |d   |j                         sdn||d   |d   |d   |d         S )zAPrepare a TypedDictField to represent a model or typeddict field.r   Fserialization_excludevalidation_aliasserialization_aliasr3  )rL  r  r  r  r3  )rf  r#   typed_dict_fieldis_required)r   name
field_infor   rL  common_fields         r|   _generate_td_field_schemaz(GenerateSchema._generate_td_field_schemaz  sf     00z:N++"","8"8":U"./F"G)*<= ,-B C!*-
 	
r~   c           	         | j                  |||      }t        j                  |d   |d   |d   |d   |d   |d         S )z0Prepare a ModelField to represent a model field.r   r  r  r  frozenr3  r  r  r  r  r3  )rf  r#   model_fieldr   r  r  r   r  s        r|   rk  z(GenerateSchema._generate_md_field_schema  s^     00z:N&&""./F"G)*<= ,-B C)!*-
 	
r~   c                    | j                  |||      }t        j                  ||d   |j                  |j                  xs d|j
                  rdnd|d   |d   |d   |d   |d   	
      S )
zJPrepare a DataclassField to represent the parameter/field, of a dataclass.r   NFr  r  r  r  r3  )init	init_onlykw_onlyr  r  r  r  r3  )rf  r#   dataclass_fieldr  init_varr  r  s        r|   _generate_dc_field_schemaz(GenerateSchema._generate_dc_field_schema  s     00z:N**" ))1T&..DE"./F"G)*<= ,-B C)!*-
 	
r~   c                   |j                   4|j                   dk  s%|j                  |j                  |j                  d\  }}}t	        | t
              r| j                  |      \  }}}nCt	        | t              r3 | |      }t	        |t              st        d|  d|j                         |j                   |j                   dk  rd|_         |j                   dk(  r)t        ||      |_        t        ||      |_        ||_        |j                  ||_        |j                  t        ||      |_        |j                  t        ||      |_        yyy)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.
        Nr9   NNNalias_generator  must return str, not )alias_priorityaliasr  r  r  r-   generate_aliasesr   ra  r   r   r   )alias_generatorr  r   r  r  r  s         r|   $_apply_alias_generator_to_field_infoz3GenerateSchema._apply_alias_generator_to_field_info  sm    %%-((A-'**2--5;K8E#%8/>:?N?_?_`j?k<')<OX6'
3!%-#&66GG]^c^m^m]n$opp
 ((0J4M4MQR4R,-
) ((A-1DEXZ_1`
..ABRTY.Z
+#(
  '#(
 --51DEXZ_1`
.**2.ABRTY.Z
+ 39 6r~   c                   |j                   |j                   dk  s|j                  d\  }}}t        | t              r| j	                  |      \  }}}nCt        | t
              r3 | |      }t        |t              st        d|  d|j                         |j                   |j                   dk  rd|_         |j                   dk(  rt        ||      |_        yyy)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.
        Nr9   r  r  r  )
r  r  r  r-   r  r   ra  r   r   r   )r  computed_field_infocomputed_field_namer  r  r  s         r|   -_apply_alias_generator_to_computed_field_infoz<GenerateSchema._apply_alias_generator_to_computed_field_info  s    $  ..6"11Q6"((0;K8E#%8/>:?N?_?_`s?t<')<OX6'(;<!%-#&66GG]^c^m^m]n$opp
 #119=P=_=_cd=d56#2
 #11Q6,?@SUZ,[#) 7) 1r~   c                    ddl m}m} ddlm} t        j                  t        t        f      r@ j                  } j                  r[|xs i j                         }|j                   j                  j                         D 	ci c]  \  }}	|j                  |	 c}	}       t        j                   j                  |      }
|
j                  urt        |
t"              s |j$                  |
      }|j                  _        |j&                  j                         D ]0  \  }}	|j&                  vs|j(                  vs$t+        ||	       2 g |j,                  j,                  _        j                  j,                  }}d fd} j.                  j1                  |      5  j2                   j5                  |||      }n j5                  ||      }d d d        t7        |j8                  j;                         |      }t=        |      rd_        |D 	cg c]  }	|	j@                  jB                  du s|	 }}	|D 	cg c]	  }	|	|vs|	 }}	tE        ||      }tG        |t7        ||      |      }tG        |t7        |jH                  j;                         |      |      }jK                         stM        |      } jO                  |t7        |jP                  j;                         |            }jR                  jT                  tW        jX                        xs jX                  dk(  xs d t[        j\                        d}|j                         D 	ci c]  \  }}	|		||	 }}}	j^                  }ta        tc        ||      g	      } jd                  jf                  }| ji                  ||       tk        jl                  ||f      rjl                  jo                         }njl                  }tq        |jr                  rdnd |jt                  jv                  |
      S c c}	}w # 1 sw Y   axY wc c}	w c c}	w c c}	}w )Nr,   )AliasChoices	AliasPathre   c                @    j                  | j                        } | S r   )r"  r!  )r   r  r   s    r|   set_discriminatorz>GenerateSchema._common_field_schema.<locals>.set_discriminator1  s     77
@X@XYFMr~   )transform_inner_schemaT )r   r   
deprecatedexamplesjs_annotation_functionsr  r   r!   r   r!   )<r  r  r  rx   re   r]   
annotationr   ra  r   r   r   r  rj  r   r>   eval_type_lenientr[   from_annotation_attributes_setmetadata_lookupsetattrr3  r   r   r!  r  r   r[  r0  $_validators_require_validate_defaultvalidate_defaultry   	each_itemr   r   rY  r  wrap_default_apply_field_serializersrZ  r   r   r  r  r$   r  json_schema_extrarB   get_json_schema_update_funcr   r  r  r  r  convert_to_aliases_common_fieldexcluder  r  )r   r  r  r   r  r  re   r   rv  rw  	evaluatednew_field_infor  r   r  r   this_field_validatorsr   json_schema_updatesr  r3  r  r  s   ` `                    r|   rf  z#GenerateSchema._common_field_schema  s    	/&
 5 5
C7HI"33O!!#2#8b">">"@&&$BTBTBZBZB\']$!Q

A']^%77
8M8M_I
 5 55>RS\^r>s!:!:!:9!E(6(A(A
% +::@@B 2DAq
 
 : ::q
HbHb?b
Aq12 'W(?(?&V*BUBU&V
##-#8#8*:M:M[	 ""''- 	''300kbs0t00		 !EZEZEZEaEaEcei j/0EF*.J'+@]aAFFDTDTX\D\]],A cqQNbEb c c+F4H$O!&*NOdfj*kmqr!89T9T9[9[9]_cdfj
 %%'!*f5F..89U9U9\9\9^`de
  %%%11z445\9N9NRT9T\X\*:+>+>?	
 1D0I0I0K]1q}q!t]]&88&%@ATVg%h$i
 ..>>&55ozSWXj11L)3LM)::MMO)::*4*<*<$$- * > >$$
 	
e (^2	 	   ^ c. ^s6   P9
,4P?"Q Q
	QQ&
Q1Q?Q	c                   | j                  |d      }g }d}|D ]9  }||t        j                  u rd}|j                  | j	                  |             ; t        |      dk(  r|d   }ntg }|D ]X  }|j                  di       j                  t        j                        }	|	|j                  ||	f       H|j                  |       Z t        j                  |      }|rt        j                  |      }|S )zGenerate schema for a Union.TrK  Fr9   r   r3  )rd  r>   r  r   r  r  r   r:   TAGGED_UNION_TAG_KEYr#   union_schemanullable_schema)
r   
union_typer  choicesr   argr~  choices_with_tagschoicetags
             r|   r  zGenerateSchema._union_schemaw  s    44Z$4O$& 	:C{c]%;%;;t33C89		: w<1
AKM! 5jjR044[5U5UV?%,,fc];%,,V45 (():;A++A.Ar~   c                $   | j                   j                  |      5 \  }}||cd d d        S t        |      xs |}|j                  }t	        |      }| j
                  j                  |      5  t        j                  || j                        }t        ||      }| j                  |      }|d   dk7  sJ ||d<   d d d        | j                   j                  |<   t        j                  |      cd d d        S # 1 sw Y   @xY w# 1 sw Y   y xY w)Nr   r,  r   )r   rW  r*   	__value__r\   r   r   r>   r  r   r_   r  r,  r#   r-  )r   r   r   rq  r  r
  r   r   s           r|   r  z&GenerateSchema._type_alias_type_schema  s    YY((- 	@1D#|'#	@ 	@  _+F))J4S9L,,11&9 $*<<ZI^I^_
*:|D
--j9f~666 #u$ *0DII!!#&::3?!	@ 	@$ $	@ 	@s*   DAD.AC:;5D:D	?DDc                n    t        j                  |      }|s
J d|        t        j                  |      S )zGenerate schema for a Literal.z(literal "expected" cannot be empty, obj=)r>   all_literal_valuesr#   literal_schema)r   literal_typeexpecteds      r|   r  zGenerateSchema._literal_schema  s8     33LARCL>RRx))(33r~   c                \   ddl m} | j                  j                  |      5  | j                  j                  |      5 \  }}||cddd       cddd       S t        |      }||}t        s%t        |      j                  dk(  rt        dd      	 t        |d      }| j                  j                  |      5  | j                  j                  |      5  | j                  j!                  |      }| j"                  } |j$                  }	i }
t'        j(                  |      }| j                  j*                  rt-        |d	
      }nd}t/        || j0                  d	      j3                         D ]  \  }}t5        ||      }||	v }t7        |      t8        j:                  k(  rd	}| j=                  |d	      d   }n4t7        |      t8        j>                  k(  rd}| j=                  |d	      d   } |j@                  |      }||jB                  ||v r
||   |_!        | jE                  ||||      |
|<    tG        tI        tJ        |      g|      }tM        jN                  |
|jP                  jS                         D cg c]  }| jU                  ||jV                          c}|||      }| jY                  ||jZ                  jS                               }t]        ||j^                  jS                         d      }|| j                  j`                  |<   tM        jb                  |      cddd       cddd       cddd       cddd       S # t        $ r d}Y w xY wc c}w # 1 sw Y   nxY wddd       n# 1 sw Y   nxY wddd       n# 1 sw Y   nxY wddd       y# 1 sw Y   yxY w)a  Generate schema for a TypedDict.

        It is not possible to track required/optional keys in TypedDict without __required_keys__
        since TypedDict.__new__ erases the base classes (it replaces them with just `dict`)
        and thus we can track usage of total=True/False
        __required_keys__ was added in Python 3.9
        (https://github.com/miss-islington/cpython/blob/1e9939657dd1f8eb9f596f77c1084d2d351172fc/Doc/library/typing.rst?plain=1#L1546-L1548)
        however it is buggy
        (https://github.com/python/typing_extensions/blob/ac52ac5f2cb0e00e7988bae1e2a1b8257ac88d6d/src/typing_extensions.py#L657-L666).

        On 3.11 but < 3.12 TypedDict does not preserve inheritance information.

        Hence to avoid creating validators that do not do what users expect we only
        support typing.TypedDict on Python >= 3.12 or typing_extension.TypedDict on all versions
        r,   r   Nr  zXPlease use `typing_extensions.TypedDict` instead of `typing.TypedDict` on Python < 3.12.ztyped-dict-versionr   __pydantic_config__T)use_inspect)localnsinclude_extrasrK  r   FrB  )rD  typed_dict_cls)rS  r   r3  rR  all)2rx   re   r   r   r   rW  r\   _SUPPORTS_TYPEDDICTr   r   r5   rT   AttributeErrorr   r   r   r^  r   __required_keys__rM   builduse_attribute_docstringsrX   rZ   r   rj  r_   r*   r>   Requiredrd  NotRequiredr  r   r  rB   r	   r   r#   typed_dict_schemarS  r0  rl  rZ  rn  ro  rg  r_  r,  r-  )r   r4  r  re   typed_dict_refrq  r   rR  r^  required_keysrx   r   field_docstringsr   r
  rL  r  r3  rx  	td_schemar   s                        r|   r  z!GenerateSchema._typed_dict_schema  s     	'""''7 V	O9T9TUc9d V	O i
'#V	O V	O V	O 5^DL!!'&4+?+J+Jh+V'n- 
,D^Uj,k ++008 @O$:U:U:Z:Z[i:j @O"22>>~N440>0P0P@B+11.A
''@@'B>_c'd$'+$.K"D,A,ARV/%'*J
 "/z<!HJ)]:H!*-1G1GG#'%)%J%J&%) &K & &
 $J/=3L3LL#(%)%J%J&%) &K & &

 ";!:!::!FJ(4&22:&*::1A*1M
.)-)G)G"J
X *H *F:&5< /")*B"W!Xiw (99 ",!;!;!B!B!D% 33Az7S7ST% '%&		 66y*B^B^BeBeBgh/
8S8S8Z8Z8\^cd8>		%%n5">>~NA@O @O @O-V	O V	O V	O& " n%i@O @O @O @O @O-V	O V	O V	O V	O V	O V	Os   N"N	N":NMN:M8F'M#	=#M BM#	'	M80	N9	N"MNMNM#	#M,(M8/	N8N=N	N"N	N""N+c                @   | j                   j                  |      5  | j                  j                  |      5 \  }}||cddd       cddd       S t	        |      }||}t        |d| j                        }|s|j                  D ci c]	  }|t         }}|r-|j                         D 	ci c]  \  }}	|t        |	|       }}}	t        j                  |j                         D 	cg c]A  \  }}	| j                  ||	|j                  j                  |t         j"                              C c}	}t%        d            }
t        j&                  |
||      cddd       cddd       S c c}w c c}	}w c c}	}w # 1 sw Y   nxY wddd       y# 1 sw Y   yxY w)z!Generate schema for a NamedTuple.NT)r3  r2  )default)js_prefer_positional_arguments)r3  )r   )r   r   r   rW  r\   rZ   r   _fieldsr   rj  r_   r#   arguments_schema_generate_parameter_schema_field_defaultsr   r
   emptyrB   call_schema)r   namedtuple_clsr  namedtuple_refrq  r   r   rv  r   r
  rF  s              r|   r  z!GenerateSchema._namedtuple_schema  s   ""''7  	a9T9TUc9d  	a i
'# 	a  	a  	a 5^DL!!'*GtT=R=R+K /=/E/EF!q#vFF 3>2C2C2E.
J j, GG 
  +;;
 3>2C2C2E	 /
J 33"J8V8V8Z8Z[egpgvgv8w 4  -DQ  **+;^Q_`A 	a  	a  	a G1 	a  	a  	a  	a  	asX   FE?	F7E?	E.E?.E3
%E?*AE90+E?	F.E??F	FFc                   ddl m} |t        j                  u r |j                  |      }n |j
                  ||      }|j                  J d       |j                  |j                  }}| j                  j                  |      5  | j                  ||      }	ddd       |j                         st        |	      }	t        j                  |	      }
|||
d<   |j                  |j                  |
d<   |
S | j                   j"                  }t%        |t&              r"|j                  |j                  |      |
d<   |
S t%        |t(              r ||      |
d<   |
S # 1 sw Y   xY w)zXPrepare a ArgumentsParameter to represent a field in a namedtuple or function signature.r,   r   Nz<field.annotation should not be None when generating a schemamoder  )rx   re   r
   rI  r  from_annotated_attributer
  r3  r   r   r  r  r  r#   arguments_parameterr  r   r  r  r-   r   )r   r  r
  rC  rN  re   rz   r  r   r   parameter_schemar  s               r|   rG  z)GenerateSchema._generate_parameter_schema<  sj    	'ioo%-I--j9E6I66z7KE+k-kk+#(#3#3U^^[""''- 	G,,[+FF	G   "!%0F&::4H'+V$;;"(-W%   #22BBO/>:?T?T?`,;,A,A$,G )   OX6,;D,A )#	G 	Gs   EE$c                ^   t        |      | j                  |      }r|rt        fd|D              }|sG|t        v r*t	        j
                  t	        j                         gd      S t	        j
                  g       S |d   t        u rCt        |      dk(  r*t	        j
                  | j                  |d         gd      S t        d      t        |      dk(  r|d   dk(  rt	        j
                  g       S t	        j
                  |D cg c]  }| j                  |       c}      S c c}w )	zIGenerate schema for a Tuple, e.g. `tuple[int, str]` or `tuple[int, ...]`.c              3  6   K   | ]  }t        |        y wr   )r_   ).0paramr   s     r|   	<genexpr>z/GenerateSchema._tuple_schema.<locals>.<genexpr>f  s     R%==Rs   r   )r   r   r,   z&Variable tuples can only have one typer9   r   )r\   rd  r   rq   r#   tuple_schemar   Ellipsisr  r  
ValueError)r   
tuple_typeparamsrU  r   s       @r|   r  zGenerateSchema._tuple_schema_  s    1<66zBFR6RRF [("//1G1G1I0J`abb #//33BZ8#6{a"//1E1EfQi1P0Qghii !!IJJ[A&)r/ ++B//++V\,]UT-A-A%-H,]^^,]s   D*c                `    t        j                  t        j                  t              dd      S )Nis_typezInput should be a typecustom_error_typecustom_error_message)r#   custom_error_schemar  r   r   s    r|   r  zGenerateSchema._type_schema}  s)    ..**40'!9
 	
r~   c           	         | j                  |d      }t        j                  |D cg c]$  }| j                  t        j
                  |         & c}      S c c}w )z*Generate schema for `Type[Union[X, ...]]`.TrK  )rd  r#   r   r  r  r   )r   r"  r  s      r|   _union_is_subclass_schemaz(GenerateSchema._union_is_subclass_schema  sL    44Z$4O'']a(bUY)=)=fkk$>O)P(bcc(bs   )Ac           	        | j                  |      }|t        k(  r| j                         S t        |t        j
                        r|j                  rbt        j                  t        |j                              r| j                  |j                        S t        j                  |j                        S |j                  rMt        j                  |j                  D cg c]$  }| j                  t        j                   |         & c}      S | j                         S t        j                  t        |            r| j                  |      S t        j                  |      S c c}w )z-Generate schema for a Type, e.g. `Type[int]`.)r  r   r  r  r  r   	__bound__r>   r  r*   rc  r#   is_subclass_schema__constraints__r   r  r   )r   type_
type_paramcs       r|   r  zGenerateSchema._subclass_schema  s   //6
$$&&
FNN3## 00J<P<P1QR99*:N:NOO"55j6J6JKK++"//CMC]C]^aT))&++a.9^  ((****:j+AB11*==11*== _s   )E c                   ddl m} | j                  |      }| j                  |      }t	        j
                  |      }t	        j                  t        j                  d      }|t        k7  r1ddl
m} t	        j                  |t	        j                  ||      g      }t	        j                  ||d      }t	        j                  |||      S )	z5Generate schema for a Sequence, e.g. `Sequence[int]`.r9   )serialize_sequence_via_listr  )cls_repr)sequence_validatorT)r   info_arg)r   python_schemar   )r  rl  r  r  r#   r  r  r  r  r   _validatorsrn  r  no_info_wrap_validator_function#wrap_serializer_function_ser_schemajson_or_python_schema)	r   sequence_typerl  	item_typeitem_type_schemar  rp  rn  r   s	            r|   r  zGenerateSchema._sequence_schema  s    B..}=	//	:!--.>?#66vQ[\7'44 K KL^`k lmM $GG'0@4
 00#=P]
 	
r~   c                l    | j                  |      }t        j                  | j                  |            S )z$Generate a schema for an `Iterable`.)r  r#   generator_schemar  )r   rh  rv  s      r|   r  zGenerateSchema._iterable_schema  s.    ..u5	++D,@,@,KLLr~   c                   ddl m} t        d g      }t        j                  t        d      dt        j                               }|t        j                  k(  s|t        j                  k(  r"t        j                  |j                  ||      S | j                  |d	
      d   }|t        k(  r"t        j                  |j                  ||      S |t        k(  r"t        j                  |j                   ||      S t#        d|d      )Nr9   )rq  c                    dddS )Nstringregex)r   formatr   )_1_2s     r|   <lambda>z0GenerateSchema._pattern_schema.<locals>.<lambda>  s    XahDi r~   rC  patternr   )r   return_schema)r   r3  TrK  r   r  r   )r  rq  rB   r#   r   r   r  r  r  r   no_info_plain_validator_functionpattern_either_validatorrd  ra  pattern_str_validatorr  pattern_bytes_validatorr3   )r   pattern_typerq  r3  serrU  s         r|   r  zGenerateSchema._pattern_schema  s   !&5i4jk>>y!V;CYCYC[
 6>>)\RZZ-G??44CRZ  55 6 
  C<??11x  e^??333QY  02^_k^nno0pqqr~   c                    t        j                  t        j                  t        j                  j
                        dd      S )Nis_hashablezInput should be hashabler^  )r#   ra  r  r  r  r  r   s    r|   r  zGenerateSchema._hashable_schema  s3    ..**;??+C+CD+!;
 	
r~   c                t     j                   j                  |      5   j                  j                  |      5 \  }}||cddd       cddd       S t	        |      }||}t               5 }|j                  D ]B  }t        j                  |      s|j                   j                  j                  |             D t        |j                        D ]O  }t        j                  |      st        |dd      }|j                   j                  j                  |             Q  j                  j                  |      }	 j                    ddlm}
  |
|      rIt%        |j&                        }|rJ|j)                         D ]  }|j+                  | j,                           nt/        | j,                  |      } j                  j0                  j2                  dk(  r7|j5                         D ]$  \  }}|j6                  du st9        d| d	d
       |j:                  j=                  d      xs t?        j@                  |      tC         fd|j5                         D        d       }tE        |d      }tE        |d      }tG        jH                  |jJ                  |jL                  j)                         D cg c]  } jO                  |jP                          c}|      }tS        |jT                  j)                         d      }jV                  j)                         }tY        ||d      }tG        jZ                  ||||t        j\                  |      D cg c]  }|j^                   c}||	      } ja                  |jb                  j)                               }tY        ||d      }| j                  jd                  |<   tG        jf                  |      cddd       cddd       cddd       S c c}w c c}w # 1 sw Y   nxY wJ d       # 1 sw Y   nxY wddd       y# 1 sw Y   yxY w)z Generate schema for a dataclass.Nr0  r,   )is_pydantic_dataclass)r   rF  FzField zd has `init=False` and dataclass has config setting `extra="allow"`. This combination is not allowed.z dataclass-init-false-extra-allowr   rX  c              3  J   K   | ]  \  }}j                  ||        y wr   )r  )rT  rv  rw  r   r   s      r|   rV  z3GenerateSchema._dataclass_schema.<locals>.<genexpr>  s$     a$!QT33Aq*Eas    #c                (    | j                  d      duS )Nr  Fr   )r   s    r|   r  z2GenerateSchema._dataclass_schema.<locals>.<lambda>  s    !%%	"2%"? r~   )key__post_init__	__slots__)rS  collect_init_onlyrM  )rQ  r   rx   slotsrR  rV  Unreachable)4r   r   r   rW  r\   r   r   dataclassesr  enter_contextr   reversedr   r   r   r^  r   r  r   __pydantic_fields__r0  apply_typevars_mapr   rY   r   extrarj  r  r5   __dict__r   rM   r9  sortedhasattrr#   dataclass_args_schemar   rS  rl  rZ  r   rm  r_  rg  dataclass_schemarx   r  rn  ro  r,  r-  )r   	dataclassr  dataclass_refrq  r   dataclass_bases_stackdataclass_baserR  r^  r  rx   rz   r   r  has_post_init	has_slotsrx  args_schemar   r_  	dc_schemar   r   s   `                      @r|   r  z GenerateSchema._dataclass_schema  s    ""''	2 ]	(DII4O4OPY4Z ]	( _
'#]	( ]	( ]	( 5Y?L!"	 NN 5&/&7&7 nN"//?-;;D<W<W<\<\]k<lmn
 '/y/@/@&A eN"//?!(9NPT!U-;;D<V<V<[<[\b<cde
 #22>>yI44?(3%i&C&CDF#%+]]_ ZE!44\4CXCXYZ 6!--%1F --2288GC-3\\^ )
E ::."3"( 5C !D%G#  '//334MNqR`RfRfgpRq
 aRXR^R^R`a? !(	? C#I{;	)??&& ",!;!;!B!B!D% 33Az7S7ST% '4  0Z=W=W=^=^=`bfg#-#>#>#E#E#G 5lDTV]^'88 +%4?4F4Fy4QR5EJJR#&	 66y*B^B^BeBeBgh/8H'R7=		%%m4">>}M]NN NN]	( ]	( ]	(B%" SONN NNd (-'5{]	( ]	( ]	( ]	( ]	(s{   P.P	P.P-%PAP-DPB9P=#O< A?PP2A.P 	P)	P.<
PPPP"	P..P7c                   t        |      }t        j                  |      }t        j                  dt        j
                  dt        j                  di}g }d}d}|j                  j                         D ]  \  }}	|	j                  |j                  u rt        }
n||   }
|j                  |	j                        }|0| j                  ||
|	j                  |      }|j!                  |       w|	j                  t        j"                  k(  r| j%                  |
      }|	j                  t        j&                  k(  sJ |	j                         | j%                  |
      } d}| j(                  }|j*                  r$|j                  d      }|| j%                  |      }t-        j.                  t-        j0                  ||||j2                        ||      S )zsGenerate schema for a Callable.

        TODO support functional validators once we support them in Config
        positional_onlypositional_or_keywordkeyword_onlyNr   )var_args_schemavar_kwargs_schemapopulate_by_name)r  )r   r>   get_function_type_hintsr
   POSITIONAL_ONLYPOSITIONAL_OR_KEYWORDKEYWORD_ONLYr  rj  r
  rI  r   r   kindrG  rC  r   VAR_POSITIONALr  VAR_KEYWORDr   validate_returnr#   rJ  rF  r  )r   functionsig
type_hintsmode_lookuparguments_listr  r  r  pr
  parameter_mode
arg_schemar  r   return_hints                   r|   r  zGenerateSchema._callable_schemaA  s   
 !"::8D
 %%'8++-D""Nr
 @B9=;?~~++- 	EGD!||syy( 
'-
(__QVV4N)!<<T:qyyZhi
%%j19333"&"6"6z"Bvv!6!66>>6$($8$8$D!	E  8<--))$..2K& $ 4 4[ A&&(( /"3!/!@!@	 '	
 		
r~   c                   t        |t        j                        sJ |j                  }|j                  }t        |dd       }|d ut        |      dk7  z   |d uz   dkD  rt        d      || j                  |      S |r"| j                  t        j                  |         S |r@| j                  |      }t        j                  d t        j                               |d<   |S t        j                         S )N__default__r   r9   zZPydantic does not support mixing more than one of TypeVar bounds, constraints and defaultsc                     ||       S r   r   )xhs     r|   r  z>GenerateSchema._unsubstituted_typevar_schema.<locals>.<lambda>  s
    QqT r~   )r   r   )r  r  r   re  rg  r   r  NotImplementedErrorr  r  r   r#   rs  r   )r   typevarrp   constraintsrC  r   s         r|   r  z,GenerateSchema._unsubstituted_typevar_schemav  s    '6>>222!!--'=$7#k"2a"78G4<OPSTT%l  ''00%%fll;&?@@))%0F&1&U&U!+*@*@*B'F?# M))++r~   c                   	 t        j                  j                  j                  j                  | j
                        }|t        u rt        dd      t        || j                        }t        j                  j                  |      _        | j                  |      }| j!                  |t#        |j%                         j&                        d      }| j(                  j*                  }|(| j-                  |j                  j&                         dfd}t/        |g	      }t1        j2                  j&                  |j                  j4                  |
      S # t        $ r}t        j                  |      |d }~ww xY w)NzComputed 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_typeTcomputed_field)r  r  r  c                    ||       }d|d<   j                   j                  }|||d<   j                   j                  }|||d<   j                   j                  sj                   j                  dk(  rd|d<   j                   j                  }|t        |      |d<   j                   j                  }|t        ||       |S )NTreadOnlyr   r   r  r  r  )ry   r   r   r  r  r$   r  add_json_schema_extra)r   r   r   r   r   r  r  rx  s          r|   set_computed_field_metadatazJGenerateSchema._computed_field_schema.<locals>.set_computed_field_metadata  s    !&/K&*K
#FFLLE ',G$&&,,K&-8M*vv  AFF$5$5$;,0L)vvH#*<X*FJ' ! 8 8 ,%k3DEr~   r  )r  r  r3  )r   rC   r   r/   r   r6   )r;   get_function_return_typefuncry   r  r   r  r4   r  r"   r5   r_   r   r  replacer  r  r   r0  r   r   r  r  rB   r#   r  r  )	r   rx  rZ  r  r  return_type_schemar  r  r3  s	    `       r|   rl  z%GenerateSchema._computed_field_schema  sk   
	H%>>qvvqvvGYGY[_[p[pqK ++#d5  $K1C1CD $$QVVE!11+>!::01B1I1I1KQ^^\ ; 
 ..>>&>> /QVVabaoao ? 	4 '@[?\]))NN*<AFFLL[c
 	
m  	H-==a@aG	Hs   ?E$ $	F-FFc                    ddl m} | j                  |d      ^}}| j                  ||      }|D ]  }t	        ||      st        ||      } |S )zdGenerate schema for an Annotated type, e.g. `Annotated[int, Field(...)]` or `Annotated[int, Gt(0)]`.r,   r   TrK  )rx   re   rd  r  r  r  )r   annotated_typere   r  r   r   r
  s          r|   r  z GenerateSchema._annotated_schema  sh    &$($I$I %J %
!k ((kB & 	:J*i0%j&9	: r~   c                    ddl m} 	 t        |       |D ]&  } |||| j                  j
                        }|$|c S  y # t        $ r Y y w xY w)Nr9   )PREPARE_METHODS)r  r  hashr   r   r  )r   r   r   r  genr  s         r|   r  z?GenerateSchema._get_prepare_pydantic_annotations_for_known_type  sa     	7	I
 # 	Cc;(<(<(H(HIC
	
   		s   ? 	A
Ac                    | S r   r   )r  s    r|   r  zGenerateSchema.<lambda>  s    q r~   c                    t        t        j                  |            } j                  |t	        |            }||\  }}g }d fd}t        |       }|D ]  }| j                  |||      }  ||      }	|r6t        |	      j                  }
|
j                  dg       j                  |       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).
        c                    j                  | |       }|j                  |       }n|}t        | |      }|4t        |j                  j
                        }|j                  ||        |      S r   )r9  r:  r;  r<  r   r,  r7  )r   r>  r   r?  r5  r   r  s        r|   inner_handlerz8GenerateSchema._apply_annotations.<locals>.inner_handler  s{     ??SIM$44S9&#DS&#Q #/"9&$))BWBW"X".))/;OP)&11r~    pydantic_js_annotation_functionsr   r   r   r!   )r/  r=   expand_grouped_metadatar  r   r`   _get_wrapped_inner_schemarA   r3  r4  extendr   r   r   )r   r  r   r  r  r  r  get_inner_schemar
  r   r3  s   `  `       r|   r  z!GenerateSchema._apply_annotations  s     4LL[YZCCKQVWbQcd?'*$KHJ(	2 8tL% 	J!#== *.N 	 "+.+*62;;H BBGNNOop;D<P<P<^<^`kmsttr~   c                   ddl m} t        ||      rM|j                  D ]  }| j	                  ||      } |j
                  | j                  ||j
                        }|S |d   dk(  r?|j                  dt        j                               }| j	                  ||      }|r||d<   |S |}|j                  dd       }|X|j                         }|dt        |       z   }|| j                  j                  v r| j                  j                  |   S ||d<   n|d   dk(  r|d	   }|| j                  j                  v rn| j                  j                  |   j                         }|dt        |       z   }|| j                  j                  v r| j                  j                  |   S ||d<   t        j                  ||j                               }	|	|	S |S )
Nr,   r   r   r   r   r   r  definition-refr  )rx   re   r  r3  _apply_single_annotationr!  r"  r   r#   r   r   reprr   r,  r=   apply_known_metadata)
r   r   r3  re   field_metadatarM  r   r   new_refmaybe_updated_schemas
             r|   r  z'GenerateSchema._apply_single_annotation"  s   &h	*"*"3"3 O66v~NO %%1;;FHDZDZ[M&>Z'JJx)?)?)ABE11%BE#(x M jj%?[[]FaX/00G$))///yy,,W55#F5MF^//&Cdii+++..s388:!DN#3 44dii333990099 'u8MMhX^XcXcXef+''r~   c                   ddl m} t        ||      r|j                  D ]  }| j	                  ||      } i }|j
                  r|j
                  |d<   |j                  r|j                  |d<   |j                  rt        |j                        |d<   |j                  }|s|r>t        |      j                  j                  dg       j                  t        ||             |S )Nr,   r   r   r   r  r  )rx   re   r  r3  $_apply_single_annotation_json_schemar   r   r  r$   r  rA   r4  r   r  )r   r   r3  re   r  json_schema_updater  s          r|   r  z3GenerateSchema._apply_single_annotation_json_schemaL  s     	'h	*"*"3"3 [BB6>Z[24~~.6nn"7+##4<4H4H"=1  1CHDUDU1V":. ( : :!%6#F+44??@bdfgnn/0BDUV r~   c                \     t        dd       xs d d fd}t        |       S )Nr  c                     ||       S r   r   )r  r   s     r|   r  z:GenerateSchema._get_wrapped_inner_schema.<locals>.<lambda>j  s
    GFO r~   c                     |       }j                  |      }j                  |      }t        |      }|j                  |       |S r   )r  r  r;  r   )r  r   r?  r
  r  metadata_get_schemar  r   s      r|   new_handlerz=GenerateSchema._get_wrapped_inner_schema.<locals>.new_handlerm  s\    (1ABF226:FF>>vzRF#DZQW#X #/0778LMMr~   )r  r   r   core_schema.CoreSchema)r   r`   )r   r  r
  r  r  r  s   ```` @r|   r  z(GenerateSchema._get_wrapped_inner_schemac  s9     6=ZIgim5n 6
3 		 	 ,K>>r~   c                   |rt        |      }|d   dk(  r|d   }| j                  ||      |d<   |S t        j                  d|j	                  dd            }|t        j                  |      }|d   }t        |j                  |j                  j                  |      \  }}	 t        j                  |j                  |j                  j                  | j                        }	|	t$        u rd}n| j'                  |	      }|j                  j                  d	k(  r=t        j(                  |j                  ||||j                  j*                  
      |d<   |S |j                  j                  dk(  sJ t        j,                  |j                  ||||j                  j*                  
      |d<   |S # t        $ r}
t!        j"                  |
      |
d}
~
ww xY w)z$Apply field serializers to a schema.r   r,  r   zstr|Noner   Nr   r  wrap)is_field_serializerro  r  r   r   plain)r   r  r  r   r   r#   r-  rU   r  ry   rN  r;   r  r  r   r  r4   r  r"   r  rs  r   r   )r   r   serializersr  r   r   
serializerr  ro  r  r  r  s               r|   r  z'GenerateSchema._apply_field_serializersy  s    &\Ff~.%h/#'#@#@{#[x kk*fjj.EF?(DDSIF %RJ,D!5!5n-)L)BBOOZ__%@%@$BWBW // $ $ 4 4[ A##v-*5*Y*YOO(;%"/(oo77+'   "++w666*5*Z*ZOO(;%"/(oo77+' 3  L1AA!D!KLs   %?F. .	G7GGc                   |j                  dd      }|r!t        |      d   }t        |j                  |j                  j
                        }	 t        j                  |j                  |j                  j                  | j                        }|t        u rd}n| j                  |      }|j                  j
                  dk(  r8t        j                   |j                  |||j                  j"                        }	n7t        j$                  |j                  |||j                  j"                        }	|	|d<   |r||d<   |S # t        $ r}t        j                  |      |d}~ww xY w)z$Apply model serializers to a schema.r   Nr   r  )ro  r  r   r   )r   r/  rV   r  ry   rN  r;   r  r  r   r  r4   r  r"   r  r#   rs  r   r   )
r   r   r  r   r  ro  r  r  r  
ser_schemas
             r|   rn  z'GenerateSchema._apply_model_serializers  s=    !**UD1k*2.J/
AUAUVHL)BBOOZ__%@%@$BWBW
 // $ $ 4 4[ A##v-4?4c4cOO%"/(oo77	5
 )MMOO%"/(oo77	
 '1F?#F5M3  L1AA!D!KLs   ?E   	E$	EE$r   )r   r?   r   dict[str, Any] | Noner   dict[Any, Any] | Noner   None)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!  zstr | Discriminator | Noner   r!   r	  )r5  r!   r6  Callable[..., Any]r   r  )T)r   r   r=  r  r   r  )r   ztype[BaseModel]r   r  )r   r   r  r   r   zcore_schema.CoreSchema | None)r   r   r   r   )r   r   rL  zLiteral[True]r   tuple[Any, ...])r   r   r   tuple[Any, ...] | None)F)r   r   rL  r  r   r  )r   r   r   ztuple[Any, Any])r   r   r   r  )r   r   r  r   r   r!   )
r  ra  r  re   r   rM   rL  r  r   zcore_schema.TypedDictField)r  ra  r  re   r   rM   r   zcore_schema.ModelField)r  ra  r  re   r   rM   r   zcore_schema.DataclassField)r  %Callable[[str], str] | AliasGeneratorr  re   r   ra  r   r  )r  r  r  rd   r  ra  )r  ra  r  re   r   rM   r   _CommonField)r"  r   r   r  )r-  r   r   r!   )r4  r   r  r   r   r  )rK  r   r  r   r   r  )
r  ra  r
  r   rC  r   rN  zJLiteral['positional_only', 'positional_or_keyword', 'keyword_only'] | Noner   zcore_schema.ArgumentsParameter)rZ  r   r   r  )r   r  )rh  r   r   r  )ru  r   r   r  )rh  r   r   zcore_schema.GeneratorSchema)r  r   r   r  )r  ztype[StandardDataclass]r  ztype[StandardDataclass] | Noner   r  )r  r  r   zcore_schema.CallSchema)r  ztyping.TypeVarr   r  )rx  zDecorator[ComputedFieldInfo]rZ  z2dict[str, Decorator[FieldSerializerDecoratorInfo]]r   zcore_schema.ComputedField)r  r   r   r  )r   r   r   r  r   ztuple[Any, list[Any]] | None)r  r   r   z	list[Any]r  z"Callable[[CoreSchema], CoreSchema]r   r!   )r   r  r3  r   r   r  )r  r.   r
  r   r  zlist[GetJsonSchemaFunction]r   r`   )r   r  r  z-list[Decorator[FieldSerializerDecoratorInfo]]r  r  r   r  )r   r  r  z1Iterable[Decorator[ModelSerializerDecoratorInfo]]r   r  )Ir   r   r   r   r  r   classmethodr   r   r   r   r   r   r  r  r  r  r  r  r  r"  	Exceptionr%  r)  r'  r7  r  r{  r  r9  r  r   rd  r  r  r:  r  r  r  rk  r  staticmethodr  r  rf  r  r  r  r  r  r
   rI  rG  r  r  rc  r  r  r  r  r  r  r  r  rl  r  r  r  r  r  r  r  rn  r   r~   r|   r   r   3  s   fI /3	#%# /# ,	#
 
# 0  3 *	
 ,  
 " / / 0 0 
 
 < <(IkHN
2	
 1K	$9 	
	6 -1-- &*- 
 	-^^J@9v,     $2T.l*.d 

 
 #	
 
 
$
&

 
 #	

 
 
"

 
 #	

 
$
* /[>/[LU/[cf/[	/[ /[b (\>(\.(\ !(\ (\Te
e
%.e
<Je
	e
N6@@ 
@,4hOT"aP ![_! !  !  	! 
 Y!  
(! F_<
d
>*
.Mr8
a(0a(:Xa(	a(F3
j,2?
'?
 N?
 
#	?
B %4	%. FQ	-u-u -u !C	-u
 
-u^(T,8;	.?.? ? +F	?
 
&?4  %	5&5 C5 	5
 
 5n&,&;l&	&r~   r   c                .    t        j                  | |      S r   )r#   !no_info_before_validator_functionfr   r  s      r|   r  r    s    0]0]^_ag0h r~   c                .    t        j                  | |      S r   )r#    no_info_after_validator_functionr  s      r|   r  r    s    {/[/[\]_e/f r~   c                ,    t        j                  |       S r   )r#   r  )r  r  r  s      r|   r  r    s    K,X,XYZ,[ r~   c                .    t        j                  | |      S r   )r#   rr  r  s      r|   r  r    s    k.Y.YZ[]c.d r~   c                2    t        j                  | ||      S N)r   )r#   #with_info_before_validator_functionr  r   r   s      r|   r  r    s    ;;j;j	6j< r~   c                2    t        j                  | ||      S r  )r#   "with_info_after_validator_functionr  s      r|   r  r    s    +:h:h	6j; r~   c                0    t        j                  | |      S r  )r#   r  )r  r  r   s      r|   r  r    s    [5c5c	j6 r~   c                2    t        j                  | ||      S r  )r#   !with_info_wrap_validator_functionr  s      r|   r  r    s    9f9f	6j: r~   ))beforeno-info)afterr  )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_MATCHc                    |D ]b  }t        |j                  |j                  j                        }|rdnd}t	        |j                  j                  |f   |j                  | |      } d | 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  )rW   r  ry   rN  r  )r   r[  r   	validatorro  val_types         r|   r   r     sg    "   i	$Y^^Y^^5H5HI"*;	#Y^^%8%8($CDY^^U[]gh	i
 Mr~   c                B    | D ]  }|j                   j                  s y y)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)ry   always)r[  r!  s     r|   r  r  	  s(       	>>   r~   c                \   | j                  dd      }|D ]  }|dk(  r|j                  j                  dk7  r#|dk(  r|j                  j                  dk(  rBt        |j                  |j                  j                        }|j                  j                  dk(  rF|r"t        j                  |j                  |       } t        j                  |j                  |       } |j                  j                  dk(  rH|r#t        j                  |j                  |       } 	t        j                  |j                  |       } ,|j                  j                  dk(  sJ |r#t        j                  |j                  |       } lt        j                  |j                  |       }  |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   NrM  r  rV  r  )r  r   r  )r   ry   rN  rW   r  r#   r  rr  r  r  r  r  )r   r[  rN  r   r!  ro  s         r|   rg  rg    sc   & jj-C n	7?y~~22h>7?y~~22h>$Y^^Y^^5H5HI>>&($FFPYP^P^gmn$DDinnekl^^  H,$HHR[R`R`iop$FFPYP^P^gmn>>&&'111$GGQZQ_Q_hno$EEy~~flm+n, uMr~   c                    | j                   r,t        j                  || j                   | j                        S | j                  t
        ur,t        j                  || j                  | j                        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_factoryr  )rC  r  )r'  r#   with_default_schemar  rC  r"   )r  r   s     r|   r  r  H  sr     !!..J$>$>Q[QlQl
 	
 
		#4	4..J..A\A\
 	
 r~   c                x   t        | dd      }t        | d      rYddlm} |duxr% |j                  j
                  |t        |dd      fv}|s&t        | dd      }t        d|rd	| d
nd dd      t        | d      r8t        | t        t        t        df               st        | j                  |      S |y|S )z`Extract `__get_pydantic_json_schema__` from a type, handling the deprecated `__modify_schema__`.__get_pydantic_json_schema__N__modify_schema__r   rf   __func__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   
__origin__placeholder)r   r  pydanticrg   r*  r,  r5   r  r   r%   r  r;  r.  )r   r   js_modify_functionrg   has_custom_v2_modify_js_funccls_names         r|   r;  r;  ^  s     %CTJr&'& d* W66??&0BJPT(UVW 	% ,r:t4H#=Zb{8*TU=Vhj<kkln)  r< BYsMGY=Z8[)\0GG!r~   c                $     	 	 	 	 	 	 d fd}|S )Nc                8    i  ||       }t        |       |S r   )r  )core_schema_or_fieldr   r   r  r  s      r|   json_schema_update_funcz<get_json_schema_update_func.<locals>.json_schema_update_func  s-     N!56M:LMk+<=r~   )r6  rC   r   r/   r   r6   r   )r  r  r7  s   `` r|   r  r  }  s(    /:N	 #"r~   c                    t        |t              r| j                  t        |             y t	        |      r	 ||        y y r   )r  r   r  r$   callable)r   r  s     r|   r  r    s:     #T*-.?@A	#	$+& 
%r~   c                  J    e Zd ZU ded<   ded<   ded<   ded<   ded	<   d
ed<   y)r  r  r   4str | list[str | int] | list[list[str | int]] | Noner  r+  r  bool | Noner  r  zdict[str, Any]r3  N)r   r   r   rG  r   r~   r|   r  r    s&    ""JJ##&&r~   r  )r  r  r  r  r3  c                   | |||||dS )Nr   r  r  r  r  r3  r   r>  s         r|   r  r    s      ,2!6 r~   c                  *    e Zd ZdZddZedd       Zy)r   z*Keeps track of references and definitions.c                0    t               | _        i | _        y r   )r   seenr,  r   s    r|   r   z_Definitions.__init__  s    !e	>@r~   c              #  H  K   t        |      }|| j                  v s|| j                  v r|t        j                  |      f y| j                  j                  |       	 |df | j                  j                  |       y# | j                  j                  |       w xY ww)ao  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:

        - BaseModel
        - Dataclasses
        - TypedDict
        - TypeAliasType
        N)rG   rA  r,  r#   r-  adddiscard)r   r   r   s      r|   rW  z_Definitions.get_schema_or_ref  s     ( 2$))sd&6&66??DEEIIMM#'Dk!		!!#&		!!#&s   AB" B &B"BB"Nr   r  )r   r   r   z3Iterator[tuple[str, None] | tuple[str, CoreSchema]])r   r   r   r   r   r   rW  r   r~   r|   r   r     s    4A ' 'r~   r   c                Z    | d   dk(  r|j                  | d   d       S | d   dk(  r| d   S | S )Nr   r  r  r,  r   r  )r   r,  s     r|   r<  r<    sA    f~))vl3T::	=	(hr~   c                  2    e Zd ZdZddZedd       ZddZy)	r   _stackc                    g | _         y r   rH  r   s    r|   r   z_FieldNameStack.__init__  s	    !#r~   c              #  ~   K   | j                   j                  |       d  | j                   j                          y wr   rI  r   r   )r   r   s     r|   r   z_FieldNameStack.push  s)     :&   ;=c                :    | j                   r| j                   d   S y r   rH  r   s    r|   r   z_FieldNameStack.get      ;;;;r?"r~   NrE  )r   ra  r   Iterator[None])r   r+  r   r   r   r  r   r   r   r   r   r~   r|   r   r     s%    I$  
r~   r   c                  2    e Zd ZdZddZedd       ZddZy)	r   rH  c                    g | _         y r   rH  r   s    r|   r   z_ModelTypeStack.__init__  s	    "$r~   c              #  ~   K   | j                   j                  |       d  | j                   j                          y wr   rL  )r   type_objs     r|   r   z_ModelTypeStack.push  s)     8$rM  c                :    | j                   r| j                   d   S y r   rH  r   s    r|   r   z_ModelTypeStack.get  rO  r~   NrE  )rU  r   r   rP  )r   ztype | NonerQ  r   r~   r|   r   r     s%    I%  
r~   r   )ry   FieldDecoratorInforz   ra  r   r  )r   zIterable[AnyFieldDecorator]rx   zIterable[str]r   r  )r   z+Iterable[Decorator[FieldDecoratorInfoType]]rz   ra  r   z'list[Decorator[FieldDecoratorInfoType]])r   r  r   z'list[Decorator[ValidatorDecoratorInfo]]r   r+  r   r  )r   rC   r   r/   r   r   r   r6   )r   zJsonEncoders | Noner   r   r   r!   r   r!   )r   r   r   r   r   r   )r   r  r[  zIterable[Decorator[RootValidatorDecoratorInfo]] | Iterable[Decorator[ValidatorDecoratorInfo]] | Iterable[Decorator[FieldValidatorDecoratorInfo]]r   r+  r   r  )r[  z+Iterable[Decorator[ValidatorDecoratorInfo]]r   r  )r   r  r[  z0Iterable[Decorator[ModelValidatorDecoratorInfo]]rN  z Literal['inner', 'outer', 'all']r   r  )r  re   r   r  r   r  )r   r   r   r!   r   zGetJsonSchemaFunction | None)r  r6   r  3JsonDict | typing.Callable[[JsonDict], None] | Noner   rk   )r   r6   r  rX  )r   r  r  r;  r  r+  r  r<  r  r<  r3  r   r   r  )r   r!   r,  zdict[str, CoreSchema]r   zCoreSchema | None)r   
__future__r   _annotationscollections.abcr  r  r   r  sysr  r   
contextlibr   r   r   r   enumr   	functoolsr	   r
   r   r   	itertoolsr   operatorr   typesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    pydantic_corer!   r"   r#   r$   typing_extensionsr%   r&   r'   r(   r)   r*   r+   aliasesr-   annotated_handlersr.   r/   rR  r0   r1   r2   errorsr3   r4   r5   r   r6   versionr7   r8   r  r:   r;   r<   r=   r>   _configr?   r@   _core_metadatarA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   _docs_extractionrX   rE  rY   rZ   _forward_refr[   	_genericsr\   r]   r^   r_   _schema_generation_sharedr`   ra   rb   _utilsrc   rx   rd   re   r   rg   rh   r[  ri   _dataclassesrj   rk   version_infor6  r   r  r  rW  ro   AnyFieldDecoratorModifyCoreSchemaWrapHandlerGetCoreSchemaFunctionr   Tuplerq   rG  r/  Listr  MutableSequencerr   r   Set
MutableSetrs   	frozenset	FrozenSetrt   r   MutableMappingru   r}   r   r   r   r   JsonEncodersr   ra  r   r   r   r   r  r   r  rg  r  r;  r  r  r  r  r   r<  r   r   r   r~   r|   <module>r~     su   3 2    	 
   0    8 8   6 6      X X n n n $ K 6 6 b b ) # 0 f f 6 D
 
 
    : L . t t C 4 &5 %0/@&&'1 iS)*13NPllm  !9AST $%)**+-  3  #'B!C[E[E[![\  !&,,/Z /[__-L-LM
J Mfjj+//*D*DE	: E )6+;+;[__=P=PQ * Q[__-K-K[__MdMde
J e
 
*6nDnMPn,n"""A" " 	"J&1EORD DI{*+&,/9CD tCH~t+,. .(%c cT5 if[d   ."7
  2 ,",@, +, 	,^,>
#'
#<o
#
#' '5h'9  NR&*)-" K $	
 '   &$' $'N & r~   