a cd@s*UddlZddlZddlZddlmZmZmZddlmZddl m Z m Z ddl m Z mZmZmZmZmZddlmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'dd l(m)Z)dd lm*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1dd l2m3Z3erdd l4m5Z5dd l6m7Z7ddl8m9Z9ddl:m;Z;ddlm?Z?ddlm@Z@mAZAmBZBmCZCmDZDee%ee"ee"eEefe"eEeeffZFdZGdZHeIeJeKeEeLeMeNe*ee eejOeeePjQeRjQhZSe!e#eeTd<eUeVeWeXeYeeehZZe!e#eeTd<eEedddZ[dde%eEeIeEdddZ\eeLdd d!Z]ee#d"eEdd#d$d%Z^ee%e#ee"e#ed&fdfeLd'd(d)Z_ee%e#ee"e#ed&fdfeLd*d+d,Z`eLd-d.d/ZaeEeLd0d1d2Zbe$d3Zceecefeecefeecefd4d5d6Zdeeefedd7d8d9Zed:d;eJeJeJeLd<d=d>Zfed?eeEd@fe#dAdBdCdDdEZge%e#d"e#dFfe#d"dGdHdIZheEeEdJdKdLZieEeEdJdMdNZje$dOZkeEdPe%eeke"ekd&ffeekgeEfeekdQdRdSZlGdTdUdUeEZmGdVdWdWZnGdXdYdYenZoGdZd[d[enZpGd\d]d]Zqd^d_d`dadbdcdddedfZrdgeEdhdidjZse$dkZtetetdGdldmZueEeLdndodpZvhdqZweEeLdndrdsZxeyZzeeeeeLdtdudvZ{eeEedwdxdyZ|eeEeEeEdzd{d|Z}eeEe"eEe"eEd&ffd}d~dZ~e#eeEe"eEe"e"eEd&fd&ffdddZdS)N) OrderedDict defaultdictdeque)deepcopy)islice zip_longest)BuiltinFunctionTypeCodeType FunctionType GeneratorType LambdaType ModuleType) TYPE_CHECKING AbstractSetAnyCallable CollectionDict GeneratorIterableIteratorListMappingNoReturnOptionalSetTupleTypeTypeVarUnion) Annotated) ConfigError)NoneType WithArgsTypesall_literal_valuesdisplay_as_typeget_args get_originis_literal_typeis_union) version_info) Signature)Path) BaseConfig) Dataclass) ModelField BaseModel)AbstractSetIntStr DictIntStrAnyIntStrMappingIntStrAnyReprArgs) import_string sequence_likevalidate_field_namelenient_isinstancelenient_issubclass in_ipythonis_valid_identifier deep_updateupdate_not_nonealmost_equal_floats get_modelto_camelis_valid_fieldsmart_deepcopy PyObjectStrRepresentation GetterDict ValueItemsr+ClassAttribute path_typeROOT_KEYget_unique_discriminator_alias"get_discriminator_alias_and_valuesDUNDER_ATTRIBUTESZ__root__IMMUTABLE_NON_COLLECTIONS_TYPESBUILTIN_COLLECTIONS) dotted_pathreturnc Csddlm}z|ddd\}}Wn6ty\}ztd|d|WYd}~n d}~00||}z t||WSty}z$td |d |d |WYd}~n d}~00dS) z Stolen approximately from django. Import a dotted module path and return the attribute/class designated by the last name in the path. Raise ImportError if the import fails. r) import_module .r!"z!" doesn't look like a module pathNzModule "z" does not define a "z " attribute) importlibrTstriprsplit ValueError ImportErrorgetattrAttributeError)rRrT module_path class_nameemodulerc[/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/pydantic/utils.pyr8ys ( r8P)max_len)vrfrScCstdtt|tr>t||dkr>|d|ddSz |}Wntyh|j|}Yn0t||kr|d|dd}|S)z` Truncate a value and add a unicode ellipsis (three dots) to the end if it was too long z:`truncate` is no-longer used by pydantic and is deprecatedNu…r!) warningswarnDeprecationWarning isinstancestrlen__repr__ TypeError __class__)rgrfrcrcrdtruncates    rsrgrScCst|ttttttfSN)rmlisttupleset frozensetr rrgrcrcrdr9sr9r2)bases field_namerScCs0|D]&}t||drtd|d|dqdS)zZ Ensure that the field's name does not shadow an existing attribute of the model. Nz Field name "zI" shadows a BaseModel attribute; use a different field name with "alias='z'".)r] NameError)r{r|basercrcrdr:s r:.)oclass_or_tuplerScCs&z t||WSty YdS0dSNF)rmrq)rrrcrcrdr;s  r;)clsrrScCs@zt|tot||WSty:t|tr4YdSYn0dSr)rmtype issubclassrqr$)rrrcrcrdr<s   r<rScCs*z tdWnty YdS0dSdS)zU Check whether we're in an ipython environment, including jupyter notebooks. Z __IPYTHON__FTN)evalr}rcrcrcrdr=s   r=) identifierrScCs|ot| S)z Checks that a string is a valid identifier and not a Python keyword. :param identifier: The identifier to test. :return: True if the identifier is valid. ) isidentifierkeyword iskeyword)rrcrcrdr>sr>KeyType)mappingupdating_mappingsrScGsd|}|D]R}|D]D\}}||vrTt||trTt|trTt|||||<q|||<qq |Sru)copyitemsrmdictr?)rrZupdated_mappingZupdating_mappingkrgrcrcrdr?s  r?)rupdaterScKs|dd|DdS)NcSsi|]\}}|dur||qSrurc).0rrgrcrcrd z#update_not_none..)rr)rrrcrcrdr@sr@g:0yE>)delta)value_1value_2rrScCst|||kS)z4 Return True if two floats are almost equal )abs)rrrrcrcrdrAsrA).Nr0r.r,)initfieldsconfigrScCs|ddlm}m}m}ddlm}||j}i}d} d} t|ddD] } | j | j ur\| } qF| || j <qF| r|j } | D]t\} }|j}| |vsz||vrqzn t|s| rt| r| }nd} qz|jsd|jini}|||jfd |ji|||<qz|j|jurd} | rh| rhd |jfd |j fg}d d |D|krrz,generate_model_signature.. extra_data_r) parametersreturn_annotation)inspectrr,rrrrvaluesrr VAR_KEYWORDrZallow_population_by_field_nameraliasr>requiredr KEYWORD_ONLYrextraZallowPOSITIONAL_OR_KEYWORDreplacerv)rrrrr,rrZpresent_paramsZ merged_paramsZvar_kwZ use_var_kwparamZ allow_namesr|field param_namekwargsZdefault_model_signatureZ var_kw_namercrcrdgenerate_model_signaturesV        rr/)objrScCsDddlm}z |j}Wnty,|}Yn0t||s@td|S)Nr!r1z7Unsupported type, must be either BaseModel or dataclass)mainr2__pydantic_model__r^rrq)rr2Z model_clsrcrcrdrB,s     rB)stringrScCsddd|dDS)Ncss|]}|VqdSru) capitalize)rwordrcrcrd :rzto_camel..r)joinsplit)rrcrcrdrC9srCcCs4t|dkr,t|}|d|ddS|S)Nr!r)rorClower)rZ pascal_stringrcrcrdto_lower_camel=s rT) name_factory) input_listrrScCsJg}g}|D]8}||}||vr6||||q ||||<q |S)z Make a list unique while maintaining order. We update the list if another one with the same name is set (e.g. root validator overridden in subclass) )appendindex)rrresultZ result_namesrgZv_namercrcrd unique_listGs   rc@seZdZdZedddZdS)rFz String class where repr doesn't include quotes. Useful with Representation when you want to return a string representation of something that valid (or pseudo-valid) python. rcCst|Sru)rnselfrcrcrdrpdszPyObjectStr.__repr__N)__name__ __module__ __qualname____doc__rnrprcrcrcrdrF^srFc@seZdZUdZeZeedfed<ddddZ eddd Z eed d d Z e e ge fe ee d d fdddZedddZedddZddddZd S)rGz Mixin to provide __str__, __repr__, and __pretty__ methods. See #884 for more details. __pretty__ is used by [devtools](https://python-devtools.helpmanual.io/) to provide human readable representations of objects. . __slots__r7rcs"fddjD}dd|DS)a6 Returns the attributes to show in __str__, __repr__, and __pretty__ this is generally overridden. Can either return: * name - value pairs, e.g.: `[('foo_name', 'foo'), ('bar_name', ['b', 'a', 'r'])]` * or, just values, e.g.: `[(None, 'foo'), (None, ['b', 'a', 'r'])]` c3s|]}|t|fVqdSru)r])rsrrcrdrzrz/Representation.__repr_args__..cSs g|]\}}|dur||fqSrurcrargrcrcrdr{rz0Representation.__repr_args__..)r)rattrsrcrrd __repr_args__rszRepresentation.__repr_args__cCs|jjS)zA Name of the instance's class, used in __repr__. )rrrrrcrcrd __repr_name__}szRepresentation.__repr_name__)join_strrScCs|dd|DS)Ncss0|](\}}|durt|n |d|VqdS)N=)reprrrcrcrdrrz.Representation.__repr_str__..)rr)rrrcrcrd __repr_str__szRepresentation.__repr_str__N)fmtrrScks^|dVdV|D]0\}}|dur6|dV||VdVdVqdVdVdS) z Used by devtools (https://python-devtools.helpmanual.io/) to provide a human readable representations of objects (r!Nr,r))rr)rrrrvaluercrcrd __pretty__s  zRepresentation.__pretty__cCs |dS)NrU)rrrcrcrd__str__szRepresentation.__str__cCs|d|ddS)Nr, r)rrrrcrcrdrpszRepresentation.__repr__RichReprResultccs0|D]"\}}|dur |Vq||fVqdS)zGet fields for Rich libraryN)r)rrZ field_reprrcrcrd __rich_repr__szRepresentation.__rich_repr__)rrrrrwrrrn__annotations__rrrrrrrrrprrcrcrcrdrGhs  &rGc@seZdZdZdZedddZeedddZd%eeed d d Z e ed ddZ e ed ddZ e ed ddZeeeefd ddZeed ddZed ddZeedddZeedddZd d d!d"Zed d#d$Zd S)&rHz Hack to make object's smell just enough like dicts for validate_model. We can't inherit from Mapping[str, Any] because it upsets cython so we have to implement all methods ourselves. _obj)rcCs ||_dSrur)rrrcrcrd__init__szGetterDict.__init__)keyrSc CsBzt|j|WSty<}zt||WYd}~n d}~00dSru)r]rr^KeyError)rrrarcrcrd __getitem__szGetterDict.__getitem__N)rrrScCst|j||Sru)r]r)rrrrcrcrdgetszGetterDict.getrcCstS)zn We don't want to get any other attributes of obj if the model didn't explicitly ask for them )rxrrcrcrd extra_keysszGetterDict.extra_keyscCst|S)z Keys of the pseudo dictionary, uses a list not set so order information can be maintained like python dictionaries. )rvrrcrcrdkeysszGetterDict.keyscsfddDS)Ncsg|] }|qSrcrcrrrrcrdrrz%GetterDict.values..rcrrcrrdrszGetterDict.valuesccs|D]}|||fVqdSru)r)rrrcrcrdrszGetterDict.itemsccs$t|jD]}|ds |Vq dS)Nr)dirr startswith)rrrcrcrd__iter__s zGetterDict.__iter__cCstdd|DS)Ncss|] }dVqdS)r!Nrc)rrrcrcrdrrz%GetterDict.__len__..)sumrrcrcrd__len__szGetterDict.__len__itemrScCs ||vSru)rrrrcrcrd __contains__szGetterDict.__contains__)otherrScCst|t|kSru)rr)rrrcrcrd__eq__szGetterDict.__eq__r7cCsdt|fgSru)rrrcrcrdrszGetterDict.__repr_args__cCsdt|jdS)Nz GetterDict[])r&rrrcrcrdrszGetterDict.__repr_name__)N)rrrrrrrrnrrrrrrrrrrrintrboolrrrrrcrcrcrdrHsrHc@seZdZdZdZeedddddZeedd d Z eedd d Z d e eddddZ de ddddZed'eeeedddZeedddddZeeedddZeeed d!d"Zd#d$d%d&ZdS)(rIzY Class for more convenient calculation of excluded or included fields on values. )_items_type)r3r6N)rrrScCs2||}t|ttfr(||t|}||_dSru) _coerce_itemsrmrvrw_normalize_indexesror)rrrrcrcrdrs zValueItems.__init__rcCs||j|S)z` Check if item is fully excluded. :param item: key or index of a value )is_truerrrrcrcrd is_excludedszValueItems.is_excludedcCs ||jvS)zh Check if value is contained in self._items :param item: key or index of value rrrcrcrd is_includedszValueItems.is_includedr5)rarScCs|j|}||s|SdS)z :param e: key or index of element on value :return: raw values for element if self._items is dict and contain needed element N)rrr)rrarrcrcrd for_elements zValueItems.for_elementr6r4)rv_lengthrSc Csi}d}|D]\}}t|tsLt|tsL||sLtd|d|j|dkr`||}qt|tsrtd|dkr||n|}| || |||<q|s|S||rt |D]}| |dq|St |D]*}| |i}||s| ||||<q|S)af :param items: dict or set of indexes which will be normalized :param v_length: length of sequence indexes of which will be >>> self._normalize_indexes({0: True, -2: True, -1: True}, 4) {0: True, 2: True, 3: True} >>> self._normalize_indexes({'__all__': True}, 4) {0: True, 1: True, 2: True, 3: True} Nz,Unexpected type of exclude value for index "z" __all__zExcluding fields from a sequence of sub-models or dicts must be performed index-wise: expected integer keys or keyword "__all__"r.) rrmrrrrqrr _coerce_valuermergerrange setdefault) rrr Znormalized_itemsZ all_itemsirgZ normalized_inormalized_itemrcrcrdr s2        zValueItems._normalize_indexesF)r~override intersectrScs||dur S|s2dur6S|rL|rHSS|rvfddDfddD}ntfddD}i}|D]0}|j|||d}|dur|||<q|S)ae Merge a ``base`` item with an ``override`` item. Both ``base`` and ``override`` are converted to dictionaries if possible. Sets are converted to dictionaries with the sets entries as keys and Ellipsis as values. Each key-value pair existing in ``base`` is merged with ``override``, while the rest of the key-value pairs are updated recursively with this function. Merging takes place based on the "union" of keys if ``intersect`` is set to ``False`` (default) and on the intersection of keys if ``intersect`` is set to ``True``. Ncsg|]}|vr|qSrcrcr)rrcrdrLrz$ValueItems.merge..csg|]}|vr|qSrcrcrr~rcrdrLrcsg|]}|vr|qSrcrcrrrcrdrNr)r)r rrvrr)rr~rrZ merge_keysmergedrZ merged_itemrc)r~rrdr1s"    & zValueItems.merge)rrScCsDt|tr n4t|tr$t|d}nt|dd}t|d||S)N.rrz???z!Unexpected type of exclude value )rmrrrfromkeysr] assert_never)rr`rcrcrdrXs   zValueItems._coerce_items)rrScCs |dus||r|S||Sru)rr)rrrcrcrdr fszValueItems._coerce_valuertcCs|dup|duS)NT.rcrzrcrcrdrlszValueItems.is_truer7rcCs d|jfgSrurrrcrcrdrpszValueItems.__repr_args__)F)rrrrrrrrrrr rr rr classmethodr staticmethodrr rrrcrcrcrdrIs  '& rIc@s<eZdZdZdZeeddddZeeedddd Z dS) rJz1 Hide class attribute from its instances rrN)rrrScCs||_||_dSrur)rrrrcrcrdr~szClassAttribute.__init__)instanceownerrScCs*|dur|jSt|jd|jddS)Nz attribute of z is class-only)rr^rr)rrrrcrcrd__get__szClassAttribute.__get__) rrrrrrnrrrrrcrcrcrdrJtsrJ directoryfilez mount pointsymlinkz block devicez char deviceZFIFOsocket)is_diris_fileis_mount is_symlinkis_block_deviceis_char_deviceis_fifo is_socketr-)rrScCs:|sJdtD]\}}t||r|SqdS)z0 Find out what sort of thing a path is. zpath does not existunknown)exists path_typesrr])rmethodrrcrcrdrKs   rKObjc CsZ|j}|tvr|Sz&|s6|tvr6|tur,|n|WSWntttfyPYn0t|S)z Return type as is for immutable built-in types Use obj.copy() for built-in empty collections Use copy.deepcopy() for non-empty collections and unknown objects ) rrrPrQrwrrqr[ RuntimeErrorr)rZobj_typercrcrdrEs rE)rrScCs|dsdSt|kS)NrT)rrLrrcrcrdrDs rD>__orig_bases__rrr __classcell__r__orig_class__cCst| o|tvSru)rDrOrrcrcrdis_valid_private_namesr4)leftrightrScCs*t||tdD]\}}||urdSqdS)a Check that the items of `left` are the same objects as those in `right`. >>> a, b = object(), object() >>> all_identical([a, b, a], [a, b, a]) True >>> all_identical([a, b, [a]], [a, b, [a]]) # new list object, while "equal" is not "identical" False ) fillvalueFT)r_EMPTY)r5r6Z left_itemZ right_itemrcrcrd all_identicals r9)rmsgrScCs t|dS)z Helper to make sure that we have covered all possible types. This is mostly useful for ``mypy``, docs: https://mypy.readthedocs.io/en/latest/literal_types.html#exhaustive-checks N)rq)rr:rcrcrdrsr) all_aliasesdiscriminator_keyrScCs<t|}t|dkr4td|ddt|d|S)zNValidate that all aliases are the same and if that's the case return the aliasr!zAliases for discriminator z must be the same (got rr)rxror"rsortedpop)r;r<Zunique_aliasesrcrcrdrMs  rM)tpr<rSc Csxt|dd}t|tur$t|d}t|dr4|j}tt|rdt||\}}|tdd|DfS|r|j t j }t||\}}t t |dkrtd|d t|||dfSz|j |j }Wnvty}z td |jd |WYd }~nFd }~0ty<}z$td |jd||WYd }~n d }~00t|s`td|d|jd|j |jt|fSd S)z Get alias and all valid values in the `Literal` type of the discriminator field `tp` can be a `BaseModel` class or directly an `Annotated` `Union` of many. Z__custom_root_type__Frrcss|]}|D] }|Vq qdSrurc)rrrgrcrcrdrrz5get_discriminator_alias_and_values..r!zField z& is not the same for all submodels of zType z* is not a valid `BaseModel` or `dataclass`NzModel z% needs a discriminator field for key z of model z needs to be a `Literal`)r]r(r r'hasattrrr*_get_union_alias_and_all_valuesrwZ __fields__rLtype_rorxr"r&r^rqrrr)rr%)r?r<Z is_root_modelr all_values union_typeZt_discriminator_typerarcrcrdrNs2       (. rN)rDr<rScs0fddt|D}t|\}}t||fS)Ncsg|]}t|qSrc)rN)rtr<rcrdr rz3_get_union_alias_and_all_values..)r'ziprM)rDr<Zzipped_aliases_valuesr;rCrcrFrdrAs rA)rrjweakref collectionsrrrrr itertoolsrrtypesrr r r r r typingrrrrrrrrrrrrrrrrrrZtyping_extensionsr errorsr"r#r$r%r&r'r(r)r*versionr+rr,pathlibr-rr.Z dataclassesr/rr0rr2r3r4r5r6r7rnrr rLrfloatcomplexrbytesrrefNotImplementedrrEllipsisrPrrvrxrwryrrQr8rsr9r:r;r<r=r>rr?r@rArrBrCrrrrFrGrHrIrJr-rKr/rErDrOr4objectr8r9rrMrNrArcrcrcrds   P  (       *  ,,   *  A$    <>     "*