
    Ѯh             	      p   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#l}m~Z~ dd$lSmZmZ dd%lmZ 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
j2                  gZd0ed1<   ee
j:                  ej<                  j>                  gZd0ed2<   ee
jD                  ej<                  jF                  gZd0ed3<   ee
jL                  ej<                  jD                  gZd0ed4<   ee
jF                  ej<                  jR                  ej<                  jP                  gZd0ed5<   	 	 	 	 	 	 d_d6Zd`d7Z	 	 	 	 	 	 dad8Z	 	 	 	 	 	 	 	 dbd9Zdd:	 	 	 	 	 	 	 	 	 dcd;Ze#e)e!   eDf   Z	 	 	 	 	 	 	 	 ddd<Ze+e#ee!f   df   Z G d= d>      Zded?Z G d@ dA      ZdB dC dD dE dF dG dH dI dJZdKedL<   	 	 	 	 	 	 	 	 dfdMZdgdNZ	 	 	 	 	 	 	 	 dhdOZdidPZdjdQZ	 	 	 	 	 	 dkdRZ	 	 	 	 dldSZ G dT dUe8      ZddddddV	 	 	 	 	 	 	 	 	 	 	 	 	 dmdWZ G dX dY      ZdndZZ G d[ d\      Z G d] d^      Zy)oz-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)MockCoreSchema)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      u/home/www/academy-backend.kofcorporation.com/venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py)check_validator_fields_against_field_namer~   r   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.
    rx   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)setrz   ry   check_fieldsr5   cls_refcls_var_name)
decoratorsry   decr{   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~   rz   )validator_functionsr{   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   )titlec                  ddl m} ddlm} ddlm} ddlm}  ||       }|j                  |      }	d|	v r|	d   }
|	j                          d|
ig|	d<   |||	d
<   nd
|	vr|j                  |	d
<   ||u s ||      s ||      rd	n|j                  }|rd|	vrt        j                  |      |	d<   |S t        ||      r5|j                  d   j                   r|j                  d   j                   |	d<   |S )a  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.
        title: The title to set for the model's schema, defaults to the model's name

    Returns:
        JsonSchemaValue: The updated JSON schema.
    r,   is_pydantic_dataclassrg   )	RootModelr9   )is_builtin_dataclassz$refallOfNr   descriptionroot)dataclassesr   mainrh   
root_modelr   _dataclassesr   resolve_ref_schemaclear__name____doc__inspectcleandoc
issubclassmodel_fieldsr   )schema_or_fieldhandlerclsr   r   rh   r   r   json_schemaoriginal_schemaref	docstrings               r}   modify_model_json_schemar      s   $ 4 &2/*K00=O f%%+SM? #( 		'#&<< y(,@,EI^_bIcilititI]/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   4  s     1$1$r   c                     e Zd ZdZdZ	 dI	 	 	 	 	 	 	 dJdZe	 	 	 	 	 	 	 	 	 	 	 	 dKd       ZedLd       Z	edMd       Z
edNd       ZedOd	       ZdPd
ZdQdZdRdZdQdZdQdZdSdZdTdZ	 	 	 	 	 	 dUdZ G d de      ZdVdZdVdZdWdZ	 dX	 	 	 	 	 dYdZdZdZe	 dI	 	 	 	 	 d[d       ZdVdZd\dZd]dZ e!d^d       Z"e!d_d       Z"d`dad Z"d]d!Z#dbd"Z$dcd#Z%dcd$Z&ddd%Z'dd&	 	 	 	 	 	 	 	 	 ded'Z(	 	 	 	 	 	 	 	 dfd(Z)	 	 	 	 	 	 	 	 dgd)Z*e	 	 	 	 	 	 	 	 dhd*       Z+e	 	 	 	 	 	 did+       Z,e	 	 	 	 	 	 	 	 djd,       Z-	 	 	 	 	 	 	 	 dkd-Z.dld.Z/	 	 	 	 dTd/Z0dmd0Z1dnd1Z2dod2Z3e4jj                  df	 	 	 	 	 	 	 	 	 dpd3Z6dqd4Z7drd5Z8dld6Z9dsd7Z:dtd8Z;dud9Z<dvd:Z=drd;Z>	 	 	 	 	 	 dwd<Z?dxd=Z@dyd>ZA	 	 	 	 	 	 dzd?ZBd{d@ZC	 	 	 	 	 	 d|dAZDdB f	 	 	 	 	 	 	 d}dCZEd~dDZF	 	 	 	 	 	 d~dEZG	 	 	 	 	 	 	 	 ddFZH	 d`	 	 	 	 	 	 	 ddGZI	 	 	 	 	 	 ddHZJy)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__I  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_parentW  sI     kk#$8!%:"/(.0
r   c                .    | j                   j                  S r   )r   r   r   s    r}   _config_wrapperzGenerateSchema._config_wrapperi  s    ))...r   c                .    | j                   j                  S r   )r   r   r   s    r}   _types_namespacezGenerateSchema._types_namespacem  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_schemaq  sV    ""33E~  &&''!!II
 	
