fL i=UdZddlmZddlZddlZddlZddlZddlZddl m Z m Z m Z ddl mZmZmZddl mZddlmZddlmZdd lmZdd lmZdd lmZmZmZmZm Z m!Z!dd l"m#Z#m$Z$m%Z%m&Z&m'Z'dd l(m)Z)m*Z*m+Z+ddl,m-Z-ddl.m/Z/m0Z0ddl1m2Z2e#r*ee3e$fee4e$fzZ5de6d<ee3ee4zZ7de6d<ddl8m9Z9e3e:e;e4ee0j~eee ejee!eAjeCjhZDde6d<eEeFeGeHeIe e e hZJde6d<d9dZKd:dZLd;dZMddZPe&d ZQd?d!ZRd@d"ZSe&d#ZTe4d$ dAd%ZUGd&d'e/jZWe#rdBd(ZXn Gd)d*ZXe&d+ZYdCd,ZZe[Z\dDd-Z]dEd.Z^ejd/0Gd1d2Z`e&d3d45Zae&d6ZbGd7d8e%eaebfZcy)FzBucket of reusable internal utilities. This should be reduced as much as possible with functions only used in one place, moved to that place. ) annotationsN) OrderedDict defaultdictdeque)CallableIterableMapping)Set)deepcopy)cached_property) Parameter) zip_longest)BuiltinFunctionTypeCodeType FunctionType GeneratorType LambdaType ModuleType) TYPE_CHECKINGAnyGenericTypeVaroverload) TypeAlias TypeGuard deprecated)PydanticDeprecatedSince211)_repr _typing_extra)import_cached_base_modelrMappingIntStrAnyAbstractSetIntStr) BaseModelzset[type[Any]]IMMUTABLE_NON_COLLECTIONS_TYPESBUILTIN_COLLECTIONScZ|jtjtjfvS)aZReturn whether the parameter accepts a positional argument. ```python {test="skip" lint="skip"} def func(a, /, b, *, c): pass params = inspect.signature(func).parameters can_be_positional(params['a']) #> True can_be_positional(params['b']) #> True can_be_positional(params['c']) #> False ``` )kindr POSITIONAL_ONLYPOSITIONAL_OR_KEYWORD)params _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pydantic/_internal/_utils.pycan_be_positionalr.Is$ ::)33Y5T5TU UUc Vt|ttttt t fSN) isinstancelisttupleset frozensetrrvs r- sequence_liker9\s a$sI}eL MMr/c: t||S#t$rYywxYwNF)r2 TypeError)oclass_or_tuples r-lenient_isinstancer?`s&!^,, s  c t|txr t||S#t$rt|tj rYywxYwr;)r2type issubclassr<r WithArgsTypes)clsr>s r-lenient_issubclassrEgsE#t$HC)HH  c=66 7 s #AAc:t}t||xr||uS)zReturns true if cls is a _proper_ subclass of BaseModel, and provides proper type-checking, unlike raw calls to lenient_issubclass. )r!rE)rDr%s r-is_model_classrGps#)*I c9 - F#Y2FFr/cR|jxrtj| S)zChecks 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) identifiers r-is_valid_identifierrMys&  " " $ JW->->z-J)JJr/KeyTypec|j}|D]Y}|jD]D\}}||vr6t||tr#t|trt |||||<@|||<F[|Sr1)copyitemsr2dict deep_update)mappingupdating_mappingsupdated_mappingupdating_mappingkr8s r-rSrSsllnO-'$**, 'DAqO# ?13Et(LQ[\]_cQd%01CQ%G"%&"  '' r/c ||j|jDcic] \}}| || c}}ycc}}wr1)updaterQ)rTrZrXr8s r-update_not_noner[s. NNV\\^ETQq}AqDEFEs 8 8 T) name_factorycg}g}|D]E}||}||vr#|j||j|2|||j|<G|S)zMake a list unique while maintaining order. We update the list if another one with the same name is set (e.g. model validator overridden in subclass). )appendindex) input_listr]result result_namesr8v_names r- unique_listresdF L 3a  %    ' MM! 12F<%%f- . 3 Mr/ceZdZdZdZddZddZddZddZddZ e dddZ e dd Z e dd Ze dd Zdd Zy ) ValueItemszOClass for more convenient calculation of excluded or included fields on values.)_items_typec|j|}t|ttfr|j |t |}||_yr1) _coerce_itemsr2r3r4_normalize_indexeslenrh)selfvaluerQs r-__init__zValueItems.__init__s=""5) edE] +++E3u:>E(- r/cV|j|jj|S)zWCheck if item is fully excluded. :param item: key or index of a value )is_truerhgetrnitems r- is_excludedzValueItems.is_excludeds ||DKKOOD122r/c||jvS)z`Check if value is contained in self._items. :param item: key or index of value rhrts r- is_includedzValueItems.is_includeds t{{""r/cb|jj|}|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)rhrsrr)rnerus r- for_elementzValueItems.for_elements,{{q!<<-t747r/ci}d}|jD]\}}t|ts>> 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.) rQr2r AbstractSetrrr< __class__ _coerce_valueintmergersrange setdefault) rnrQv_lengthnormalized_items all_itemsir8 normalized_inormalized_items r-rlzValueItems._normalize_indexessh24 KKM _DAqq'*jK.HDLLYZO"NqcQSTUT_T_S` abbI~ ..q1 a%A,-q58a|Scc}wcc}wcc}w)aHMerge 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`. ) intersect)rrrr3rrs)rDbaseoverriderrX merge_keysmerged merged_items r-rzValueItems.merges $$X.  &  K ;;t  O ;;x $4 2( 2 %);Q(]!;(>`QVW[_V_q>``Jd(&LQatmq&LLJ') (A))DHHQKaI)VK&'q  (  <>`&Ls$ C'#C'- C,7C, C1C1ct|tr |St|trtj |d}|St |dd}t d|)N.rz???z!Unexpected type of exclude value )r2r rrRfromkeysgetattrr<)rQ class_names r-rkzValueItems._coerce_itemss\ eW %   { +MM%-E ! U;J? |LM Mr/cN||j|r|S|j|Sr1)rrrk)rDros r-rzValueItems._coerce_value$s( =CKK.L  ''r/c|duxs|duS)NT.r7s r-rrzValueItems.is_true*sDy$AH$r/c d|jfgSr1rxrns r- __repr_args__zValueItems.__repr_args__.st{{#$$r/N)rorrQ$AbstractSetIntStr | MappingIntStrAnyreturnNone)rurrbool)r{z int | strrz+AbstractSetIntStr | MappingIntStrAny | None)rQr"rrrzdict[int | str, Any])F)rrrrrrrr)rQrrr")rorrrr8rrr)rz_repr.ReprArgs)__name__ __module__ __qualname____doc__ __slots__rprvryr|rl classmethodr staticmethodrkrrrrrr/r-rgrgszY#I.3#8# J##J(( %%%r/rgcyr1rname get_values r-LazyClassAttributer4sr/c2eZdZdZddZeddZddZy) rzA descriptor exposing an attribute only accessible on a class (hidden from instances). The attribute is lazily computed and cached during the first access. c ||_||_yr1r)rnrrs r-rpzLazyClassAttribute.__init__>sDI&DNr/c"|jSr1)rrs r-rozLazyClassAttribute.valueBs>># #r/ch| |jSt|jd|jd)Nz attribute of z is class-only)roAttributeErrorrr)rninstanceowners r-__get__zLazyClassAttribute.__get__Fs4zz! DII=u~~>PP^!_` `r/N)rstrrzCallable[[], Any]rr)rr)rrrz type[Any]rr)rrrrrpr rorrr/r-rr8s&  '  $  $ ar/rObjc|j}|tvr|S |s"|tvr|tur|S|j St|S#t t tf$r Yt|SwxYw)zReturn 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. ) rr&r'r4rPr< ValueError RuntimeErrorr )objobj_types r-smart_deepcopyrOst }}H22  x#66"e+3 ; ; C= z< 0  C=  sAAA('A(cDt||tD] \}}||us yy)aCheck 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 _SENTINEL)leftright left_item right_items r- all_identicalres1"-T5I!N : J & r/c||S|S)zTReturn the first argument if it is not `None`, otherwise return the second argument.r)abs r-get_first_not_nonerts 1$1$r/T)frozenc6eZdZUdZdZded<ddZerd dZyy) SafeGetItemProxyzWrapper redirecting `__getitem__` to `get` with a sentinel value as default This makes is safe to use in `operator.itemgetter` when some keys may be missing )wrappedzMapping[str, Any]rcB|jj|tSr1)rrsrrnkeys r- __getitem__zSafeGetItemProxy.__getitem__s||Y//r/c8|jj|Sr1)r __contains__rs r-rzSafeGetItemProxy.__contains__s<<,,S1 1r/N)rrrr)rrrr) rrrrr__annotations__rrrrr/r-rrys(I 0 2r/r_ModelTr%)bound_RTc^eZdZdZd dZed dZeeddd dZd dZy) deprecated_instance_propertyaA decorator exposing the decorated class method as a property, with a warning on instance access. This decorator takes a class method defined on the `BaseModel` class and transforms it into an attribute. The attribute can be accessed on both the class and instances of the class. If accessed via an instance, a deprecation warning is emitted stating that instance access will be removed in V3. c||_yr1)fget)rnrs r-rpz%deprecated_instance_property.__init__s  r/cyr1rrnrobjtypes r-rz$deprecated_instance_property.__get__sFIr/zAccessing this attribute on the instance is deprecated, and will be removed in Pydantic V3. Instead, you should access this attribute from the model class.N)categorycyr1rrs r-rz$deprecated_instance_property.__get__s JMr/c|itjdk\r|jjn|jjj}t j d|dtd|jj||S)N) zAccessing the zi attribute on the instance is deprecated. Instead, you should access this attribute from the model class.r$)r stacklevel) sys version_inforr__func__warningswarnrr)rnrr attr_names r-rz$deprecated_instance_property.__get__s  ##w. ""YY''00  MM  .RR3   4tyy  7355r/)rzCallable[[type[_ModelT]], _RT]rr)rrr type[_ModelT]rr)rrrrrr)rz_ModelT | Nonerrrr)rrrrrprrrrr/r-rrsKII  J M  M6r/r)r,r rrr)r=rr>z(type[Any] | tuple[type[Any], ...] | Nonerr)rDrr>rrr)rDrrzTypeGuard[type[BaseModel]])rLrrr)rTdict[KeyType, Any]rUrrr)rTzdict[Any, Any]rZrrr)razlist[T] | tuple[T, ...]r]zCallable[[T], str]rzlist[T])rrrzCallable[[], T]rr\)rrrr)r Iterable[Any]rrrr)rrrrrr)dr __future__r _annotations dataclassesrJrrweakref collectionsrrrcollections.abcrrr r rrPr functoolsr inspectr itertoolsrtypesrrrrrrtypingrrrrrtyping_extensionsrrrpydanticrrr _import_utilsr!rrr"rr#mainr%floatcomplexrbytesrANoneTyperefNotImplementedrEllipsisr&r3r5r4r6rRr'r.r9r?rErGrMrNrSr[r\reRepresentationrgrrrobjectrrr dataclassrrrrrr/r-rs  3 7777.%!ddAA>>/"3")#s("3gc3h6G"GiG#.s#3k#6F#FyF     KK  '30     '^ V&NGK ) G CL (+'% ,C%%%C%LKaa(en& H  % d#22$22 ); / en$677C<#8$6r/