
    YՁiQL                    $   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jh                  ejj                        Z6ejn                  ejp                  js                  d01       G d2 d3ejt                  ejv                                      Z< G d4 d5      Z= G d6 d7ee2         Z> G d8 d9e>e2         Z?y:);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                  P    e Zd ZdZd
dZed        Zed        Zd Zd Z	d Z
d	 Zy)WriteOnlyHistoryzDOverrides AttributeHistory to receive append/remove events directly.Nc                   |rt|t         j                  z  rt        j                  d| d| d      |j                  | _        |j
                  | _        |j                  | _        |j                  | _        y t        j                         | _        t        j                         | _        t        j                         | _        d| _        y )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/home/ccuser/rateright-main-site/.venv/Lib/site-packages/sqlalchemy/orm/writeonly.py__init__zWriteOnlyHistory.__init__G   s    +++--  '3 48& 933  $,#;#;D '33D!)!7!7D)1)G)GD&!%!8!8!:D#668D#'#:#:#<D ).D&    c                ^    t        | j                  j                  | j                              S N)listr3   unionr2   r7   s    r<   added_plus_unchangedz%WriteOnlyHistory.added_plus_unchanged\   s$    D$$**4+?+?@AAr>   c                    t        | j                  j                  | j                        j                  | j                              S r@   )rA   r3   rB   r2   r4   rC   s    r<   	all_itemszWriteOnlyHistory.all_items`   s=    ""4#7#78>>""
 	
r>   c                   | j                   rf| j                  j                  | j                        }| 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    %%$$//0D0DEE((55d6J6JKG,,77@I   $$"" &9E
 !!$u+tIWNNr>   c                2    t        | j                        |   S r@   )rA   r3   )r7   indexs     r<   indexedzWriteOnlyHistory.indexedu   s    D$$%e,,r>   c                :    | j                   j                  |       y r@   )r3   addr7   values     r<   	add_addedzWriteOnlyHistory.add_addedx   s    U#r>   c                    || j                   v r| j                   j                  |       y | j                  j                  |       y r@   )r3   remover4   rS   rT   s     r<   add_removedzWriteOnlyHistory.add_removed{   s8    D$$$##E*""5)r>   r@   )__name__
__module____qualname____doc__r=   propertyrD   rF   rN   rQ   rV   rY    r>   r<   r.   r.   D   sI    N/* B B 
 
O-$*r>   r.   c                  b    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	 	 d	 	 	 	 	 	 	 	 	 dd       Ze	 	 d	 	 	 	 	 	 	 	 	 dd       Ze	 	 d	 	 	 	 	 	 	 	 	 dd       Zd	ej                  f	 	 	 	 	 	 	 	 	 dd
Zej(                  d        Zej(                  d        Z	 ddZ	 ddZd Zd	ej                  d	ddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd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dZ$ xZ%S )WriteOnlyAttributeImplTFr_   c                v    t        |   ||||fi | || _        t        | _        |rt        |      | _        y y 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*.!(ODM r>   c                    |t         j                  z  s*| j                  |t         j                        j                  S | j                  | |      S r@   )r   r0   _get_collection_historyPASSIVE_NO_INITIALIZEr3   rf   )r7   r9   dict_r:   s       r<   getzWriteOnlyAttributeImpl.get   sH    ***//z77k ##D%00r>   c                     y r@   r_   r7   r9   rr   	user_datar:   s        r<   get_collectionz%WriteOnlyAttributeImpl.get_collection        	r>   c                     y r@   r_   ru   s        r<   rw   z%WriteOnlyAttributeImpl.get_collection   rx   r>   c                     y r@   r_   ru   s        r<   rw   z%WriteOnlyAttributeImpl.get_collection   s     	r>   Nc                    |t         j                  z  s'| j                  ||      j                  }t        |      S | j                  ||      }|j                  }t        |      S r@   )r   r0   rp   r3   rD   DynamicCollectionAdapter)r7   r9   rr   rv   r:   datahistorys          r<   rw   z%WriteOnlyAttributeImpl.get_collection   sa     ***//w?KKD (-- 225'BG//D'--r>   c                J    t        j                  | t         j                        S r@   )r   r&   	OP_APPENDrC   s    r<   _append_tokenz$WriteOnlyAttributeImpl._append_token       --dJ4H4HIIr>   c                J    t        j                  | t         j                        S r@   )r   r&   	OP_REMOVErC   s    r<   _remove_tokenz$WriteOnlyAttributeImpl._remove_token   r   r>   c                    || j                  ||      }|j                  |       | j                  j                  D ]  } ||||xs | j                        } | j
                  r*|'| j                  t        j                  |      |d       y y y 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$$U+--&& 	FBueY%D$2D2DEE	F  1j77>tL !2r>   c                   || j                  ||      }|j                  |       | j                  r(|&| j                  t	        j
                  |      |d       | j                  j                  D ]  } ||||xs | j                          y )NF)	r   rY   r   r   r   r   rl   rX   r   r   s          r<   fire_remove_eventz(WriteOnlyAttributeImpl.fire_remove_event   s     %!%!5!5eU!C&&u- 1j77>uM--&& 	>BueY<$*<*<=	>r>   c                4   | j                   |j                  vr8| j                  | |t        j                        |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   s~    885000.2.I.Ie[99/E!!$((+ 	eT:+?+?@ dhh$$TXX..r>   c	                   |r|j                   | j                   u ry |r|y |}	t        |	      }
|j                  rL| j                  st	        j
                  d|  d      t        j                  | j                  |||            }| j                  ||      }|j                  s|j                  }nj                  |j                        }|j                  |
      }t        j                  |
      j                  |      }|j                  |      }|
