
    [h!W                       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 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rNdd)lm.Z. dd*l/m0Z0 dd+lm1Z1 dd,lm2Z2 dd-l3m4Z4 dd.l3m5Z5 dd/l6m7Z7 dd0lm8Z8 dd1l9m:Z: dd2l"m;Z; dd3l<m=Z= dd4l>m?Z? dd5l>m@Z@  ed6e7          ZA G d8 d9eeA                   ZB G d: d;ejC        ejD                  ZEe!jF        ejG        H                    d<=           G d> d?ejI        e!jJ                                          ZK G d@ dA          ZL G dB dCeeA                   ZM G dD dEeMeA                   ZNdFS )GzWrite-only collection API.

This is an alternate mapped attribute style that only supports single-item
collection mutation operations.   To read the collection, a select()
object must be executed each time.

.. versionadded:: 2.0


    )annotations)Any)
Collection)Dict)Generic)Iterable)Iterator)List)NoReturn)Optional)overload)Tuple)Type)TYPE_CHECKING)TypeVar)Union)	bindparam   )
attributes)
interfaces)relationships)
strategies)	NEVER_SET)object_mapper)PassiveFlag)RelationshipDirection   )exc)inspect)log)util)delete)insert)select)update)Delete)Insert)Update)Literal)QueryableAttribute)_InstanceDict)AttributeEventToken)LoaderCallableStatus)_AdaptedCollectionProtocol)CollectionAdapter)Mapper)_RelationshipOrderByArg)InstanceState)AliasedClass)	_Dispatch)
FromClause)Select_T)boundc                      e Zd ZU dZded<   ded<   ded<   ded<   	 d!d"dZed#d            Zed#d            Zd$dZ	d%dZ
d&dZd&d ZdS )'WriteOnlyHistoryzDOverrides AttributeHistory to receive append/remove events directly.zutil.OrderedIdentitySetunchanged_itemsadded_itemsdeleted_itemsbool_reconcile_collectionNattrWriteOnlyAttributeImplstateInstanceState[_T]passiver   apply_toOptional[WriteOnlyHistory[_T]]returnNonec                `   |r\|t           j        z  rt          j        d| d| d          |j        | _        |j        | _        |j        | _        |j        | _        d S t          j	                    | _        t          j	                    | _        t          j	                    | _        d| _        d S )Nz
Attribute z can't load the existing state from the database for this operation; full iteration is not permitted.  If this is a delete operation, configure passive_deletes=True on the z- relationship in order to resolve this error.F)
r   SQL_OKr   InvalidRequestErrorr;   r<   r=   r?   r!   OrderedIdentitySet)selfr@   rB   rD   rE   s        g/var/www/api.easyaligner.net/htdocs/venv_linux/lib/python3.11/site-packages/sqlalchemy/orm/writeonly.py__init__zWriteOnlyHistory.__init__U   s      	/++ -3 3 3 483 3 3   $,#;D '3D!)!7D)1)GD&&&!%!8!:!:D#688D#'#:#<#<D ).D&&&    List[_T]c                Z    t          | j                            | j                            S N)listr<   unionr;   rM   s    rN   added_plus_unchangedz%WriteOnlyHistory.added_plus_unchangedp   s$    D$**4+?@@AAArP   c                    t          | j                            | j                                      | j                            S rS   )rT   r<   rU   r;   r=   rV   s    rN   	all_itemszWriteOnlyHistory.all_itemst   sA    ""4#788>>" 
 
 	
rP   attributes.Historyc                f   | j         rY| j                            | j                  }| j                            | j                  }| j                            |          }n| j        | j        | j        }}}t          j        t          |          t          |          t          |                    S rS   )	r?   r<   
differencer;   r=   intersectionr   HistoryrT   )rM   addeddeleted	unchangeds       rN   
as_historyzWriteOnlyHistory.as_history|   s    % 		$//0DEEE(55d6JKKG,77@@II  $" &9E
 !$u++tIWNNNrP   indexUnion[int, slice]Union[List[_T], _T]c                6    t          | j                  |         S rS   )rT   r<   )rM   rc   s     rN   indexedzWriteOnlyHistory.indexed   s    D$%%e,,rP   valuer7   c                :    | j                             |           d S rS   )r<   addrM   rh   s     rN   	add_addedzWriteOnlyHistory.add_added   s    U#####rP   c                    || j         v r| j                             |           d S | j                            |           d S rS   )r<   remover=   rj   rk   s     rN   add_removedzWriteOnlyHistory.add_removed   sJ    D$$$##E*****""5)))))rP   rS   )
