U nf?e@s4UddlZddlZddlZddlmZmZmZddlmZddl m Z m Z ddl m Z mZmZmZmZmZddlmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'ddl(m)Z)dd l*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2dd l3m4Z4erdd l5m6Z6dd l7m8Z8dd l9m:Z:ddl;mZ>ddl?m@Z@ddl*mAZAmBZBmCZCmDZDmEZEee%ee"ee"eFefe"eFeeffZGdZHdZIeJeKeLeFeMeNeOe+ee eejPeeeQjReSjRhZTe!e#eeUd<eVeWeXeYeZeeehZ[e!e#eeUd<eFedddZ\dde%eFeJeFdddZ]eeMddd Z^ee#d!eFdd"d#d$Z_ee%e#ee"e#ed%fdfeMd&d'd(Z`ee%e#ee"e#ed%fdfeMd)d*d+ZaeMd,d-d.ZbeFeMd/d0d1Zce$d2Zdeedefeedefeedefd3d4d5Zeeeefedd6d7d8Zfd9d:eKeKeKeMd;deeFd?fe#d@dAdBdCdDZhe%e#d!e#dEfe#d!dFdGdHZieFeFdIdJdKZjeFeFdIdLdMZke$dNZleFdOe%eele"eld%ffeelgeFfeeldPdQdRZmGdSdTdTeFZnGdUdVdVZoGdWdXdXeoZpGdYdZdZeoZqGd[d\d\Zrd]d^d_d`dadbdcdddeZsdfeFdgdhdiZte$djZueueudFdkdlZveFeMdmdndoZwdpdqdrdsdtdudvhZxeFeMdmdwdxZyezZ{eeeeeMdydzd{Z|eeFed|d}d~Z}eeFeFeFdddZ~eeFe"eFe"eFd%ffdddZe#eeFe"eFe"e"eFd%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\}}Wn4tk rZ}ztd|d|W5d}~XYnX||}z t||WStk r}ztd |d |d |W5d}~XYnXdS) 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 ."z!" doesn't look like a module pathNzModule "z" does not define a "z " attribute) importlibrSstriprsplit ValueError ImportErrorgetattrAttributeError)rQrS module_path class_nameemodulerc?/opt/hc_python/lib/python3.8/site-packages/pydantic/v1/utils.pyr7ys $ r7P)max_len)vrfrRcCstdtt|tr>t||dkr>|d|ddSz |}Wn tk rj|j|}YnXt||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…rV) warningswarnDeprecationWarning isinstancestrlen__repr__ TypeError __class__)rgrfrcrcrdtruncates   rsrgrRcCst|ttttttfSN)rmlisttupleset frozensetr rrgrcrcrdr8sr8r1)bases field_namerRcCs0|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|basercrcrdr9s  r9.)oclass_or_tuplerRcCs(z t||WStk r"YdSXdSNF)rmrq)rrrcrcrdr:s r:)clsrrRcCsBzt|tot||WStk r<t|tr6YdSYnXdSr)rmtype issubclassrqr#)rrrcrcrdr;s  r;rRcCs,z tdWntk r"YdSXdSdS)zU Check whether we're in an ipython environment, including jupyter notebooks. Z __IPYTHON__FTN)evalr}rcrcrcrdr<s  r<) identifierrRcCs|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_mappingsrRcGsd|}|D]R}|D]D\}}||krTt||trTt|trTt|||||<q|||<qq |Sru)copyitemsrmdictr>)rrZupdated_mappingZupdating_mappingkrgrcrcrdr>s  r>)rupdaterRcKs|dd|DdS)NcSsi|]\}}|dk r||qSrurc).0rrgrcrcrd sz#update_not_none..)rr)rrrcrcrdr?sr?g:0yE>)delta)value_1value_2rrRcCst|||kS)z4 Return True if two floats are almost equal )abs)rrrrcrcrdr@sr@).Nr/r-r+)initfieldsconfigrRcCs|ddlm}m}m}ddlm}||j}i}d} d} t|ddD] } | j | j kr\| } qF| || j <qF| r|j } | D]t\} }|j}| |ksz||krqzn t|s| rt| r| }nd} qz|jsd|jini}|||jfd |ji|||<qz|j|jkrd} | rh| rhd |jfd |j fg}d d |D|krsz,generate_model_signature.. extra_data_r) parametersreturn_annotation)inspectrr+rpydantic.v1.configrrvaluesrr 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_signaturesX        rr.)objrRcCsFddlm}z |j}Wntk r.|}YnXt||sBtd|S)Nrr0z7Unsupported type, must be either BaseModel or dataclass)pydantic.v1.mainr1__pydantic_model__r^rrq)rr1Z model_clsrcrcrdrA,s    rA)stringrRcCsddd|dDS)Ncss|]}|VqdSru) capitalize)rwordrcrcrd :szto_camel..r)joinsplit)rrcrcrdrB9srBcCs4t|dkr,t|}|d|ddS|S)NrVr)rorBlower)rZ pascal_stringrcrcrdto_lower_camel=s rT) name_factory) input_listrrRcCsJg}g}|D]8}||}||kr6||||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)rEz 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__rnrprcrcrcrdrE^srEc@seZdZUdZeZeedfed<ddddZ eddd Z eed d d Z e e ge fe ee d d fdddZedddZedddZddddZd S)rFz 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__r6rcs"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])rsrrcrdrzsz/Representation.__repr_args__..cSs g|]\}}|dk r||fqSrurcrargrcrcrdr{sz0Representation.__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_strrRcCs|dd|DS)Ncss0|](\}}|dkrt|n |d|VqdS)N=)reprrrcrcrdrsz.Representation.__repr_str__..)rr)rrrcrcrd __repr_str__szRepresentation.__repr_str__N)fmtrrRcks^|dVdV|D]0\}}|dk r6|dV||VdVdVqdVdVdS) z Used by devtools (https://python-devtools.helpmanual.io/) to provide a human readable representations of objects (rVNr,r))rr)rrrrvaluercrcrd __pretty__s  zRepresentation.__pretty__cCs |dS)NrT)rrrcrcrd__str__szRepresentation.__str__cCs|d|ddS)Nr, r)rrrrcrcrdrpszRepresentation.__repr__RichReprResultccs0|D]"\}}|dkr |Vq||fVqdS)zGet fields for Rich libraryN)r)rrZ field_reprrcrcrd __rich_repr__szRepresentation.__rich_repr__)rrrrrwrrrn__annotations__rrrrrrrrrprrcrcrcrdrFhs  &rFc@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)&rGz 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__)keyrRc Cs@zt|j|WStk r:}zt||W5d}~XYnXdSru)r]rr^KeyError)rrrarcrcrd __getitem__szGetterDict.__getitem__N)rrrRcCst|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|] }|qSrcrcrrrrcrdrsz%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)rVNrc)rrrcrcrdrsz%GetterDict.__len__..)sumrrcrcrd__len__szGetterDict.__len__itemrRcCs ||kSru)rrrrcrcrd __contains__szGetterDict.__contains__)otherrRcCst|t|kSru)rr)rrrcrcrd__eq__szGetterDict.__eq__r6cCsdt|fgSru)rrrcrcrdrszGetterDict.__repr_args__cCsdt|jdS)Nz GetterDict[])r%rrrcrcrdrszGetterDict.__repr_name__)N)rrrrrrrrnrrrrrrrrrrrintrboolrrrrrcrcrcrdrGsrGc@seZdZdZdZeedddddZeedd d Z eedd d Z d e eddddZ de ddddZed'eeeedddZeedddddZeeedddZeeed d!d"Zd#d$d%d&ZdS)(rHzY Class for more convenient calculation of excluded or included fields on values. )_items_type)r2r5N)rrrRcCs2||}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 ||jkS)zh Check if value is contained in self._items :param item: key or index of value rrrcrcrd is_includedszValueItems.is_includedr4)rarRcCs|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_elementr5r3)rv_lengthrRc 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 intersectrRcs||dkr S|s2dkr6S|rL|rHSS|rvfddDfddD}ntfddD}i}|D]0}|j|||d}|dk r|||<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|]}|kr|qSrcrcr)rrcrdrLsz$ValueItems.merge..csg|]}|kr|qSrcrcrr~rcrdrLscsg|]}|kr|qSrcrcrrrcrdrNs)r)r rrvrr)rr~rrZ merge_keysZmergedrZ merged_itemrc)r~rrdr1s"    & zValueItems.merge)rrRcCsDt|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)rrRcCs |dks||r|S||Sru)rr)rrrcrcrdr fszValueItems._coerce_valuertcCs|dkp|dkS)NT.rcrzrcrcrdrlszValueItems.is_truer6rcCs d|jfgSrurrrcrcrdrpszValueItems.__repr_args__)F)rrrrrrrrrrr rr rr classmethodr staticmethodrr rrrcrcrcrdrHs  '& rHc@s<eZdZdZdZeeddddZeeedddd Z dS) rIz1 Hide class attribute from its instances rrN)rrrRcCs||_||_dSrur)rrrrcrcrdr~szClassAttribute.__init__)instanceownerrRcCs*|dkr|jSt|jd|jddS)Nz attribute of z is class-only)rr^rr)rrrrcrcrd__get__szClassAttribute.__get__) rrrrrrnrrrrrcrcrcrdrItsrI directoryfilez mount pointsymlinkz block devicez char deviceZFIFOsocket)is_diris_fileis_mount is_symlinkis_block_deviceis_char_deviceis_fifo is_socketr,)rrRcCs:|stdtD]\}}t||r|SqdS)z0 Find out what sort of thing a path is. zpath does not existunknown)existsAssertionError path_typesrr])rmethodrrcrcrdrJs   rJObjc Cs\|j}|tkr|Sz&|s6|tkr6|tkr,|n|WSWntttfk rRYnXt|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 ) rrrOrPrwrrqr[ RuntimeErrorr)robj_typercrcrdrDs rD)rrRcCs|dsdSt|kS)NrT)rrKrrcrcrdrCs rCr __classcell__rr__orig_bases____orig_class__rcCst| o|tkSru)rCrNrrcrcrdis_valid_private_namesr5)leftrightrRcCs*t||tdD]\}}||k rdSqdS)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)r6r7Z left_itemZ right_itemrcrcrd all_identicals r:)rmsgrRcCs 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_keyrRcCs<t|}t|dkr4td|ddt|d|S)zNValidate that all aliases are the same and if that's the case return the aliasrVzAliases for discriminator z must be the same (got rr)rxror!rsortedpop)r<r=Zunique_aliasesrcrcrdrLs  rL)tpr=rRc Cstt|dd}t|tkr$t|d}t|dr4|j}tt|rdt||\}}|tdd|DfS|r|j t j }t||\}}t t |dkrtd|d t|||dfSz|j |j }Wnrtk r}ztd |jd |W5d }~XYn<tk r8}ztd |jd||W5d }~XYnXt|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)rrrgrcrcrdrsz5get_discriminator_alias_and_values..rVzField 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__rKtype_rorxr!r%r^rqrrr(rr$)r@r=Z is_root_modelr all_values union_typeZt_discriminator_typerarcrcrdrMs2       $* rM)rEr=rRcs0fddt|D}t|\}}t||fS)Ncsg|]}t|qSrc)rM)rtr=rcrdr sz3_get_union_alias_and_all_values..)r&ziprL)rEr=Zzipped_aliases_valuesr<rDrcrGrdrBs rB)rrjweakref collectionsrrrrr itertoolsrrtypesrr r r r r typingrrrrrrrrrrrrrrrrrrtyping_extensionsr Zpydantic.v1.errorsr!Zpydantic.v1.typingr"r#r$r%r&r'r(r)Zpydantic.v1.versionr*rr+pathlibr,rr-Zpydantic.v1.dataclassesr.Zpydantic.v1.fieldsr/rr1r2r3r4r5r6rnrr rKrfloatcomplexrbytesrrefNotImplementedrrEllipsisrOrrvrxrwryrrPr7rsr8r9r:r;r<r=rr>r?r@rrArBrrrrErFrGrHrIr-rJr/rDrCrNr5objectr9r:rrLrMrBrcrcrcrds  P  (       *  ,,   *   A$    <>     "*