D ]  }||v s| j                  |||d |        |D ]  }| j                  |||d |        y )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:   	check_oldpop_adaptiterable
new_valuesold_collectionr   	constants	additionsremovalsmembers                    r<   setzWriteOnlyAttributeImpl.set  sz    //43D3DD5=(^
33--"4& )$ $ 
 "--w7N "11%?!!/;;N+11"..N #//
;	$$Z0;;IF	!,,Y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                F    | j                  ||      }|j                         S r@   )rp   rN   )r7   r9   rr   r:   cs        r<   get_historyz"WriteOnlyAttributeImpl.get_historyL  s     ((8||~r>   c                    | j                  ||      }|j                  D cg c]  }t        j                  |      |f c}S c c}w r@   )rp   rF   r   r   )r7   r9   rr   r:   r   xs         r<   get_all_pendingz&WriteOnlyAttributeImpl.get_all_pendingP  s>     ((8;<;;Ga**1-q1GGGs   Ac                   | j                   |j                  v r|j                  | j                      }n!| j                  | |t        j                        }|j
                  r(|t        j                  z  r| j                  | |||      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    88u,,,%%dhh/A++e[99A 7Z-?-?#?..eWq /   Hr>   c                6    || ur| j                  ||||       y y r@   )r   r7   r9   rr   rU   r   r:   s         r<   r   zWriteOnlyAttributeImpl.appende  %     D ""5%	B !r>   c                6    || ur| j                  ||||       y y r@   )r   r   s         r<   rX   zWriteOnlyAttributeImpl.removep  r   r>   c                0    | j                  |||||       y )Nr   )rX   r   s         r<   r   zWriteOnlyAttributeImpl.pop{  s     	E5%GDr>   )..)
r9   InstanceState[Any]rr   r$   rv   zLiteral[None]r:   z Literal[PassiveFlag.PASSIVE_OFF]returnr'   )
r9   r   rr   r$   rv   r%   r:   r   r   r'   )
r9   r   rr   r$   rv   z$Optional[_AdaptedCollectionProtocol]r:   r   r   zIUnion[Literal[LoaderCallableStatus.PASSIVE_NO_RESULT], CollectionAdapter]r@   )r9   r   rr   r$   rU   r   r   zOptional[AttributeEventToken]r:   r   r   r   r   boolr   r   r   None)&rZ   r[   r\   uses_objectsdefault_accepts_scalar_loadersupports_populationr   
collectiondynamicrh   r.   r   r=   r   PASSIVE_OFFrs   r	   rw   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 
 $'47!  !	
 2 
  
 14"!  .	
  
  
 ;>"	!	 	 8		
 	
	 	 ;?*66.!. . 8	.
 .
.  
J J 
J J BFM BF>/$ 48*66;!; ; 	;
 1; ; ; ; ; 
;z$

 1;0K0K 
 %/$D$DH* ++	C" ++	C" ++Er>   ra   
write_only)lazyc                      e Zd ZeZd Zy)WriteOnlyLoaderc           	        d| _         | j                  r6| 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                         y )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3==  !!F
  
 ))!#'#7#78  	&&  ..55))22,,88	
