
    ,hvi                   	   S r SSKJr  SSKrSSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSKJ!r!  SSKJ"r"  SSKJ#r#  SSKJ$r$  SS KJ%r%  SS!KJ&r&  SS"KJ'r'  SS#KJ(r(  SS$KJ)r)  SS%KJ*r*  SS&KJ+r+  SS'KJ,r,  SS(KJ-r-  SS)KJ.r.  SS*KJ/r/  SS+KJ0r0  SS,KJ1r1  SS-KJ2r2  SS.KJ3r3  SS/KJ4r4  SS0KJ5r5  SS1KJ6r6  SS2KJ7r7  SS3KJ8r8  SS4KJ9r9  SS5KJ:r:  SS6KJ;r;  SS7KJ<r<  SS8KJ=r=  SS9KJ>r>  SS:KJ?r?  SS;KJ@r@  S<S=KJArA  S<SKJr  S<S>KJBrB  S<S?KJCrC  S<S@KAJDrD  S<SAKAJErE  S<SBKFJrG  S<SCKFJHrH  S<SDKFJIrI  S<SEKFJJrJ  S<SFKFJKrK  S<SGKLJMrM  S<SHKNJOrO  S<SIKNJPrP  S<SJKQJRrR  S<SKKQJSrS  S<SLKQJTrT  \(       a  SSMKJUrU  SSNKJVrV  SSOKJWrW  SSPKJXrX  SSQKJYrY  SSRKJZrZ  SSSKJ[r[  SSTKJ\r\  SSUKJ]r]  SSVK^J_r_  SSWK`Jara  SSXKCJbrb  SSYKcJdrd  S<SZKeJfrf  S<S[KgJhrh  S<S\KgJiri  S<S]KgJjrj  S<S^KgJkrk  S<S_KlJmrm  S<S`KnJoro  S<SaKnJprp  S<SbKqJrrr  S<ScKsJtrt  \" Sd5      ru\" Se\SfSg9rv\\\Sh   \\w   4      rx\w" 5       ry\BR                   " Si Sj\\v   \?\v   \R                  \R                  \v   \JR                  \JR                  \GR                  \HGR                   \CGR                  \E5      5       r          SSk jr " Sl Sm\\v   5      r\GR
                  " SfSn9 " So Sp\M5      5       r    SSq jr\CGR                  " Sr5      r\CGR                  " Ss5      r\CGR                  " St5      r\CGR                  " Su5      r\CGR                  " Sv5      r " Sw Sx5      r\r\r " Sy Sz5      r " S{ S|\5      r " S} S~\5      r " S S5      r\(       a
      SS jrO\GR,                  " S5      r " S S\\5      r        SS jr\CGR                  " S5      r\" \" \85      \" \15      /5      r " S S\5      r\" SSS5      r\94       SS jjr\94       SS jjr S         SS jjrSS.             SS jjr     S                 SS jjrSS.           SS jjrSS jrSS jr        SS jrS r S         SS jjrSS jrSS jrSS jrSS jrg)zDefines instrumentation for class attributes and their interaction
with instances.

This module is usually not directly visible to user applications, but
defines a large part of the ORM's interactivity.


    )annotationsN)Any)Callable)cast)ClassVar)Dict)Iterable)List)
NamedTuple)Optional)overload)Sequence)Tuple)Type)TYPE_CHECKING)TypeVar)Union   )collections)exc)
interfaces)insp_is_aliased_class)_DeclarativeMapped)
ATTR_EMPTY)ATTR_WAS_SET)CALLABLES_OK)DEFERRED_HISTORY_LOAD)INCLUDE_PENDING_MUTATIONS)INIT_OK)instance_dict)instance_state)instance_str)LOAD_AGAINST_COMMITTED)LoaderCallableStatus)manager_of_class)Mapped)	NEVER_SET)NO_AUTOFLUSH)	NO_CHANGE)NO_KEY)NO_RAISE)NO_VALUE)NON_PERSISTENT_OK)opt_manager_of_class)PASSIVE_CLASS_MISMATCH)PASSIVE_NO_FETCH)PASSIVE_NO_FETCH_RELATED)PASSIVE_NO_INITIALIZE)PASSIVE_NO_RESULT)PASSIVE_OFF)PASSIVE_ONLY_PERSISTENT)PASSIVE_RETURN_NO_VALUE)PassiveFlag)RELATED_OBJECT_OK)SQL_OK)SQLORMExpression)	state_str   )event)
inspection)util)
dispatcher)EventTarget)base)	cache_key)	coercions)roles)visitors)HasCacheKey)_TraverseInternalsType)InternalTraversal)Literal)Self)	TypeGuard)_EntityType)_ExternalEntityType)_InstanceDict)_InternalEntityType)_LoaderCallable)_O)_AdaptedCollectionProtocol)CollectionAdapter)MapperProperty)RelationshipProperty)InstanceState)AliasedInsp)WriteOnlyAttributeImpl)	_Dispatch)_ColumnExpressionArgument)_DMLColumnArgument)	_InfoType)_PropagateAttrsType)_AnnotationDict)ColumnElement)Label)OperatorType)
FromClause_T_T_coT)bound	covariantInstanceState[Any]c                     \ rS rSr% SrSrSrS\S'   S\S'   S	\S
'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   Sr   S5             S6S jjr	S
\
R                  R                  4S\
R                  R                  4S\
R                  R                  4S\
R                  R                  4/rS7S jr\S8S j5       r\4     S9S jjr\S:S j5       rS\S'    S \S!'    S;S" jrS<S# jr\S=S$ j5       r\S>S% j5       rS?S& jr\S@S' j5       r    SAS( jrSBS) jrSCS* jr    SDS+ jr SES, jr!SFS- jr"        SGS. jr#        SGS/ jr$ SH     SIS0 jjr%SJS1 jr&SKS2 jr'SLS3 jr(S4r)g)MQueryableAttribute   a  Base 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_keyimpl
comparatorpropertyparent
expression_of_type_extra_criteria_slots_dispatch_propagate_attrs_docTz%dispatcher[QueryableAttribute[_T_co]]dispatch_ExternalEntityType[Any]rl   strrm   _InternalEntityType[Any]parententityAttributeImplrn    interfaces.PropComparator[_T_co]ro   "Optional[_InternalEntityType[Any]]rs   Tuple[ColumnElement[bool], ...]rt   Optional[str]rw   orm_instrumented_attributeNc                   Xl         X l        U=U l        U l        XPl        Uc   eX@l        X`l        Xpl        S U l        [        U5      nU(       ar  UR                   Ha  n	X);   d  M
  U R                  R                  X   R                  5        X   R                  R                  (       d  MP  SU R                  l        Mc     g g NT)rl   rm   _parententityrq   rn   ro   rs   rt   rw   r.   _basesrx   _update_active_history)
selfrl   rm   r|   ro   rn   of_typeextra_criteriamanagerrB   s
             Q/var/www/auris/envauris/lib/python3.13/site-packages/sqlalchemy/orm/attributes.py__init__QueryableAttribute.__init__   s     +77T[ 	%%%$-	&v.  ;MM))$)*<*<=y))9998<5	 '     r   c                    [         U R                  U R                  R                  R                  U R                  U R                  R
                  44$ N)_queryable_attribute_unreducerm   r   mapperrl   entityr   s    r   
