
    Mj&                       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 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/                   Z0 G d( d)e          Z1ej2        3                    d*+           G d, d-e                       Z4 G d. d/ee/                   Z5 G d0 d1e5e/         ee/                   Z6d8d6Z7d7S )9zDynamic 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)overload)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         j/lsinfo/ai/hellotax_ai/training_center/backend/venv/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/   r0   r1   )__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   r0   r1   c                   t          j        j        | ||d |fi | || _        |rt	          |          | _        |st          | _        d S t          |	                                v r	|| _        d S t          |          | _        d S r?   )r   AttributeImplr=   rL   tuplerN   r3   rE   AppenderMixinmromixin_user_query)r:   rF   rH   rJ   rL   rN   rE   rP   s           r<   r=   zDynamicAttributeImpl.__init__X   s     	 )&#tX	
 	
13	
 	
 	
 + 	,!(OODM 	=,Dkoo////*D/<<Dr>   r?   )rF   rG   rH   rI   rJ   rK   rL   rM   rN   r   rE   rO   rP   r   r0   r1   )	r@   rA   rB   _supports_dynamic_iterationr(   r   collection_history_cls__annotations__r=   rC   r>   r<   r*   r*   S   sQ         "&5c:)))) :>= = = = = = =r>   r*   dynamic)lazyc                      e Zd ZeZdS )
DynaLoaderN)r@   rA   rB   r*   
impl_classrC   r>   r<   r]   r]   p   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d0dZ
erd1dZed2d            Zed3d            Zd4d Zd5d!Z	 d6d7d$Zd8d'Zd9d)Zd8d*Zd9d+Zd9d,Z xZS ):rT   zTA mixin that expects to be mixing in a Query class with
    AbstractAppender.


    NzOptional[Type[Query[_T]]]rE   zTuple[ColumnElement[Any], ...]_order_by_clausesr)   r*   r+   r,   r0   r1   c                    t          j        | |j        d            t                                          ||           d S r?   )r   r=   rL   super)r:   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   instancer4   flushorm_utilhas_identityr:   sesss     r<   sessionzAppenderMixin.session   sV    dm,,4=D3H3HJJLLL$T]33 	4Kr>   rl   r    c                    || _         d S r?   )rk   )r:   rl   s     r<   rl   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)rl   r   instance_staterf   detachedr   warnrh   	state_strr   IteratorResultSimpleResultMetaDatar)   rF   r@   iter_get_collection_historyr   PASSIVE_NO_INITIALIZEr7   scalars	_generate_iter)r:   rk   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?   rC   )r:   s    r<   __iter__zAppenderMixin.__iter__   s      r>   indexintr%   c                    d S r?   rC   r:   r   s     r<   __getitem__zAppenderMixin.__getitem__   s    -0Sr>   sliceList[_T]c                    d S r?   rC   r   s     r<   r   zAppenderMixin.__getitem__   s    58Sr>   Union[int, slice]Union[_T, List[_T]]c                   | j         }|O| j                            t          j        | j                  t          j                                      |          S | 	                    |          
                    |          S r?   )rl   r)   rx   r   rq   rf   r   ry   indexedr{   r   )r:   r   rk   s      r<   r   zAppenderMixin.__getitem__   sm    |<944)$-881  genn
 >>$''33E:::r>   c                    | j         }|Nt          | j                            t	          j        | j                  t          j                  j	                  S | 
                    |                                          S r?   )rl   lenr)   rx   r   rq   rf   r   ry   r7   r{   countrj   s     r<   r   zAppenderMixin.count   sp    |<	11-dm<<5  	   >>$''--///r>   rk   	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)rl   )rf   r   orm_excDetachedInstanceErrorrh   instance_strr)   rH   rE   rL   query_where_criteria	_from_objr`   )r:   rk   rf   r   s       r<   r{   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:   r   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

        Nr   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.

        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,   r0   r1   )r0   rd   )rl   r    r0   r1   )r0   rn   )r0   r}   )r   r   r0   r%   )r   r   r0   r   )r   r   r0   r   )r0   r   r?   )rk   rd   r0   r   )r   r   r0   r1   )r   r%   r0   r1   )r@   rA   rB   __doc__rE   rY   r=   propertyrl   setterr|   r   r   r	   r   r   r{   r   r   r   r   r   __classcell__)rc   s   @r<   rT   rT   u   s          .2K11115555& & & & & &    X ^   ^0 0 0 02  0////000 X0888 X8; ; ; ;
0 
0 
0 
0 #'    :% % % %# # # #% % % %# # # #               r>   rT   c                      e Zd ZdZdS )r3   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@   rA   rB   r   rC   r>   r<   r3   r3   %  s           r>   r3   clsr   r0   type[AppenderMixin[Any]]c                J    d| j         z   }t          |t          | fd| i          S )zAReturn a new class with AppenderQuery functionality layered over.AppenderrE   )r@   typerT   )r   names     r<   rV   rV   0  s*    $D}c*]C,@AAAr>   N)r   r   r0   r   )8r   
__future__r   typingr   r   r   r   r   r	   r
   r   r   r   r    r   r   r   r   r   rh   baser   r   r   rl   r   	writeonlyr   r   r   r   enginer   r   mapperr   r   r    r+   r!   r"   eventr#   sql.elementsr$   r%   r(   r*   RelationshipPropertystrategy_forr]   rT   r3   rV   rC   r>   r<   <module>r      s  	 	 # " " " " "                                                                                                             # # # # # # / / / / / / - - - - - - ' ' ' ' ' ' & & & & & &              -$$$$$$666666      $$$$$$""""""!!!!!!,,,,,,WT/ / / / //3 / / /*= = = = =1 = = =: #00i0@@& & & & & & & A@&m  m  m  m  m ,R0 m  m  m `    M"%uRy   B B B B B Br>   