
    ,hX&                    n   S 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!  \(       a0  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$9r. " S% S&\\.   5      r/ " S' S(\5      r0\Rb                  Re                  S)S*9 " S+ S,\5      5       r3 " S- S.\\.   5      r4 " S/ S0\4\.   \\.   5      r5S3S1 jr6g2)4zDynamic collection API.

Dynamic collections act like Query() objects for read operations and support
basic add/delete mutation.

.. legacy:: the "dynamic" loader is a legacy feature, superseded by the
 "write_only" loader.


    )annotations)Any)Iterable)Iterator)List)Optional)Tuple)Type)TYPE_CHECKING)TypeVar)Union   )
attributes)exc)relationships)util)PassiveFlag)Query)object_session)AbstractCollectionWriter)WriteOnlyAttributeImpl)WriteOnlyHistory)WriteOnlyLoader   )result)QueryableAttribute)Mapper)_RelationshipOrderByArg)Session)InstanceState)AliasedClass)	_Dispatch)ColumnElement_T)boundc                  6    \ rS rSr S         SS jjrSrg)DynamicCollectionHistory=   Nc                z   U(       a_  [        X5      R                  S5      n[        R                  " U5      U l        UR
                  U l        UR                  U l        SU l        g [        R                  " 5       U l        [        R                  " 5       U l        [        R                  " 5       U l        SU l        g )NFT)AppenderQuery	autoflushr   OrderedIdentitySetunchanged_itemsadded_itemsdeleted_items_reconcile_collection)selfattrstatepassiveapply_tocolls         N/var/www/auris/envauris/lib/python3.13/site-packages/sqlalchemy/orm/dynamic.py__init__!DynamicCollectionHistory.__init__>   s      -77>D#'#:#:4#@D '33D!)!7!7D)-D&!%!8!8!:D#668D#'#:#:#<D ).D&    )r0   r.   r/   r-   N)
r2   DynamicAttributeImplr3   InstanceState[_T]r4   r   r5   z&Optional[DynamicCollectionHistory[_T]]returnNone)__name__
__module____qualname____firstlineno__r8   __static_attributes__ r:   r7   r'   r'   =   sB     <@/"/ !/ 	/
 9/ 
/ /r:   r'   c                  \    \ rS rSr% Sr\\   rS\S'    S               S	S jjr	Sr
g)
r<   R   TzType[AppenderMixin[Any]]query_classNc                
   [         R                  R                  " XUS U40 UD6  X@l        U(       a  [	        U5      U l        U(       d  [        U l        g [        UR                  5       ;   a  X`l        g [        U5      U l        g r;   )r   AttributeImplr8   target_mappertupleorder_byr*   rH   AppenderMixinmromixin_user_query)r1   class_keydispatchrK   rM   rH   kws           r7   r8   DynamicAttributeImpl.__init__W   sl     	  ))#tX	
13	
 +!(ODM,Dkoo//*/<Dr:   )rM   rH   rK   r;   )rQ   z#Union[Type[Any], AliasedClass[Any]]rR   strrS   z"_Dispatch[QueryableAttribute[Any]]rK   z
Mapper[_T]rM   r   rH   z!Optional[Type[AppenderMixin[_T]]]rT   r   r>   r?   )r@   rA   rB   rC   _supports_dynamic_iterationr'   r   collection_history_cls__annotations__r8   rD   rE   r:   r7   r<   r<   R   sv    "&5c:)) :>=3= = 5	=
 "= *= 7= = 
= =r:   r<   dynamic)lazyc                      \ rS rSr\rSrg)
DynaLoadero   rE   N)r@   rA   rB   rC   r<   
impl_classrD   rE   r:   r7   r]   r]   o   s    %Jr:   r]   c                    ^  \ rS rSr% SrSrS\S'   S\S'         SU 4S jjr\SS	 j5       r	\	R                  SS
 j5       r	SS jr\(       a  SS jrSS jrSS jr S   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rU =r$ )!rN   t   zLA mixin that expects to be mixing in a Query class with
AbstractAppender.


