a cs @sBUddlZddlmZddlmZddlmZddlmZddl m Z ddl m Z m Z mZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZdd l m!Z!d d l"m#Z#m$Z$m%Z%m&Z&d d l'm(Z(m)Z)m*Z*m+Z+d d l,m-Z-m.Z.d dl/m0Z0m1Z1m2Z2m3Z3d dl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;mZ>m?Z?d dl@mAZAmBZBmCZCd dlDmEZEmFZFd dl mGZGmHZHd dlmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPd dlQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_erZdS)@N)ABCMeta)deepcopy)Enum)partial)Path) FunctionType prepare_class resolve_bases) TYPE_CHECKING AbstractSetAnyCallableClassVarDictListMappingOptionalTupleTypeTypeVarUnioncast no_type_checkoverload)dataclass_transform)ValidatorGroupextract_root_validatorsextract_validatorsinherit_validators) BaseConfigExtrainherit_configprepare_config) ErrorWrapperValidationError) ConfigError DictError ExtraError MissingError)MAPPING_LIKE_SHAPESField FieldInfo ModelFieldModelPrivateAttr PrivateAttr Undefinedis_finalvar_with_default_val)custom_pydantic_encoderpydantic_encoder)Protocol load_fileload_str_bytes)default_ref_template model_schema)PyObjectStrBytes) AnyCallableget_args get_origin is_classvar is_namedtupleis_unionresolve_annotationsupdate_model_forward_refs)DUNDER_ATTRIBUTESROOT_KEYClassAttribute GetterDictRepresentation ValueItemsgenerate_model_signatureis_valid_fieldis_valid_private_namelenient_issubclass sequence_likesmart_deepcopy unique_listvalidate_field_name) Signature)ValidatorListDict) ModelOrDc) AbstractSetIntStrAnyClassMethodCallableGeneratorDictAny DictStrAnyMappingIntStrAnyReprArgsSetStrTupleGeneratorModel BaseModel)bound)r^ create_modelvalidate_model_T)fieldsreturncCst|dkrttddS)Nrz" cannot be mixed with other fields)len ValueErrorrD)rcrgZ/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/pydantic/main.pyvalidate_custom_root_typebs ri)frozenrdcCsttddd}|r|SdS)N)self_rdcSst|jtt|jSN)hash __class__tuple__dict__values)rkrgrgrh hash_functionhsz-generate_hash_function..hash_function)r int)rjrrrgrgrhgenerate_hash_functiongsrt.ANNOTATED_FIELD_UNTOUCHED_TYPESUNTOUCHED_TYPESFT)Zkw_only_defaultZfield_specifierscs4eZdZefddZeedfdd ZZS)ModelMetaclassc( sti}t}i}gg}} i} i} |dd} t| tr:| hnt| } t} d}t|D]t}trTt|trT|tkrT| t |j t |j |}t|j|}||j7}| |j7} | |j| |j|j}qTdd}ddt|D}fdd|@D}|d }|r |r td t ||fi|}tt||}t|}|D]6}||||j}|rP|j || qPt!||t"t#t$d fd d }|d|dfdkrt%|di|dd}|&D]\}}t'|r| (|nt)|||t*r$| (|nt+|rt,||||t*}t-t.|rZt/|n|f}||r|t0krt1dd|Dsqt2j3||||||d||<n||vr|j4rt5| |<qt6|j7|&D]\}}|| vo|| }t|t8r8t9|s.t:d|d|d|d|| |<n|j4r`t9|r`|r`t5|d| |<nt+|r||vr|rt,||t2j3||||t*|||d}||vrt;|j<||j<r||j<|_||?|j@r(tAtB|j@}!ntC}!tD|\}"}#|durLtE|jF}|| BdhB||dd|&Dpxddd|&Dpd|jGtH||"dd d!tH| |#d"d d!itI|!| i| | | | B|| d#fd$d|&D}$tJjK||||$fi}%tLd%tM|%jN|||%_O|r2|%P|&D]4\}}&||$vr:tQ|&d&d}'tR|'r:|'|%|q:|%S)'N __slots__rgZ__resolve_forward_refs__TcSs$h|]}|dr|ds|qS)__) startswithendswith.0keyrgrgrh sz)ModelMetaclass.__new__..csi|]}||qSrg)popr|)kwargsrgrh z*ModelMetaclass.__new__..ConfigzYSpecifying config in two places is ambiguous, use either Config attribute or class kwargs)vrdcst|p|jjdkS)NZcython_function_or_method) isinstancern__name__r)untouched_typesrgrh is_untouchedsz,ModelMetaclass.__new__..is_untouched __module__ __qualname__)z pydantic.mainr^__annotations__css|]}tt|tVqdSrl)rLr=r)r}Z allowed_typergrgrh sz)ModelMetaclass.__new__..)namevalue annotationclass_validatorsconfigzPrivate attributes "zF" must not be a valid field name; Use sunder or dunder names, e. g. "_z" or "__z__")defaultz The type of .zo differs from the new default value; if you wish to change the type of this field, please use a type annotationcSs&i|]\}}|jjdur||jjqSrl) field_infoexcluder}rfieldrgrgrhrscSs&i|]\}}|jjdur||jjqSrl)rincluderrgrgrhrscSs|jSrlrrrgrgrh rz(ModelMetaclass.__new__..)Z name_factorycSs |djS)Nrr)Zskip_on_failure_and_vrgrgrhrr) __config__ __fields____exclude_fields____include_fields____validators____pre_root_validators____post_root_validators____schema_cache____json_encoder____custom_root_type____private_attributes__rx__hash____class_vars__csi|]\}}|vr||qSrgrg)r}nr)exclude_from_namespacergrhrr __signature__ __set_name__)Sr getrstrsetreversed_is_base_model_class_defined issubclassr^updaterNrr"rrrrrrrrrdirkeys TypeErrorrrrqZ set_configZget_validatorsrrZpopulate_validatorsr#rur boolrAitemsr>addr1r0rJrPr@r=r<r9anyr-ZinferZunderscore_attrs_are_privater/rvZkeep_untouchedr.rK NameErrorrLtype_rDriZcheck_for_unused json_encodersrr2r3rrtrj validatorsrO staticmethodsuper__new__rErI__init__r__try_update_forward_refs__getattrcallable)(Zmcsrbases namespacerrcrrZpre_root_validatorsZpost_root_validatorsZprivate_attributesZbase_private_attributesslotsZ class_varsZ hash_funcbaseZresolve_forward_refsZallowed_config_kwargsZ config_kwargsZconfig_from_namespaceZvgfZextra_validatorsr annotationsZann_nameZann_typerZ allowed_typesvar_nameZcan_be_changedinferredZ_custom_root_typeZ json_encoderZ pre_rv_newZ post_rv_newZ new_namespaceclsobjset_namern)rrrrhr{s,                                         zModelMetaclass.__new__)instancerdcst|dot|S)z| Avoid calling ABC _abc_subclasscheck unless we're pretty sure. See #3829 and python/cpython#92810 r)hasattrr__instancecheck__)selfrrrgrhr+sz ModelMetaclass.__instancecheck__) rrrrrr rr __classcell__rgrgrrhrwys0rwc @seZdZUer0iZeeeefe d<dZ ee e ee fe d<dZee e ee fe d<iZeeeefe d<eeee d<eeeeefe d<eZeeee d<d d Zeee ge fe d <iZed e d <dZeee d<ede d<eeeefe d<eee d<eZeee d<eZdZ dZ!e ddddZ"e#ddZ$d dddZ%d ddd d!Z&ddd"d#Z'dddddddd$e e(d%e e(d%ee eeeed&d'd(d)Z)ddddddddd*d+ e e(d%e e(d%ee eeeee ee ge fee ed, d-d.Z*e+e e d/d0d1Z,e+ed2e d2d3d4d5Z-e+dd6ddd7ed2e.eee/ed2d8d9d:Z0e+dd6ddd7ed2e(ee1feee/ed2d;dd?Z3e+dred2e d@e d2dAdBdCZ4d2d&d@ed2dDdEdFZ5dddddGd2e e(d%e e(d%e d&ed2dHdIdJZ6e+d*e7feed&dKdLdMZ8e+d*e7dNeee edOdPdQZ9e+dRddSdTZ:e+ed2e d2dUdVdWZ;e+ed2e ee+e dd]d^d_Z?e+e dd]d`daZ@dbddcddZAdseee e(d%e e(d%eeedbdedfdgZBdte dhe dhee d&e eCedidjdkZDe edldmdnZEdoddpdqZFdS)ur^rNrrrrrrcCs|Srlrg)xrgrgrhrArzBaseModel.rrWrFrrQrrr__fields_set__)rpr)datardc Ksrt|j|\}}}|r|zt|d|Wn.tyX}ztd|WYd}~n d}~00t|d||dS)z Create a new model by parsing and validating input data from keyword arguments. Raises ValidationError if the input data cannot be parsed to form a valid model. rpzYModel values must be a dict; you may not have returned a dictionary from a root validatorNr)rarnobject_setattrr_init_private_attributes)Z__pydantic_self__rrq fields_setvalidation_errorergrgrhrMs zBaseModel.__init__c sZ|jvstvrt||S|jjtjurT|jvrTtd|j j ddn|jj rd|jj r|t d|j j dnΈ|jvr|jjrt d|j j ddn|jjr@i|j|i}|jD]X}z||j |}Wqtt tfy(}z"tt|tdg|j WYd}~qd}~00q|jd}|r|jj s\t d|jdfdd |jD}|j|||j d \}}|rt|g|j n||<g} |jD]j\} }| r| r̐qz||j |}Wn>tt tfy}z| t|tdWYd}~n d}~00q| r2t| |j t|d |n ||j<|jdS) N"z" object has no field "z3" is immutable and does not support item assignmentz " object "z2" field is final and does not support reassignmentlocz8" has allow_mutation set to False and cannot be assignedcsi|]\}}|kr||qSrgrgr}krrrgrhr~rz)BaseModel.__setattr__..rrrp)rrCrrextrar!allowrrfrnrZallow_mutationrjrfinalZvalidate_assignmentrprAssertionErrorr%r$rDrrrrvalidaterappendrr) rrr new_values validatorexcZ known_fieldZdict_without_original_valueZerror_errorsskip_on_failurergrrh __setattr__`sN   .  ,  zBaseModel.__setattr__)rdcs.fddjD}jjdd|DdS)Nc3s|]}|t|tfVqdSrl)rr0)r}rrrgrhrrz)BaseModel.__getstate__..cSsi|]\}}|tur||qSrg)r0rrgrgrhrrz*BaseModel.__getstate__..)rpr__private_attribute_values__)rrpr)rZ private_attrsrgrrh __getstate__s  zBaseModel.__getstate__)staterdcCsJt|d|dt|d|d|diD]\}}t|||q0dS)Nrprr)rrr)rrrrrgrgrh __setstate__szBaseModel.__setstate__cCs4|jD]$\}}|}|tur t|||q dSrl)rr get_defaultr0r)rrZ private_attrrrgrgrhrsz"BaseModel._init_private_attributes)rrby_alias skip_defaults exclude_unsetexclude_defaults exclude_none)rTrYrX)rrrrrrrrdc Cs>|dur"t|jjdt|}t|jd||||||dS)z Generate a dictionary representation of the model, optionally specifying which fields to include or exclude. NzF.dict(): "skip_defaults" is deprecated and replaced by "exclude_unset"Tto_dictrrrrrr)warningswarnrnrDeprecationWarningdict_iter)rrrrrrrrrgrgrhrs" zBaseModel.dictT) rrrrrrrencodermodels_as_dict) rrrrrrrrr dumps_kwargsrdc Ks~|dur"t|jjdt|}tttgtf|p8|j}t |j | ||||||d} |j rf| t } |j j| fd|i| S)z Generate a JSON representation of the model, `include` and `exclude` arguments as per `dict()`. `encoder` is an optional function to supply as `default` to json.dumps(), other arguments as per `json.dumps()`. NzF.json(): "skip_defaults" is deprecated and replaced by "exclude_unset"rr)rrrnrrrr r rrrrrDr json_dumps) rrrrrrrrrrrrrgrgrhjsons*  zBaseModel.json)rrdcCsX|jrPt|tr|thks8t|trH|jthkrH|jtjtvrPt|iS|SdSrl) rrrrrDr^rshaper*rrrgrgrh_enforce_dict_if_roots zBaseModel._enforce_dict_if_rootr])rrrdc Cs||}t|tsxz t|}WnVttfyv}z:t|jd|jj}tt|t dg||WYd}~n d}~00|fi|S)Nz expected dict not r) r rrrrfrrnr%r$rD)rrrrrgrgrh parse_objs   ,zBaseModel.parse_objutf8) content_typeencodingproto allow_pickle)rbrrrrrdc Csfzt||||||jjd}Wn>tttfyZ}z tt|tdg|WYd}~n d}~00| |S)Nrrrr json_loadsr) r6rrrfrUnicodeDecodeErrorr%r$rDr)rrrrrrrrrgrgrh parse_raws  *zBaseModel.parse_raw)rpathrrrrrdcCs"t||||||jjd}||S)Nr)r5rrr)rrrrrrrrgrgrh parse_file(s zBaseModel.parse_filecCsn|jjstd|jrt|in||}||}t||\}}}|rJ|t|d|t|d|| |S)Nz@You must have the config attribute orm_mode=True to use from_ormrpr) rorm_moder&rrD_decompose_classrrarr)rrmrqrrrgrgrhfrom_orm<s   zBaseModel.from_ormr[)r _fields_setrqrdcKs||}i}|jD]P\}}|jr@|j|vr@||j||<q||vrV||||<q|js|||<q||t|d||durt | }t|d|| |S)a Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if `Config.extra = 'allow'` was set since it adds all passed values rpNr) rrr alt_aliasaliasrequiredrrrrrr)rrrqrZ fields_valuesrrrgrgrh constructJs      zBaseModel.construct)rrqrdeeprdcCsp|r t|}|j}||}t|d|t|d||jD]0}t||t}|tur:|r^t|}t|||q:|S)Nrpr)rrnrrrrr0)rrqrr$rrrrrgrgrh_copy_and_set_valuesbs     zBaseModel._copy_and_set_values)rrrr$)rrrrr$rdcCsRt|jdd||ddfi|pi}|r8|j|B}n t|j}|j|||dS)a Duplicate a model, optionally choose which fields to include, exclude and change. :param include: fields to include in new model :param exclude: fields to exclude from new model, as with values this takes precedence over include :param update: values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data :param deep: set to `True` to make a deep copy of the model :return: new model instance F)rrrrrr$)rrrrrr%)rrrrr$rqrrgrgrhcopyts zBaseModel.copy)r ref_templaterdcCs<|j||f}|dur|St|||d}||j||f<|S)Nrr()rrr8)rrr(cachedsrgrgrhschemas zBaseModel.schemar))rr(rrdcKs.ddlm}|jj|j||dfd|i|S)Nr)r3r)r)r r3rr r,)rrr(rr3rgrgrh schema_jsons  zBaseModel.schema_jsonrVccs |jVdSrl)r)rrgrgrh__get_validators__szBaseModel.__get_validators__)rrrdc Cst||rl|jj}d}|dvr2tdt|r2d}|dkr@d}n |dkrLd}|durX|S|j|j|j|dS| |}t|t r|fi|S|jj r| |Sz t |}Wn0t tfy}zt|WYd}~n d}~00|fi|SdS)N>r$shallownonezJ`copy_on_model_validation` should be a string: 'deep', 'shallow' or 'none'Fr/r$Tr&)rrcopy_on_model_validationrrrr%rprr rrrrrfr')rrr1Z deep_copyZ value_as_dictrrgrgrhrs4     zBaseModel.validatecCst|tr|S|j|Srl)rrFrZ getter_dictr rgrgrhrs zBaseModel._decompose_class) rrrrrrrrrdc s t|trFr8|j||d} t| vr4| tS| S|j||dS|rTt||nd|rft||ndt|trfdd|DSt|rfddt|D} t |j r|j | S| | St|t rt j ddr|jS|SdS) N)rrrrrr)rrc s\i|]T\}}r|sr(|r|j|oD|oP|dqS)rrrrrrrZ is_excludedZ is_included _get_value for_element)r}Zk_v_rrrrrr value_exclude value_includergrhrs   z(BaseModel._get_value..c 3s\|]T\}}r|sr&|rj|o@|oL|dVqdS)r2Nr3)r}ir6r7rgrhr s   z'BaseModel._get_value..Zuse_enum_valuesF)rr^rrDr'rHrrM enumerater?rnrrrr) rrrrrrrrrZv_dictZseq_argsrgr7rhr4s8    zBaseModel._get_value)localnsrdcKs t||j|jj|tfdS)z{ Same as update_forward_refs but will not raise exception when forward references are not defined. N)rBrrqrrrrr<rgrgrhr#sz%BaseModel.__try_update_forward_refs__cKst||j|jj|dS)z` Try to update ForwardRefs on fields based on this Model, globalns and localns. N)rBrrqrrr=rgrgrhupdate_forward_refs+szBaseModel.update_forward_refsr\ccs|jEdHdS)z( so `dict(model)` works Nrprrrgrgrh__iter__2szBaseModel.__iter__)rrrrrrrrdc cs|dus|jdur t|j|}|dus2|jdurDtj|j|dd}|j|||d}|dur|s|s|s|s|s|jEdHdS|durt||nd} |durt||nd} |jD]\} } |dur| |vs|r| durq|r|j| } t | ddst | dt | krq|r4| |jvr4|j| j }n| }|sJ| sJ| r||j | ||| ob| | | op| | |||d} || fVqdS)NT)Z intersect)rrrr"rr)rrHmerger_calculate_keysrprrrr_missingr!r4r5)rrrrrrrrZ allowed_keysr8r9Z field_keyrZ model_fieldZdict_keyrgrgrhr8sD    zBaseModel._iterrY)rrrrrdcCsx|dur|dur|durdS|r,|j}n |j}|durJ||M}|rZ||8}|rt|dd|D8}|S)NFcSsh|]\}}t|r|qSrg)rHZis_truerrgrgrhrrz,BaseModel._calculate_keys..)rr'rprr)rrrrrrrgrgrhrBqs    zBaseModel._calculate_keys)otherrdcCs*t|tr||kS||kSdSrl)rr^r)rrDrgrgrh__eq__s zBaseModel.__eq__rZcsfddjDS)Ncs8g|]0\}}|tvr|jvs,j|jjr||fqSrg)rCrrreprrrrgrh s z+BaseModel.__repr_args__..r?rrgrrh __repr_args__s zBaseModel.__repr_args__)N)FFNNFFF)N)Grrrr rrrrr-rrrrr rrr;rrrr rrrr rrr.r[rrrrx__doc__rrrrrrrrr  classmethodr rr:r4rrrrr#r%r'r7r,r-r.rrFrr4rr>r@rr rBrErHrgrgrgrhr^7sT    7    %   -         &  I   > ) metaclass)r__base__rr__cls_kwargs__rU) __model_namerrLrrrMfield_definitionsrdcKsdSrlrgrNrrLrrrMrOrgrgrhr`s r`)rrrrMcKsdSrlrgrPrgrgrhr`s )rrLrrrMrx) rNrrLrrrMrxrOrdc Ksv|durtdt|dur>|dur,tdt|tsN|f}nttdtf}|pTi}i}i} | D]\} } t | std| dtt| trz | \} } Wqt y}ztd|WYd}~qd}~00n d| } } | r| | | <| || <qf| |d}|r | || ||r*t |t|d <t|}t|||d \}}}||urX||d <| |||||fi|S) a Dynamically create a model. :param __model_name: name of the created model :param __config__: config class to use for the new model :param __base__: base class for the new model to inherit from :param __module__: module of the created model :param __validators__: a dict of method names and @validator class methods :param __cls_kwargs__: a dict for class creation :param __slots__: Deprecated, `__slots__` should not be passed to `create_model` :param field_definitions: fields of the model (or extra fields if a base is supplied) in the format `=(, )` or `=, e.g. `foobar=(str, ...)` or `foobar=123`, or, for complex use-cases, in the format `=` or `=(, )`, e.g. `foo=Field(datetime, default_factory=datetime.utcnow, alias='bar')` or `foo=(str, FieldInfo(title='Foo'))` Nz.__slots__ should not be passed to create_modelzBto avoid confusion __config__ and __base__ cannot be used togetherr]z3fields may not start with an underscore, ignoring "rzfield definitions should either be a tuple of (, ) or just a default value, unfortunately this means tuples as default values are not allowed)rrr)kwds__orig_bases__)rrRuntimeWarningr&rrorrr^rrJrfrr"r r r)rNrrLrrrMrxrOrcrf_nameZf_defZ f_annotationZf_valuerrresolved_basesmetansrQrgrgrhr`sN           rXrSr[)model input_datarrdc Csi}g}t}t}|j}|jtju}|p,|} |jD]^} z| | |}Wq4tttfy} z,itt t | t dg| fWYd} ~ Sd} ~ 00q4|j D]\} } || jt}d}|tur|jr| jr|| jt}d}|tur.| jr |t t| jdq| }|jsV| jsV||| <qn(|| |rV||rN| jn| j| j||| j| d\}}t|t r||qt|tr||q||| <q|r.t|tr| |}n |!|}|r.||O}|jtj"ur |D]}||||<qn$t#|D]}|t t$|dq|j%D]h\}} |rL|rLq4z| | |}Wn>tttfy} z|t | t dWYd} ~ n d} ~ 00q4|r||t || fS||dfSdS)z( validate data against a model. rNFTr)&rrrr!ignorerrfrrr%r$rDrrrr!rCZallow_population_by_field_namer rr"rr)rZ validate_allZvalidate_alwaysrrrlistextendrFZ extra_keysrrsortedr(r)rXrYrrqrZ names_usedrrZ check_extraZcls_rrrrrZ using_namer6Zerrors_rrrrgrgrhra sp  8           ,ra)N)rabcrr'renumr functoolsrpathlibrtypesrrr typingr r r r rrrrrrrrrrrrZtyping_extensionsrrrrrrrr r!r"r#Zerror_wrappersr$r%rr&r'r(r)rcr*r+r,r-r.r/r0r1r r2r3parser4r5r6r,r7r8r9r:r;r<r=r>r?r@rArButilsrCrDrErFrGrHrIrJrKrLrMrNrOrPinspectrQrRrSrTrUrVrWrXrYrZr[r\r]__all__rbrrirrsrtpropertytyperJrrurrvrrwobjectrrr^rr`rCrargrgrgrhs      H ( ( @   , ;g           M