
    WdQL                    4   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' er*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)l0m1Z1  ed*e+          Z2 G d, d-          Z3 G d. d/ej4        ej5                  Z6ej7        ej8        9                    d01           G d2 d3ej:        ej;                                          Z< G d4 d5          Z= G d6 d7ee2                   Z> G d8 d9e>e2                   Z?d:S );zWrite-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)Generic)Iterable)NoReturn)Optional)overload)Tuple)TYPE_CHECKING)TypeVar)Union)	bindparam   )
attributes)
interfaces)relationships)
strategies)object_mapper)PassiveFlag)RelationshipDirection   )exc)inspect)log)util)delete)insert)select)update)Delete)Insert)Update)Literal)_InstanceDict)_AdaptedCollectionProtocol)AttributeEventToken)CollectionAdapter)LoaderCallableStatus)InstanceState)Select_T)boundc                  ^    e Zd ZdZd
dZed             Zed             Zd Zd Z	d Z
d	 ZdS )WriteOnlyHistoryzDOverrides AttributeHistory to receive append/remove events directly.Nc                `   |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   InvalidRequestErrorunchanged_itemsadded_itemsdeleted_items_reconcile_collectionr   OrderedIdentitySet)selfattrstatepassiveapply_tos        T/var/www/html/t/fyr/venv311/lib/python3.11/site-packages/sqlalchemy/orm/writeonly.py__init__zWriteOnlyHistory.__init__G   s     	/++ -3 3 3 483 3 3   $,#;D '3D!)!7D)1)GD&&&!%!8!:!:D#688D#'#:#<#<D ).D&&&    c                Z    t          | j                            | j                            S N)listr3   unionr2   r7   s    r<   added_plus_unchangedz%WriteOnlyHistory.added_plus_unchanged\   s$    D$**4+?@@AAAr>   c                    t          | j                            | j                                      | j                            S r@   )rA   r3   rB   r2   r4   rC   s    r<   	all_itemszWriteOnlyHistory.all_items`   sA    ""4#788>>" 
 
 	
r>   c                f   | j         rY| j                            | j                  }| j                            | j                  }| j                            |          }n| j        | j        | j        }}}t          j        t          |          t          |          t          |                    S r@   )	r5   r3   
differencer2   r4   intersectionr   HistoryrA   )r7   addeddeleted	unchangeds       r<   
as_historyzWriteOnlyHistory.as_historyh   s    % 		$//0DEEE(55d6JKKG,77@@II  $" &9E
 !$u++tIWNNNr>   c                6    t          | j                  |         S r@   )rA   r3   )r7   indexs     r<   indexedzWriteOnlyHistory.indexedu   s    D$%%e,,r>   c                :    | j                             |           d S r@   )r3   addr7   values     r<   	add_addedzWriteOnlyHistory.add_addedx   s    U#####r>   c                    || j         v r| j                             |           d S | j                            |           d S r@   )r3   remover4   rS   rT   s     r<   add_removedzWriteOnlyHistory.add_removed{   sJ    D$$$##E*****""5)))))r>   r@   )__name__