r@   rA   rB   rC   rD   r   rE   rF   rG   rH   )rG   rQ   )rG   rZ   )rc   rd   rG   re   )rh   r7   rG   rH   )__name__
__module____qualname____doc____annotations__rO   propertyrW   rY   rb   rg   rl   ro    rP   rN   r:   r:   M   s        NN,,,,((((**** 48/ / / / /6 B B B XB 
 
 
 X
O O O O- - - -$ $ $ $* * * * * *rP   r:   c                  ,    e Zd ZU dZded<   dZded<   dZded<   dZded<   dZded<   dZ	ded	<   d
Z
ded<   eZded<   ded<   dP fdZej        fdQd$Ze	 	 dRdSd*            Ze	 	 dRdTd,            Ze	 	 dRdUd/            Zd0ej        fdUd1Zej        dVd3            Zej        dVd4            Z	 dWdXd;Z	 dWdXd<ZdYd>Zd0ej        d0ddfdZdBZd[dFZd\dGZej        fd]dIZej        fd^dKZ d_dLZ!ej        fd`dMZ"ej        fd`dNZ#ej        fd`dOZ$ xZ%S )arA   Tr>   uses_objectsFdefault_accepts_scalar_loadersupports_population_supports_dynamic_iteration
collectiondynamicrv   r1   order_byzType[WriteOnlyHistory[Any]]collection_history_clszType[WriteOnlyCollection[Any]]query_classclass_#Union[Type[Any], AliasedClass[Any]]keystrdispatch"_Dispatch[QueryableAttribute[Any]]target_mapper
Mapper[_T]kwr   c                     t                      j        ||d |fi | || _        t          | _        |rt          |          | _        d S d S rS   )superrO   r   WriteOnlyCollectionr   tupler~   )rM   r   r   r   r   r~   r   	__class__s          rN   rO   zWriteOnlyAttributeImpl.__init__   s]     	dH;;;;;*. 	,!(OODMMM	, 	,rP   rB   InstanceState[Any]dict_r+   rD   r   rG   8Union[util.OrderedIdentitySet, WriteOnlyCollection[Any]]c                    |t           j        z  s%|                     |t           j                  j        S |                     | |          S rS   )r   rJ   _get_collection_historyPASSIVE_NO_INITIALIZEr<   r   )rM   rB   r   rD   s       rN   getzWriteOnlyAttributeImpl.get   sO     ++ 	1//{8  ##D%000rP   .	user_dataLiteral[None] Literal[PassiveFlag.PASSIVE_OFF]r/   c                    d S rS   rv   rM   rB   r   r   rD   s        rN   get_collectionz%WriteOnlyAttributeImpl.get_collection   	      CrP   r.   c                    d S rS   rv   r   s        rN   r   z%WriteOnlyAttributeImpl.get_collection   r   rP   $Optional[_AdaptedCollectionProtocol]IUnion[Literal[LoaderCallableStatus.PASSIVE_NO_RESULT], CollectionAdapter]c                    d S rS   rv   r   s        rN   r   z%WriteOnlyAttributeImpl.get_collection   s	     srP   Nc                    |t           j        z  s|                     ||          j        }n|                     ||          }|j        }t          |          S rS   )r   rJ   r   r<   rW   DynamicCollectionAdapter)rM   rB   r   r   rD   datahistorys          rN   r   z%WriteOnlyAttributeImpl.get_collection   sY     ++ 	0//w??KDD225'BBG/D'---rP   attributes.AttributeEventTokenc                @    t          j        | t           j                  S rS   )r   r,   	OP_APPENDrV   s    rN   _append_tokenz$WriteOnlyAttributeImpl._append_token        -dJ4HIIIrP   c                @    t          j        | t           j                  S rS   )r   r,   	OP_REMOVErV   s    rN   _remove_tokenz$WriteOnlyAttributeImpl._remove_token   r   rP   rh   	initiatorOptional[AttributeEventToken]collection_historyOptional[WriteOnlyHistory[Any]]rH   c                   ||                      ||          }|                    |           | j        j        D ]} ||||p| j                  }| j        r-|-|                     t          j        |          |d           d S d S d S NT)	_modified_eventrl   r   appendr   trackparentsethasparentr   instance_staterM   rB   r   rh   r   r   fns          rN   fire_append_eventz(WriteOnlyAttributeImpl.fire_append_event   s     %!%!5!5eU!C!C$$U+++-& 	F 	FBBueY%D$2DEEEE 	M 1j7>>tLLLLL	M 	M 1 1rP   c                
   ||                      ||          }|                    |           | j        r+|)|                     t	          j        |          |d           | j        j        D ]} ||||p| j                   d S )NF)	r   ro   r   r   r   r   r   rn   r   r   s          rN   fire_remove_eventz(WriteOnlyAttributeImpl.fire_remove_event  s     %!%!5!5eU!C!C&&u--- 	N 1j7>>uMMM-& 	> 	>BBueY<$*<====	> 	>rP   WriteOnlyHistory[Any]c                    | j         |j        vr.|                     | |t          j                  |j        | j         <   |                    || t                     d|| j         <   |j        | j                  S r   )r   committed_stater   r   PASSIVE_NO_FETCHr   r   )rM   rB   r   s      rN   r   z&WriteOnlyAttributeImpl._modified_event   st     85000.2.I.Ie[9/ /E!$(+ 	eT9555 dh$TX..rP   	check_oldpop_adaptc	                   |r|j         | j         u rd S |r|d S |}	t          |	          }
