L ik dZddlmZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$dd lm%Z%dd!lm&Z&dd"lm'Z'dd#lm(Z(dd$lm)Z)dd%lm*Z*dd&lm+Z+dd'lm,Z,dd(lm-Z-dd)lm.Z.dd*lm/Z/dd+lm0Z0dd,lm1Z1dd-lm2Z2dd.lm3Z3dd/lm4Z4dd0lm5Z5dd1lm6Z6dd2lm7Z7dd3lm8Z8dd4lm9Z9dd5lm:Z:dd6lm;Z;dd7lmZ>dd:lm?Z?dd;lm@Z@dlmBZBdd%Zed?d&Z d@d'ZdAd(ZdBd)Z dCd*ZdDd+Z dEd,Z! dFd-Z" dFd.Z# dG dHd/Z$dId0Z%dJd1Z&dKd2Z'dLd3Z(y)MQueryableAttributeaBase class for :term:`descriptor` objects that intercept attribute events on behalf of a :class:`.MapperProperty` object. The actual :class:`.MapperProperty` is accessible via the :attr:`.QueryableAttribute.property` attribute. .. seealso:: :class:`.InstrumentedAttribute` :class:`.MapperProperty` :attr:`_orm.Mapper.all_orm_descriptors` :attr:`_orm.Mapper.attrs` ) class_keyimpl comparatorpropertyparent expression_of_type_extra_criteria_slots_dispatch_propagate_attrs_docTz%dispatcher[QueryableAttribute[_T_co]]dispatch_ExternalEntityType[Any]rkstrrl_InternalEntityType[Any] parententity AttributeImplrm interfaces.PropComparator[_T_co]rn"Optional[_InternalEntityType[Any]]rrTuple[ColumnElement[bool], ...]rs Optional[str]rvorm_instrumented_attributeNcx||_||_|x|_|_||_|J||_||_||_d|_t|}|rj|jD]Z} || vs|jj| |j| |jjsJd|j_ \yyNT)rkrl _parententityrprmrnrrrsrvr._basesrw_update_active_history) selfrkrlr{rnrmof_typeextra_criteriamanagerrBs _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/orm/attributes.py__init__zQueryableAttribute.__init__s +77T[  %%%$ - &v.   =$;MM))$s)*<*<=Cy))998< 5  = rct|j|jjj|j|jj ffSN)_queryable_attribute_unreducerlrmapperrkentityrs r __reduce__zQueryableAttribute.__reduce__sJ *""))00""""))    rc.|jjSr)rm uses_objectsrs r_impl_uses_objectsz%QueryableAttribute._impl_uses_objectssyy%%%rc`|jjt|t||Sr)rm get_historyr!r )rinstancepassives rrzQueryableAttribute.get_historys,yy$$ 8 $mH&=w  rc.|jjS)aReturn the 'info' dictionary for the underlying SQL element. The behavior here is as follows: * If the attribute is a column-mapped property, i.e. :class:`.ColumnProperty`, which is mapped directly to a schema-level :class:`_schema.Column` object, this attribute will return the :attr:`.SchemaItem.info` dictionary associated with the core-level :class:`_schema.Column` object. * If the attribute is a :class:`.ColumnProperty` but is mapped to any other kind of SQL expression other than a :class:`_schema.Column`, the attribute will refer to the :attr:`.MapperProperty.info` dictionary associated directly with the :class:`.ColumnProperty`, assuming the SQL expression itself does not have its own ``.info`` attribute (which should be the case, unless a user-defined SQL construct has defined one). * If the attribute refers to any other kind of :class:`.MapperProperty`, including :class:`.Relationship`, the attribute will refer to the :attr:`.MapperProperty.info` dictionary associated with that :class:`.MapperProperty`. * To access the :attr:`.MapperProperty.info` dictionary of the :class:`.MapperProperty` unconditionally, including for a :class:`.ColumnProperty` that's associated directly with a :class:`_schema.Column`, the attribute can be referred to using :attr:`.QueryableAttribute.property` attribute, as ``MyClass.someattribute.property.info``. .. seealso:: :attr:`.SchemaItem.info` :attr:`.MapperProperty.info` )rninfors rrzQueryableAttribute.info sP###rrpColumnElement[_T_co]rqc|j}t|tsJ|jturd|i}n|j|j |d}|j j} trt|tsJ|j}||S#t$r!}tjd|d||d}~wwxYw)Nentity_namespace) proxy_key proxy_ownerrzWhen interpreting attribute "z\" as a SQL expression, expected __clause_element__() to return a ClauseElement object, got: )_entity_namespace isinstancerGrl_UNKNOWN_ATTR_KEYrrn__clause_element__rr` _annotateAttributeErrorrInvalidRequestError)rrrceannoaes r_memoized_attr_expressionz,QueryableAttribute._memoized_attr_expressionGs 11*K888 88( (-/?@K"XX#11$4K __ / / 1 %!"m444<inspectrs)rrs rrzQueryableAttribute.of_typesV! KK HH   ..v6&&v.//  rc ttr&t|jtjsJt dt j|D}t|j|j|j|j|jj||j|j|zS)Nc3dK|](}tjtj|*ywr)rDexpectrEWhereHavingRole).0clauses r z*QueryableAttribute.and_..s+    U22F ; s.0r)rrrnrV Comparatortupler?coerce_generator_argrjrkrlrrmand_rrrs)rclausesexprss rrzQueryableAttribute.and_s doo/C/N/NO OO 33G<   " KK HH   +t++U3MM//%7  rc t|j|j|j|j|j |j |jSr)rjrkrlrrmrnrrrsrkws r_clonezQueryableAttribute._clonesD! KK HH   MM//  rc@|jj|Sr)rlabel)rnames rrzQueryableAttribute.labels&&(..t44rc.||jg|i|Srrnropotherkwargss roperatezQueryableAttribute.operates$//4E4V44rc *|||jfi|Srrrs rreverse_operatez"QueryableAttribute.reverse_operates%3F33rc@|jj||duS)N) optimisticFrm hasparent)rstaters rrzQueryableAttribute.hasparents#yy""5Z"@MMrc|fSrrs r_column_strategy_attrsz)QueryableAttribute._column_strategy_attrss wrc B tjj||S#t$rYnwxYw t |j |S#t$rM}tdt |jdt |j jd|d||d}~wwxYw)NNeither object nor  object associated with  has an attribute r? MemoizedSlots __getattr__rgetattrrntype__name__)rrlerrs rrzQueryableAttribute.__getattr__s %%11$< <    4??C0 0  J'')22    s$" ..A BABBcL|jjd|jSN.rkrrlrs r__str__zQueryableAttribute.__str__"++&&'q 33rc.|jjSrrnrors r_memoized_attr_propertyz*QueryableAttribute._memoized_attr_propertys'''r)NNr)rk_ExternalEntityType[_O]rlryr{_InternalEntityType[_O]rnr}rmzOptional[AttributeImpl]rr~rr)returnrrbool)rrrr7rHistory)rr])rzColumnElement[_T])rr^)rrz)rr_)rr)rzList[FromClause])rrrz(Sequence[Tuple[_DMLColumnArgument, Any]])rzAliasedInsp[Any]rrK)rz_EntityType[_T]rQueryableAttribute[_T])rz_ColumnExpressionArgument[bool]rzQueryableAttribute[bool])rrrr)rrrz Label[_T_co])rrbrrrrrzColumnElement[Any]Frrhrrrrrz!Sequence[QueryableAttribute[Any]])rlryrrrry)rzOptional[MapperProperty[Any]]))r __module__ __qualname____doc__ __slots__ is_attribute__annotations____visit_name__rrFExtendedInternalTraversal dp_stringdp_multirIdp_clauseelement_list_cache_key_traversalrrorr4rrrrrrrrrrrrrrrrrrrrrrrrrjrjsz$ IL33 $$ H** 000044 2N)-6::<$='$=$=. $= 5 $= & $=4$=8$=N 22<<= (<<EEF X77@@A H66LLM   &&5@  &1  '$'$R %$%$ %D  ""66--:: 1:    7 ! *  555(+57:5 5 44'*4694 4 =BN'N59N N (4(rrjcVt|r|j|||St||Sr)r_get_from_serializedr)rl mapped_classr{rs rrrs.\***3 lKKvs##rceZdZdZdZdZ ejd dZejd dZejd fd ZddZ ddZ e dd Z e dd Z dd Z xZS)InstrumentedAttributezClass bound instrumented attribute which adds basic :term:`descriptor` methods. See :class:`.QueryableAttribute` for a description of most features. rTc|jSrrvrs rrzInstrumentedAttribute.__doc__s yyrc||_yrrrs rrzInstrumentedAttribute.__doc__s  rct|Sr)superr)clsrs rrzInstrumentedAttribute.__doc__s wrcd|jjt|t||dyr)rmsetr!r )rrrs r__set__zInstrumentedAttribute.__set__s% 8 $mH&=ud rc`|jjt|t|yr)rmdeleter!r )rrs r __delete__z InstrumentedAttribute.__delete__ s  1=3JKrcyrrrrowners r__get__zInstrumentedAttribute.__get__#s(+rcyrrr+s rr-zInstrumentedAttribute.__get__(s>Arc$||St|}|jjr|j|vr||jS t |}|jj||S#t $r}t j||d}~wwxYwr) r rmsupports_populationrlr!rorm_excUnmappedInstanceErrorget)rrr,dict_rrs rr-zInstrumentedAttribute.__get__+s  Kh' 99 ( (TXX->? " G&x099==. ." G33H=3F Gs A++ B4B  B)rr)rrrNone)robjectrrrr5rr6rr5)rr5r,rrzInstrumentedAttribute[_T_co])rr6r,rrre)rOptional[object]r,rrz*Union[InstrumentedAttribute[_T_co], _T_co])rr rrr inherit_cacher?rw_hybridpropertysetter classlevelr&r)r r- __classcell__rs@rrrsIM   ^^  L++%(+ %++AA/(/14/ 3/rr)frozencpeZdZUdejfgZded<dZded<dZded<dZ ded <e d Z y ) AdHocHasEntityNamespacerz ClassVar[_TraverseInternalsType]_traverse_internals)rrzFzClassVar[bool] is_mapperis_aliased_classc.|jjSr)rrrs rrz(AdHocHasEntityNamespace.entity_namespaceHs%%666rN) rr rrIdp_has_cache_keyrBrrrCrDrorrrrrArA<sW /@@A=9 'I// %I~%',n, 77rrAcGfddtt}tjdz|_t j |td|S)zCreate an QueryableAttribute / user descriptor hybrid. Returns a new QueryableAttribute type that delegates descriptor behavior and getattr() to the given descriptor. cDeZdZdZdZ d ddZedZedZdZ de jjfd e jjfgZdd Zed Zed Zed Zej&dZdZdZdZddZfdZy)'create_proxied_attribute..ProxyzPresents the :class:`.QueryableAttribute` interface as a proxy on top of a Python descriptor / :class:`.PropComparator` combination. rNrlct||_||_||_||_||_||_|x|_|_yr)rkrl descriptororiginal_property _comparator_adapt_to_entityrvr)rrkrlrKrnrdocrLs rrz0create_proxied_attribute..Proxy.__init__fs?!DKDH(DO%6D ")D $3D !'* *DI rcDtj|jdSNF)raiseerrr>rrkrs rrz5create_proxied_attribute..Proxy._parententityx%%dkkEB BrcDtj|jdSrQrSrs rrpz.create_proxied_attribute..Proxy.parent|rTrTrc@|j}|y|jSNr)rLr)rprops rrz>create_proxied_attribute..Proxy._column_strategy_attrss$))D|2244rc|jduxr4t|j|jjj Sr)rLrrkrlrmrrs rrz:create_proxied_attribute..Proxy._impl_uses_objectss;&&d2EDKK277DD rct|jdr|jjSt|jS)Nr)hasattrrMrrArs rrz9create_proxied_attribute..Proxy._entity_namespaces7t''9''555/t/A/ABBrc.|jjSrrrs rroz0create_proxied_attribute..Proxy.propertys??++ +rct|jr|j|_|jr*|jj|j|_|jSr)callablerMrNrrs rrnz2create_proxied_attribute..Proxy.comparatorsZ(()#'#3#3#5 $$#'#3#3#C#C))$ ## #rc||j|j|j|j|j|Sr)rrrlrKrMrs rrz7create_proxied_attribute..Proxy.adapt_to_entitys6>>&&    rc|j|j|j|j|j|j |j S)N)rrL)rrkrlrKrMrNrLrs rrz.create_proxied_attribute..Proxy._clonesH>>   $ 5 5"&"8"8 " rcb|jj||}||jur||S|Sr)rKr-)rrr,retvals rr-z/create_proxied_attribute..Proxy.__get__s5__,,Xu=F(X-=  rcL|jjd|jSrrrs rrz/create_proxied_attribute..Proxy.__str__s"kk**+1TXXJ7 7rc  tjj||S#t$rYnwxYw t |S#t$r}|dk(r td| |j } t ||cYd}~S#t$rC}tdt jdt |jd|d||d}~wwxYw#t$r-}tdt jd|d||d}~wwxYwd}~wwxYw)zNDelegate __getattr__ to the original descriptor and/or comparator.rnNrrrrz; object nor unconfigured comparator object associated with r)r attributerrnerr3err2rKs rrz3create_proxied_attribute..Proxy.__getattr__s ))55dIFF!   $z955! $ ,(6C?$!%J $&z9==) $,!%Z 0 9 9 $Z 0 9 9 $ )   $ $ $& ( +44dIG    $sc# // ? DD C' A82D8 C>B??CD C=(C88C==DD)NNN)rkrxrlryrKrrnr}rzOptional[AliasedInsp[Any]]rOrrLz#Optional[QueryableAttribute[_T_co]]r r )rr rrrsrrorrp_is_internal_proxyrFrrrrrrrr?memoized_propertyrnrrr-rr)rKsrProxyrIYs@ ;?!%EI +, + +  + 9  + 8  + + C +$  C  C  C  C"H66@@ A h@@II J   5      C  C  ,  ,    $  $    8( $rrjrK)r from_instance)rjrerrr?monkeypatch_proxied_specials)rKrjs` rcreate_proxied_attributermMsT[$"5)[$z*%..8EN%% tJl* LrREMOVEAPPENDREPLACE BULK_REPLACEMODIFIEDc8eZdZdZdZddZdZedZdZ y) AttributeEventTokenaA token propagated throughout the course of a chain of attribute events. Serves as an indicator of the source of the event and also provides a means of controlling propagation across a chain of attribute operations. The :class:`.Event` object is sent as the ``initiator`` argument when dealing with events such as :meth:`.AttributeEvents.append`, :meth:`.AttributeEvents.set`, and :meth:`.AttributeEvents.remove`. The :class:`.Event` object is currently interpreted by the backref event handlers, and is used to control the propagation of operations across two mutually-dependent attributes. .. versionchanged:: 2.0 Changed the name from ``AttributeEvent`` to ``AttributeEventToken``. :attribute impl: The :class:`.AttributeImpl` which is the current event initiator. :attribute op: The symbol :attr:`.OP_APPEND`, :attr:`.OP_REMOVE`, :attr:`.OP_REPLACE`, or :attr:`.OP_BULK_REPLACE`, indicating the source operation. rmr parent_tokencV||_||_|jj|_yrru)rattribute_implrs rrzAttributeEventToken.__init__$s""  II22rct|txr3|j|juxr|j|jk(Sr)rrtrmr)rrs r__eq__zAttributeEventToken.__eq__)s< u1 2 $ dii' $DGG# rc.|jjSr)rmrlrs rrlzAttributeEventToken.key0syy}}rc8|jj|Srr)rrs rrzAttributeEventToken.hasparent4syy""5))rN)rxr|rz util.symbol) rr rrrrrzrorlrrrrrtrts18-I3  *rrtc<eZdZUdZded<ded<ded<ded<ded<dZd ed <d ed <d ed < d! d"dZdZd#dZdZ dZ e e e Z d$ d%dZ d&dZef d'dZef d(dZ d)dZef d*dZ d+dZef d,dZef d,dZef d,dZd ed df d-dZd.dZef d*dZd Zy )/r|z4internal implementation for instrumented attributes.r collectiondefault_accepts_scalar_loaderrr0dynamicFrt_replace_token _remove_token _append_tokenNc  r||_||_||_||_||_|xs||_| |_|tj|_ n||_ | | |_ n|j|_ | jdd} | |_ |rd|j_| |_t!|t"|_y)aConstruct an AttributeImpl. :param \class_: associated class :param key: string name of the attribute :param \callable_: optional function which generates a callable based on a parent instance, which produces the "default" values for a scalar or collection attribute when it's first accessed, if not present already. :param trackparent: if True, attempt to track if an instance has a parent attached to it via this attribute. :param compare_function: a function that compares two values which are normally assignable to this attribute. :param active_history: indicates that get_history() should always return the "old" value, even if it means executing a lazy callable upon attribute change. :param parent_token: Usually references the MapperProperty, used as a key for the hasparent() function to identify an "owning" attribute. Allows multiple AttributeImpls to all match a single owner attribute. :param load_on_unexpire: if False, don't include this attribute in a load-on-expired operation, i.e. the "expired_attribute_loader" process. The attribute can still be in the "expired" list and be considered to be "expired". Previously, this flag was called "expire_missing" and is only used by a deferred column attribute. :param send_modified_events: if False, the InstanceState._modified_event method will have no effect; this means the attribute will never show up as changed in a history entry. N_deferred_historyFT)rkrl callable_rw trackparentrvsend_modified_eventsoperatoreqis_equalaccepts_scalar_loaderrpoprrload_on_unexpirert OP_MODIFIED_modified_token)rrkrlrrwrcompare_functionactive_historyrvrrrrrs rrzAttributeImpl.__init__Ksv "  &(0D$8!  #$KKDM,DM ,)>D &)-)K)KD &"JJ':EB!2 ,0DMM ) 024Er) rkrlrrwrrvrrrrrrcL|jjd|jSrrrs rrzAttributeImpl.__str__rrc.|jjS)z(Backwards compat for impl.active_historyrwrrs r_get_active_historyz!AttributeImpl._get_active_historys}},,,rc&||j_yrrrs r_set_active_historyz!AttributeImpl._set_active_historys(- %rcd}|jsJ||jjt|j|duS)a4Return the boolean value of a `hasparent` flag attached to the given state. The `optimistic` flag determines what the default return value should be if no `hasparent` flag can be located. As this function is used to determine if an instance is an *orphan*, instances that were loaded from storage should be assumed to not be orphans, until a True/False value for this flag is set. An instance attribute that is loaded by a callable function will also not have a `hasparent` flag. 6This AttributeImpl is not configured to track parents.F)rparentsr3idrv)rrrmsgs rrzAttributeImpl.hasparentsI$G$$ MM  b!2!23Z @ M rc d}|jsJ|t|j}|r||j|<y||jvrx|j|}|dure|j|jk7rL|j ;t jdt|dt|d|jdyd|j|<y)zSet a boolean flag on the given item corresponding to whether or not it is attached to a parent object via the attribute represented by this ``InstrumentedAttribute``. rFNzRemoving state z from parent state z along attribute 'zV', but the parent record has gone stale, can't be sure this is the most recent parent.) rrrvrrlobjr1StaleDataErrorr;)rr parent_staterrid_ last_parents r sethasparentzAttributeImpl.sethasparentsG$$""# !-EMM# emm##mmC0  u,#<+;+;;"(0%44!*% 0 ), 7 $   !&EMM# rctrNotImplementedErrorrrr4rs rrzAttributeImpl.get_historys "##rct)aReturn a list of tuples of (state, obj) for all objects in this attribute's current state + history. Only applies to object-based attributes. This is an inlining of existing functionality which roughly corresponds to: get_state_history( state, key, passive=PASSIVE_NO_INITIALIZE).sum() rrs rget_all_pendingzAttributeImpl.get_all_pendings *"##rc|j|vsJdd}|jjD]}||||}|tus|}|S)z=Produce an empty value for an uninitialized scalar attribute.O_default_value should only be invoked for an uninitialized or expired attributeN)rlrw init_scalarr)rrr4rfnrets r_default_valuezAttributeImpl._default_valuesd xxu$  1 $ --++ BUE5)C*$   rc|j|vr||jS|j}||jvs|j|tur]|tzstS|j |||}|tus|tur|S|t ur ||S|tur|j|||S|tzstS|j||S#t$r}td|z|d}~wwxYw)zRetrieve a value from the given object. If a callable is assembled on this object's attribute, and passive is False, the callable will be executed and the resulting value will be set as the new value for this attribute. z=Deferred loader for attribute %r failed to populate correctlyN) rlcommitted_stater,rr3_fire_loader_callablesrKeyErrorrset_committed_valuerr)rrr4rrlrrs rr3zAttributeImpl.get1s 88u ? "((C5000((-9-,,33E3H--(1B Ll*#$Sz)*,33E5%HHW$**5%88$#&(*-. # ##s C C(C##C(c|jr,|jr ||jvr|j||S||jvr|j|}|||S|j r|j ||St Sr)rrexpired_attributes _load_expired callablesrr)rrrlrrs rrz$AttributeImpl._fire_loader_callables^s|  & &%%u///&&ug6 6 EOO #,IUG, , ^^>>%1 1 rc0|j|||||yNrr%rrr4r initiatorrs rappendzAttributeImpl.appendos uiArc2|j||d|||y)N)r check_oldrrs rremovezAttributeImpl.removeys"  5$ 7e  rc 4|j||d|||dy)NT)rrrrrs rrzAttributeImpl.pops*       rctrr)rrr4rrrrrs rr%zAttributeImpl.sets "##rctrr)rrr4s rr(zAttributeImpl.deletes !##rc|j|jvr$|j|j}|tury|S|j|||S)z,return the unchanged value of this attributeNr)rlrr,r3)rrr4rrs rget_committed_valuez!AttributeImpl.get_committed_valuesO 88u,, ,))$((3E  88E5'8: :rc^|||j<|j||jg|S)z=set an attribute value on the given instance and 'commit' it.)rl_commit)rrr4rs rrz!AttributeImpl.set_committed_values* dhh edhhZ( r)FNFNTTN)rkrrlryrOptional[_LoaderCallable]rw"_Dispatch[QueryableAttribute[Any]]rrrzOptional[Callable[..., bool]]rrrvOptional[AttributeEventToken]rrrrrzOptional[bool]rrr r r )rrhrrhrrrr5rrhr4rOrr7rrrrhr4rOrr7r_AllPendingType)rrhr4rOrr)rrhr4rOrr7rr)rrhrlryrr7rr rrhr4rOrrrrrr7rr5rrhr4rOrrrrrr7rrrrrr5rrhr4rOrr5)rr rrr_is_has_collection_adapterrrrrrrorrrr4rr2rrr3rrrrr%r(rrrrrr|r|<s>#'' M!&''&&&&":>$6:!%%)04SF'SFSF- SF 5 SF  SF8SFSF4SFSF#SF .SFSFj I4- .13FGN=B ' 59  2)'!)'))' )'  )'^ + $!$$ $  $ 5 $!$$ $  $.'0= , + +9!+9+9 +9 +9Z'.1B ueY<$*<*< = >rr)rrhr4Dict[str, Any]rr7rr)rrhr4rrrrrrr7rr8rrrr5 rrhr4rOrrdrrrrrrd rrhr4rOrrrrrr5)rr rrrrr0r~rrrr(r4rr%rrr=r>s@rrrs<B$(!LJGBIBK. + K!KK K  K048*&* !    1    $    , !      1   >!>> > 1 >  >rrceZdZdZdZdZdZdZdZd dZ e f d dZ e f ddZ de ddf dd Z dd Z dd Zy)ScalarObjectAttributeImplzrepresents a scalar-holding InstrumentedAttribute, where the target object is also instrumented. Adds events to delete/set operations. FTrc|jjr'|j||ttzt z}n-|j||t tz t ztz}|j||||j|j|jt}|tur$|tur|jtd|zyyy)Nrr)rwrr3r5r(r#r0rr+rrrrlr,r3rrs rr(z ScalarObjectAttributeImpl.delete5s == ( (((/()C(((72()C ueS$2D2DE99TXXx0  ,, ! !BT!IJ J"- !rc|j|vr||j}n4|tzr |tz}|j|||}|turtS|j st j|||S|jj|jt}|turB|ttztztztzz}|j||j|}t j||||S)Nr)original)rlrr3r3rrrfrom_object_attributer _NO_HISTORYr5r(r#r+rr)rrr4rrrloader_passives rrz%ScalarObjectAttributeImpl.get_historyUs 88u DHHoG 7"hhueWh=G++$$%%00ugF F,,00;GH,,!(+"#,-, ," 66488^00eWx1 rc|j|vr||j}n |tzr|j|||}ngS||tur|turt ||fg}ndg}|j|j vrK|j |j}|0|tur(|tur ||ur|jt ||f|S)Nr)NN)rlrr3r3r,r!rr)rrr4rrrrs rrz)ScalarObjectAttributeImpl.get_all_pendingws 88u DHHoG | #hhueWh=GI  00x'"7+W56C.C 88u,, ,,,TXX6H$$55H,G+ N84h?@ rNc |jjr'|j||ttzt z}n-|j||t tz t ztz}|@|tur8||ur4|rytdt|dt|d|jd|j|||||}|||j<y)z'Set a value on the given InstanceState.rNzObject z not associated with z on attribute '')rwrr3r5r(r#r0rr+r3 ValueErrorr"r;rlrrs rr%zScalarObjectAttributeImpl.sets == ( (((/()C(((72()C  !,,$ #I. %0@$((L ''ueS)Ldhhrc|jr+|dttfvr|jt ||d|j j D]}||||xs |j|j|||y)NF) rr3r,rr!rwrrrrs rrz+ScalarObjectAttributeImpl.fire_remove_events      . !   nU3UE B--&& >B ueY<$*<*< = > eT51rc^|jr/||ur+|dttfvr|jt ||d|j j D]}|||||xs |j}|j||||jr||jt ||d|S)NFT) rr3r,rr!rwr%rrrs rrz,ScalarObjectAttributeImpl.fire_replace_events   u$!:* !!.":E5I--## Buh (HT5H5HE  eT84    !!."7E rrrrrrr)rr rrrrr0r~rr(r4rr2rr%rrrrrrr&sc%*!LJIKH + !     L 5 "!"" "  "R48*+ !+ +  + 1 +  + + +  + Z2!22 2 1 2  2&!    1  rrc8eZdZUdZded<dZ d dZe d ddZe d ddZe d ddZd e jf dd Zd e jd d df dd Z y )HasCollectionAdapterrrr~Tctrrrrr~adapter fire_events r_dispose_previous_collectionz1HasCollectionAdapter._dispose_previous_collections "##rcyrrrrr4 user_datars rget_collectionz#HasCollectionAdapter.get_collection rcyrrrs rr z#HasCollectionAdapter.get_collectionr rcyrrrs rr z#HasCollectionAdapter.get_collection rNctrrrs rr z#HasCollectionAdapter.get_collection%s "##rFc trr) rrr4rrrrr_adapts rr%zHasCollectionAdapter.set0s "##r rrhr~rSrrTrrrr5.. rrhr4rOr z Literal[None]rz Literal[PassiveFlag.PASSIVE_OFF]rrT rrhr4rOr rSrr7rrT rrhr4rOr z$Optional[_AdaptedCollectionProtocol]rr7rzIUnion[Literal[LoaderCallableStatus.PASSIVE_NO_RESULT], CollectionAdapter]rrhr4rOrrrrrr7rrrrrrrr5) rr rrrrrr r r7r4r%rrrrrsI!%$!$/$# $  $  $ $'47  !  !  2      14"  !  .        ;>"  !  8        ;?*66 $! $ $8 $  $   $ 48*66 $! $ $ $ 1 $  $ $ $ $  $rrcyrr)rms r_is_collection_attribute_implr@s-0rr~ceZdZUdZdZdZdZdZdZde d<dZ dfd Z d Z e f d d Zef d!d Z d"d Z d"d Z d#dZ d$dZd%dZ d&dZ d'dZe f d(dZe f d(dZe f d(dZdejdddf d)dZ d*dZ d+dZ d,dZe d- d.dZ!e d- d/dZ!e de f d0dZ!de f d0dZ!xZ"S)1CollectionAttributeImplaA collection-holding attribute that instruments changes in membership. Only handles collections of instrumented objects. InstrumentedCollectionAttribute holds an arbitrary, user-specified container object (defaulting to a list) and brokers access to the CollectionAdapter, a "view" onto that object that presents consistent bag semantics to the orm layer independent of the user data implementation. TFrt_bulk_replace_token)copycollection_factoryrrr_duck_typed_asNc  t |||||f||d| | |j}||_||_t |t |_t |t|_ t |t|_ tj|j |_t|jddr9t!j"|dd} t!j"|dd} yy)N)rr _sa_linkerinit_collectionc&|j|yrr!targetr~collection_adapters rlinkz.CollectionAttributeImpl.__init__..links%%&89rdispose_collectionc&|jdyrr$r%s runlinkz0CollectionAttributeImpl.__init__..unlinks%%d+r)r"r_CollectionAttributeImpl__copyrrrt OP_APPENDrrrOP_BULK_REPLACErr?duck_type_collectionrrr= listens_for) rrkrlrrw typecallabler copy_functionrrr(r+rs rrz CollectionAttributeImpl.__init__es       $-      KKM! ".0yA0yA#6t_#M "77  # # %  4**L$ ?   t%6 7 :8 :  t%9 : ,; , @rcRtj|Dcgc]}|c}Scc}wr)rr')ritemys r__copyzCollectionAttributeImpl.__copys!&99$?@a@@@s $c|j|||}|tur_|tjzrF|j|j vr.|j |j}|j tStS|tjzr|j|j vsJtj|||Sr) r3r3r7rrl_pending_mutationsmerge_with_historyrrfrom_collection)rrr4rrpendings rrz#CollectionAttributeImpl.get_historys ((5%(9 ' '+???HH 8 8822488<11-@@$$>>>xxu'?'????**4@ @rc|j|vrgS||j}t|d}|j|jvr|j|j}|tur|Dcgc]}|duxr t |xsd|f}}|Dcgc]}|duxr t |xsd|f}}t |} t |} |D cgc] \} } | | vr| | fc} } |D cgc]\} } | | vs | | fc} } z|D cgc] \} } | | vr| | fc} } zS|D cgc]} t | | fc} Scc}wcc}wcc} } wcc} } wcc} } wcc} w)N _sa_adapter)rlrrr,r!dict) rrr4rrrccurrent_statesoriginal_states current_set original_setsos rrz'CollectionAttributeImpl.get_all_pendings 885 I/'=1 88u,, ,,,TXX6Hx'%"tm:):BdAF"" &#tm:):BdAF## #>2 #O4 %3 AqL0A +9N$!QAclear_with_event)rrr4r~s rr(zCollectionAttributeImpl.deletesT 885  eT8T:(( ; ##% $((Orc|j|vsJd|j|jvr|j|jS|j|\}}|j||S)z;Produce an empty collection for an un-initialized attributer)rl_empty_collections_initialize_collection _set_empty)rrr4rr s rrz&CollectionAttributeImpl._default_value&st xxu$  1 $ 88u// /++DHH5 5!88?9%rc|jj|j||j\}}|jj |||||fSr)rinitialize_collectionrlrrwr")rrrr~s rrTz.CollectionAttributeImpl._initialize_collection7sQ$mmAA HHeT44  %%eZA ""rcF|j||d|}|turZ|j||||t}|j|vsJd|j |jj |ytrt|tsJ|j||yN)r rrGz,Collection was loaded during event handling.) r r3rIr*rl_get_pending_mutationrrrrTappend_with_eventrrr4rrrr~s rrzCollectionAttributeImpl.appendBs(( 5D')  * ***ueYF+E% >= >%  ' ' 1 8 8 ?!*.?@@@  ( ( :rcZ|j||jd|}|turZ|j||||t|j |vsJd|j |j j|ytrt|tsJ|j||yrY) r r>r3rr*rlrZrrrrTremove_with_eventr\s rrzCollectionAttributeImpl.removeZs(( 5::w)  * *  " "5% v " N% >= >%  ' ' 1 8 8 ?!*.?@@@  ( ( :rcf |j|||||y#tttf$rYywxYwr)rrr IndexErrorrs rrzCollectionAttributeImpl.popps8  KKueYK HHj1   s 00c |x} } d} |j|\} } |r| j| j| } ntj| }|j}||urH| duxrdxs| j j }|jj }td|d|dt| dr| j} nV|turt| } | j} n2t| } n&tj| tur t|} t| }|j}|jj!|||| |j#||t$|t&j(zz }|t*ur|j-||}n|| ury|j/|||d|j0}| ||j2<t5j ||| | |j7|||dy) Nr5zIncompatible collection type: z is not z-like _sa_iterator)keysrT)r)rT _converterr?r/rrr TypeErrorr[rbr>listvaluesiterrrw bulk_replacer3r5r7r+r3rrr=rlrr)rrr4rrrrrriterable orig_iterablenew_keysnew_collectionr  setting_typereceiving_typegivenwanted new_valuesevtrold_collections rr%zCollectionAttributeImpl.sets$)(=%)$?$?$F! ((4)44X>#88B !%!4!4~5 D(#"7#--66 "0099F# &*8^4'446H!T)#H~H'0H#H~H  & &x 0D 8E{H(^ && ""5*c"Ihh  +w9M9M/MN  # #%%eU3C M !  eT35#dhh  #  ))%ndKrc|`|jj|jd|r|jj |||yyr)r=rSrrlrwr)rs rrz4CollectionAttributeImpl._dispose_previous_collectionsD  "   $$TXXt4  MM , ,UJ H rc*t|d}d|_y)Nr=T)r invalidated)rr~rs r_invalidate_collectionz.CollectionAttributeImpl._invalidate_collections*m4"rc|j|\}}|r|j|||j|j<|j ||jg|j|j vr|j |||d|j j|j}|j}|j}|D]} |j| |D]} |j| |S)z=Set an attribute value on the given instance and 'commit' it.T) rTappend_multiple_without_eventr>rlrr8rr added_items deleted_itemsappend_without_eventremove_without_event) rrr4rr~r r;addedremovedr4s rrz+CollectionAttributeImpl.set_committed_values !% ; ;E B I   4 4U ;( 488 edhhZ( 88u// /  ! !%y$ ?..22488s@rrrHs LJ$)!G,,I),VA + A!AA A  A: 5 +9!+9+9 +9  +9Z!  1    $ !    1     ;!;;1 ;  ;  ;";!;; ; 1 ;  ; ; '0= #" #' # = #" + ;!;; ; 1 ;  ; ;< + ;!;; ; 1 ;  ; ;8 + !  1    *48*66OL!OLOL OL 1 OL  OLOLOLOL OLb I! I/ I# I  I  I#4# # '0=FI #: $'47  !  !  2      14"  !  .        ;>*  !  8        ;?* %!%%8 %  %   %rrc2jjjfdfd}fd}fd}rtjd|dddntjd|dddtjd |dddy ) z6Apply listeners to synchronize a two-way relationship.c tdt|d|jd|jdjjd )Nz:Bidirectional attribute conflict detected: Passing object z to attribute "z(" triggers a modify event on attribute "z" via the backref "z".)rr;rvrm) child_stater child_implres r_acceptable_key_errz.backref_listeners.._acceptable_key_errJs> +&&&''++   rc||ur|S||tur|turt|t|}}|jj }|j s|js |j}n |j}||ur2|j|||jjt|t|t|} } | jj } |jur"|j| jur ||| | j} t| r | j nd} || ur,|| ur(| j#| | |j|t|Sr)r3r,r!r rrmr~rrrrrrr0rvrrr)rchildoldchildrr old_stateold_dictrmcheck_recursive_tokenr child_dictrcheck_append_tokencheck_bulk_replace_tokenrrl parent_implrvs r"emit_backref_from_scalar_set_eventz=backref_listeners..emit_backref_from_scalar_set_eventXs u L   11( x(h' I$$S)..D??4<<(,(;(;%(,(:(:% 55IIK--,   u%e$$K%,,S166J&&l:***2I2II#E9jA",!9!9 1<.. %!33%==!!IIK, " rcv|yt|t|}}|j j}|j ur"|j|jur  ||||j }t |r |jnd}||ur,||ur(|j|||j|t|Sr) r!r rrmrvrrrrrr0) rrrrrrrrrrrlrvs r)emit_backref_from_collection_append_eventzDbackref_listeners..emit_backref_from_collection_append_events = "0"7u9MZ  ((-22   " ", 6&&j.E.EE y* =(55-Z8  * * ! / /!99    (   rc(||tur|turt|t|}}|j j }|j s6|js*|j}|j} xr  j } n'|j}t|r |jnd}d} ||ur^||urY| r-tj|j j|s)|j!|||j#|t$yyyyyyy)NFr)r3r,r!r rrmr~rrrrrr? has_dupesr>rlrrr0) rrrrrrrcheck_remove_tokencheck_replace_tokencheck_for_dupes_on_removerlruselists r)emit_backref_from_collection_remove_eventzDbackref_listeners..emit_backref_from_collection_remove_events:  ..X%u%e$$K%,,S166J ((1C1C%/%=%="&0&?&?#,3,OK>..L..K  AF"H.`   5      .   LL1  r NO_HISTORYceZdZUdZded<ded<ded<ddZddZddZdd Zdd Z dd Z dd Z dd Z e ddZe ef ddZe ddZy)raA 3-tuple of added, unchanged and deleted values, representing the changes which have occurred on an instrumented attribute. The easiest way to get a :class:`.History` object for a particular attribute on an object is to use the :func:`_sa.inspect` function:: from sqlalchemy import inspect hist = inspect(myobject).attrs.myattribute.history Each tuple member is an iterable sequence: * ``added`` - the collection of items added to the attribute (the first tuple element). * ``unchanged`` - the collection of items that have not changed on the attribute (the second tuple element). * ``deleted`` - the collection of items that have been removed from the attribute (the third tuple element). zUnion[Tuple[()], List[Any]]r unchangeddeletedc|tk7Sr)rrs r__bool__zHistory.__bool__- s }$$rcft|jxs |jxs |j S)zhReturn True if this :class:`.History` has no changes and no existing, unchanged state. )rrrrrs remptyz History.empty0 s( 3t||FGGGrcf|jxsg|jxsgz|jxsgzS)z3Return a collection of added + unchanged + deleted.)rrrrs rsumz History.sum8 s1ZZ 2$.."6B 74<<;M2 N rcD|jxsg|jxsgzS)z)Return a collection of added + unchanged.)rrrs r non_deletedzHistory.non_deleted? s!  bT^^%9r::rcD|jxsg|jxsgzS)z+Return a collection of unchanged + deleted.)rrrs r non_addedzHistory.non_addedD s!$");<) r#rerrrr?r@rArBrCrDrEs rr:zHistory.from_collection sj((,,Y]]KH h r2r? "'=1 x tG}b"- -  $r4="- -!4-6^A%6>$BN "4-6^A%6>$BO ~.K0L-Gtq!,1FG-Ctq!l1BC.Gtq!!;2FG HCGs0D/'D4$ D9 1D9 = D? D?  E#ENr)rz Sequence[Any])r Iterable[Any]rrrr)rr)rerrrhrrrr) rerrrhrrrrrr)rerrrhrrrr)rr rrrrrrrrrrr classmethodrrrr:rrrrr s0 '&** ((%H ; = 0   &3&&3"&3 &3  &3&3P $ $3,$3"$3 $3  $3  $3$3L * "     rrrc.tt|||S)a Return a :class:`.History` record for the given object and attribute key. This is the **pre-flush** history for a given attribute, which is reset each time the :class:`.Session` flushes changes to the current database transaction. .. note:: Prefer to use the :attr:`.AttributeState.history` and :meth:`.AttributeState.load_history` accessors to retrieve the :class:`.History` for instance attributes. :param obj: an object whose class is instrumented by the attributes package. :param key: string attribute name. :param passive: indicates loading behavior for the attribute if the value is not already present. This is a bitflag attribute, which defaults to the symbol :attr:`.PASSIVE_OFF` indicating all necessary SQL should be emitted. .. seealso:: :attr:`.AttributeState.history` :meth:`.AttributeState.load_history` - retrieve history using loader callables if the value is not locally present. )get_state_historyr!)rrlrs rrr sJ ^C0#w ??rc&|j||Sr)r)rrlrs rrr s   S' **rcTt|}t|}|j|||S)TODO)r%r! has_parent)r#rrlrrrs rrr s-s#G 3 E   eS* 55r)rOc @t|||||}t||fi||S)N)rnr{rO)register_descriptorregister_attribute_impl)rkrlrnr{rOrdescs rregister_attributer s/  3 DFC.2. Krc t|}|r-|jdd} |j|| xst} n|jdd} t d||j } |rt d|||| fi|} n5|rt |||| fd| i|} n!|rt|||| fi|} nt|||| fi|} | ||_ |rt|||||j|||S)Nr1rzType[WriteOnlyAttributeImpl]) r%rinstrument_collection_classrfrrwrrrrmrpost_configure_attribute) rkrlrr useobject impl_classbackrefrrfactoryr1rwrms rrr# s&v&G&&.:: D vvnd3 ,gcl.C.CH @t2J? C %'  & CH ;G KM  ( CH 02 #63 8JrJGCL'#,9 $$S) 3<rclt|}t||||}||_|j|||S)N)rnr{)r%rrinstrument_attribute)rkrlrnr{rOrrKs rrrV sAv&G& JJ   j1 rc8t|j|yr)r%uninstrument_attribute)rkrls runregister_attributerj sV33C8rcJt|}|j}t|||S)a4Initialize a collection attribute and return the collection adapter. This function is used to provide direct access to collection internals for a previously unloaded attribute. e.g.:: collection_adapter = init_collection(someobject, "elements") for elem in values: collection_adapter.append_without_event(elem) For an easier way to do the above, see :func:`~sqlalchemy.orm.attributes.set_committed_value`. :param obj: a mapped object :param key: string attribute name where the collection is located. )r!r>init_state_collection)rrlrr4s rr"r"n s&$ 3 E JJE s 33rcZ|j|j}trt|tsJ|j |d}| |j }|j|||d|j||}|j|||tj}|j|S)zInitialize a collection attribute and return the collection adapter. Discards any existing collection which may be there. NFr) rrmrrrrr=rrr r7r0 _reset_empty)rr4rlattrrrtr rs rrr s ==  " "D$ 4555 ))C C  ))%neL##E51I!%!4!4 ui)E)E"5"G  Nrct|t|}}|j|jj |||y)a[Set the value of an attribute with no history events. Cancels any previous history present. The value should be a scalar value for scalar-holding attributes, or an iterable for any collection-holding attribute. This is the same underlying method used when a lazy loader fires off and loads additional data from the database. In particular, this method can be used by application code which has loaded additional attributes or collections through separate queries, which can then be attached to an instance as though it were part of its original loaded state. N)r!r rrmr)rrlrrr4s rrr s8"(+]8-D5E MM#//ueDrct|t|}}|j|jj ||||y)asSet the value of an attribute, firing history events. This function may be used regardless of instrumentation applied directly to the class, i.e. no descriptors are required. Custom attribute management schemes will need to make usage of this method to establish attribute state as understood by SQLAlchemy. :param instance: the object that will be modified :param key: string name of the attribute :param value: value to assign :param initiator: an instance of :class:`.Event` that would have been propagated from a previous event listener. This argument is used when the :func:`.set_attribute` function is being used within an existing event listening function where an :class:`.Event` object is being supplied; the object may be used to track the origin of the chain of events. .. versionadded:: 1.2.3 N)r!r rrmr%)rrlrrrr4s r set_attributer s:<"(+]8-D5E MM#ueY?rct|t|}}|j|jj ||S)aZGet the value of an attribute, firing any callables required. This function may be used regardless of instrumentation applied directly to the class, i.e. no descriptors are required. Custom attribute management schemes will need to make usage of this method to make usage of attribute state as understood by SQLAlchemy. )r!r rrmr3rrlrr4s r get_attributer s9"(+]8-D5E ==  " " & &ue 44rct|t|}}|j|jj ||y)aQDelete the value of an attribute, firing history events. This function may be used regardless of instrumentation applied directly to the class, i.e. no descriptors are required. Custom attribute management schemes will need to make usage of this method to establish attribute state as understood by SQLAlchemy. N)r!r rrmr(rs r del_attributer s6"(+]8-D5E MM#""5%0rct|t|}}|j|j}|jj ||j |j||tdy)aMark an attribute on an instance as 'modified'. This sets the 'modified' flag on the instance and establishes an unconditional change event for the given attribute. The attribute must have a value present, else an :class:`.InvalidRequestError` is raised. To mark an object "dirty" without referring to any specific attribute so that it is considered within a flush, use the :func:`.attributes.flag_dirty` call. .. seealso:: :func:`.attributes.flag_dirty` T is_userlandN) r!r rrmrwmodifiedrrr,)rrlrr4rms r flag_modifiedr s\""(+]8-D5E ==  " "DMM5$"6"67 %xTBrcbt|t|}}|j|dtdy)aMark an instance as 'dirty' without any specific attribute mentioned. This is a special operation that will allow the object to travel through the flush process for interception by events such as :meth:`.SessionEvents.before_flush`. Note that no SQL will be emitted in the flush process for an object that has no changes, even if marked dirty via this method. However, a :meth:`.SessionEvents.before_flush` handler will be able to see the object in the :attr:`.Session.dirty` collection and may establish changes on it, which will then be included in the SQL emitted. .. versionadded:: 1.2 .. seealso:: :func:`.attributes.flag_modified` NTr)r!r rr,)rrr4s r flag_dirtyr s.("(+]8-D5E %xTBr) rlryrType[_O]r{rrrxrr)rKrrz&Callable[..., QueryableAttribute[Any]])rmr|rz"TypeGuard[CollectionAttributeImpl])reQueryableAttribute[Any]rlryrrrr5)rr6rlryrr7rr)rrhrlryrr7rrr ) r#rrrRrlryrrrr)rkrrlryrninterfaces.PropComparator[_T]r{rrOrrrrInstrumentedAttribute[_T])FNFNN)rkrrlryrrrrrrrzOptional[Type[AttributeImpl]]rrrrrr) rk Type[Any]rlryrnrr{rzrOrrr)rkrrlryrr5)rr6rlryrrT)rrhr4rOrlryrrT)rr6rlryrrrr5r) rr6rlryrrrrrr5)rr6rlryrr)rr6rlryrr5r7)r __future__r dataclassesrtypingrrrrrr r r r r rrrrrrrrr1r_typingrrBrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r=r>r?r@rAsqlsql_baserCrDrErF sql.cache_keyrG sql.visitorsrHrI util.typingrJrKrLrMrNrOrPrQrRrSrTrU relationshipsrVrrWrX writeonlyrY event.baserZ sql._typingr[r\r]r^sql.annotationr_ sql.elementsr`ra sql.operatorsrbsql.selectablercrdrer6rr_self_inspectsInspectionAttrPropComparatorJoinTargetRole OnClauseRole ImmutableSlotsMemoizedHasCacheKeyrrjrr dataclassrArmsymbolrr-rr.rrtAttributeEventEventr|rrrr attrgetterrrr frozensetrrrrrrrrrrrr"rrrrrrrrrrrs# *$'+02(&6"#>("*'#))#""'1,!#$,&,(7.*3$!1&70'10,$,+ T]sd3 (' ((6*: :; H e(uUe$    &&e(e(P $  $ $* $ % $  $</.u5</~d# 7k 7$ 7 nn+nb DKK ! DKK ! T[[ # $++n-dkk*% 0*0*f%@@F d>-d>NP 3PfB$B$J11 +1 %8H$7$7 $E!o%2Mo%dO&O-0O;?O Oddkk,' r"34blCDFjFRB# 3>%@ %@%@$/%@ %@RAL+ +$'+2=+ +:?6 66!$6266 6     .  *      &+/04!0 0 00) 0  0 . 00 00r   .  +   (94. &3:=6E.04 @@ @ @- @  @D 5 1C.Cr