gvi 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&Z d?d'Zd@d(ZdAd)Z dBd*ZdCd+Z dDd,Z! dEd-Z" dEd.Z# dF dGd/Z$dHd0Z%dId1Z&dJd2Z'y)KQueryableAttributeaBase 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 J/opt/hc_python/lib64/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 ;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)robjectrrrr2rr3rr2)rr2r)rrzInstrumentedAttribute[_T_co])rr3r)rrre)rOptional[object]r)rrz*Union[InstrumentedAttribute[_T_co], _T_co])rr r r r  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_namespaceEs%%666rN) rr r rIdp_has_cache_keyr?rr r@rArorrrrr>r>9sW /@@A=9 'I// %I~%',n, 77rr>cGfddtt}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. c eZdZdZdZ ddZedZedZdZ de jjfd e jjfgZed Zed Zed Zej$d ZdZdZdZddZfdZy)'create_proxied_attribute..ProxyzPresents the :class:`.QueryableAttribute` interface as a proxy on top of a Python descriptor / :class:`.PropComparator` combination. rNct||_||_||_||_||_||_|x|_|_yr)rkrl descriptororiginal_property _comparator_adapt_to_entityrvr )rrkrlrHrnrdocrIs rrz0create_proxied_attribute..Proxy.__init__cs?!DKDH(DO%6D ")D $3D !'* *DI rcDtj|jdSNF)raiseerrr>rrkrs rrz5create_proxied_attribute..Proxy._parententityu%%dkkEB BrcDtj|jdSrNrPrs rrpz.create_proxied_attribute..Proxy.parentyrQrTrlrc|jduxr4t|j|jjj Sr)rIrrkrlrmrrs rrz:create_proxied_attribute..Proxy._impl_uses_objectss;&&d2EDKK277DD rct|jdr|jjSt|jS)Nr)hasattrrJrr>rs rrz9create_proxied_attribute..Proxy._entity_namespaces7t''9''555/t/A/ABBrc.|jjSrrrs rroz0create_proxied_attribute..Proxy.propertys??++ +rct|jr|j|_|jr*|jj|j|_|jSr)callablerJrKrrs rrnz2create_proxied_attribute..Proxy.comparatorsZ(()#'#3#3#5 $$#'#3#3#C#C))$ ## #rc||j|j|j|j|j|Sr)rrrlrHrJrs rrz7create_proxied_attribute..Proxy.adapt_to_entitys6>>&&    rc|j|j|j|j|j|j |j S)N)rrI)rrkrlrHrJrKrIrs rrz.create_proxied_attribute..Proxy._clonesH>>   $ 5 5"&"8"8 " rcb|jj||}||jur||S|Sr)rHr*)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 attributerrnerr3err2rHs 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)NNNr )rr r r rsrrorrp_is_internal_proxyrFrrrrrrr?memoized_propertyrnrrr*rr)rHsrProxyrFVs !" +$  C  C  C  C"H66@@ A h@@II J       C  C  ,  ,    $  $    8( $rrdrH)r from_instance)rjrrrr?monkeypatch_proxied_specials)rHrds` rcreate_proxied_attributergJsTT$"3'T$l*%..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|_yrro)rattribute_implrs rrzAttributeEventToken.__init__s""  II22rct|txr3|j|juxr|j|jk(Sr)rrnrmr)rrs r__eq__zAttributeEventToken.__eq__s< u1 2 $ dii' $DGG# rc.|jjSr)rmrlrs rrlzAttributeEventToken.key&syy}}rc8|jj|Srr)rrs rrzAttributeEventToken.hasparent*syy""5))rN)rrr|rz util.symbol) rr r r r rrtrorlrrrrrnrns18-I3  *rrnc<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_loaderrr-dynamicFrn_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 trackparentrpsend_modified_eventsoperatoreqis_equalaccepts_scalar_loaderrypoprrload_on_unexpirern OP_MODIFIED_modified_token)rrkrlrrwrcompare_functionactive_historyrprrrrrs rrzAttributeImpl.__init__Asv "  &(0D$8!  #$KKDM,DM ,)>D &)-)K)KD &"JJ':EB!2 ,0DMM ) 024Er) rkrlrrwrrprrrrrrcL|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)rparentsr0idrp)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.) rrrprrlobjr.StaleDataErrorr;)rr parent_staterrid_ last_parents r sethasparentzAttributeImpl.sethasparentsG$$""# !-EMM# emm##mmC0  u,#<+;+;;"(0%44!*% 0 ), 7 $   !&EMM# rctrNotImplementedErrorrrr1rs 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)rrr1rfnrets r_default_valuezAttributeImpl._default_values_ 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)rrr1rrlrrs rr0zAttributeImpl.get's 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_callablesTs|  & &%%u///&&ug6 6 EOO #,IUG, , ^^>>%1 1 rc0|j|||||yNrr"rrr1r initiatorrs rappendzAttributeImpl.appendes uiArc2|j||d|||y)N)r check_oldrrs rremovezAttributeImpl.removeos"  5$ 7e  rc 4|j||d|||dy)NT)rrrrrs rrzAttributeImpl.pop{s*       rctrr)rrr1rrrrrs rr"zAttributeImpl.sets "##rctrr)rrr1s rr%zAttributeImpl.deletes !##rc|j|jvr$|j|j}|tury|S|j|||S)z,return the unchanged value of this attributeNr)rlrr,r0)rrr1rrs 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)rrr1rs rrz!AttributeImpl.set_committed_values* dhh edhhZ( r)FNFNTTN)rkrrlryrOptional[_LoaderCallable]rw"_Dispatch[QueryableAttribute[Any]]rrrzOptional[Callable[..., bool]]rrrpOptional[AttributeEventToken]rrrrrzOptional[bool]rrr rr)rrhrrhrrrr2rrhr1rOrr7rrrrhr1rOrr7r_AllPendingType)rrhr1rOrr)rrhr1rOrr7rr)rrhrlryrr7rr rrhr1rOrrrrrr7rr2rrhr1rOrrrrrr7rrrrrr2rrhr1rOrr2)rr r r r_is_has_collection_adapterrr rrrrorrrr4rr2rrr0rrrrr"r%rrrrrr|r|2s>#'' M!&''&&&&":>$6:!%%)04SF'SFSF- SF 5 SF  SF8SFSF4SFSF#SF .SFSFj I4- .13FGN=B ' 59  2)'!)'))' )'  )'^ + $!$$ $  $ 5 $!$$ $  $.'0= , + +9!+9+9 +9 +9Z'.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)rwrr0r5r(r#r0rr+rr|rrlr,r3rrs rr%z ScalarObjectAttributeImpl.delete+s == ( (((/()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)rlrr0r3rrrfrom_object_attributer _NO_HISTORYr5r(r#r+rr)rrr1rrrloader_passives rrz%ScalarObjectAttributeImpl.get_historyKs 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)rlrr0r3r,r!rr)rrr1rrrrs rrz)ScalarObjectAttributeImpl.get_all_pendingms 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 '')rwrr0r5r(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!rwrr|rrs rrz+ScalarObjectAttributeImpl.fire_remove_eventsz      . !   nU3UE B--&&B ueY<$*<*< =' eT51rc^|jr/||ur+|dttfvr|jt ||d|j j D]}|||||xs |j}|j||||jr||jt ||d|S)NFT) rr3r,rr!rwr"r{rrs rrz,ScalarObjectAttributeImpl.fire_replace_events   u$!:* !!.":E5I--##Buh (HT5H5HE$ eT84    !!."7E rrrrrrr)rr r r ryrr-rxr r%r4rr2rr"rrrrrrrsc%*!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 )HasCollectionAdapterrrrxTctrrrrrxadapter fire_events r_dispose_previous_collectionz1HasCollectionAdapter._dispose_previous_collections "##rcyrrrrr1 user_datars rget_collectionz#HasCollectionAdapter.get_collection rcyrrrs rrz#HasCollectionAdapter.get_collectionrrcyrrrs rrz#HasCollectionAdapter.get_collection rNctrrrs rrz#HasCollectionAdapter.get_collections "##rFc trr) rrr1rrrrr_adapts rr"zHasCollectionAdapter.set&s "##r rrhrxrSrrTrrrr2.. rrhr1rOrz Literal[None]rz Literal[PassiveFlag.PASSIVE_OFF]rrT rrhr1rOrrSrr7rrT rrhr1rOrz$Optional[_AdaptedCollectionProtocol]rr7rzIUnion[Literal[LoaderCallableStatus.PASSIVE_NO_RESULT], CollectionAdapter]rrhr1rOrrrrrr7rrrrr rrr2) rr r r rrrr rr7r4r"rrrrrsI!%$!$/$# $  $  $ $'47  !  !  2      14"  !  .        ;>"  !  8        ;?*66 $! $ $8 $  $   $ 48*66 $! $ $ $ 1 $  $ $ $ $  $rrcyrr)rms r_is_collection_attribute_implr6s-0rrxceZdZUdZdZdZdZdZdZde 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. TFrn_bulk_replace_token)copycollection_factoryr}r|r_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|yrrtargetrxcollection_adapters rlinkz.CollectionAttributeImpl.__init__..link~s%%&89rdispose_collectionc&|jdyrrrs runlinkz0CollectionAttributeImpl.__init__..unlinks%%d+r)rr_CollectionAttributeImpl__copyrrrn OP_APPENDr}rr|OP_BULK_REPLACErr?duck_type_collectionrrr= listens_for) rrkrlrrw typecallabler copy_functionrrr"r%rs rrz CollectionAttributeImpl.__init__[s       $-      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) r0r3r7rrl_pending_mutationsmerge_with_historyrrfrom_collection)rrr1rrpendings 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) rrr1rrrccurrent_statesoriginal_states current_set original_setsos rrz'CollectionAttributeImpl.get_all_pendings 885 I/'=1 88u,, ,,,TXX6Hx'%"$tm:):BdAF$" &#%tm:):BdAF% # #>2 #O4 %3$2DAqL0A$2 +9N.$!QA= >%  ' ' 1 8 8 ?!*.?@@@  ( ( :rcZ|j||jd|}|turZ|j||||t|j |vsJd|j |j j|ytrt|tsJ|j||yrS) rr8r3rr*rlrTrrrrTremove_with_eventrVs rrzCollectionAttributeImpl.removePs(( 5::w)  * *  " "5% v " N% >= >%  ' ' 1 8 8 ?!*.?@@@  ( ( :rcf |j|||||y#tttf$rYywxYwr)rrr IndexErrorrs rrzCollectionAttributeImpl.popfs8  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) Nr2zIncompatible collection type: z is not z-like _sa_iterator)keysrT)r)rN _converterr?r)rrr TypeErrorrUr\r8listvaluesiterrrw bulk_replacer0r5r7r+r3rrr7rlrr)rrr1rrrrrr iterable orig_iterablenew_keysnew_collectionr setting_typereceiving_typegivenwanted new_valuesevtrold_collections rr"zCollectionAttributeImpl.setvs$)(=%)$?$?$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)r7rMrrlrwr#rs rrz4CollectionAttributeImpl._dispose_previous_collectionsD  "   $$TXXt4  MM , ,UJ H rc*t|d}d|_y)Nr7T)r invalidated)rrxrs 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) rNappend_multiple_without_eventr8rlrr2rr added_items deleted_itemsappend_without_eventremove_without_event) rrr1rrxrr5addedremovedr.s rrz+CollectionAttributeImpl.set_committed_values !% ; ;E B I   4 4U ;( 488 edhhZ( 88u// /  ! !%y$ ?..22488s 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;rprm) child_stater child_implr_s r_acceptable_key_errz.backref_listeners.._acceptable_key_err@s> +&&&''++   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 rrmrxrzr{r|rrr}r0rprrr)rchildoldchildrr old_stateold_dictrmcheck_recursive_tokenr child_dictrcheck_append_tokencheck_bulk_replace_tokenrrl parent_implrps r"emit_backref_from_scalar_set_eventz=backref_listeners..emit_backref_from_scalar_set_eventNs 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 rrmrpr}rrrrr0) rrrrrrrrrrrlrps 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 rrmrxrzr|r{rrr? has_dupesr8rlrrr0) 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]]ry 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. )rryrrrs remptyz History.empty& s( 3t||FGGGrcf|jxsg|jxsgz|jxsgzS)z3Return a collection of added + unchanged + deleted.)ryrrrs rsumz History.sum. s1ZZ 2$.."6B 74<<;M2 N rcD|jxsg|jxsgzS)z)Return a collection of added + unchanged.)ryrrs r non_deletedzHistory.non_deleted5 s!  bT^^%9r::rcD|jxsg|jxsgzS)z+Return a collection of unchanged + deleted.)rrrs r non_addedzHistory.non_added: s!$");<r?s rr4zHistory.from_collection s|((,,Y]]KH h r2r? "'=1 x tG}b"- -  $r4="- -! A4-6^A%6>$B   "!A4-6^A%6>$B!  ~.K0L-G~tq!,1F~G-C~tq!l1B~C.Gtq!!;2FG HCGs0D/'D4$ D9 1D9 = D? D?  E#ENr)rz Sequence[Any])ry Iterable[Any]rrrr)rr)r_rrrhrrrr) r_rrrhrrrrrr)r_rrrhrrrr)rr r r rrrrrrrrr classmethodrrrr4rrrrr 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)rLc @t|||||}t||fi||S)N)rnr{rL)register_descriptorregister_attribute_impl)rkrlrnr{rLrdescs 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)Nr+rzType[WriteOnlyAttributeImpl]) r%rinstrument_collection_classr`rrwrrrrmrpost_configure_attribute) rkrlrr useobject impl_classbackrefrrfactoryr+rwrms 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%rr instrument_attribute)rkrlrnr{rLrrHs rrrL sAv&G& JJ   j1 rc8t|j|yr)r%uninstrument_attribute)rkrls runregister_attributer` 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!r8init_state_collection)rrlrr1s rrrd 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) rrmrrrrr7rrrr7r0 _reset_empty)rr1rlattrrrnrrs 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)rrlrrr1s 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")rrlrrrr1s 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 rrmr0rrlrr1s 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,)rrlrr1rms 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,)rrr1s r flag_dirtyr s.("(+]8-D5E %xTBr) rlryrType[_O]r{rrrxrr)rHrrz&Callable[..., QueryableAttribute[Any]])rmr|rz"TypeGuard[CollectionAttributeImpl])r_QueryableAttribute[Any]rlryrrrr2)rr3rlryrr7rr)rrhrlryrr7rrr) r rrrRrlryrrrr)rkrrlryrninterfaces.PropComparator[_T]r{rrLrrrrInstrumentedAttribute[_T])FNFNN)rkrrlryrrrrrrrzOptional[Type[AttributeImpl]]rrrrrr) rk Type[Any]rlryrnrr{rzrLrrr)rkrrlryrr2)rr3rlryrrT)rrhr1rOrlryrrTr) rr3rlryrrrrrr2)rr3rlryrr)rr3rlryrr2r4)r  __future__r dataclassesrtypingrrrrrr r r r r rrrrrrrrr.r_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.selectablercrdrer3rr_self_inspectsInspectionAttrPropComparatorJoinTargetRole OnClauseRole ImmutableSlotsMemoizedHasCacheKeyrrjrr dataclassr>rgsymbolrr'rr(rrnAttributeEventEventr|rrrr attrgetterrrr frozensetrrrrrrrrrrrrrrrrrrrrrrrs# *$'+02(&6"#>("*'#))#""'1,!#$,&,(7.*3$!1&70'10,$,+ T]sd3 (' ((6*: :; H b(uUe$    &&b(b(J $  $ $* $ % $  $</.u5</~d# 7k 7$ 7 gg+gT 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