|j        rI| j        st	          j        d|  d          t          j        |                     |||                    }| 	                    ||          }|j        s|j
        }n|                    |j
                  }|                    |
          }t          j        |
                              |          }|                    |          }|
D ] }||v r|                     |||d |           !|D ]}|                     |||d |           d S )NzCollection "zV" does not support implicit iteration; collection replacement operations can't be usedrD   )r   )parent_tokenrT   has_identityr{   r   rK   r!   IdentitySetr   r   r<   rU   r]   r\   r   r   )rM   rB   r   rh   r   rD   r   r   r   iterable
new_valuesold_collectionr   	constants	additionsremovalsmembers                    rN   setzWriteOnlyAttributeImpl.set/  s     	/43DDDF 	5=F(^^
 		3 -$4 $ $ $  
 "-w77 N "11%??! 	/;NN+11". N #//
;;	$Z00;;IFF	!,,Y77  	 	F""&&'9 '     	 	F""#5 #    	 	rP   argskwargsr   c                    t                      rS   NotImplementedError)rM   r   r   s      rN   r"   zWriteOnlyAttributeImpl.deletel  s    !###rP   c                     t          d          )Nz7Dynamic attributes don't support collection population.r   )rM   rB   r   rh   s       rN   set_committed_valuez*WriteOnlyAttributeImpl.set_committed_valueo  s     "E
 
 	
rP   rZ   c                V    |                      ||          }|                                S rS   )r   rb   rM   rB   r   rD   cs        rN   get_historyz"WriteOnlyAttributeImpl.get_historyv  s'     ((88||~~rP   $List[Tuple[InstanceState[Any], Any]]c                P    |                      ||          }d |j        D             S )Nc                :    g | ]}t          j        |          |fS rv   )r   r   ).0xs     rN   
<listcomp>z:WriteOnlyAttributeImpl.get_all_pending.<locals>.<listcomp>  s(    GGGa*1--q1GGGrP   )r   rY   r   s        rN   get_all_pendingz&WriteOnlyAttributeImpl.get_all_pending  s/     ((88GG1;GGGGrP   c                    | j         |j        v r|j        | j                  }n!|                     | |t          j                  }|j        r(|t          j        z  r|                     | |||          S |S )N)rE   )r   r   r   r   r   r   INIT_OK)rM   rB   rD   r   s       rN   r   z.WriteOnlyAttributeImpl._get_collection_history  s     8u,,,%dh/AA++e[9 A  	7[-@#@ 	..eWq /    HrP   c                B    || ur|                      ||||           d S d S rS   )r   rM   rB   r   rh   r   rD   s         rN   r   zWriteOnlyAttributeImpl.append  7     D  ""5%	BBBBB ! rP   c                B    || ur|                      ||||           d S d S rS   )r   r   s         rN   rn   zWriteOnlyAttributeImpl.remove  r   rP   c                :    |                      |||||           d S )Nr   )rn   r   s         rN   r   zWriteOnlyAttributeImpl.pop  s&     	E5%GDDDDDrP   )r   r   r   r   r   r   r   r   r~   r1   r   r   )rB   r   r   r+   rD   r   rG   r   )..)
rB   r   r   r+   r   r   rD   r   rG   r/   )
rB   r   r   r+   r   r.   rD   r   rG   r/   )
rB   r   r   r+   r   r   rD   r   rG   r   )rG   r   rS   )rB   r   r   r+   rh   r   r   r   r   r   rG   rH   )rB   r   r   r+   rG   r   )rB   r   r   r+   rh   r   r   r   rD   r   r   r   r   r>   r   r>   rG   rH   )r   r   r   r   rG   r   )rB   r   r   r+   rh   r   rG   r   )rB   r   r   r+   rD   r   rG   rZ   )rB   r   r   r+   rD   r   rG   r   )rB   r   rD   r   rG   r   )rB   r   r   r+   rh   r   r   r   rD   r   rG   rH   )&rp   rq   rr   rx   rt   ry   rz   r{   r|   r}   r~   r:   r   rO   r   PASSIVE_OFFr   r   r   r!   memoized_propertyr   r   r   r   r   r   r"   r   r   r   r   r   r   r   rn   r   __classcell__)r   s   @rN   rA   rA      ss         L*/!//// %%%%%(-----JG(*H****:JJJJJ////, , , , , ,&  +6	1 1 1 1 1 
 $'47        X  
 14"        X  
 ;>"    X ;?*6. . . . ." 