r>   N)rZ   r[   r\   ra   r   r   r_   r>   r<   r   r     s     (J
r>   r   c                  .    e Zd ZdZd Zd Zd Zd Zd Zy)r|   z9simplified CollectionAdapter for internal API consistencyc                    || _         y 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    DIIr>   c                     y 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    499~r>   c                     yr   r_   rC   s    r<   __bool__z!DynamicCollectionAdapter.__bool__  s    r>   N)	rZ   r[   r\   r]   r=   r   r   r   r   r_   r>   r<   r|   r|     s    Cr>   r|   c                  .    e Zd ZdZesdZd ZddZddZy)	AbstractCollectionWriterzsVirtual collection which includes append/remove methods that synchronize
    into the attribute event system.

    r_   c                   |j                         x| _        }|| _        t        |      }|j                  | j                  j
                     }|j                  ,|j                  j                         |j                  f| _	        nd| _	        |j                  |d      f| _        | j                  j                  r| j                  j                  | _        y d| _        y )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(}}TYY]]+>>% #kk<<>ODNDN h> 
 99%)YY%7%7D"%'D"r>   c                    |D ]Z  }| j                   j                  t        j                  | j                        t        j
                  | j                        |d        \ y r@   )r8   r   r   r   r   instance_dict)r7   iteratoritems      r<   _add_all_implz&AbstractCollectionWriter._add_all_impl  sM     	DII))$--8((7		r>   c                    | j                   j                  t        j                  | j                        t        j
                  | j                        |d        y r@   )r8   rX   r   r   r   r   r7   r   s     r<   _remove_implz%AbstractCollectionWriter._remove_impl  s>    		%%dmm4$$T]]3		
r>   Nr   zIterable[_T]r   r   r   r+   r   r   )	rZ   r[   r\   r]   r   	__slots__r=   r   r   r_   r>   r<   r   r     s     
 	(<
r>   r   c                  T    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y)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   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>   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  sl    
 5vdii--.44d6J6JK>>#4##T^^4D!! 4==$"8"89Dr>   c                   t        | j                        }|j                  }|j                  | j                  j
                     }|j                  t        j                  urt        j                  d      i }|j                  D ]=  \  }}|j                  |||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     &}}TYY]]+>>!6!@!@@))/  ** 	9DAq..

	B %TR8E!%%L	9 6vdii--.55>>>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   r8   rd   r  r   rC   s    r<   r   zWriteOnlyCollection.updateB  ,    
 5vdii--.44d6J6JKKr>   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>   c                &    | j                  |       y)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>   c                (    | j                  |g       y)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                &    | j                  |       y)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)r   r   )r   zSelect[Tuple[_T]])r   z
Insert[_T])r   z
Update[_T])r   z
Delete[_T]r   r   )rZ   r[   r\   r]   r   r   r   r   r   r   r  rS   rX   r_   r>   r<   re   re     s9     I

&?P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>r'     s3  	 #            $       0            !&6/-*$' T;* ;*|AE##Z%=%=AEH ##00l0C
j;;S^^ 
 D 
4 &6
wr{ 6
r{ 226 { r>   