__reduce__QueryableAttribute.__reduce__   sJ     *""))00""""))	
 	
r   c                .    U R                   R                  $ r   )rn   uses_objectsr   s    r   _impl_uses_objects%QueryableAttribute._impl_uses_objects   s    yy%%%r   c                `    U R                   R                  [        U5      [        U5      U5      $ r   )rn   get_historyr!   r    )r   instancepassives      r   r   QueryableAttribute.get_history  s,     yy$$8$mH&=w
 	
r   c                .    U R                   R                  $ )a  Return 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`

)ro   infor   s    r   r   QueryableAttribute.info
  s    P ###r   rq   ColumnElement[_T_co]rr   c                   U R                   n[        U[        5      (       d   eU R                  [        L a  SU0nOU R                  U R
                  US.nU R                  R                  5       n [        (       a  [        U[        5      (       d   eUR                  nU" U5      $ ! [         a$  n[        R                  " SU < SU< 35      UeS nAff = f)Nentity_namespace)	proxy_keyproxy_ownerr   zWhen interpreting attribute "z\" as a SQL expression, expected __clause_element__() to return a ClauseElement object, got: )_entity_namespace
isinstancerG   rm   _UNKNOWN_ATTR_KEYr   ro   __clause_element__r   r`   	_annotateAttributeErrorr   InvalidRequestError)r   r   r   ceannoaes         r   _memoized_attr_expression,QueryableAttribute._memoized_attr_expressionG  s      11*K888888((-/?@K "XX#11$4K __//1	%}!"m4444<<D $$  	)) 6:2? 		s   1.B' '
C1CCc                H    [         R                  " SU R                  S.5      $ )Norm)compile_state_pluginplugin_subject)r?   immutabledict_parentmapperr   s    r   _memoized_attr__propagate_attrs2QueryableAttribute._memoized_attr__propagate_attrsi  s(     !!(-"&"4"4
 	
r   c                    U R                   $ r   )r   r   s    r   r   $QueryableAttribute._entity_namespacet  s    !!!r   c                6    U R                  5       R                  $ r   )r   _annotationsr   s    r   r   QueryableAttribute._annotationsx  s    &&(555r   c                    U R                   $ r   )rr   r   s    r   r   %QueryableAttribute.__clause_element__|  s    r   c                .    U R                   R                  $ r   )rr   _from_objectsr   s    r   r    QueryableAttribute._from_objects  s    ,,,r   c                8    U R                   R                  U5      $ )z'Return setter tuples for a bulk UPDATE.)ro   _bulk_update_tuplesr   values     r   r   &QueryableAttribute._bulk_update_tuples  s    
 22599r   c                    U R                   (       a   eU R                  UR                  U R                  U R                  U R
                  R                  U5      US9$ )N)rn   ro   r|   )rs   	__class__r   rm   rn   ro   adapt_to_entityr   r   s     r   r   "QueryableAttribute.adapt_to_entity  sQ    ==  ~~""HH66G(  
 	
r   c           
         [        U R                  U R                  U R                  U R                  U R
                  R                  U5      [        R                  " U5      U R                  S9$ Nrn   ro   r   r   )
rj   rl   rm   r   rn   ro   r   r>   inspectrt   )r   r   s     r   r   QueryableAttribute.of_type  sV    !KKHH..v6&&v.//
 	
r   c           
        [         (       a+  [        U R                  [        R                  5      (       d   e[        S [        R                  " U5       5       5      n[        U R                  U R                  U R                  U R                  U R                  R                  " U6 U R                  U R                  U-   S9$ )Nc              3  l   #    U  H*  n[         R                  " [        R                  U5      v   M,     g 7fr   )rD   expectrE   WhereHavingRole).0clauses     r   	<genexpr>*QueryableAttribute.and_.<locals>.<genexpr>  s-      
< U22F;;<s   24r   )r   r   ro   rV   
Comparatortupler?   coerce_generator_argrj   rl   rm   r   rn   and_rs   rt   )r   clausesexprss      r   r   QueryableAttribute.and_  s     =doo/C/N/NOOOO 
33G<
 

 "KKHH++U3MM//%7
 	
r   c           
         [        U R                  U R                  U R                  U R                  U R
                  U R                  U R                  S9$ r   )rj   rl   rm   r   rn   ro   rs   rt   r   kws     r   _cloneQueryableAttribute._clone  sD    !KKHHMM//
 	
r   c                @    U R                  5       R                  U5      $ r   )r   label)r   names     r   r   QueryableAttribute.label  s    &&(..t44r   c                .    U" U R                   /UQ70 UD6$ r   ro   r   opotherkwargss       r   operateQueryableAttribute.operate  s     $//4E4V44r   c                (    U" X R                   40 UD6$ r   r   r   s       r   reverse_operate"QueryableAttribute.reverse_operate  s     %3F33r   c                8    U R                   R                  XS9SL$ )N)
optimisticFrn   	hasparent)r   stater   s      r   r   QueryableAttribute.hasparent  s!     yy""5"@MMr   c                L    [         R                  R                  X5      $ ! [         a     Of = f [	        U R
                  U5      $ ! [         aQ  n[        S[        U 5      R                  < S[        U R
                  5      R                  < SU < SU< 35      UeS nAff = f)NNeither  object nor  object associated with  has an attribute r?   MemoizedSlots__getattr__r   getattrro   type__name__)r   rm   errs      r   r  QueryableAttribute.__getattr__  s    	%%11$<< 			4??C00 
	  J'')22	 	
	s$   ! 
..A 
B#ABB#c                L    U R                   R                   SU R                   3$ N.rl   r
  rm   r   s    r   __str__QueryableAttribute.__str__  "    ++&&'q
33r   c                .    U R                   R                  $ r   ro   rp   r   s    r   _memoized_attr_property*QueryableAttribute._memoized_attr_property  s    '''r   )	rw   rt   rs   r   rl   ro   rn   rm   rq   )NN )rl   _ExternalEntityType[_O]rm   rz   r|   _InternalEntityType[_O]ro   r~   rn   zOptional[AttributeImpl]r   r   r   r   )returnr   r  bool)r   r   r   r7   r  History)r  r]   )r  zColumnElement[_T])r  r^   )r  r{   )r  r_   )r  r   )r  zList[FromClause])r   r   r  z(Sequence[Tuple[_DMLColumnArgument, Any]])r   zAliasedInsp[Any]r  rK   )r   z_EntityType[_T]r  QueryableAttribute[_T])r   z_ColumnExpressionArgument[bool]r  zQueryableAttribute[bool])r   r   r  r  )r   r   r  zLabel[_T_co])r   rb   r   r   r   r   r  zColumnElement[Any]Fr   rh   r   r  r  r  )rm   rz   r  r   r  rz   )r  zOptional[MapperProperty[Any]])*r
  
__module____qualname____firstlineno____doc__	__slots__is_attribute__annotations____visit_name__r   rF   ExtendedInternalTraversal	dp_stringdp_multirI   dp_clauseelement_list_cache_key_traversalr   rp   r   r4   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  __static_attributes__r  r   r   rj   rj      su   $I L33$$	H**
000044
 2N )-6::<$='$= $= .	$=
 5$= &$= 4$= 8$=N 
22<<=	(<<EEF	X77@@A	H66LLM	
 & & 5@

&1
	
 '$ '$R %$ %$ %D	
 " " 6 6 - -::	1:
	

7
	!
*	
555(+57:5	5
44'*4694	4 =BN'N59N	N
(4(r   rj   c                \    [        U5      (       a  UR                  XU5      $ [        X05      $ r   )r   _get_from_serializedr  )rm   mapped_classr|   r   s       r   r   r     s-     \****3lKKv##r   c                    ^  \ rS rSrSrSrSr \R                  SS j5       r\R                  SS j5       r\R                  SU 4S jj5       rSS jrSS	 jr\      SS
 j5       r\SS j5       r      SS jrSrU =r$ )InstrumentedAttributei  zClass bound instrumented attribute which adds basic
:term:`descriptor` methods.

See :class:`.QueryableAttribute` for a description of most features.


r  Tc                    U R                   $ r   rw   r   s    r   r&  InstrumentedAttribute.__doc__  s    yyr   c                    Xl         g r   r7  r   s     r   r&  r8    s    	r   c                   > [         TU ]  $ r   )superr&  )clsr   s    r   r&  r8    s    wr   c                d    U R                   R                  [        U5      [        U5      US 5        g r   )rn   setr!   r    )r   r   r   s      r   __set__InstrumentedAttribute.__set__  s%    		8$mH&=ud	
r   c                `    U R                   R                  [        U5      [        U5      5        g r   )rn   deleter!   r    )r   r   s     r   
__delete__ InstrumentedAttribute.__delete__  s     		1=3JKr   c                    g r   r  r   r   owners      r   __get__InstrumentedAttribute.__get__   s     (+r   c                    g r   r  rF  s      r   rH  rI  %  s    >Ar   c                4   Uc  U $ [        U5      nU R                  R                  (       a  U R                  U;   a  X0R                     $  [	        U5      nU R                  R                  XC5      $ ! [
         a  n[        R                  " U5      UeS nAff = fr   )	r    rn   supports_populationrm   r!   r   orm_excUnmappedInstanceErrorget)r   r   rG  dict_r   r  s         r   rH  rI  (  s     Kh'99((TXX->?"G&x0 99==.. " G33H=3FGs   A1 1
B;BBr7  )r  r   )r   r   r  None)r   objectr   r   r  rQ  r   rR  r  rQ  )r   rQ  rG  r   r  zInstrumentedAttribute[_T_co])r   rR  rG  r   r  re   )r   Optional[object]rG  r   r  z*Union[InstrumentedAttribute[_T_co], _T_co])r
  r#  r$  r%  r&  r'  inherit_cacher?   rw_hybridpropertysetter
classlevelr?  rC  r   rH  r0  __classcell__r   s   @r   r5  r5    s     IM 
  ^^   

L ++%(+	%+ + A A/(/14/	3/ /r   r5  )frozenc                  x    \ rS rSr% S\R
                  4/rS\S'   SrS\S'   Sr	S\S	'   Sr
S\S
'   \S 5       rSrg)AdHocHasEntityNamespacei9  r   z ClassVar[_TraverseInternalsType]_traverse_internals)r   r{   FzClassVar[bool]	is_mapperis_aliased_classc                .    U R                   R                  $ r   )r   r   r   s    r   r   (AdHocHasEntityNamespace.entity_namespaceE  s    %%666r   r  N)r
  r#  r$  r%  rI   dp_has_cache_keyr^  r)  r'  r_  r`  rp   r   r0  r  r   r   r]  r]  9  sW     
/@@A=9 
 'I// %I~%',n,7 7r   r]  c                   ^   " U 4S jS[         [           5      n[        T 5      R                  S-   Ul        [        R
                  " U[        T 5      ST S9  U$ )zCreate an QueryableAttribute / user descriptor hybrid.

Returns a new QueryableAttribute type that delegates descriptor
behavior and getattr() to the given descriptor.
c                  .  > \ rS rSrSrSr   SS jr\S 5       r\S 5       r	Sr
S	\R                  R                  4S
\R                  R                  4/r\S 5       r\S 5       r\S 5       r\R&                  S 5       rS rS rS rSS jrU 4S jrSrg)'create_proxied_attribute.<locals>.ProxyiV  zPresents the :class:`.QueryableAttribute` interface as a
proxy on top of a Python descriptor / :class:`.PropComparator`
combination.

r  Nc                h    Xl         X l        X0l        Xpl        X@l        XPl        U=U l        U l        g r   )rl   rm   
descriptororiginal_property_comparator_adapt_to_entityrw   r&  )r   rl   rm   rh  ro   r   docri  s           r   r   0create_proxied_attribute.<locals>.Proxy.__init__c  s3     !KH(O%6")$3!'**DIr   c                @    [         R                  " U R                  SS9$ NF)raiseerrr>   r   rl   r   s    r   r   5create_proxied_attribute.<locals>.Proxy._parententityu      %%dkkEBBr   c                @    [         R                  " U R                  SS9$ ro  rq  r   s    r   rq   .create_proxied_attribute.<locals>.Proxy.parenty  rs  r   Trm   r   c                    U R                   S L=(       a4    [        U R                  U R                  5      R                  R
                  $ r   )ri  r  rl   rm   rn   r   r   s    r   r   :create_proxied_attribute.<locals>.Proxy._impl_uses_objects  s;     &&d2 EDKK277DDr   c                    [        U R                  S5      (       a  U R                  R                  $ [        U R                  5      $ )Nr   )hasattrrj  r   r]  r   s    r   r   9create_proxied_attribute.<locals>.Proxy._entity_namespace  s:    t''99''555 /t/A/ABBr   c                .    U R                   R                  $ r   r  r   s    r   rp   0create_proxied_attribute.<locals>.Proxy.property  s    ??+++r   c                    [        U R                  5      (       a  U R                  5       U l        U R                  (       a*  U R                  R                  U R                  5      U l        U R                  $ r   )callablerj  rk  r   r   s    r   ro   2create_proxied_attribute.<locals>.Proxy.comparator  s]    (())#'#3#3#5 $$#'#3#3#C#C))$  ###r   c                |    U R                  UR                  U R                  U R                  U R                  U5      $ r   )r   r   rm   rh  rj  r   s     r   r   7create_proxied_attribute.<locals>.Proxy.adapt_to_entity  s6    >>&&   r   c           	         U R                  U R                  U R                  U R                  U R                  U R
                  U R                  S9$ )N)r   ri  )r   rl   rm   rh  rj  rk  ri  r   s     r   r   .create_proxied_attribute.<locals>.Proxy._clone  sH    >>   $ 5 5"&"8"8 "  r   c                b    U R                   R                  X5      nX0R                   L a  Uc  U $ U$ r   )rh  rH  )r   r   rG  retvals       r   rH  /create_proxied_attribute.<locals>.Proxy.__get__  s1    __,,X=F (X-=r   c                L    U R                   R                   SU R                   3$ r  r  r   s    r   r  /create_proxied_attribute.<locals>.Proxy.__str__  s"    kk**+1TXXJ77r   c                $  >  [         R                  R                  X5      $ ! [         a     Of = f [	        TU5      $ ! [         a  nUS:X  a  [        S5      Ue U R
                  n [	        X15      s SnA$ ! [         aG  n[        S[        T5      R                  < S[        U5      R                  < SU < SU< 35      UeSnAff = f! [         a0  n[        S[        T5      R                  < SU < SU< 35      UeSnAff = fSnAff = f)zBDelegate __getattr__ to the original descriptor and/or
comparator.ro   Nr  r  r  r  z; object nor unconfigured comparator object associated with r  )r   	attributer  ro   err3err2rh  s         r   r  3create_proxied_attribute.<locals>.Proxy.__getattr__  s   ))55dFF! $z955! $,(6C?$!%J$&z==) 
$, !%Z 0 9 9 $Z 0 9 9 $ )	  $	$
$ &  (  
+44dIG  	  $sd   " 
//? 
D	D
C)
A93D9
C
ACC

D

D+DDD

D)r&  rk  rj  rw   rl   rh  rm   ri  )NNNr"  )r
  r#  r$  r%  r&  rt   r   rp   r   rq   _is_internal_proxyrF   r+  r,  r-  r/  r   r   r?   memoized_propertyro   r   r   rH  r  r  r0  )rh  s   r   Proxyrf  V  s    	  !"	+$ 
	C 
	C 
	C 
	C " H66@@Ah@@IIJ 

 
	 
	 
	C 
	C 
	, 
	, 
			$ 
 	$				8(	$ (	$r   r  rh  )r   from_instance)rj   r   r	  r
  r?   monkeypatch_proxied_specials)rh  r  s   ` r   create_proxied_attributer  J  sT    T$"3' T$l *%..8EN%%tJl* Lr   REMOVEAPPENDREPLACEBULK_REPLACEMODIFIEDc                  B    \ rS rSrSrSrS	S jrS r\S 5       r	S r
Srg)
AttributeEventTokeni  a  A 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.

rn   r   parent_tokenc                R    Xl         X l        U R                   R                  U l        g r   r  )r   attribute_implr   s      r   r   AttributeEventToken.__init__  s    "	 II22r   c                    [        U[        5      =(       a8    UR                  U R                  L =(       a    UR                  U R                  :H  $ r   )r   r  rn   r   )r   r   s     r   __eq__AttributeEventToken.__eq__  s<    u12 $

dii'$DGG#	
r   c                .    U R                   R                  $ r   )rn   rm   r   s    r   rm   AttributeEventToken.key&  s    yy}}r   c                8    U R                   R                  U5      $ r   r   )r   r   s     r   r   AttributeEventToken.hasparent*  s    yy""5))r   N)r  r}   r   zutil.symbol)r
  r#  r$  r%  r&  r'  r   r  rp   rm   r   r0  r  r   r   r  r    s1    8 -I3

  *r   r  c                  v   \ rS rSr% SrS\S'   S\S'   S\S'   S\S'   S\S'   S	rS
\S'   S
\S'   S
\S'          S#                       S$S jjrSrS%S jr	S r
S r\" \
\5      r S&     S'S jjr        S(S jr\4       S)S jjr\4       S*S jjr      S+S jr\4       S,S jjr        S-S jr\4           S.S jjr\4           S.S jjr\4           S.S jjrS\SS	4               S/S jjrS0S jr\4       S,S  jjrS! rS"rg)1r}   i2  z4internal implementation for instrumented attributes.r  
collectiondefault_accepts_scalar_loaderr   rL  dynamicFr  _replace_token_remove_token_append_tokenNc                v   Xl         X l        X0l        X@l        XPl        U=(       d    U U l        Xl        Uc  [        R                  U l	        OX`l	        Ub  Xl
        OU R                  U l
        UR                  SS5      nXl        U(       a  SU R                  l        Xl        [!        U ["        5      U l        g)a  Construct 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)rl   rm   	callable_rx   trackparentr  send_modified_eventsoperatoreqis_equalaccepts_scalar_loaderr  popr  r   load_on_unexpirer  OP_MODIFIED_modified_token)r   rl   rm   r  rx   r  compare_functionactive_historyr  r  r  r  r   r  s                 r   r   AttributeImpl.__init__A  s    v " &(0D$8!#$KKDM,M ,)>&)-)K)KD&"JJ':EB!2,0DMM) 024Er   )rl   rm   r  rx   r  r  r  r  r  r  r  r  c                L    U R                   R                   SU R                   3$ r  r  r   s    r   r  AttributeImpl.__str__  r  r   c                .    U R                   R                  $ )z(Backwards compat for impl.active_historyrx   r   r   s    r   _get_active_history!AttributeImpl._get_active_history  s     }},,,r   c                $    XR                   l        g r   r  r   s     r   _set_active_history!AttributeImpl._set_active_history  s    (-%r   c                    SnU R                   (       d   U5       eUR                  R                  [        U R                  5      U5      SL$ )a  Return 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)r  parentsrO  idr  )r   r   r   msgs       r   r   AttributeImpl.hasparent  sI    $ G$$ MMb!2!23Z@M	
r   c           	        SnU R                   (       d   U5       e[        U R                  5      nU(       a  X!R                  U'   gXQR                  ;   a  UR                  U   nUSLak  UR                  UR                  :w  aQ  UR                  5       c?  [        R                  " S[        U5      < S[        U5      < SU R                  < S35      egSUR                  U'   g)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``.

r  FNzRemoving 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.)	r  r  r  r  rm   objrM  StaleDataErrorr;   )r   r   parent_stater   r  id_last_parents          r   sethasparentAttributeImpl.sethasparent  s     G$$""#!-MM#mm##mmC0  u,#<+;+;;"(0%44 !*% 0 ), 7 $	  !&EMM#r   c                    [        5       er   NotImplementedErrorr   r   rP  r   s       r   r   AttributeImpl.get_history  s     "##r   c                    [        5       e)aV  Return 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()

r  r  s       r   get_all_pendingAttributeImpl.get_all_pending  s    * "##r   c                    U R                   U;  d   S5       eSnU R                  R                   H  nU" XU5      nU[        Ld  M  UnM     U$ )z=Produce an empty value for an uninitialized scalar attribute.O_default_value should only be invoked for an uninitialized or expired attributeN)rm   rx   init_scalarr   )r   r   rP  r   fnrets         r   _default_valueAttributeImpl._default_value  s]    
 xxu$ 	
1	
$
 --++BU5)C*$ ,
 r   c                   U R                   U;   a  X R                      $ U R                   nXAR                  ;  d  UR                  U   [        L ac  U[        -  (       d  [        $ U R                  XU5      nU[        L d	  U[        L a  U$ U[        L a   X$   $ U[        La  U R                  XU5      $ U[        -  (       d  [        $ U R                  X5      $ ! [         a  n[        SU-  5      UeSnAff = f)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)rm   committed_stater,   r   r3   _fire_loader_callablesr   KeyErrorr   set_committed_valuer   r  )r   r   rP  r   rm   r   r  s          r   rO  AttributeImpl.get'  s     88u?" ((C000((-9-,,33EH--(1B Ll*#$z) *,33E%HHW$**588 $ #&(*-.  #	##s   C 
C6"C11C6c                "   U R                   (       a1  U R                  (       a   X!R                  ;   a  UR                  X5      $ X!R                  ;   a  UR                  U   nU" X5      $ U R
                  (       a  U R                  X5      $ [        $ r   )r  r  expired_attributes_load_expired	callablesr  r   )r   r   rm   r   r  s        r   r  $AttributeImpl._fire_loader_callablesT  sr     &&%%///&&u66OO#,IU,,^^>>%11r   c                &    U R                  XX4US9  g Nr   r>  r   r   rP  r   	initiatorr   s         r   appendAttributeImpl.appende  s     	uAr   c           	     (    U R                  XS XEUS9  g )N)r   	check_oldr  r  s         r   removeAttributeImpl.removeo  s     	$	e 	 	
r   c           
     .    U R                  UUS UUUSS9  g )NT)r   r  r  r  r  s         r   r  AttributeImpl.pop{  s*     	 	 	
r   c                    [        5       er   r  )r   r   rP  r   r  r   r  r  s           r   r>  AttributeImpl.set  s     "##r   c                    [        5       er   r  )r   r   rP  s      r   rB  AttributeImpl.delete  s    !##r   c                    U R                   UR                  ;   a%  UR                  U R                      nU[        L a  gU$ U R                  XUS9$ )z,return the unchanged value of this attributeNr  )rm   r  r,   rO  )r   r   rP  r   r   s        r   get_committed_value!AttributeImpl.get_committed_value  sM     88u,,,))$((3E 88E'8::r   c                Z    X2U R                   '   UR                  X R                   /5        U$ )z=set an attribute value on the given instance and 'commit' it.)rm   _commit)r   r   rP  r   s       r   r  !AttributeImpl.set_committed_value  s&      dhhehhZ(r   )r  r  r  r  rl   rx   r  rm   r  r  r  r  )FNFNTTN)rl   r  rm   rz   r  Optional[_LoaderCallable]rx   "_Dispatch[QueryableAttribute[Any]]r  r  r  zOptional[Callable[..., bool]]r  r  r  Optional[AttributeEventToken]r  r  r  r  r  zOptional[bool]r   r   r"  r   r!  )r   rh   r  rh   r   r  r  rQ  r   rh   rP  rO   r   r7   r  r  r   rh   rP  rO   r   r7   r  _AllPendingType)r   rh   rP  rO   r  r   )r   rh   rP  rO   r   r7   r  r   )r   rh   rm   rz   r   r7   r  r   r   rh   rP  rO   r   r   r  r	  r   r7   r  rQ  r   rh   rP  rO   r   r   r  r	  r   r7   r  r   r  r  r  rQ  r   rh   rP  rO   r  rQ  )r
  r#  r$  r%  r&  r)  _is_has_collection_adapterr   r'  r  r  r  rp   r  r   r  r4   r   r2   r  r  rO  r  r  r  r  r>  rB  r  r  r0  r  r   r   r}   r}   2  s   >#''M!&''&&&& ":>$6:!%%)04SF'SF SF -	SF
 5SF SF 8SF SF 4SF SF #SF  .SF SFjI4-
. 13FGN =B
'
59
	
2)'!)' ))' 	)'
 
)'^  +	$!$ $ 	$
 
$  5	$!$ $ 	$
 
$.'0=	,  +	+9!+9 +9 	+9
 
+9Z'.1<G	.  +B!B B 	B
 1B B 
B   +

!

 

 	


 1

 

 


$  +
!
 
 	

 1
 
 

. 48*
$!
$ 
$ 	
$
 1
$ 
$ 
$ 
$ 

$$  +	;!; ; 	;
 
;"r   r}   c                     ^  \ rS rSrSrSrSrSrSrSr	Sr
U 4S jrSS jr\4       SS jjrS	\S	S4               SS
 jjr            SS jr          SS jrSrU =r$ )ScalarAttributeImpli  z8represents a scalar value-holding InstrumentedAttribute.TF)r  r  r  c                   > [         TU ]  " U0 UD6  [        U [        5      =U l        U l        [        U [        5      U l        g r   )r;  r   r  
OP_REPLACEr  r  	OP_REMOVEr  )r   argr   r   s      r   r   ScalarAttributeImpl.__init__  sB    #$$3F*4
 	
d0 1yAr   c                   U R                   R                  (       a  U R                  X[        5      nO UR                  U R                  [
        5      nU R                   R                  (       a  U R                  XX0R                  5        UR                  X U5        UR                  U R                  [
        5      nU[
        L aE  U[
        L a;  UR                  (       d)  U R                  UR                  ;  a  [        SU -  5      eg g g g )N%s object does not have a value)rx   r   rO  r6   rm   r,   r  fire_remove_eventr  _modified_eventr  expiredr  r   r   r   rP  oldexistings        r   rB  ScalarAttributeImpl.delete  s    ==((((5)@AC))DHHh/C==""56H6HIe3/99TXXx0 xMM 8 88 !BT!IJJ 9 "   !r   c                f   U R                   U;   a"  [        R                  XX R                      5      $ U R                   UR                  ;   a  [        R                  X[        5      $ U[
        -  (       a	  U[
        -  nU R                  XUS9nU[        L a  [        $ [        R                  XU5      $ r  )	rm   r  from_scalar_attributer  r,   r   rO  r3   HISTORY_BLANK)r   r   rP  r   currents        r   r   ScalarAttributeImpl.get_history  s     88u00eHHoNNXX...00hGG 7"hhuWh=G++$$44T'JJr   Nc                D   U R                   R                  (       a  U R                  X[        5      nO UR                  U R                  [
        5      nU R                   R                  (       a  U R                  XX8U5      nUR                  X U5        X2U R                  '   g r   )	rx   r   rO  r6   rm   r,   r>  fire_replace_eventr  	r   r   rP  r   r  r   r  r  r  s	            r   r>  ScalarAttributeImpl.set  sw     ==((((5)@AC))DHHh/C==++e)E 	e3/dhhr   c                x    U R                   R                   H  nU" XXE=(       d    U R                  5      nM!     U$ r   )rx   r>  r  r   r   rP  r   previousr  r  s          r   r'  &ScalarAttributeImpl.fire_replace_event  s9     --##Bh(HT5H5HE $ r   c                v    U R                   R                   H  nU" XU=(       d    U R                  5        M!     g r   )rx   r  r  r   r   rP  r   r  r  s         r   r  %ScalarAttributeImpl.fire_remove_event  s-     --&&BuY<$*<*<= 'r   )r  r  r  r  )r   rh   rP  Dict[str, Any]r   r7   r  r  )r   rh   rP  r1  r   r   r  r	  r   r7   r  rT  r  r  r  rQ  r   rh   rP  rO   r   rd   r,  r   r  r	  r  rd   
r   rh   rP  rO   r   r   r  r	  r  rQ  )r
  r#  r$  r%  r&  r  r   rL  r  r  r'  r   rB  r4   r   r>  r'  r  r0  rY  rZ  s   @r   r  r    sA   B$(!LJGBIBK.  +	K!K K 	K
 
K0 48*&* !    	 
 1    $    
 ,!  	
  1 
>!> > 	>
 1> 
> >r   r  c                      \ rS rSrSrSrSrSrSrSr	SS jr
\4       SS jjr\4       SS jjrS	\S	S4               SS
 jjr          SS jr            SS jrSrg	)ScalarObjectAttributeImpli  zrepresents a scalar-holding InstrumentedAttribute,
where the target object is also instrumented.

Adds events to delete/set operations.

FTr  c                   U R                   R                  (       a$  U R                  UU[        [        -  [
        -  S9nO*U R                  UU[        [        -  [
        -  [        -  S9nU R                  XX0R                  5        UR                  U R                  [        5      nU[        L a&  U[        La  UR                  c  [        SU -  5      eg g g )Nr  r  )rx   r   rO  r5   r(   r#   r0   r   r+   r  r  r  rm   r,   r3   r   r  s        r   rB   ScalarObjectAttributeImpl.delete+  s    ==((((/()  C (((72()  C 	uS2D2DE99TXXx0  ,,		! !BT!IJJ " - !r   c                
   U R                   U;   a  X R                      nO6U[        -  (       a	  U[        -  nU R                  XUS9nU[        L a  [        $ U R
                  (       d  [        R                  XU5      $ UR                  R                  U R                   [        5      nU[        L aA  U[        [        -  [        -  [        -  [        -  -  nU R                  XR                   U5      n[        R                  XXES9$ )Nr  )original)rm   r   rO  r3   r#  r  r  from_object_attributer  _NO_HISTORYr5   r(   r#   r+   r   r  )r   r   rP  r   r$  r9  loader_passives          r   r   %ScalarObjectAttributeImpl.get_historyK  s     88uHHoG 7"hhuWh=G++$$%%00gFF,,00;GH,,!(+"#,-  ,	,"  6688^ 00W 1  r   c                   U R                   U;   a  X R                      nO!U[        -  (       a  U R                  XUS9nO/ $ Ub!  U[        La  U[        La  [        U5      U4/nOS/nU R                   UR                  ;   aN  UR                  U R                      nUb2  U[        La)  U[        La   XdLa  UR                  [        U5      U45        U$ )Nr  )NN)rm   r   rO  r3   r,   r!   r  r  )r   r   rP  r   r$  r  r9  s          r   r  )ScalarObjectAttributeImpl.get_all_pendingm  s     88uHHoG|#hhuWh=GI 00x'"7+W56C.C88u,,,,,TXX6H$$55H,+

N84h?@
r   Nc           	        U R                   R                  (       a$  U R                  UU[        [        -  [
        -  S9nO*U R                  UU[        [        -  [
        -  [        -  S9nUbI  U[        La@  XhLa<  U(       a  g[        S[        U5      < S[        U5      < SU R                  < S35      eU R                  XX8U5      nX2U R                  '   g)z'Set a value on the given InstanceState.r  NzObject z not associated with z on attribute '')rx   r   rO  r5   r(   r#   r0   r   r+   r3   
ValueErrorr"   r;   rm   r'  r(  s	            r   r>  ScalarObjectAttributeImpl.set  s     ==((((/()  C (((72()  C !,,$ #I.	%0@$((L 
 ''e)Ldhhr   c                   U R                   (       a-  US [        [        4;  a  U R                  [	        U5      US5        U R
                  R                   H  nU" XU=(       d    U R                  5        M!     UR                  X U5        g )NF)	r  r3   r,   r  r!   rx   r  r  r  r/  s         r   r  +ScalarObjectAttributeImpl.fire_remove_event  sv     .
 !

 nU3UEB--&&BuY<$*<*<= ' 	e51r   c                   U R                   (       a1  XCLa-  US [        [        4;  a  U R                  [	        U5      US5        U R
                  R                   H  nU" XXE=(       d    U R                  5      nM!     UR                  X U5        U R                   (       a  Ub  U R                  [	        U5      US5        U$ )NFT)	r  r3   r,   r  r!   rx   r>  r  r  r+  s          r   r'  ,ScalarObjectAttributeImpl.fire_replace_event  s     $!: *
 !!.":E5I--##Bh(HT5H5HE $
 	e84 !!."7Er   r  r
  r  r  r3  r2  )r
  r#  r$  r%  r&  r  r   rL  r  r'  rB  r4   r   r2   r  r>  r  r'  r0  r  r   r   r5  r5    sc    %*!LJIKH  +	 !    	 
 
 L  5	"!" " 	"
 
"R 48*+ !+  +  	+ 
 1+  +  +  +  
+ Z2!2 2 	2
 12 
2&!  	
  1 
r   r5  c                  V   \ rS rSr% SrS\S'   Sr          SS jr\  S         SS jj5       r	\  S         SS jj5       r	\  S         SS	 jj5       r	S
\
R                  4         SS jjr	S
\
R                  S
SS4                 SS jjrSrg
)HasCollectionAdapteri  r  r  r  Tc                    [        5       er   r  r   r   r  adapter
fire_events        r   _dispose_previous_collection1HasCollectionAdapter._dispose_previous_collection  s     "##r   c                    g r   r  r   r   rP  	user_datar   s        r   get_collection#HasCollectionAdapter.get_collection        r   c                    g r   r  rQ  s        r   rS  rT    rU  r   c                    g r   r  rQ  s        r   rS  rT         r   Nc                    [        5       er   r  rQ  s        r   rS  rT    s     "##r   Fc	                    [        5       er   r  )	r   r   rP  r   r  r   r  r  _adapts	            r   r>  HasCollectionAdapter.set&  s     "##r   
r   rh   r  rS   rL  rT   rM  r  r  rQ  ..
r   rh   rP  rO   rR  zLiteral[None]r   z Literal[PassiveFlag.PASSIVE_OFF]r  rT   
r   rh   rP  rO   rR  rS   r   r7   r  rT   
r   rh   rP  rO   rR  z$Optional[_AdaptedCollectionProtocol]r   r7   r  zIUnion[Literal[LoaderCallableStatus.PASSIVE_NO_RESULT], CollectionAdapter]r   rh   rP  rO   r   r   r  r	  r   r7   r  r   r  r  r[  r  r  rQ  )r
  r#  r$  r%  r'  r)  r  rN  r   rS  r7   r4   r>  r0  r  r   r   rI  rI    s   I!%$!$ /$ #	$
 $ 
$ 
 $'47 !    !	 
 2  
    
 14" !    .	 
   
    
 ;>"!  8	
 
  ;?*66	$!	$ 	$ 8		$
 	$
	$  48*66$!$ $ 	$
 1$ $ $ $ $ 
$ $r   rI  c                    g r   r  )rn   s    r   _is_collection_attribute_implrd  6  s    -0r   r  c                    ^  \ rS rSr% SrSrSrSrSrSr	S\
S'   Sr    S!U 4S	 jjrS
 r\4       S"S jjr\4       S#S jjr            S$S jr            S$S jr          S%S jr            S&S jrS'S jr      S(S jr    S)S jr\4           S*S jjr\4           S*S jjr\4           S*S jjrS\R                  SSS4                 S+S jjr          S,S jr    S-S jr        S.S jr \!  S/         S0S jj5       r"\!  S/         S1S jj5       r"\!S\4         S2S jj5       r"S\4         S2S jjr"S r#U =r$$ )3CollectionAttributeImpli>  a  A 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.

TFr  _bulk_replace_token)copycollection_factoryr  r  rg  _duck_typed_asNc	                  > [         TU ]  " UUUU4UUS.U	D6  Uc  U R                  nXpl        XPl        [        U [        5      U l        [        U [        5      U l	        [        U [        5      U l        [        R                  " U R	                  5       5      U l        [        U R                  SS 5      (       a;  [         R"                  " U S5      S 5       n
[         R"                  " U S5      S 5       ng g )N)r  r  
_sa_linkerinit_collectionc                &    UR                  U5        g r   rl  targetr  collection_adapters      r   link.CollectionAttributeImpl.__init__.<locals>.link~  s    %%&89r   dispose_collectionc                &    UR                  S 5        g r   ro  rp  s      r   unlink0CollectionAttributeImpl.__init__.<locals>.unlink  s    %%d+r   )r;  r   _CollectionAttributeImpl__copyrh  ri  r  	OP_APPENDr  r  r  OP_BULK_REPLACErg  r?   duck_type_collectionrj  r  r=   listens_for)r   rl   rm   r  rx   typecallabler  copy_functionr  r   rs  rw  r   s               r   r    CollectionAttributeImpl.__init__[  s     			

 $-	
 	
   KKM!	".0yA0yA#6t_#M "77##%
 4**L$??t%67: 8: t%9:, ;, @r   c                X    [         R                  " U5       Vs/ s H  o"PM     sn$ s  snf r   )r   rr  )r   itemys      r   __copyCollectionAttributeImpl.__copy  s'    &99$?@?a?@@@s   'c                   U R                  XUS9nU[        L af  U[        R                  -  (       aH  U R                  UR
                  ;   a.  UR
                  U R                     nUR                  [        5      $ [        $ U[        R                  -  (       a  U R                  UR
                  ;  d   e[        R                  XU5      $ r  )
rO  r3   r7   r   rm   _pending_mutationsmerge_with_historyr#  r  from_collection)r   r   rP  r   r$  pendings         r   r   #CollectionAttributeImpl.get_history  s     ((5(9''+???HH 8 8822488<11-@@$$>>> xxu'?'????**4@@r   c                   U R                   U;  a  / $ X R                      n[        US5      nU R                   UR                  ;   a  UR                  U R                      nU[        La  U Vs/ s H$  nUS L=(       a    [	        U5      =(       d    S U4PM&     nnU Vs/ s H$  nUS L=(       a    [	        U5      =(       d    S U4PM&     nn[        U5      n	[        U5      n
U VVs/ s H  u  pX;  d  M  X4PM     snnU VVs/ s H  u  pX;   d  M  X4PM     snn-   U VVs/ s H  u  pX;  d  M  X4PM     snn-   $ U Vs/ s H  n[	        U5      U4PM     sn$ s  snf s  snf s  snnf s  snnf s  snnf s  snf )N_sa_adapter)rm   r  r  r,   r!   dict)r   r   rP  r   r$  r9  ccurrent_statesoriginal_statescurrent_setoriginal_setsos                r   r  'CollectionAttributeImpl.get_all_pending  s    885 I/'=188u,,,,,TXX6Hx' %"$ tm:):BdAF$  " &#% tm:):BdAF%   #
 #>2#O4
 %3$2DA0 $2
 +9N.$!A<Mvv.NO %4$3DA/ $3
 1881"A&885"#
 O 9s6   -+E+E#&E(5E(E.E.$E43E4E:c                   U R                   R                   H  nU" XU=(       d    U R                  US9nM      UR                  X [        S5        U R
                  (       a  Ub  U R                  [        U5      US5        U$ )Nrm   T)rx   r  r  r  r,   r  r  r!   r   r   rP  r   r  rm   r  s          r   fire_append_event)CollectionAttributeImpl.fire_append_event  so     --&&BuY%D$2D2D#NE ' 	e8T: 1nU3UDAr   c                v    U R                   R                   H  nU" XU=(       d    U R                  US9nM      U$ )Nr  )rx   append_wo_mutationr  r  s          r   fire_append_wo_mutation_event5CollectionAttributeImpl.fire_append_wo_mutation_event  s8     --22BuY%D$2D2D#NE 3 r   c                2    UR                  X [        S5        g)a>  A special event used for pop() operations.

The "remove" event needs to have the item to be removed passed to
it, which in the case of pop from a set, we don't have a way to access
the item before the operation.   the event is used for all pop()
operations (even though set.pop is the one where it is really needed).

TN)r  r,   )r   r   rP  r  rm   s        r   fire_pre_remove_event-CollectionAttributeImpl.fire_pre_remove_event  s     	e8T:r   c                   U R                   (       a  Ub  U R                  [        U5      US5        U R                  R                   H  nU" XU=(       d    U R
                  US9  M      UR                  X [        S5        g )NFr  T)r  r  r!   rx   r  r  r  r,   r  s          r   r  )CollectionAttributeImpl.fire_remove_event  sh      1nU3UEB--&&BuY<$*<*<#F ' 	e8T:r   c                    U R                   U;  a  g UR                  X [        S5        U R                  XR                  5      nUR                  5         X R                   	 g r   )rm   r  r,   rS  r  clear_with_event)r   r   rP  r  s       r   rB  CollectionAttributeImpl.delete  sN    885 e8T:((

;
##% ((Or   c                    U R                   U;  d   S5       eU R                   UR                  ;   a  UR                  U R                      $ U R                  U5      u  p4UR                  U5        U$ )z;Produce an empty collection for an un-initialized attributer  )rm   _empty_collections_initialize_collection
_set_empty)r   r   rP  rL  rR  s        r   r  &CollectionAttributeImpl._default_value  sr    
 xxu$ 	
1	
$
 88u///++DHH55!88?9%r   c                    UR                   R                  U R                  XR                  5      u  p#U R                  R                  XU5        X#4$ r   )r   initialize_collectionrm   ri  rx   rm  )r   r   rL  r  s       r   r  .CollectionAttributeImpl._initialize_collection-  sI     $mmAAHHe44
 	%%eA""r   c                L   U R                  XS US9nU[        L aW  U R                  XX4[        S9nU R                  U;  d   S5       eUR                  U R                  5      R                  U5        g [        (       a  [        U[        5      (       d   eUR                  X45        g N)rR  r   r  z,Collection was loaded during event handling.)rS  r3   r  r*   rm   _get_pending_mutationr  r   r   rT   append_with_eventr   r   rP  r   r  r   r  s          r   r  CollectionAttributeImpl.append8  s     ((D' ) 

 ****eF + E %>=>%''188?}!*.?@@@@((:r   c                `   U R                  XR                  S US9nU[        L aW  U R                  XX4[        S9  U R
                  U;  d   S5       eUR                  U R
                  5      R                  U5        g [        (       a  [        U[        5      (       d   eUR                  X45        g r  )rS  r  r3   r  r*   rm   r  r  r   r   rT   remove_with_eventr  s          r   r  CollectionAttributeImpl.removeP  s     ((::w ) 

 **""5v"N%>=>%''188?}!*.?@@@@((:r   c                ^     U R                  XX4US9  g ! [        [        [        4 a     g f = fr  )r  rB  r  
IndexErrorr  s         r   r  CollectionAttributeImpl.popf  s4    	 KKeKHHj1 		s    ,,c	                   U=pS nU R                  U5      u  pU(       a  UR                  b  UR                  U	5      n	O[        R                  " U	5      nU R                  nXLaT  U	S L =(       a    S=(       d    U	R
                  R                  nU R                  R                  n[        SU< SU< S35      e[        U	S5      (       a  U	R                  5       n	OYU[        L a  [        U	5      nU	R                  5       n	O4[        U	5      n	O([        R                  " U	5      [        L a  [        U5      n[        U	5      nU R                  nU R                  R!                  UUUUS9  U R#                  UU[$        U[&        R(                  -  -  S9nU[*        L a  U R-                  X5      nOUU
L a  g UR/                  X US5        UR0                  nXU R2                  '   [4        R                   " UUUUS	9  U R7                  UUUS5        g )
NrQ  zIncompatible collection type: z is not z-like_sa_iterator)keysr  T)r  )r  
_converterr?   r|  rj  r   r
  	TypeErrorry  r  r  listvaluesiterrg  rx   bulk_replacerO  r5   r7   r+   r3   r  r  r  rm   r   rN  )r   r   rP  r   r  r   r  r  r[  iterableorig_iterablenew_keysnew_collectionrR  setting_typereceiving_typegivenwanted
new_valuesevtr  old_collections                         r   r>  CollectionAttributeImpl.setv  s    $)( %)$?$?$F!((4)44X>#88B!%!4!45 D( #"7#--66 
 "0099F# &*  8^44'446H!T)#H~H'0H#H~H&&x0D8E{H(^
&&""5*c"I hh+w9M9M/MN  

 ##%%e3CM!  	e35#dhh  #	
 	))%ndKr   c                    U? UR                  R                  U R                  S 5        U(       a  U R                  R                  XU5        g g r   )r  r  r  rm   rx   ru  rK  s        r   rN  4CollectionAttributeImpl._dispose_previous_collection  sB     " 	  $$TXXt4MM,,UH r   c                *    [        US5      nSUl        g )Nr  T)r  invalidated)r   r  rL  s      r   _invalidate_collection.CollectionAttributeImpl._invalidate_collection  s     *m4"r   c                    U R                  U5      u  pEU(       a  UR                  U5        XQR                  U R                  '   UR	                  X R                  /5        U R                  UR
                  ;   a  UR                  X US5        UR
                  R                  U R                  5      nUR                  nUR                  nU H  n	UR                  U	5        M     U H  n	UR                  U	5        M     U$ )z=Set an attribute value on the given instance and 'commit' it.T)r  append_multiple_without_eventr  rm   r  r  r  r  added_itemsdeleted_itemsappend_without_eventremove_without_event)
r   r   rP  r   r  rR  r  addedremovedr  s
             r   r  +CollectionAttributeImpl.set_committed_value  s    
 !% ; ;E B
44U;(

488ehhZ(88u/// !!%y$?..22488<G''E++G//5 //5   r   .c                    g r   r  rQ  s        r   rS  &CollectionAttributeImpl.get_collection  rU  r   c                    g r   r  rQ  s        r   rS  r    rU  r   c                    g r   r  rQ  s        r   rS  r    rX  r   c                    Uc1  U R                  XUS9nU[        R                  L a  U$ [        SU5      nUR                  $ )zRetrieve the CollectionAdapter associated with the given state.

if user_data is None, retrieves it from the state using normal
"get()" rules, which will fire lazy callables or return the "empty"
collection value.

r  rS   )rO  r$   r3   r   r  )r   r   rP  rR  r   fetch_user_datas         r   rS  r    sJ      "hhuWhEO"6"H"HH&& !=O	$$$r   )r  rg  rj  r  ri  rh  )NFNNr
  r  )r   rh   rP  rO   r   rd   r  r	  rm   Optional[Any]r  rd   )
r   rh   rP  rO   r  r	  rm   r  r  rQ  )r   rh   rP  rO   r   r   r  r	  rm   r  r  rQ  r  )r   rh   rP  rO   r  rS   )r   rh   r  z4Tuple[CollectionAdapter, _AdaptedCollectionProtocol]r  rb  r]  )r  rS   r  rQ  )r   rh   rP  rO   r   r   r  rS   r^  r_  r`  ra  )%r
  r#  r$  r%  r&  r   r  r  rL  r  r)  r'  r   ry  r4   r   r2   r  r  r  r  r  rB  r  r  r  r  r  r7   r>  rN  r  r  r   rS  r0  rY  rZ  s   @r   rf  rf  >  s   	 LJ$)!G,,I ),VA  +	A!A A 	A
 
A:  5	+9!+9 +9 	+9
 
+9Z!  	
 1  
$!  	
 1  
;!; ; 1	;
 ; 
;";!; ; 	;
 1; ; 
; '0=	#"	#'	#	=	#"  +;!; ; 	;
 1; ; 
;<  +;!; ; 	;
 1; ; 
;8  +!  	
 1  
* 48*66OL!OL OL 	OL
 1OL OL OL OL OL 
OLbI!I /I #	I
 I 
I#4#	#'0=FI	#: 
 $'47 !    !	 
 2  
    
 14" !    .	 
   
    
 ;>*!  8	
 
  ;?*%!% % 8	%
 %
% %r   rf  c           	     8  ^ ^^^^^ T R                   R                  mT R                   mU 4S jmUUUU4S jnUUU4S jnUUU4S jnT(       a  [        R                  " T SUSSSS9  O[        R                  " T SUSSSS9  [        R                  " T S	USSSS9  g
)z6Apply listeners to synchronize a two-way relationship.c                   > [        S[        U 5      < SUR                  < SUR                  < STR                  R                  < S3	5      e)Nz:Bidirectional attribute conflict detected: Passing object z to attribute "z(" triggers a modify event on attribute "z" via the backref "z".)rB  r;   r  rn   )child_stater  
child_implr  s      r   _acceptable_key_err.backref_listeners.<locals>._acceptable_key_err@  s>     +&&&''++	
 	
r   c                  > X!L a  U$ Ub  U[         La  U[        La  [        U5      [        U5      peUR                  T   R
                  nUR                  (       d  UR                  (       d  UR                  nOUR                  nX8La/  UR                  UUU R                  5       TR                  [        S9  Ub  [        U5      [        U5      pU	R                  T   R
                  nUR                  TLa"  UR                  UR                  La	  T" XU5        UR                  n[        U5      (       a  UR                   OS nX<La)  X=La%  UR#                  U	U
U R                  5       U[        S9  U$ r  )r3   r,   r!   r    r   rn   r  r  r  r  r  r  r  r0   r  rd  rg  r  )r   childoldchildr  r   	old_stateold_dictrn   check_recursive_tokenr  
child_dictr  check_append_tokencheck_bulk_replace_tokenr  rm   parent_implr  s                 r   "emit_backref_from_scalar_set_event=backref_listeners.<locals>.emit_backref_from_scalar_set_eventN  s}    L  11(
 x(h'   $$S)..D ??4<<(,(;(;%(,(:(:%5IIK--,   u%e$ $ %,,S166J &&l:***2I2II#EjA ",!9!9 1<< .. % 3=!!IIK, "  r   c                |  > Uc  g [        U5      [        U5      pTUR                  T
   R                  nUR                  TLa"  UR                  UR                  La	  T	" XU5        UR
                  n[        U5      (       a  UR                  OS nX'La)  X(La%  UR                  UUU R                  5       U[        S9  U$ r  )r!   r    r   rn   r  r  rd  rg  r  r  r0   )r   r  r  r   r  r  r  r  r  r  rm   r  s            r   )emit_backref_from_collection_append_eventDbackref_listeners.<locals>.emit_backref_from_collection_append_event  s     ="0"7u9MZ ((-22
 "",6&&j.E.EE*= (55 -Z88 ** 	! /9		(   r   c                n  > UGb0  U[         LGa%  U[        LGa  [        U5      [        U5      pTUR                  T
   R
                  nUR                  (       dD  UR                  (       d3  UR                  nUR                  nT=(       a    TR                  (       + n	O,UR                  n[        U5      (       a  UR                  OS nSn	X'Laf  X(Laa  U	(       a3  [        R                  " U R                  TR                     U5      (       d&  UR!                  UUU R#                  5       U[$        S9  g g g g g g g )NFr  )r3   r,   r!   r    r   rn   r  r  r  r  rd  rg  r?   	has_dupesr  rm   r  r  r0   )r   r  r  r   r  r  r  check_remove_tokencheck_replace_tokencheck_for_dupes_on_removerm   r  uselists             r   )emit_backref_from_collection_remove_eventDbackref_listeners.<locals>.emit_backref_from_collection_remove_event  s:    ..X% u%e$ $ %,,S166J
 ((1C1C%/%=%="&0&?&?#,3,OK<O<O8O)%/%=%=" 5Z@@ 22 $
 -2) 380 JJ{/	9 9 NN#"		! 0 # 9 9 43 & / r   r  T)r  rawinclude_keyr>  r  N)rn   r  r=   listen)	r  rm   r  r  r  r  r  r  r  s	   ```   @@@r   backref_listenersr  0  s     >>..L..K
A AF"H.` 5	
 	.	
 
LL1r   
NO_HISTORYc                      \ rS rSr% SrS\S'   S\S'   S\S'   SS jrSS jrSS	 jrSS
 jr	SS jr
SS jrSS jrSS jr\        SS j5       r\\4         SS jj5       r\        SS j5       rSrg)r  i	  a  A 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).

zUnion[Tuple[()], List[Any]]r  	unchangeddeletedc                    U [         :g  $ r   )r#  r   s    r   __bool__History.__bool__#	  s    }$$r   c                    [        U R                  =(       d    U R                  =(       d    U R                  5      (       + $ )zXReturn True if this :class:`.History` has no changes
and no existing, unchanged state.

)r  r  r  r
  r   s    r   emptyHistory.empty&	  s(     3t||FGGGr   c                    U R                   =(       d    / U R                  =(       d    / -   U R                  =(       d    / -   $ )z3Return a collection of added + unchanged + deleted.)r  r
  r  r   s    r   sumHistory.sum.	  s1     ZZ2$.."6B74<<;M2N	
r   c                X    U R                   =(       d    / U R                  =(       d    / -   $ )z)Return a collection of added + unchanged.)r  r
  r   s    r   non_deletedHistory.non_deleted5	  s!     

 bT^^%9r::r   c                X    U R                   =(       d    / U R                  =(       d    / -   $ )z+Return a collection of unchanged + deleted.)r
  r  r   s    r   	non_addedHistory.non_added:	  s!     $");<<r   c                R    [        U R                  =(       d    U R                  5      $ )z2Return True if this :class:`.History` has changes.)r  r  r  r   s    r   has_changesHistory.has_changes?	  s     DJJ.$,,//r   c                    [        [        U R                  5      [        U5      -   U R                  [        U R                  5      [        U5      -   5      $ r   )r  r  r  r
  r  )r   r  r  s      r   _mergeHistory._mergeD	  s@    tE{*NNg.
 	
r   c           
        [        U R                   Vs/ s H"  nUS L=(       a    [        U5      =(       d    S PM$     snU R                   Vs/ s H"  nUS L=(       a    [        U5      =(       d    S PM$     snU R                   Vs/ s H"  nUS L=(       a    [        U5      =(       d    S PM$     sn5      $ s  snf s  snf s  snf r   )r  r  r!   r
  r  )r   r  s     r   as_stateHistory.as_stateK	  s     #A $5N1$5==# 'A $5N1$5==' %A $5N1$5==%
 	
s   )B6)B;
)C c                   UR                   R                  UR                  [        5      nU[        L a  U[        L a
  U " SSS5      $ U " SU/S5      $ U[        La  UR                  X45      SL a  U " SU/S5      $ [        U5      [        ;   a  Sn[        U5      [        ;   a  S nOU/nU[        L a
  U " SSU5      $ U " U/SU5      $ )Nr  T)r  rO  rm   r;  r,   r  r  _NO_STATE_SYMBOLSr<  r  r   r$  r9  r  s         r   r"  History.from_scalar_attribute[	  s     ((,,Y]]KH {"("2r2&2y"-- 8#""75=rG9b)) (|00 g;"33"G#*("2r7++G9b'22r   c                   U[         L a*  UR                  R                  UR                  [         5      nU[         L a  U[        L a
  U " SSS5      $ U " SU/S5      $ X4L a  U[        La  U " SU/S5      $ [        U5      [        ;   d  Uc  Sn[        U5      [        ;   a  S nOU/nU[        L a
  U " SSU5      $ U " U/SU5      $ )Nr  )r;  r  rO  rm   r,   r  r%  r&  s         r   r:  History.from_object_attribute	  s     {",,00LH{"("2r2&2y"-- WH%<rG9b)) (|00H4D g;"33"G#*("2r7++G9b'22r   c           
        UR                   R                  UR                  [        5      nU[        L a
  U " SSS5      $ [        US5      nU[        L a  U " [        U5      SS5      $ U[        L a  U " S[        U5      S5      $ U Vs/ s H$  nUS L=(       a    [        U5      =(       d    S U4PM&     nnU Vs/ s H$  nUS L=(       a    [        U5      =(       d    S U4PM&     nn[        U5      n[        U5      n	U " U V
Vs/ s H  u  pX;  d  M  UPM     snn
U V
Vs/ s H  u  pX;   d  M  UPM     snn
U V
Vs/ s H  u  pX;  d  M  UPM     snn
5      $ s  snf s  snf s  snn
f s  snn
f s  snn
f )Nr  r  )	r  rO  rm   r;  r,   r  r  r!   r  )r<  r  r   r$  r9  r  r  r  r  r  r  r  s               r   r  History.from_collection	  sp    ((,,Y]]KHhr2r?"'=1xtG}b"--$r4="-- ! A 4-6^A%6>$B    "!A 4-6^A%6>$B!  
 ~.K0L-G~tq1F~G-C~tq1B~C.Gtq!2FG  HCGs0   +E7+EE"
E"
E(-E(;E.
E.r  Nr  )r  zSequence[Any])r  Iterable[Any]r  r,  r  r  )r  r  )r  r  r   rh   r$  r   r  r  )
r  r5  r   rh   r$  r   r9  r   r  r  )r  rf  r   rh   r$  r   r  r  )r
  r#  r$  r%  r&  r)  r  r  r  r  r  r  r  r"  classmethodr"  r;  r:  r  r0  r  r   r   r  r  	  s   0 '&**((%H
;
=
0


  &3&&3 "&3 	&3
 
&3 &3P  $$3,$3 "$3 	$3
 $3 
$3 $3L  *  "  	 
 
   r   r  r  c                ,    [        [        U 5      X5      $ )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!   )r  rm   r   s      r   r   r   	  s    J ^C0#??r   c                $    U R                  X5      $ r   )r   )r   rm   r   s      r   r/  r/  	  s     S**r   c                R    [        U 5      n[        U5      nUR                  XRU5      $ )TODO)r%   r!   
has_parent)r<  r  rm   r   r   r   s         r   r3  r3   
  s+     s#G3Ee*55r   )rl  c               4    [        XX#US9n[        X40 UD6  U$ )N)ro   r|   rl  )register_descriptorregister_attribute_impl)rl   rm   ro   r|   rl  r   descs          r   register_attributer8  	
  s)     
3D F.2.Kr   c                   [        U 5      nU(       a1  UR                  SS 5      n	UR                  X=(       d    [        5      n
OUR                  SS 5      n
[	        SX   R
                  5      nU(       a  [	        SU5      " XU40 UD6nO9U(       a  [        XX;4SU
0UD6nO"U(       a  [        XX;40 UD6nO[        XX;40 UD6nXU   l	        U(       a  [        X   Xb5        UR                  U5        X   $ )Nr~  r  zType[WriteOnlyAttributeImpl])r%   r  instrument_collection_classr  r   rx   rf  r5  r  rn   r  post_configure_attribute)rl   rm   r  r  	useobject
impl_classbackrefr   r   factoryr~  rx   rn   s                r   r6  r6  
  s	    v&G&&.::D
 vvnd3,gl.C.CH  2J?
%'
 
&
;G
KM
 
(
02
 #6	JrJCL',9$$S)<r   c               ^    [        U 5      n[        XX#S9nXFl        UR                  X5        U$ )N)ro   r|   )r%   r5  r&  instrument_attribute)rl   rm   ro   r|   rl  r   rh  s          r   r5  r5  L
  s9     v&G&
J   1r   c                8    [        U 5      R                  U5        g r   )r%   uninstrument_attribute)rl   rm   s     r   unregister_attributerD  `
  s    V33C8r   c                H    [        U 5      nUR                  n[        X#U5      $ )a  Initialize 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)r  rm   r   rP  s       r   rm  rm  d
  s$    $ 3EJJE s33r   c                d   U R                   U   R                  n[        (       a  [        U[        5      (       d   eUR                  US5      nUb  UR                  nUR                  XUS5        UR                  X5      nUR                  XU[        R                  S9nUR                  5         U$ )z|Initialize a collection attribute and return the collection adapter.

Discards any existing collection which may be there.

NFr  )r   rn   r   r   rI  r  r  rN  r  rS  r7   r0   _reset_empty)r   rP  rm   attrr  r  rR  rL  s           r   rF  rF  {
  s     ==""D}$ 45555
))C
C
))%neL##E1I!%!4!4i)E)E "5 "G Nr   c                    [        U 5      [        U 5      pCUR                  U   R                  R	                  X4U5        g)a3  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    r   rn   r  )r   rm   r   r   rP  s        r   r  r  
  s4     "(+]8-D5	MM#//eDr   c                    [        U 5      [        U 5      pTUR                  U   R                  R	                  XEX#5        g)a3  Set 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    r   rn   r>  )r   rm   r   r  r   rP  s         r   set_attributerL  
  s4    < "(+]8-D5	MM#e?r   c                |    [        U 5      [        U 5      p2UR                  U   R                  R	                  X#5      $ )aB  Get 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    r   rn   rO  r   rm   r   rP  s       r   get_attributerO  
  s5     "(+]8-D5==""&&u44r   c                ~    [        U 5      [        U 5      p2UR                  U   R                  R	                  X#5        g)a9  Delete 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    r   rn   rB  rN  s       r   del_attributerQ  
  s2     "(+]8-D5	MM#""50r   c                    [        U 5      [        U 5      p2UR                  U   R                  nUR                  R                  X$R                  5        UR                  X4[        SS9  g)a  Mark 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    r   rn   rx   modifiedr  r  r,   )r   rm   r   rP  rn   s        r   flag_modifiedrV  
  sV    " "(+]8-D5==""DMM5"6"67	%xTBr   c                Z    [        U 5      [        U 5      p!UR                  US[        SS9  g)a  Mark 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`

NTrS  )r!   r    r  r,   )r   r   rP  s      r   
flag_dirtyrX  
  s,    ( "(+]8-D5	%xTBr   )
rm   rz   r3  Type[_O]r|   r  r   ry   r  r   )rh  r   r  z&Callable[..., QueryableAttribute[Any]])rn   r}   r  z"TypeGuard[CollectionAttributeImpl])r  QueryableAttribute[Any]rm   rz   r  r  r  rQ  )r  rR  rm   rz   r   r7   r  r  )r   rh   rm   rz   r   r7   r  r  r   )
r<  rY  r  rR   rm   rz   r   r  r  r  )rl   rY  rm   rz   ro   interfaces.PropComparator[_T]r|   r  rl  r   r   r   r  InstrumentedAttribute[_T])FNFNN)rl   rY  rm   rz   r  r  r  r  r<  r  r=  zOptional[Type[AttributeImpl]]r>  r   r   r   r  rZ  )rl   	Type[Any]rm   rz   ro   r[  r|   r{   rl  r   r  r\  )rl   r]  rm   rz   r  rQ  )r  rR  rm   rz   r  rT   )r   rh   rP  rO   rm   rz   r  rT   r   )
r   rR  rm   rz   r   r   r  r	  r  rQ  )r   rR  rm   rz   r  r   )r   rR  rm   rz   r  rQ  rS  )r&  
__future__r   dataclassesr  typingr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r    r   r   rM  r   _typingr   rB   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r=   r>   r?   r@   rA   sqlsql_baserC   rD   rE   rF   sql.cache_keyrG   sql.visitorsrH   rI   util.typingrJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   relationshipsrV   r   rW   rX   	writeonlyrY   
event.baserZ   sql._typingr[   r\   r]   r^   sql.annotationr_   sql.elementsr`   ra   sql.operatorsrb   sql.selectablerc   rd   re   rR  r  r   _self_inspectsInspectionAttrPropComparatorJoinTargetRoleOnClauseRole	ImmutableSlotsMemoizedHasCacheKeyr  rj   r   r5  	dataclassr]  r  symbolr  rz  r  r{  r  r  AttributeEventEventr}   r  r5  rI  rd  
attrgetterrf  r  r;  	frozensetr  r%  r  r#  r   r/  r3  r8  r6  r5  rD  rm  rF  r  rL  rO  rQ  rV  rX  r  r   r   <module>r}     s   #                       * $    ' +  0 2  ( & 6 "       # > ( " * ' #  ) )  #  "        "     ' 1 , !  #$,&,(7.*3$!1&70'10,$,+ T]sd3 	('
((6*:
:;
 H  b(uUe$		&&b( b(J$	$$ *$ %	$
 	$</.u5 </~ d#7k 7 $7 gg+gT KK!	KK!	[[#
++n-kk*%0* 0*f %@ @Fd>- d>NP 3 PfB$ B$J 11	+1
 %-$7$7$E!o%2M o%dO&O-0O;?O	Od kk,'r"34blCD Fj FR B# 3>%@	%@%@$/%@%@R AL++$'+2=++ :?6	66!$6266	6 	 .	
 * 
  & +/04!00	0 0 )	0
 0 .0 0 0 0r 	 .	
 + 
 (94.&3:=6E. 04	@@	@ @ -	@
 
@D51C.Cr   