r   c                .    | j                   j                  S r   )r   arbitrary_types_allowedr   s    r}   _arbitrary_typeszGenerateSchema._arbitrary_types|  s    ##;;;r   c                *    t        j                         S )zGenerate a CoreSchema for `str`)r#   
str_schemar   s    r}   r  zGenerateSchema.str_schema  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_functionr9  r8  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   r2  r=  r   r   r   )r   r   from_dunder_get_core_schemar   from_propertymetadata_js_functionr;  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                	   | 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                  |      }| 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      }|#t1        |t2              r6t5        j6                  t5        j8                  |dd      | j:                        }t=        |      }|t>        t@        fvrtC        d      | jE                  |d      d   }|tF        us| jI                  |      } n | jJ                  jM                  |      5  | jN                  jM                  |      5  | jP                  } |jR                  r]| jU                  d|d   |      }|d   }tW        ||d      }tY        jZ                  ||t/        |dd      dt/        |dd      |||
      }n	tY        j\                  |j_                         D ci c]  \  }}|| ja                  |||       c}}|j                         D cg c]  }| jc                  ||j                          c}||jd                        }tg        ||jh                  j                         d      }tk        |tm                     }||}tW        ||d      }tY        jZ                  ||t/        |dd      dt/        |dd      |||
      }| jo                  ||jp                  j                               }tW        ||d      }|| j                   jr                  |<   tY        jt                  |      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   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   r9  )computed_fieldsextras_schema
