
    [hX&                       d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 dd	lm
Z
 dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! er0ddlm"Z" ddl#m$Z$ ddlm%Z% ddlm&Z& ddl'm(Z( dd lm)Z) dd!l*m+Z+ dd"l,m-Z-  ed#e$          Z. G d% d&ee.                   Z/ G d' d(e          Z0ej1        2                    d)*           G d+ d,e                      Z3 G d- d.ee.                   Z4 G d/ d0e4e.         ee.                   Z5d7d5Z6d6S )8zDynamic 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                      e Zd Z	 dddZdS )DynamicCollectionHistoryNattrDynamicAttributeImplstateInstanceState[_T]passiver   apply_to&Optional[DynamicCollectionHistory[_T]]returnNonec                b   |r]t          ||                              d          }t          j        |          | _        |j        | _        |j        | _        d| _        d S t          j                    | _        t          j                    | _        t          j                    | _        d| _        d S )NFT)AppenderQuery	autoflushr   OrderedIdentitySetunchanged_itemsadded_itemsdeleted_items_reconcile_collection)selfr(   r*   r,   r-   colls         e/var/www/api.easyaligner.net/htdocs/venv_linux/lib/python3.11/site-packages/sqlalchemy/orm/dynamic.py__init__z!DynamicCollectionHistory.__init__>   s      
	/ u--77>>D#'#:4#@#@D '3D!)!7D)-D&&&!%!8!:!:D#688D#'#:#<#<D ).D&&&    N)
r(   r)   r*   r+   r,   r   r-   r.   r/   r0   )__name__
__module____qualname__r<    r=   r;   r'   r'   =   s3         <@/ / / / / / /r=   r'   c                  :    e Zd ZU dZee         Zded<   	 dddZdS )r)   TzType[AppenderMixin[Any]]query_classNclass_#Union[Type[Any], AliasedClass[Any]]keystrdispatch"_Dispatch[QueryableAttribute[Any]]target_mapper
Mapper[_T]order_byr   !Optional[Type[AppenderMixin[_T]]]kwr   r/   r0   c                   t          j        j        | ||d |fi | || _        |rt	          |          | _        |st          | _        d S t          |	                                v r	|| _        d S t          |          | _        d S r>   )r   AttributeImplr<   rK   tuplerM   r2   rD   AppenderMixinmromixin_user_query)r9   rE   rG   rI   rK   rM   rD   rO   s           r;   r<   zDynamicAttributeImpl.__init__W   s     	 )&#tX	
 	