J J J J
 
J J J J ?CM M M M M2 ?C> > > > >&/ / / /( 48*6; ; ; ; ;z$ $ $ $
 
 
 
  +;	      +@	H H H H H   0  +;	C 	C 	C 	C 	C"  +;	C 	C 	C 	C 	C"  +;E E E E E E E E ErP   rA   
write_only)lazyc                      e Zd ZeZddZdS )WriteOnlyLoadermapperMapper[Any]rG   rH   c           	     (   d| _         | j        r$| j        j        t          j        t          j        fvrt          j        d| j        z            t          j
        | j        |d| j        | j        j        | j        j        | j        j                   d S )NTztOn relationship %s, 'dynamic' loaders cannot be used with many-to-one/one-to-one relationships and/or uselist=False.)	useobject
impl_classr   r~   r   )is_class_leveluselistparent_property	directionr   	ONETOMANY
MANYTOMANYr   rK   r   _register_attributer   r   r~   r   )rM   r   s     rN   init_class_attributez$WriteOnlyLoader.init_class_attribute  s    "| 	t3= !F
  
  
 )!#'#78   	& .5)2,8	
 	
 	
 	
 	
 	
rP   N)r   r   rG   rH   )rp   rq   rr   rA   r   r   rv   rP   rN   r   r     s/         (J
 
 
 
 
 
rP   r   c                  F    e Zd ZU dZded<   ddZddZdd	ZddZddZ	dS )r   z9simplified CollectionAdapter for internal API consistencyCollection[Any]r   c                    || _         d S rS   )r   )rM   r   s     rN   rO   z!DynamicCollectionAdapter.__init__  s    			rP   rG   Iterator[Any]c                *    t          | j                  S rS   )iterr   rV   s    rN   __iter__z!DynamicCollectionAdapter.__iter__  s    DIrP   rH   c                    d S rS   rv   rV   s    rN   _reset_emptyz%DynamicCollectionAdapter._reset_empty  s    rP   intc                *    t          | j                  S rS   )lenr   rV   s    rN   __len__z DynamicCollectionAdapter.__len__  s    49~~rP   r>   c                    dS r   rv   rV   s    rN   __bool__z!DynamicCollectionAdapter.__bool__  s    trP   N)r   r   )rG   r  )rG   rH   )rG   r  )rG   r>   )
rp   rq   rr   rs   rt   rO   r  r  r
  r  rv   rP   rN   r   r     s         CC                 rP   r   c                  H    e Zd ZU dZesdZded<   ded<   ddZddZddZ	dS )AbstractCollectionWriterzsVirtual collection which includes append/remove methods that synchronize
    into the attribute event system.

    rv   r7   instancezTuple[FromClause, ...]	_from_objr@   rA   rB   rC   c                   |                                 }t          r|sJ || _        || _        t	          |          }|j        | j        j                 }|j        &|j        	                                |j        f| _
        nd| _
        |                    |d          f| _        | j        j        r| j        j        | _        d S d| _        d S )Nrv   F)alias_secondary)objr   r  r@   r   _propsr   	secondaryr   __clause_element__r  _with_parent_where_criteriar~   _order_by_clauses)rM   r@   rB   r  r   props         rN   rO   z!AbstractCollectionWriter.__init__  s    99;; 	OOO 	x((}TY]+>% #k<<>>ODNNDN h>> 
 9 	(%)Y%7D"""%'D"""rP   iteratorIterable[_T]rG   rH   c                    |D ]M}| j                             t          j        | j                  t          j        | j                  |d            Nd S rS   )r@   r   r   r   r  instance_dict)rM   r  items      rN   _add_all_implz&AbstractCollectionWriter._add_all_impl  s`     	 	DI)$-88(77	   	 	rP   r  c                    | j                             t          j        | j                  t          j        | j                  |d            d S rS   )r@   rn   r   r   r  r  rM   r  s     rN   _remove_implz%AbstractCollectionWriter._remove_impl"  sL    	%dm44$T]33		
 	
 	
 	
 	
rP   N)r@   rA   rB   rC   r  r  rG   rH   r  r7   rG   rH   )
rp   rq   rr   rs   r   	__slots__rt   rO   r   r#  rv   rP   rN   r  r    s          
  	LLL%%%%( ( ( (B   
 
 
 
 
 
rP   r  c                  V    e Zd ZdZ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dS )r   a  Write-only collection which can synchronize changes into the
    attribute event system.

    The :class:`.WriteOnlyCollection` is used in a mapping by
    using the ``"write_only"`` lazy loading strategy with
    :func:`_orm.relationship`.     For background on this configuration,
    see :ref:`write_only_relationship`.

    .. versionadded:: 2.0

    .. seealso::

        :ref:`write_only_relationship`

    )r  r@   r  r  r  rG   r   c                     t          d          )NzWriteOnly collections don't support iteration in-place; to query for collection items, use the select() method to produce a SQL statement and execute it with session.scalars().)	TypeErrorrV   s    rN   r  zWriteOnlyCollection.__iter__D  s    M
 
 	
rP   Select[Tuple[_T]]c                     t          | j        j                  j        | j         }| j        r |j        | j         }| j        r |j        | j         }|S )zProduce a :class:`_sql.Select` construct that represents the
        rows within this instance-local :class:`_orm.WriteOnlyCollection`.

        )	r$   r@   r   wherer  r  select_fromr  r~   )rM   stmts     rN   r$   zWriteOnlyCollection.selectK  s_    
 5vdi-..4d6JK> 	5#4#T^4D! 	: 4=$"89DrP   r'   c                   t          | j                  }|j        }|j        | j        j                 }|j        t          j        urt          j
        d          i }|j        D ];\  }}|                    |||j        |          }t          d|          ||j        <   < t          | j        j                  j        di |S )aN  For one-to-many collections, produce a :class:`_dml.Insert` which
        will insert new rows in terms of this this instance-local
        :class:`_orm.WriteOnlyCollection`.

        This construct is only supported for a :class:`_orm.Relationship`
        that does **not** include the :paramref:`_orm.relationship.secondary`
        parameter.  For relationships that refer to a many-to-many table,
        use ordinary bulk insert techniques to produce new objects, then
        use :meth:`_orm.AbstractCollectionWriter.add_all` to associate them
        with the collection.


        zWrite only bulk INSERT only supported for one-to-many collections; for many-to-many, use a separate bulk INSERT along with add_all().N)	callable_rv   )r   r  r   r  r@   r   r   r   r   r   rK   synchronize_pairs_get_attr_w_warn_on_nonedictr   r#   r   values)rM   rB   r   r  r   lrr   s           rN   r#   zWriteOnlyCollection.insertW  s     &&}TY]+>!6!@@@)/   !#* 	9 	9DAq..
	 B %TR888E!%LL5vdi-..5>>>>>rP   r(   c                N     t          | j        j                  j        | j         S )zProduce a :class:`_dml.Update` which will refer to rows in terms
        of this instance-local :class:`_orm.WriteOnlyCollection`.

        )r%   r@   r   r,  r  rV   s    rN   r%   zWriteOnlyCollection.update  $    
 5vdi-..4d6JKKrP   r&   c                N     t          | j        j                  j        | j         S )zProduce a :class:`_dml.Delete` which will refer to rows in terms
        of this instance-local :class:`_orm.WriteOnlyCollection`.

        )r"   r@   r   r,  r  rV   s    rN   r"   zWriteOnlyCollection.delete  r8  rP   r  r  rH   c                0    |                      |           dS )zAdd an iterable of items to this :class:`_orm.WriteOnlyCollection`.

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

        Nr   )rM   r  s     rN   add_allzWriteOnlyCollection.add_all  s     	8$$$$$rP   r  r7   c                2    |                      |g           dS )zAdd an item to this :class:`_orm.WriteOnlyCollection`.

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

        Nr;  r"  s     rN   rj   zWriteOnlyCollection.add  s      	D6"""""rP   c                0    |                      |           dS )zRemove an item from this :class:`_orm.WriteOnlyCollection`.

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

        N)r#  r"  s     rN   rn   zWriteOnlyCollection.remove  s     	$rP   N)rG   r   )rG   r*  )rG   r'   )rG   r(   )rG   r&   r$  r%  )rp   rq   rr   rs   r&  r  r$   r#   r%   r"   r<  rj   rn   rv   rP   rN   r   r   +  s          I
 
 
 

 
 
 
&? &? &? &?PL L L LL L L L% % % %# # # #           rP   r   N)Ors   
__future__r   typingr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   sqlalchemy.sqlr    r   r   r   r   baser   r   r   r   r   r   r    r!   sqlr"   r#   r$   r%   sql.dmlr&   r'   r(   util.typingr)   r*   _typingr+   r,   r-   collectionsr.   r/   r   r0   r1   rB   r2   r3   eventr4   sql.selectabler5   r6   r7   r:   HasCollectionAdapterAttributeImplrA   class_loggerRelationshipPropertystrategy_forAbstractRelationshipLoader
Identifiedr   r   r  r   rv   rP   rN   <module>rR     s(  	 	 # " " " " "                                                                                                 $ $ $ $ $ $                                           ' ' ' ' ' '                                                                   ! ! ! ! ! ! ($$$$$$&&&&&&//////******777777......666666$$$$$$""""""!!!!!!++++++''''''WTF* F* F* F* F*wr{ F* F* F*RbE bE bE bE bE#Z%=bE bE bEJ	 #00l0CC
 
 
 
 
j;S^ 
 
 DC 
4       *<
 <
 <
 <
 <
wr{ <
 <
 <
~{  {  {  {  { 226 {  {  {  {  { rP   