
    Wd!                       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 erddlmZ  ede          Z G d de          Z G d de          Zej                             d           G d de                      Z! G d  d!ee                   Z" G d" d#e"e         ee                   Z#d$ Z$d%S )&zDynamic 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)TYPE_CHECKING)TypeVar   )
attributes)exc)relationships)util)Query)object_session)AbstractCollectionWriter)WriteOnlyAttributeImpl)WriteOnlyHistory)WriteOnlyLoader   )result)Session_T)boundc                      e Zd ZddZdS )DynamicCollectionHistoryNc                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)selfattrstatepassiveapply_tocolls         R/var/www/html/t/fyr/venv311/lib/python3.11/site-packages/sqlalchemy/orm/dynamic.py__init__z!DynamicCollectionHistory.__init__2   s     
	/ u--77>>D#'#:4#@#@D '3D!)!7D)-D&&&!%!8!:!:D#688D#'#:#<#<D ).D&&&    N)__name__
__module____qualname__r*    r+   r)   r   r   1   s(        / / / / / /r+   r   c                       e Zd ZdZeZ	 ddZdS )DynamicAttributeImplTNc                   t          j        j        | ||||fi | || _        |rt	          |          | _        |st          | _        d S t          |	                                v r	|| _        d S t          |          | _        d S r,   )r
   AttributeImplr*   target_mappertupleorder_byr   query_classAppenderMixinmromixin_user_query)	r#   class_keytypecallabledispatchr5   r7   r8   kws	            r)   r*   zDynamicAttributeImpl.__init__D   s     	 )&#|X	
 	
9;	
 	
 	
 + 	,!(OODM 	=,Dkoo////*D/<<Dr+   r,   )r-   r.   r/   _supports_dynamic_iterationr   collection_history_clsr*   r0   r+   r)   r2   r2   @   s9        "&5 = = = = = =r+   r2   dynamic)lazyc                      e Zd ZeZdS )
DynaLoaderN)r-   r.   r/   r2   
impl_classr0   r+   r)   rF   rF   ]   s        %JJJr+   rF   c                       e Zd ZdZdZ fdZedd            Zej        dd	            Zd
 Z	e
rddZddZd dZd!dZd"dZd#dZd"dZd#dZd#dZ xZS )$r9   zTA mixin that expects to be mixing in a Query class with
    AbstractAppender.


    Nc                    t          j        | |j        d            t                                          ||           d S r,   )r   r*   r5   super)r#   r$   r%   	__class__s      r)   r*   zAppenderMixin.__init__k   s:    tT/666u%%%%%r+   returnr   c                    t          | j                  }|+| j        r$|j        r| j        |v r|                                 t	          j        | j                  sd S |S r,   )r   instancer   flushorm_utilhas_identityr#   sesss     r)   sessionzAppenderMixin.sessiono   sf    dm,,   %%JJLLL$T]33 	4Kr+   rT   Nonec                    || _         d S r,   )rS   )r#   rT   s     r)   rT   zAppenderMixin.session~   s    			r+   c                   | j         }|t          j        | j                  }|j        r)t          j        dt          j        |          z             t          j
        t          j        | j        j        j        g          | 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)rT   r
   instance_staterN   detachedr   warnrP   	state_strr   IteratorResultSimpleResultMetaDatar$   r<   r-   _get_collection_historyPASSIVE_NO_INITIALIZEr    scalars	_generate_iter)r#   rS   r%   s      r)   rc   zAppenderMixin._iter   s    |<-dm<<E~ 	C  )%002   (+TY-=-F,GHH	11-dm<<4  )-   gii >>$''--///r+   Iterator[_T]c                    d S r,   r0   )r#   s    r)   __iter__zAppenderMixin.__iter__   s    Cr+   indexr   r   c                   | j         }|O| j                            t          j        | j                  t          j                                      |          S |                     |          	                    |          S r,   )
rT   r$   r_   r
   rY   rN   r`   indexedrb   __getitem__)r#   rg   rS   s      r)   rj   zAppenderMixin.__getitem__   sm    |<944)$-880  genn
 >>$''33E:::r+   intc                    | j         }|Nt          | j                            t	          j        | j                  t          j                  j                  S | 	                    |          
                                S r,   )rT   lenr$   r_   r
   rY   rN   r`   r    rb   countrR   s     r)   rn   zAppenderMixin.count   sp    |<	11-dm<<4  	   >>$''--///r+   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)rT   )rN   r   orm_excDetachedInstanceErrorrP   instance_strr$   r=   r8   r5   query_where_criteria	_from_obj_order_by_clauses)r#   rS   rN   rs   s       r)   rb   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r#   rw   s     r)   add_allzAppenderMixin.add_all   s     	8$$$$$r+   itemc                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

        Nrz   r#   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.

        Nrz   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.

        Nrz   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+   )rL   r   )rT   r   rL   rU   )rL   rd   )rg   r   rL   r   )rL   rk   r,   )rw   rx   rL   rU   )r~   r   rL   rU   )r-   r.   r/   __doc__r8   r*   propertyrT   setterrc   r   rf   rj   rn   rb   r}   r   r   r   r   __classcell__)rK   s   @r)   r9   r9   b   sX         K& & & & &    X ^   ^0 0 0.  	 	 	 	; ; ; ;
0 
0 
0 
0   4% % % %# # # #% % % %# # # #               r+   r9   c                      e Zd ZdZdS )r   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.   r/   r   r0   r+   r)   r   r     s           r+   r   c                J    d| j         z   }t          |t          | fd| i          S )zAReturn a new class with AppenderQuery functionality layered over.Appenderr8   )r-   typer9   )clsnames     r)   r;   r;     s*    $D}c*]C,@AAAr+   N)%r   
__future__r   typingr   r   r   r   r    r
   r   rp   r   r   rP   rs   r   rT   r   	writeonlyr   r   r   r   enginer   r   r   r   r2   RelationshipPropertystrategy_forrF   r9   r   r;   r0   r+   r)   <module>r      s  	 	 # " " " " "                                                                   # # # # # # / / / / / / - - - - - - ' ' ' ' ' ' & & & & & &             !       WT/ / / / // / / /= = = = =1 = = =: #00i0@@& & & & & & & A@&a  a  a  a  a ,R0 a  a  a H    M"%uRy   B B B B Br+   