13	
 	
 	
 + 	,!(OODM 	=,Dkoo////*D/<<Dr=   r>   )rE   rF   rG   rH   rI   rJ   rK   rL   rM   r   rD   rN   rO   r   r/   r0   )	r?   r@   rA   _supports_dynamic_iterationr'   r   collection_history_cls__annotations__r<   rB   r=   r;   r)   r)   R   sQ         "&5c:)))) :>= = = = = = =r=   r)   dynamic)lazyc                      e Zd ZeZdS )
DynaLoaderN)r?   r@   rA   r)   
impl_classrB   r=   r;   r\   r\   o   s        %JJJr=   r\   c                       e Zd ZU dZdZded<   ded<   d) fdZed*d            Zej	        d+d            Zd,dZ
erd-dZd.dZd/dZ	 d0d1dZd2d"Zd3d%Zd2d&Zd3d'Zd3d(Z xZS )4rS   zTA mixin that expects to be mixing in a Query class with
    AbstractAppender.


    NzOptional[Type[Query[_T]]]rD   zTuple[ColumnElement[Any], ...]_order_by_clausesr(   r)   r*   r+   r/   r0   c                    t          j        | |j        d            t                                          ||           d S r>   )r   r<   rK   super)r9   r(   r*   	__class__s      r;   r<   zAppenderMixin.__init__~   sG     		
 	
 	

 	u%%%%%r=   Optional[Session]c                    t          | j                  }|$|j        r| j        |v r|                                 t	          j        | j                  sd S |S r>   )r   instancer3   flushorm_utilhas_identityr9   sesss     r;   sessionzAppenderMixin.session   sV    dm,,4=D3H3HJJLLL$T]33 	4Kr=   rk   r   c                    || _         d S r>   )rj   )r9   rk   s     r;   rk   zAppenderMixin.session   s    			r=   1Union[result.ScalarResult[_T], result.Result[_T]]c           
     "   | j         }|t          j        | j                  }|j        r)t          j        dt          j        |          z             t          j
        t          j        | j        j        j        g          t          | j                            t          j        | j                  t"          j                  j                  d                                          S |                     |                                          S )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)rk   r   instance_statere   detachedr   warnrg   	state_strr   IteratorResultSimpleResultMetaDatar(   rE   r?   iter_get_collection_historyr   PASSIVE_NO_INITIALIZEr6   scalars	_generate_iter)r9   rj   r*   s      r;   r{   zAppenderMixin._iter   s    |<-dm<<E~ 	C  )%002   (+TY-=-F,GHHI55"1$-@@#9  "	  *.	 	 	 gii	 >>$''--///r=   Iterator[_T]c                    d S r>   rB   )r9   s    r;   __iter__zAppenderMixin.__iter__   s      r=   indexr   Union[_T, List[_T]]c                   | j         }|O| j                            t          j        | j                  t          j                                      |          S | 	                    |          
                    |          S r>   )rk   r(   rw   r   rp   re   r   rx   indexedrz   __getitem__)r9   r   rj   s      r;   r   zAppenderMixin.__getitem__   sm    |<944)$-881  genn
 >>$''33E:::r=   intc                    | j         }|Nt          | j                            t	          j        | j                  t          j                  j	                  S | 
                    |                                          S r>   )rk   lenr(   rw   r   rp   re   r   rx   r6   rz   countri   s     r;   r   zAppenderMixin.count   sp    |<	11-dm<<5  	   >>$''--///r=   rj   	Query[_T]c                   | j         }|Ht          |          }|7t          j        dt	          j        |          d| j        j        d          | j        r"|                     | j        j	        |          }n|
                    | j        j	                  }| j        |_        | j        |_        | j        |_        |S )NzParent instance zh is not bound to a Session, and no contextual session is established; lazy load operation of attribute 'z' cannot proceed)rk   )re   r   orm_excDetachedInstanceErrorrg   instance_strr(   rG   rD   rK   query_where_criteria	_from_objr_   )r9   rj   re   r   s       r;   rz   zAppenderMixin._generate   s     =<!(++D|33  ,X6666	G    	8$$TY%<d$KKEEJJty677E $ 4."&"8r=   iteratorIterable[_T]c                0    |                      |           dS )a~  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r9   r   s     r;   add_allzAppenderMixin.add_all   s     	8$$$$$r=   itemr$   c                2    |                      |g           dS )ap  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   r9   r   s     r;   addzAppenderMixin.add   s      	D6"""""r=   c                0    |                      |           dS )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     r;   extendzAppenderMixin.extend  s     	8$$$$$r=   c                2    |                      |g           dS )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     r;   appendzAppenderMixin.append  s      	D6"""""r=   c                0    |                      |           dS )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     r;   removezAppenderMixin.remove  s     	$r=   )r(   r)   r*   r+   r/   r0   )r/   rc   )rk   r   r/   r0   )r/   rm   )r/   r|   )r   r   r/   r   )r/   r   r>   )rj   rc   r/   r   )r   r   r/   r0   )r   r$   r/   r0   )r?   r@   rA   __doc__rD   rX   r<   propertyrk   setterr{   r   r~   r   r   rz   r   r   r   r   r   __classcell__)rb   s   @r;   rS   rS   t   s~          .2K11115555& & & & & &    X ^   ^0 0 0 02  0////; ; ; ;
0 
0 
0 
0 #'    :% % % %# # # #% % % %# # # #               r=   rS   c                      e Zd ZdZdS )r2   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.


    N)r?   r@   rA   r   rB   r=   r;   r2   r2     s           r=   r2   clsr   r/   type[AppenderMixin[Any]]c                J    d| j         z   }t          |t          | fd| i          S )zAReturn a new class with AppenderQuery functionality layered over.AppenderrD   )r?   typerS   )r   names     r;   rU   rU   )  s*    $D}c*]C,@AAAr=   N)r   r   r/   r   )7r   
__future__r   typingr   r   r   r   r   r	   r
   r   r   r    r   r   r   r   r   rg   baser   r   r   rk   r   	writeonlyr   r   r   r   enginer   r   mapperr   r   r   r*   r    r!   eventr"   sql.elementsr#   r$   r'   r)   RelationshipPropertystrategy_forr\   rS   r2   rU   rB   r=   r;   <module>r      s  	 	 # " " " " "                                                                                                       # # # # # # / / / / / / - - - - - - ' ' ' ' ' ' & & & & & &              -$$$$$$666666      $$$$$$""""""!!!!!!,,,,,,WT/ / / / //3 / / /*= = = = =1 = = =: #00i0@@& & & & & & & A@&g  g  g  g  g ,R0 g  g  g T    M"%uRy   B B B B B Br=   