model_nameouter);r   get_schema_or_refr   __pydantic_decorators__rY  r   r   field_validatorsr6  field_serializers
validatorskeysr?   model_configcore_config_get_model_title_from_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_serializersr2  r3  )r   r   	model_refmaybe_schemary   r   rY  r   rd  r   r9  rf  rZ  candidate_clsextras_annotationr   extra_items_type
root_fieldr   ro  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55c>JE*AY_bjo9p8qrH)::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B i)'.J .J .J .J .J_]	J ]	J ]	Jst   R;FR;3BR;</R;+R&BRR=R#R5C5R*	R&3	R;RRR&	R;&R/	+R;;Sc                    |y|j                   r|j                   S |j                  }|r5 ||       }t        |t              st	        d| d|j
                         |S y)zfGet the title of a model if `model_title_generator` or `title` are set in the config, else return NoneNzmodel_title_generator  must return str, not )r   model_title_generatorr  rh  r   r   )modelr   r  r   s       r}   re  z+GenerateSchema._get_model_title_from_configm  sq    
 !!''' . D D )%0EeS)"89N8OOefkfufuev wxxLr   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_ref  s    U8Or   r   r2  r   )r  r!   r   rh  )r   r2  update)r   r   rF   r  s       r}   _unpack_refs_defsz GenerateSchema._unpack_refs_defs  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}(t        |t              s|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!        j0                  |      S |S # 1 sw Y   x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   )rc   r   r   r   r]  r   lenr   r   
parametersra   r@  r  r`   r    r8   r#   chain_schema"with_info_plain_validator_functionr  rH   r   rF   r2  r3  )r   r   source_rx  r  
get_schemar   existing_schemara  r~  r   s               r}   r?  z-GenerateSchema._generate_schema_from_property  s    ''++-CYY((- 	$1B!\'#	$ 	$'	$ &=HH "#'EtLLJY7$$Z0;;<A#F+#89T9TVZemn
 !(-G NN_[?##E40C7$F#C)=tDDjQu) !--jtjv.wef{/]/]^_/`.wxF ''/(0"&&ud3C #u&/C)/DII!!#&::3??c	$ 	$> /xs   G5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>   ri  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   rR  s      r}   rk  z/GenerateSchema._get_args_resolving_forward_refs  s    fir   c                     y r   r   r!  s     r}   rk  z/GenerateSchema._get_args_resolving_forward_refs  s    TWr   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   rR  argsr   s        r}   rk  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   )rk  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   )rk  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,   rg   )
schema_ref)r  _AnnotatedType_annotated_schemar   rh  r   r  r  r   rh   rd   r   r   r  r[   r#   r3  type_ref
match_type)r   r   rh   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@        u 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   )Orh  r  bytesr#   bytes_schemaint
int_schemafloatfloat_schemaboolbool_schemar   rg  r   r>   NoneTypenone_schemarr   _tuple_schemars   r  r  rt   r  ru   r  rv   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_schemarb   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  r?  origin_is_union_union_schemarr   r  rs   r  r  rt   r  ru   r  rv   r  r  r+   r  r  r   r   _subclass_schemaSequencer  r  _sequence_schemar   	Generator_iterable_schemar  r  r  r  r  r"  )r   r   r  rD  s       r}   r  z"GenerateSchema._match_generic_typem  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   rQ  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_aliasr9  )rR  r  r  r  r9  )rm  r#   typed_dict_fieldis_required)r   name
field_infor   rR  common_fields         r}   _generate_td_field_schemaz(GenerateSchema._generate_td_field_schema  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  frozenr9  r  r  r  r  r9  )rm  r#   model_fieldr   r  r  r   r  s        r}   rr  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  r9  )init	init_onlykw_onlyr  r  r  r  r9  )rm  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 r  )alias_priorityaliasr  r  r  r-   generate_aliasesr   rh  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   rh  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                    |j                   xs | j                   }|y|j                  < |||      }t        |t              st	        d| d|j
                         ||_        yy)ae  Apply a field_title_generator on a FieldInfo or ComputedFieldInfo instance if appropriate
        Args:
            config_wrapper: The config of the model
            field_info: The FieldInfo or ComputedField instance to which the title_generator is (maybe) applied.
            field_name: The name of the field from which to generate the title.
        Nzfield_title_generator r  )field_title_generatorr   r  rh  r   r   )r   r  r   r  r   s        r}   *_apply_field_title_generator_to_field_infoz9GenerateSchema._apply_field_title_generator_to_field_info/  sw     !+ @ @ hNDhDh (#)*jAEeS)"89N8OOefkfufuev wxx$J $r   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;                         |            } jS                   jT                  |       jV                  jX                  t[        j\                        xs j\                  dk(  xs d t_        j`                        d}|j                         D 	ci c]  \  }}	|		||	 }}}	jb                  }te        tg        ||      g	      } jT                  jh                  }| jk                  ||       tm        jn                  ||f      rjn                  jq                         }njn                  }ts        |jt                  rdnd |jv                  jx                  |
      S c c}	}w # 1 sw Y   ~xY wc c}	w c c}	w c c}	}w )Nr,   )AliasChoices	AliasPathrf   c                @    j                  | j                        } | S r   )r(  r'  )r   r  r   s    r}   set_discriminatorz>GenerateSchema._common_field_schema.<locals>.set_discriminatorf  s     77
@X@XYFMr   )transform_inner_schemaT )r   r   
deprecatedexamplesjs_annotation_functionsr  r   r!   r   r!   )=r  r
  r  ry   rf   r]   
annotationr   rh  r   r   r   r  rq  r   r>   eval_type_lenientr[   from_annotation_attributes_setmetadata_lookupsetattrr9  r   r   r'  r  r   ra  r6  $_validators_require_validate_defaultvalidate_defaultrz   	each_itemr   r   r_  r  wrap_default_apply_field_serializersr`  r  r   r   r   r  r  r$   r  json_schema_extrarB   get_json_schema_update_funcr   r  r  r  convert_to_aliases_common_fieldexcluder  r  )r   r  r  r   r
  r  rf   r   r}  r~  	evaluatednew_field_infor  r   r  r   this_field_validatorsr   json_schema_updatesr!  r9  r   r  s   ` `                    r}   rm  z#GenerateSchema._common_field_schemaE  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
 	778L8LjZ^_  %%%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*<*<$$- * > >$$
 	
i (^2	 	   ^ c2 ^s6   Q
,4Q"Q) Q)
	Q.Q.
Q3Q3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.TrQ  Fr9   r   r9  )rk  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_schema  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   r2  r   )r   r]  r*   	__value__r\   r   r   r>   r  r   r_   r  r2  r#   r3  )r   r   r   rx  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                  | j                  ||       | jG                  ||||      |
|<    | jI                  |tK        |            }tM        tO        tP        ||      g|      }tS        jT                  |
|jV                  jY                         D cg c]  }| j[                  ||j\                          c}|||      }| j_                  ||j`                  jY                               }tc        ||jd                  jY                         d      }|| j                  jf                  |<   tS        jh                  |      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_extrasrQ  r   FrH  )rJ  typed_dict_cls)rY  r   r9  rX  all)5ry   rf   r   r   r   r]  r\   _SUPPORTS_TYPEDDICTr   r   r5   rT   AttributeErrorr   r   r   rd  r  __required_keys__rM   builduse_attribute_docstringsrX   rZ   r   rq  r_   r*   r>   Requiredrk  NotRequiredr  r   r  r  re  r?   rB   r	   r   r#   typed_dict_schemarY  r6  rs  r`  ru  rv  rn  rf  r2  r3  )r   r@  r  rf   typed_dict_refrx  r   rX  rd  required_keysry   r   field_docstringsr   r  rR  r  r   r9  r  	td_schemar   s                         r}   r  z!GenerateSchema._typed_dict_schema  s     	'""''7 X	O9T9TUc9d X	O i
'#X	O X	O X	O 5^DL!!'&4+?+J+Jh+V'n- 
,D^Uj,k ++008 BO$:U:U:Z:Z[i:j B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
.CCDDXDXZdfpq)-)G)G"J
X *H *F:&7> 99.-X^J_`.")*B^c"d!e#1 (99 ",!;!;!B!B!D% 33Az7S7ST% '%&		 66y*B^B^BeBeBgh/
8S8S8Z8Z8\^cd8>		%%n5">>~NEBO BO BO-X	O X	O X	O& " r%mBO BO BO BO BO-X	O X	O X	O X	O X	O X	Os   OO	O:ONO:N1G N	6#NBN	 	N1)	O2	ONONON	N%!N1(	O1N:6O=	OO	OO$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)r?  r>  )default)js_prefer_positional_arguments)r9  )r   )r   r   r   r]  r\   rZ   r   _fieldsr   rq  r_   r#   arguments_schema_generate_parameter_schema_field_defaultsr   r
   emptyrB   call_schema)r   namedtuple_clsr  namedtuple_refrx  r   r   r}  r   r  rR  s              r}   r  z!GenerateSchema._namedtuple_schemaQ  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  )ry   rf   r
   rU  r  from_annotated_attributer  r9  r   r   r  r  r  r#   arguments_parameterr  r   r   r  r-   r   )r   r  r  rO  rZ  rf   r{   r  r   r   parameter_schemar   s               r}   rS  z)GenerateSchema._generate_parameter_schemau  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>  s     R%==Rs   r   )r   r   r,   z&Variable tuples can only have one typer9   r   )r\   rk  r   rr   r#   tuple_schemar   Ellipsisr  r  
ValueError)r   
tuple_typeparamsra  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, ...]]`.TrQ  )rk  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*   ro  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  rx  r  r  r#   r
  r  r  r  r   _validatorsrz  r  no_info_wrap_validator_function#wrap_serializer_function_ser_schemajson_or_python_schema)	r   sequence_typerx  	item_typeitem_type_schemar
  r|  rz  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   rt  r  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        u r"t        j                  |j                  ||      S |t        u r"t        j                  |j                   ||      S t#        d|d      )Nr9   )r}  c                    dddS )Nstringregex)r   formatr   )_1_2s     r}   <lambda>z0GenerateSchema._pattern_schema.<locals>.<lambda>  s    XahDi r   rI  patternr   )r   return_schema)r   r9  TrQ  r   r   r   )r  r}  rB   r#   r   r   r  r  r  r   no_info_plain_validator_functionpattern_either_validatorrk  rh  pattern_str_validatorr  pattern_bytes_validatorr3   )r   pattern_typer}  r9  serra  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 hashablerj  )r#   rm  r  r  r  r  r   s    r}   r  zGenerateSchema._hashable_schema  s3    ..**;??+C+CD+!;
 	
r   c                     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 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      } j[                  |t]        |            }t_        ta        tb        ||      g      }tG        jd                  ||||t        jf                  |      D cg c]  }|jh                   c}||	|      } jk                  |jl                  j)                               }tY        ||d      }| j                  jn                  |<   tG        jp                  |      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.Nr<  r,   r   )r   rL  FzField zd has `init=False` and dataclass has config setting `extra="allow"`. This combination is not allowed.z dataclass-init-false-extra-allowr   r^  c              3  J   K   | ]  \  }}j                  ||        y wr   )r  )r`  r}  r~  r   r   s      r}   rb  z3GenerateSchema._dataclass_schema.<locals>.<genexpr>T  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>U  s    !%%	"2%"? r   )key__post_init__	__slots__)rY  collect_init_onlyrS  rH  rI  )rW  r   ry   slotsrX  r9  r\  Unreachable)9r   r   r   r]  r\   r   r   r   r  enter_contextr   reversedr   r   r   rd  r  r   r   __pydantic_fields__r6  apply_typevars_mapr   rY   r   extrarq  r  r5   __dict__r   rM   rE  sortedhasattrr#   dataclass_args_schemar   rY  rs  r`  r   rt  rf  rn  re  r?   rB   r	   r   dataclass_schemary   r  ru  rv  r2  r3  )r   	dataclassr  dataclass_refrx  r   dataclass_bases_stackdataclass_baserX  rd  r   ry   r{   r   r  has_post_init	has_slotsr  args_schemar   rf  r   r9  	dc_schemar   r   s   `                        @r}   r  z GenerateSchema._dataclass_schema  sT    ""''	2 d	(DII4O4OPY4Z d	( _
'#d	( d	( d	( 5Y?L!"	 U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]^99)]SYEZ[.")*B	Y^"_!` (88 +%4?4F4Fy4QR5EJJR#&%		 66y*B^B^BeBeBgh/8H'R7=		%%m4">>}MkUN UNd	( d	( d	(D%, S[UN UNr (-'5Id	( d	( d	( d	( d	(s{   Q)Q	Q)Q-%QAQ/DQB9Q?#P7"B7QP<,A/Q	Q$	Q)7
QQ
QQ	Q))Q2c                   t        |      }t        j                  || j                        }t        j
                  dt        j                  dt        j                  di}g }d}d}|j                  j                         D ]  \  }}	|	j                  |j                  u rt        j                  t        t              }
n||   }
|j                  |	j                         }|0| j#                  ||
|	j$                  |      }|j'                  |       |	j                   t        j(                  k(  r| j+                  |
      }|	j                   t        j,                  k(  sJ |	j                          | j+                  |
      } d}| j.                  }|j0                  r$|j                  d      }|| j+                  |      }t3        j4                  t3        j6                  ||||j8                        ||      S )	zsGenerate schema for a Callable.

        TODO support functional validators once we support them in Config
        )r   positional_onlypositional_or_keywordkeyword_onlyNr   )var_args_schemavar_kwargs_schemapopulate_by_name)r  )r   r>   get_function_type_hintsr   r
   POSITIONAL_ONLYPOSITIONAL_OR_KEYWORDKEYWORD_ONLYr  rq  r  rU  r  r   r   r   kindrS  rO  r   VAR_POSITIONALr  VAR_KEYWORDr   validate_returnr#   rV  rR  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_schema  s   
 !"::8UYUjUjk
 %%'8++-D""Nr
 @B9=;?~~++- 	EGD!||syy(#[[c2
'-
(__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                  }	 |j                         }|d ut        |      dk7  z   |z   dkD  rt        d      |r| j                  |j                        S |r"| j                  t        j                  |         S |r@| j                  |      }t        j                  d t        j                                |d<   |S t        j                          S # t        $ r t        |dd       d u}Y w xY w)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   rq  rs  has_defaultrC  r   r  NotImplementedErrorr  r  r  r   r#   r  r   )r   typevarrq   constraintstypevar_has_defaultr   s         r}   r  z,GenerateSchema._unsubstituted_typevar_schema  s"   '6>>222!!--	T")"5"5"7
 #k"2a"78;NNQRR%l  ''(;(;<<%%fll;&?@@))%0F&1&U&U!+*@*@*B'F?# M))++)  	T")'=$"Gt"S	Ts   D DDc                x   	 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&                         | j/                  | j(                  j                  j&                         dfd}t1        |g	      }t3        j4                  j&                  |j                  j6                  |
      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  )rz   r   r   r  r  r$   r!  add_json_schema_extra)r   r   r   r   r   r  r!  r  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  r9  )r   rC   r   r/   r   r6   )r;   get_function_return_typefuncrz   r  r   r  r4   r  r"   r5   r_   r   r   replacer  r   r   r6  r   r   r   r  r  rB   r#   r  r  )	r   r  r`  r  r  return_type_schemar   r  r9  s	    `       r}   rs  z%GenerateSchema._computed_field_schema  s   
	H%>>qvvqvvGYGY[_[p[pqK ++#d5  $K1C1CD $$QVVE!11+>!::01B1I1I1KQ^^\ ; 
 ..>>&>> /QVVabaoao ?  	778L8LaffVWVdVde	4 '@[?\]))NN*<AFFLL[c
 	
o  	H-==a@aG	Hs   ?F 	F9F44F9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  TrQ  )ry   rf   rk  r  r  r  )r   annotated_typerf   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   )r?  r@  rA  rB  r   r2  r=  )r   rD  r   rE  r;  r   r  r  s        r}   inner_handlerz8GenerateSchema._apply_annotations.<locals>.inner_handlerL  s{     ??[QM$44S9&#DS&#Q #/"9&$))BWBW"X".))/;OP)&11r    pydantic_js_annotation_functionsr   r   r   r!   )r5  r=   expand_grouped_metadatar  r   ra   _get_wrapped_inner_schemarA   r9  r:  extendr   r   r   )r   r  r   r  r  r  r  get_inner_schemar  r   r9  s   `` `       r}   r  z!GenerateSchema._apply_annotations9  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  )ry   rf   r  r9  _apply_single_annotationr'  r(  r   r#   r   r   reprr   r2  r=   apply_known_metadata)
r   r   r9  rf   field_metadatarS  r   r   new_refmaybe_updated_schemas
             r}   r  z'GenerateSchema._apply_single_annotationh  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  )ry   rf   r  r9  $_apply_single_annotation_json_schemar   r   r  r$   r!  rA   r:  r   r"  )r   r   r9  rf   r  json_schema_updater!  s          r}   r  z3GenerateSchema._apply_single_annotation_json_schema  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>  s
    GFO r   c                     |       }j                  |      }j                  |      }t        |      }|j                  |       |S r   )r  r  rA  r   )r  r   rE  r  r  metadata_get_schemar  r   s      r}   new_handlerz=GenerateSchema._get_wrapped_inner_schema.<locals>.new_handler  s\    (1ABF226:FF>>vzRF#DZQW#X #/0778LMMr   )r  r   r   core_schema.CoreSchema)r   ra   )r   r  r  r  r  r   s   ```` @r}   r  z(GenerateSchema._get_wrapped_inner_schema  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   r2  r   zstr|Noner   Nr   r  wrap)is_field_serializerr{  r  r   r   plain)r   r   r  r   r   r#   r3  rU   r  rz   rZ  r;   r  r  r   r  r4   r  r"   r  r  r   r   )r   r   serializersr  r   r   
serializerr  r{  r  r  r  s               r}   r   z'GenerateSchema._apply_field_serializers  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  )r{  r  r   r   )r   r5  rV   r  rz   rZ  r;   r  r  r   r  r4   r  r"   r  r#   r  r   r   )
r   r   r  r   r  r{  r  r  r  
ser_schemas
             r}   ru  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  )r;  r!   r<  Callable[..., Any]r   r  )T)r   r   rC  r  r   r  )r   ztype[BaseModel]r   r  )r  z#type[BaseModel | StandardDataclass]r   zConfigWrapper | Noner   r1  )r   r   r  r   r   zcore_schema.CoreSchema | None)r   r   r   r   )r   r   rR  zLiteral[True]r   tuple[Any, ...])r   r   r   tuple[Any, ...] | None)F)r   r   rR  r  r   r  )r   r   r   ztuple[Any, Any])r   r   r   r  )r   r   r  r   r   r!   )
r  rh  r  rf   r   rM   rR  r  r   zcore_schema.TypedDictField)r  rh  r  rf   r   rM   r   zcore_schema.ModelField)r  rh  r  rf   r   rM   r   zcore_schema.DataclassField)r   %Callable[[str], str] | AliasGeneratorr  rf   r   rh  r   r  )r   r  r  re   r  rh  )r   r?   r  zFieldInfo | ComputedFieldInfor   rh  r   r  )r  rh  r  rf   r   rM   r   _CommonField)r.  r   r   r  )r9  r   r   r!   )r@  r   r  r   r   r  )rW  r   r  r   r   r  )
r  rh  r  r   rO  r   rZ  zJLiteral['positional_only', 'positional_or_keyword', 'keyword_only'] | Noner   zcore_schema.ArgumentsParameter)rf  r   r   r  )r   r  )rt  r   r   r  )r  r   r   r  )rt  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  )r  zDecorator[ComputedFieldInfo]r`  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  r9  r   r   r  )r  r.   r  r   r  zlist[GetJsonSchemaFunction]r   ra   )r   r  r  z-list[Decorator[FieldSerializerDecoratorInfo]]r  r  r   r  )r   r  r  z1Iterable[Decorator[ModelSerializerDecoratorInfo]]r   r  )Kr   r   r   r   r  r   classmethodr  r   r   r   r  r  r  r  r  r  r  r  r"  r(  	Exceptionr+  r/  r-  r=  r  r  staticmethodre  r  r?  r  r   rk  r  r  r@  r  r  r  rr  r  r  r  r  rm  r  r  r  r  r  r
   rU  rS  r  r  ro  r  r  r  r  r  r  r  r  rs  r  r  r  r  r  r  r   ru  r   r   r}   r   r   =  s3   fI /3	#%# /# ,	#
 
# 0  3 *	
 ,  
 " / / 0 0 
 
 < <(IkHN
2	
 1K	$9 	
	6 -1-- &*- 
 	-^_JB [_2DX	 &;z, i iW W $2T.l*.d 

 
 #	
 
 
$
&

 
 #	

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

 
$
* /[>/[LU/[cf/[	/[ /[b (\>(\.(\ !(\ (\T %%%3P%^a%	% %*g
g
%.g
<Jg
	g
R6@@ 
@,4jOX"aP ![_! !  !  	! 
 Y!  
(! F_<
d
>*
.Mr8
h(0h(:Xh(	h(T3
j,<@
'@
 N@
 
#	@
D %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#   r~  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  0  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  rz   rZ  r+  )r   ra  r   	validatorr{  val_types         r}   r   r   6  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)rz   always)ra  r-  s     r}   r  r  O  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   NrS  r'  r\  r  )r  r   r)  )r   rz   rZ  rW   r  r#   r&  r~  r   r  r#  r  )r   ra  rZ  r   r-  r{  s         r}   rn  rn  _  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  )rO  r  )r3  r#   with_default_schemar  rO  r"   )r  r   s     r}   r  r    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   rg   __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  pydanticrh   r6  r8  r5   r  r   r%   r  rA  r:  )r   r   js_modify_functionrh   has_custom_v2_modify_js_funccls_names         r}   rA  rA    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   )rB  rC   r   r/   r   r6   r   )r  r!  rC  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  r1  r  bool | Noner  r  zdict[str, Any]r9  N)r   r   r   rM  r   r   r}   r  r    s&    ""JJ##&&r   r  )r  r  r  r  r9  c                   | |||||dS )Nr   r  r  r  r  r9  r   rJ  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   seenr2  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   rM  r2  r#   r3  adddiscard)r   r   r   s      r}   r]  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   r]  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  r2  r   r  )r   r2  s     r}   rB  rB  	  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   rT  r   s    r}   r   z_FieldNameStack.__init__(	  s	    !#r   c              #  ~   K   | j                   j                  |       d  | j                   j                          y wr   rU  r   r   )r   r   s     r}   r   z_FieldNameStack.push+	  s)     :&   ;=c                :    | j                   r| j                   d   S y r   rT  r   s    r}   r   z_FieldNameStack.get1	      ;;;;r?"r   NrQ  )r   rh  r   Iterator[None])r   r1  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   rT  c                    g | _         y r   rT  r   s    r}   r   z_ModelTypeStack.__init__;	  s	    "$r   c              #  ~   K   | j                   j                  |       d  | j                   j                          y wr   rX  )r   type_objs     r}   r   z_ModelTypeStack.push>	  s)     8$rY  c                :    | j                   r| j                   d   S y r   rT  r   s    r}   r   z_ModelTypeStack.getD	  r[  r   NrQ  )ra  r   r   r\  )r   ztype | Noner]  r   r   r}   r   r   8	  s%    I%  
r   r   )rz   FieldDecoratorInfor{   rh  r   r  )r   zIterable[AnyFieldDecorator]ry   zIterable[str]r   r  )r   z+Iterable[Decorator[FieldDecoratorInfoType]]r{   rh  r   z'list[Decorator[FieldDecoratorInfoType]])r   r  r   z'list[Decorator[ValidatorDecoratorInfo]]r   r1  r   r  )
r   rC   r   r/   r   r   r   r1  r   r6   )r   zJsonEncoders | Noner   r   r   r!   r   r!   )r   r   r   r   r   r   )r   r  ra  zIterable[Decorator[RootValidatorDecoratorInfo]] | Iterable[Decorator[ValidatorDecoratorInfo]] | Iterable[Decorator[FieldValidatorDecoratorInfo]]r   r1  r   r  )ra  z+Iterable[Decorator[ValidatorDecoratorInfo]]r   r  )r   r  ra  z0Iterable[Decorator[ModelValidatorDecoratorInfo]]rZ  z Literal['inner', 'outer', 'all']r   r  )r  rf   r   r  r   r  )r   r   r   r!   r   zGetJsonSchemaFunction | None)r  r6   r!  3JsonDict | typing.Callable[[JsonDict], None] | Noner   rl   )r   r6   r!  rd  )r   r  r  rG  r  r1  r  rH  r  rH  r9  r   r   r  )r   r!   r2  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/   rX  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   rQ  rY   rZ   _forward_refr[   	_genericsr\   r]   r^   r_   _mock_val_serr`   _schema_generation_sharedra   rb   rc   _utilsrd   ry   re   rf   r   rh   ri   ra  rj   r   rk   rl   version_inforB  r   r  r  rc  rp   AnyFieldDecoratorModifyCoreSchemaWrapHandlerGetCoreSchemaFunctionr   Tuplerr   rM  r5  Listr  MutableSequencers   r   Set
MutableSetrt   	frozenset	FrozenSetru   r   MutableMappingrv   r~   r   r   r   r   JsonEncodersr   rh  r   r   r   r   r+  r   r  rn  r  rA  r"  r  r  r$  r   rB  r   r   r   r   r}   <module>r     s   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" " 	"T (&(!( 
	(
 ( (V DI{*+&,/9CD tCH~t+,. .(%_ _L7 if[d   ."7
  2 ,",@, +, 	,^,>
#'
#<o
#
#' '5h'9  NR&*)-" K $	
 '   &$' $'N & r   