__module____qualname____doc__r=   propertyrD   rF   rN   rQ   rV   rY    r>   r<   r.   r.   D   s        NN/ / / /* B B XB 
 
 X
O O O- - -$ $ $* * * * *r>   r.   c                      e Zd ZdZdZdZdZdZdZdZ	e
Z fdZej        fdZe	 	 d1d2d            Ze	 	 d1d3d            Ze	 	 d1d4d            Zdej        fd4dZej        d             Zej        d             Z	 d5dZ	 d5dZd Zdej        dddfd6d(Zd) Zd* Zej        fd+Zej        fd,Z d- Z!ej        fd.Z"ej        fd/Z#ej        fd0Z$ xZ%S )7WriteOnlyAttributeImplTFr_   c                     t                      j        ||||fi | || _        t          | _        |rt          |          | _        d S d S r@   )superr=   target_mapperWriteOnlyCollectionquery_classtupleorder_by)	r7   class_keytypecallabledispatchrd   rh   kw	__class__s	           r<   r=   zWriteOnlyAttributeImpl.__init__   s]     	lHCCCCC*. 	,!(OODMMM	, 	,r>   c                    |t           j        z  s%|                     |t           j                  j        S |                     | |          S r@   )r   r0   _get_collection_historyPASSIVE_NO_INITIALIZEr3   rf   )r7   r9   dict_r:   s       r<   getzWriteOnlyAttributeImpl.get   sM    ** 	1//z7  ##D%000r>   .r9   InstanceState[Any]rr   r$   	user_dataLiteral[None]r:    Literal[PassiveFlag.PASSIVE_OFF]returnr'   c                    d S r@   r_   r7   r9   rr   ru   r:   s        r<   get_collectionz%WriteOnlyAttributeImpl.get_collection   	     	r>   r%   r   c                    d S r@   r_   rz   s        r<   r{   z%WriteOnlyAttributeImpl.get_collection   r|   r>   $Optional[_AdaptedCollectionProtocol]IUnion[Literal[LoaderCallableStatus.PASSIVE_NO_RESULT], CollectionAdapter]c                    d S r@   r_   rz   s        r<   r{   z%WriteOnlyAttributeImpl.get_collection   s	     	r>   Nc                    |t           j        z  s|                     ||          j        }n|                     ||          }|j        }t          |          S r@   )r   r0   rp   r3   rD   DynamicCollectionAdapter)r7   r9   rr   ru   r:   datahistorys          r<   r{   z%WriteOnlyAttributeImpl.get_collection   sY     ** 	0//w??KDD225'BBG/D'---r>   c                @    t          j        | t           j                  S r@   )r   r&   	OP_APPENDrC   s    r<   _append_tokenz$WriteOnlyAttributeImpl._append_token       -dJ4HIIIr>   c                @    t          j        | t           j                  S r@   )r   r&   	OP_REMOVErC   s    r<   _remove_tokenz$WriteOnlyAttributeImpl._remove_token   r   r>   c                   ||                      ||          }|                    |           | j        j        D ]} ||||p| j                  }| j        r-|-|                     t          j        |          |d           d S d S d S NT)	_modified_eventrV   rl   appendr   trackparentsethasparentr   instance_stater7   r9   rr   rU   	initiatorcollection_historyfns          r<   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 1r>   c                
   ||                      ||          }|                    |           | j        r+|)|                     t	          j        |          |d           | j        j        D ]} ||||p| j                   d S )NF)	r   rY   r   r   r   r   rl   rX   r   r   s          r<   fire_remove_eventz(WriteOnlyAttributeImpl.fire_remove_event   s     %!%!5!5eU!C!C&&u--- 	N 1j7>>uMMM-& 	> 	>BBueY<$*<====	> 	>r>   c                    | j         |j        vr.|                     | |t          j                  |j        | j         <   |                    || t          j                   d|| j         <   |j        | j                  S r   )rj   committed_statecollection_history_clsr   PASSIVE_NO_FETCHr   r   	NEVER_SET)r7   r9   rr   s      r<   r   z&WriteOnlyAttributeImpl._modified_event   su    85000.2.I.Ie[9/ /E!$(+ 	eT:+?@@@ dh$TX..r>   rU   r   r   Optional[AttributeEventToken]	check_oldpopbool_adaptNonec	                   |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r:   )r   )parent_tokenrA   has_identity_supports_dynamic_iterationr   r1   r   IdentitySetrs   r   r3   rB   rI   rH   r   r   )r7   r9   rr   rU   r   r:   r   r   r   iterable
new_valuesold_collectionr   	constants	additionsremovalsmembers                    r<   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 #    	 	r>   c                    t                      r@   NotImplementedError)r7   argskwargss      r<   r   zWriteOnlyAttributeImpl.deleteD  s    !###r>   c                     t          d          )Nz7Dynamic attributes don't support collection population.r   )r7   r9   rr   rU   s       r<   set_committed_valuez*WriteOnlyAttributeImpl.set_committed_valueG  s    !E
 
 	
r>   c                V    |                      ||          }|                                S r@   )rp   rN   r7   r9   rr   r:   cs        r<   get_historyz"WriteOnlyAttributeImpl.get_historyL  s%    ((88||~~r>   c                P    |                      ||          }d |j        D             S )Nc                :    g | ]}t          j        |          |fS r_   )r   r   ).0xs     r<   
<listcomp>z:WriteOnlyAttributeImpl.get_all_pending.<locals>.<listcomp>T  s(    GGGa*1--q1GGGr>   )rp   rF   r   s        r<   get_all_pendingz&WriteOnlyAttributeImpl.get_all_pendingP  s/     ((88GG1;GGGGr>   c                    | j         |j        v r|j        | j                  }n!|                     | |t          j                  }|j        r(|t          j        z  r|                     | |||          S |S )N)r;   )rj   r   r   r   r   r   r   INIT_OK)r7   r9   r:   r   s       r<   rp   z.WriteOnlyAttributeImpl._get_collection_historyV  s    8u,,,%dh/AA++e[9 A  	7Z-?#? 	..eWq /    Hr>   c                B    || ur|                      ||||           d S d S r@   )r   r7   r9   rr   rU   r   r:   s         r<   r   zWriteOnlyAttributeImpl.appende  7     D  ""5%	BBBBB ! r>   c                B    || ur|                      ||||           d S d S r@   )r   r   s         r<   rX   zWriteOnlyAttributeImpl.removep  r   r>   c                :    |                      |||||           d S )Nr   )rX   r   s         r<   r   zWriteOnlyAttributeImpl.pop{  s&     	E5%GDDDDDr>   )..)
r9   rt   rr   r$   ru   rv   r:   rw   rx   r'   )
r9   rt   rr   r$   ru   r%   r:   r   rx   r'   )
r9   rt   rr   r$   ru   r~   r:   r   rx   r   r@   )r9   rt   rr   r$   rU   r   r   r   r:   r   r   r   r   r   r   r   rx   r   )&rZ   r[   r\   uses_objectsdefault_accepts_scalar_loadersupports_populationr   
collectiondynamicrh   r.   r   r=   r   PASSIVE_OFFrs   r	   r{   r   r   memoized_propertyr   r   r   r   r   r   r   r   r   r   rq   r   rp   r   rX   r   __classcell__)rn   s   @r<   ra   ra      s        L$)!"'JGH-, , , , ,  )3(> 1 1 1 1 
 $'47    X 
 14"    X 
 ;>"	 	 	 	 X	 ;?*6. . . . .  
J J J 
J J J BFM M M M BF> > > >/ / /$ 48*6; ; ; ; ;z$ $ $
 
 

 1;0K    
 %/$DH H H H  * +	C 	C 	C 	C" +	C 	C 	C 	C" +E E E E E E E Er>   ra   
write_only)lazyc                      e Zd ZeZd ZdS )WriteOnlyLoaderc           	     (   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_classrd   rh   rf   )is_class_leveluselistparent_property	directionr   	ONETOMANY
MANYTOMANYr   r1   r   _register_attributer   mapperrh   rf   )r7   r   s     r<   init_class_attributez$WriteOnlyLoader.init_class_attribute  s    "| 	t3= !F
  
  
 )!#'#78   	& .5)2,8	
 	
 	
 	
 	
 	
r>   N)rZ   r[   r\   ra   r   r   r_   r>   r<   r   r     s*         (J
 
 
 
 
r>   r   c                  0    e Zd ZdZd Zd Zd Zd Zd ZdS )r   z9simplified CollectionAdapter for internal API consistencyc                    || _         d S r@   )r   )r7   r   s     r<   r=   z!DynamicCollectionAdapter.__init__  s    			r>   c                *    t          | j                  S r@   )iterr   rC   s    r<   __iter__z!DynamicCollectionAdapter.__iter__  s    DIr>   c                    d S r@   r_   rC   s    r<   _reset_emptyz%DynamicCollectionAdapter._reset_empty  s    r>   c                *    t          | j                  S r@   )lenr   rC   s    r<   __len__z DynamicCollectionAdapter.__len__  s    49~~r>   c                    dS r   r_   rC   s    r<   __bool__z!DynamicCollectionAdapter.__bool__  s    tr>   N)	rZ   r[   r\   r]   r=   r   r   r   r   r_   r>   r<   r   r     se        CC            r>   r   c                  0    e Zd ZdZesdZd ZddZddZdS )AbstractCollectionWriterzsVirtual collection which includes append/remove methods that synchronize
    into the attribute event system.

    r_   c                   |                                 x| _        }|| _        t          |          }|j        | j        j                 }|j        &|j                                        |j        f| _	        nd| _	        |
                    |d          f| _        | j        j        r| j        j        | _        d S d| _        d S )Nr_   F)alias_secondary)objinstancer8   r   _propsrj   	secondaryr   __clause_element__	_from_obj_with_parent_where_criteriarh   _order_by_clauses)r7   r8   r9   r   r   props         r<   r=   z!AbstractCollectionWriter.__init__  s    #(99;;.	x((}TY]+>% #k<<>>ODNNDN h>> 
 9 	(%)Y%7D"""%'D"""r>   iteratorIterable[_T]rx   r   c                    |D ]M}| j                             t          j        | j                  t          j        | j                  |d            Nd S r@   )r8   r   r   r   r   instance_dict)r7   r   items      r<   _add_all_implz&AbstractCollectionWriter._add_all_impl  s`     	 	DI)$-88(77	   	 	r>   r  r+   c                    | j                             t          j        | j                  t          j        | j                  |d            d S r@   )r8   rX   r   r   r   r   r7   r  s     r<   _remove_implz%AbstractCollectionWriter._remove_impl  sL    	%dm44$T]33		
 	
 	
 	
 	
r>   Nr   r   rx   r   r  r+   rx   r   )	rZ   r[   r\   r]   r   	__slots__r=   r  r  r_   r>   r<   r   r     sd         
  	( ( (<   
 
 
 
 
 
r>   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 )re   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   r8   r   r   r   rx   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().)	TypeErrorrC   s    r<   r   zWriteOnlyCollection.__iter__  s    M
 
 	
r>   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   r8   rd   wherer   r   select_fromr   rh   )r7   stmts     r<   r   zWriteOnlyCollection.select  s_    
 5vdi-..4d6JK> 	5#4#T^4D! 	: 4=$"89Dr>   
Insert[_T]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_r_   )r   r   r   r   r8   rj   r   r   r   r   r1   synchronize_pairs_get_attr_w_warn_on_nonedictr   r   rd   values)r7   r9   r   r   rr   lrr   s           r<   r   zWriteOnlyCollection.insert  s     &&}TY]+>!6!@@@)/   * 	9 	9DAq..
	 B %TR888E!%LL5vdi-..5>>>>>r>   
Update[_T]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   r8   rd   r  r   rC   s    r<   r   zWriteOnlyCollection.updateB  $    
 5vdi-..4d6JKKr>   
Delete[_T]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   r8   rd   r  r   rC   s    r<   r   zWriteOnlyCollection.deleteI  r  r>   r   r   r   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  )r7   r   s     r<   add_allzWriteOnlyCollection.add_allP  s     	8$$$$$r>   r  r+   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     r<   rS   zWriteOnlyCollection.addY  s      	D6"""""r>   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     r<   rX   zWriteOnlyCollection.removeb  s     	$r>   N)rx   r   )rx   r  )rx   r  )rx   r  )rx   r  r  r  )rZ   r[   r\   r]   r  r   r   r   r   r   r!  rS   rX   r_   r>   r<   re   re     s          I
 
 
 

 
 
 
&? &? &? &?PL L L LL L L L% % % %# # # #           r>   re   N)@r]   
__future__r   typingr   r   r   r   r   r	   r
   r   r   r   sqlalchemy.sqlr    r   r   r   r   baser   r   r   r   r   r   r   sqlr   r   r   r   sql.dmlr    r!   r"   util.typingr#   _typingr$   r%   r&   r'   r(   r9   r)   sql.selectabler*   r+   r.   HasCollectionAdapterAttributeImplra   class_loggerRelationshipPropertystrategy_forAbstractRelationshipLoader
Identifiedr   r   r   re   r_   r>   r<   <module>r5     sD  	 	 # " " " " "                                                                   $ $ $ $ $ $                                     0 0 0 0 0 0                                                                   ! ! ! ! ! ! (&&&&&&666666//////------******$$$$$$'''''' WT;* ;* ;* ;* ;* ;* ;* ;*|AE AE AE AE AE#Z%=AE AE AEH #00l0CC
 
 
 
 
j;S^ 
 
 DC 
4       &6
 6
 6
 6
 6
wr{ 6
 6
 6
r{  {  {  {  { 226 {  {  {  {  { r>   