NzOptional[Type[Query[_T]]]rH   zTuple[ColumnElement[Any], ...]_order_by_clausesc                h   > [         R                  " U UR                  S 5        [        TU ]  X5        g r;   )r   r8   rK   super)r1   r2   r3   	__class__s      r7   r8   AppenderMixin.__init__~   s/     		

 	%r:   c                    [        U R                  5      nUb1  UR                  (       a   U R                  U;   a  UR                  5         [        R
                  " U R                  5      (       d  g U$ r;   )r   instancer+   flushorm_utilhas_identityr1   sesss     r7   sessionAppenderMixin.session   sM    dmm,4==D3HJJL$$T]]33Kr:   c                    Xl         g r;   rm   )r1   rn   s     r7   rn   ro      s    	r:   c           
     |   U R                   nUGc  [        R                  " U R                  5      nUR                  (       a-  [
        R                  " S[        R                  " U5      -  5        [        R                  " [        R                  " U R                  R                  R                  /5      [        U R                  R!                  [        R                  " U R                  5      ["        R$                  5      R&                  5      SS9R)                  5       $ U R+                  U5      R-                  5       $ )NzInstance %s is detached, dynamic relationship cannot return a correct result.   This warning will become a DetachedInstanceError in a future release.T)_source_supports_scalars)rn   r   instance_staterh   detachedr   warnrj   	state_strr   IteratorResultSimpleResultMetaDatar2   rQ   r@   iter_get_collection_historyr   PASSIVE_NO_INITIALIZEr.   scalars	_generate_iter)r1   rm   r3   s      r7   r   AppenderMixin._iter   s    ||<--dmm<E~~		C  ))%02 ((++TYY-=-=-F-F,GHII55"11$--@#99 "k	 *.	 gi	 >>$'--//r:   c                    g r;   rE   )r1   s    r7   __iter__AppenderMixin.__iter__   s    Cr:   c                   U R                   nUcW  U R                  R                  [        R                  " U R
                  5      [        R                  5      R                  U5      $ U R                  U5      R                  U5      $ r;   )rn   r2   r{   r   rt   rh   r   r|   indexedr~   __getitem__)r1   indexrm   s      r7   r   AppenderMixin.__getitem__   si    ||<9944))$--811 gen
 >>$'33E::r:   c                   U R                   nUc[  [        U R                  R                  [        R
                  " U R                  5      [        R                  5      R                  5      $ U R                  U5      R                  5       $ r;   )rn   lenr2   r{   r   rt   rh   r   r|   r.   r~   countrl   s     r7   r   AppenderMixin.count   sk    ||<		11--dmm<55 +	  >>$'--//r:   c                   U R                   nUcU  [        U5      nUcG  [        R                  " S[        R
                  " U5      < SU R                  R                  < S35      eU R                  (       a%  U R                  U R                  R                  US9nO%UR                  U R                  R                  5      nU R                  Ul        U R                  Ul        U R                  Ul        U$ )NzParent instance zh is not bound to a Session, and no contextual session is established; lazy load operation of attribute 'z' cannot proceed)rn   )rh   r   orm_excDetachedInstanceErrorrj   instance_strr2   rR   rH   rK   query_where_criteria	_from_objrb   )r1   rm   rh   r   s       r7   r~   AppenderMixin._generate   s     ==<!(+D|33  ,,X6		G  $$TYY%<%<d$KEJJtyy667E $ 4 4.."&"8"8r:   c                &    U R                  U5        g)aN  Add an iterable of items to this :class:`_orm.AppenderQuery`.

The given items will be persisted to the database in terms of
the parent instance's collection on the next flush.

This method is provided to assist in delivering forwards-compatibility
with the :class:`_orm.WriteOnlyCollection` collection class.

.. versionadded:: 2.0

N_add_all_implr1   iterators     r7   add_allAppenderMixin.add_all   s     	8$r:   c                (    U R                  U/5        g)a@  Add an item to this :class:`_orm.AppenderQuery`.

The given item will be persisted to the database in terms of
the parent instance's collection on the next flush.

This method is provided to assist in delivering forwards-compatibility
with the :class:`_orm.WriteOnlyCollection` collection class.

.. versionadded:: 2.0

Nr   r1   items     r7   addAppenderMixin.add   s     	D6"r:   c                &    U R                  U5        g)zAdd an iterable of items to this :class:`_orm.AppenderQuery`.

The given items will be persisted to the database in terms of
the parent instance's collection on the next flush.

Nr   r   s     r7   extendAppenderMixin.extend  s     	8$r:   c                (    U R                  U/5        g)zAppend an item to this :class:`_orm.AppenderQuery`.

The given item will be persisted to the database in terms of
the parent instance's collection on the next flush.

Nr   r   s     r7   appendAppenderMixin.append  s     	D6"r:   c                &    U R                  U5        g)zRemove an item from this :class:`_orm.AppenderQuery`.

The given item will be removed from the parent instance's collection on
the next flush.

N)_remove_implr   s     r7   removeAppenderMixin.remove  s     	$r:   rq   )r2   r<   r3   r=   r>   r?   )r>   Optional[Session])rn   r   r>   r?   )r>   z1Union[result.ScalarResult[_T], result.Result[_T]])r>   zIterator[_T])r   r   r>   zUnion[_T, List[_T]])r>   intr;   )rm   r   r>   z	Query[_T])r   zIterable[_T]r>   r?   )r   r$   r>   r?   )r@   rA   rB   rC   __doc__rH   rY   r8   propertyrn   setterr   r   r   r   r   r~   r   r   r   r   r   rD   __classcell__)re   s   @r7   rN   rN   t   s     .2K*155&(&1B&	&   ^^ 02 /;
0 #' 
:%#%#   r:   rN   c                      \ rS rSrSrSrg)r*   i  zA dynamic query that supports basic collection storage operations.

Methods on :class:`.AppenderQuery` include all methods of
:class:`_orm.Query`, plus additional methods used for collection
persistence.


rE   N)r@   rA   rB   rC   r   rD   rE   r:   r7   r*   r*     s    r:   r*   c                J    SU R                   -   n[        U[        U 4SU 05      $ )zAReturn a new class with AppenderQuery functionality layered over.AppenderrH   )r@   typerN   )clsnames     r7   rP   rP   )  s)    $D}c*]C,@AAr:   N)r   r   r>   ztype[AppenderMixin[Any]])7r   
__future__r   typingr   r   r   r   r   r	   r
   r   r   r    r   r   r   r   r   rj   baser   r   r   rn   r   	writeonlyr   r   r   r   enginer   r   mapperr   r   r   r3   r    r!   eventr"   sql.elementsr#   r$   r'   r<   RelationshipPropertystrategy_forr]   rN   r*   rP   rE   r:   r7   <module>r      s   	 #                  # / - ' &   $6 $"!,T//3 /*=1 =: ##00i0@& & A&g ,R0 g TM"%uRy Br:   