a
    [g!W                     @  s  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rbd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d7ZAG d8d9 d9eeA ZBG d:d; d;ejCejDZEe!jFejGjHd<d=G d>d? d?ejIe!jJZKG d@dA dAZLG dBdC dCeeA ZMG dDdE 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                   @  s   e Zd ZU dZded< ded< ded< ded< d%d	d
ddddddZeddddZeddddZddddZ	dddddZ
ddd d!d"Zddd 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WriteOnlyAttributeImplInstanceState[_T]r   zOptional[WriteOnlyHistory[_T]]None)attrstatepassiveapply_toreturnc                 C  sp   |rH|t j@ r&td| d| d|j| _|j| _|j| _|j| _n$t	 | _t	 | _t	 | _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   InvalidRequestErrorr9   r:   r;   r=   r    ZOrderedIdentitySet)selfrA   rB   rC   rD    rI   f/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/sqlalchemy/orm/writeonly.py__init__U   s    




zWriteOnlyHistory.__init__zList[_T]rE   c                 C  s   t | j| jS N)listr:   unionr9   rH   rI   rI   rJ   added_plus_unchangedp   s    z%WriteOnlyHistory.added_plus_unchangedc                 C  s   t | j| j| jS rM   )rN   r:   rO   r9   r;   rP   rI   rI   rJ   	all_itemst   s
    zWriteOnlyHistory.all_itemsattributes.Historyc                 C  s`   | j r0| j| j}| j| j}| j|}n| j| j| j  }}}tt|t|t|S rM   )	r=   r:   
differencer9   r;   intersectionr   ZHistoryrN   )rH   addedZdeletedZ	unchangedrI   rI   rJ   
as_history|   s    
zWriteOnlyHistory.as_historyzUnion[int, slice]zUnion[List[_T], _T])indexrE   c                 C  s   t | j| S rM   )rN   r:   )rH   rX   rI   rI   rJ   indexed   s    zWriteOnlyHistory.indexedr6   )valuerE   c                 C  s   | j | d S rM   )r:   addrH   rZ   rI   rI   rJ   	add_added   s    zWriteOnlyHistory.add_addedc                 C  s(   || j v r| j | n| j| d S rM   )r:   remover;   r[   r\   rI   rI   rJ   add_removed   s    
zWriteOnlyHistory.add_removed)N)__name__
__module____qualname____doc____annotations__rK   propertyrQ   rR   rW   rY   r]   r_   rI   rI   rI   rJ   r8   M   s   
 r8   c                      s  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< ddddddd fddZejfdddddddZedZddd!d"d#d$d%d&Zed[ddd'dd#d$d(d&Zed\ddd)dd*d$d+d&Zd,ejfddd)dd*d$d-d&Zejd.d/d0d1Zejd.d/d2d3Zd]dddd4d5d6d7d8d9Zd^dddd4d5d6d7d:d;Zddd<d=d>d?Zd,ejd,ddfdddd4ddddd6d@	dAdBZdddCdDdEdFZddddCdGdHdIZejfddddJddKdLZejfddddMddNdOZ ddd<dPdQdRZ!ejfdddd4dd6dSdTdUZ"ejfdddd4dd6dSdVdWZ#ejfdddd4dd6dSdXdYZ$  Z%S )_r>   Tr<   uses_objectsFdefault_accepts_scalar_loadersupports_population_supports_dynamic_iteration
collectiondynamicrI   r0   order_byzType[WriteOnlyHistory[Any]]collection_history_clszType[WriteOnlyCollection[Any]]query_classz#Union[Type[Any], AliasedClass[Any]]strz"_Dispatch[QueryableAttribute[Any]]z
Mapper[_T]r   )class_keydispatchtarget_mapperrl   kwc                   s8   t  j||d |fi | || _t| _|r4t|| _d S rM   )superrK   rs   WriteOnlyCollectionrn   tuplerl   )rH   rp   rq   rr   rs   rl   rt   	__class__rI   rJ   rK      s
    	zWriteOnlyAttributeImpl.__init__zInstanceState[Any]r*   r   z8Union[util.OrderedIdentitySet, WriteOnlyCollection[Any]])rB   dict_rC   rE   c                 C  s*   |t j@ s| |t jjS | | |S d S rM   )r   rF   _get_collection_historyPASSIVE_NO_INITIALIZEr:   rn   )rH   rB   rz   rC   rI   rI   rJ   get   s
    
zWriteOnlyAttributeImpl.get.zLiteral[None]z Literal[PassiveFlag.PASSIVE_OFF]r.   )rB   rz   	user_datarC   rE   c                 C  s   d S rM   rI   rH   rB   rz   r~   rC   rI   rI   rJ   get_collection   s    z%WriteOnlyAttributeImpl.get_collectionr-   c                 C  s   d S rM   rI   r   rI   rI   rJ   r      s    z$Optional[_AdaptedCollectionProtocol]zIUnion[Literal[LoaderCallableStatus.PASSIVE_NO_RESULT], CollectionAdapter]c                 C  s   d S rM   rI   r   rI   rI   rJ   r      s    	Nc                 C  s4   |t j@ s| ||j}n| ||}|j}t|S rM   )r   rF   r{   r:   rQ   DynamicCollectionAdapter)rH   rB   rz   r~   rC   datahistoryrI   rI   rJ   r      s
    

zattributes.AttributeEventTokenrL   c                 C  s   t | t jS rM   )r   r+   Z	OP_APPENDrP   rI   rI   rJ   _append_token   s    z$WriteOnlyAttributeImpl._append_tokenc                 C  s   t | t jS rM   )r   r+   Z	OP_REMOVErP   rI   rI   rJ   _remove_token   s    z$WriteOnlyAttributeImpl._remove_tokenzOptional[AttributeEventToken]zOptional[WriteOnlyHistory[Any]]r@   )rB   rz   rZ   	initiatorcollection_historyrE   c                 C  sd   |d u r|  ||}|| | jjD ]}||||p8| j}q&| jr`|d ur`| t||d d S NT)	_modified_eventr]   rr   appendr   trackparentsethasparentr   instance_staterH   rB   rz   rZ   r   r   fnrI   rI   rJ   fire_append_event   s    
z(WriteOnlyAttributeImpl.fire_append_eventc                 C  sd   |d u r|  ||}|| | jr@|d ur@| t||d | jjD ]}||||pZ| j qHd S )NF)	r   r_   r   r   r   r   rr   r^   r   r   rI   rI   rJ   fire_remove_event  s    
z(WriteOnlyAttributeImpl.fire_remove_eventzWriteOnlyHistory[Any])rB   rz   rE   c                 C  sH   | j |jvr$| | |tj|j| j < ||| t d|| j < |j| j  S r   )rq   committed_staterm   r   PASSIVE_NO_FETCHr   r   )rH   rB   rz   rI   rI   rJ   r      s    
z&WriteOnlyAttributeImpl._modified_event)	rB   rz   rZ   r   rC   	check_oldpop_adaptrE   c	                 C  s   |r|j | j u rd S |r$|d u r$d S |}	t|	}
|jrd| jsNtd|  dt| j|||d}| 	||}|js~|j
}n||j
}||
}t|
|}||}|
D ] }||v r| j|||d |d q|D ]}| j|||d |d qd S )NzCollection "zV" does not support implicit iteration; collection replacement operations can't be usedrC   )r   )Zparent_tokenrN   has_identityri   r   rG   r    ZIdentitySetr}   r   r:   rO   rU   rT   r   r   )rH   rB   rz   rZ   r   rC   r   r   r   iterable
new_valuesZold_collectionr   	constants	additionsZremovalsmemberrI   rI   rJ   set/  sP    


zWriteOnlyAttributeImpl.setr
   )argskwargsrE   c                 O  s
   t  d S rM   NotImplementedError)rH   r   r   rI   rI   rJ   r!   l  s    zWriteOnlyAttributeImpl.delete)rB   rz   rZ   rE   c                 C  s   t dd S )Nz7Dynamic attributes don't support collection population.r   )rH   rB   rz   rZ   rI   rI   rJ   set_committed_valueo  s    z*WriteOnlyAttributeImpl.set_committed_valuerS   c                 C  s   |  ||}| S rM   )r{   rW   rH   rB   rz   rC   crI   rI   rJ   get_historyv  s    z"WriteOnlyAttributeImpl.get_historyz$List[Tuple[InstanceState[Any], Any]]c                 C  s   |  ||}dd |jD S )Nc                 S  s   g | ]}t ||fqS rI   )r   r   ).0xrI   rI   rJ   
<listcomp>      z:WriteOnlyAttributeImpl.get_all_pending.<locals>.<listcomp>)r{   rR   r   rI   rI   rJ   get_all_pending  s    z&WriteOnlyAttributeImpl.get_all_pending)rB   rC   rE   c                 C  sT   | j |jv r|j| j  }n| | |tj}|jrL|tj@ rL| j| |||dS |S d S )N)rD   )rq   r   rm   r   r   r   ZINIT_OK)rH   rB   rC   r   rI   rI   rJ   r{     s    z.WriteOnlyAttributeImpl._get_collection_history)rB   rz   rZ   r   rC   rE   c                 C  s   || ur|  |||| d S rM   )r   rH   rB   rz   rZ   r   rC   rI   rI   rJ   r     s    zWriteOnlyAttributeImpl.appendc                 C  s   || ur|  |||| d S rM   )r   r   rI   rI   rJ   r^     s    zWriteOnlyAttributeImpl.removec                 C  s   | j |||||d d S )Nr   )r^   r   rI   rI   rJ   r     s    zWriteOnlyAttributeImpl.pop)..)..)..)N)N)&r`   ra   rb   rf   rd   rg   rh   ri   rj   rk   rl   r8   rm   rK   r   ZPASSIVE_OFFr}   r   r   r    Zmemoized_propertyr   r   r   r   r   r   r!   r   r   r   r|   r   r{   r   r^   r   __classcell__rI   rI   rx   rJ   r>      sn   
         =	r>   Z
write_only)Zlazyc                   @  s    e Zd ZeZdddddZdS )WriteOnlyLoaderzMapper[Any]r@   )mapperrE   c              	   C  s\   d| _ | jr | jjtjtjfvr0td| j t	j
| j|d| j| jj| jj| jjd d S )NTztOn relationship %s, 'dynamic' loaders cannot be used with many-to-one/one-to-one relationships and/or uselist=False.)Z	useobject
impl_classrs   rl   rn   )Zis_class_levelZuselistZparent_property	directionr   	ONETOMANYZ
MANYTOMANYr   rG   r   Z_register_attributer   r   rl   rn   )rH   r   rI   rI   rJ   init_class_attribute  s&    z$WriteOnlyLoader.init_class_attributeN)r`   ra   rb   r>   r   r   rI   rI   rI   rJ   r     s   r   c                   @  s`   e Zd ZU dZded< ddddZddd	d
ZddddZddddZddddZ	dS )r   z9simplified CollectionAdapter for internal API consistencyzCollection[Any]r   r   c                 C  s
   || _ d S rM   r   )rH   r   rI   rI   rJ   rK     s    z!DynamicCollectionAdapter.__init__zIterator[Any]rL   c                 C  s
   t | jS rM   )iterr   rP   rI   rI   rJ   __iter__  s    z!DynamicCollectionAdapter.__iter__r@   c                 C  s   d S rM   rI   rP   rI   rI   rJ   _reset_empty  s    z%DynamicCollectionAdapter._reset_emptyintc                 C  s
   t | jS rM   )lenr   rP   rI   rI   rJ   __len__  s    z DynamicCollectionAdapter.__len__r<   c                 C  s   dS r   rI   rP   rI   rI   rJ   __bool__  s    z!DynamicCollectionAdapter.__bool__N)
r`   ra   rb   rc   rd   rK   r   r   r   r   rI   rI   rI   rJ   r     s   
r   c                   @  sZ   e Zd ZU dZesdZded< ded< ddd	d
dZdddddZdddddZ	dS )AbstractCollectionWriterzsVirtual collection which includes append/remove methods that synchronize
    into the attribute event system.

    rI   r6   instancezTuple[FromClause, ...]	_from_objr>   r?   )rA   rB   c                 C  s   |  }tr|sJ || _|| _t|}|j| jj }|jd urT|j	 |jf| _
nd| _
|j|ddf| _| jjr| jj| _nd| _d S )NrI   F)Zalias_secondary)objr   r   rA   r   _propsrq   Z	secondaryr   Z__clause_element__r   Z_with_parent_where_criteriarl   _order_by_clauses)rH   rA   rB   r   r   proprI   rI   rJ   rK     s    

z!AbstractCollectionWriter.__init__Iterable[_T]r@   iteratorrE   c                 C  s0   |D ]&}| j t| jt| j|d  qd S rM   )rA   r   r   r   r   instance_dict)rH   r   itemrI   rI   rJ   _add_all_impl  s    

z&AbstractCollectionWriter._add_all_implr   rE   c                 C  s&   | j t| jt| j|d  d S rM   )rA   r^   r   r   r   r   rH   r   rI   rI   rJ   _remove_impl"  s    

z%AbstractCollectionWriter._remove_implN)
r`   ra   rb   rc   r   	__slots__rd   rK   r   r   rI   rI   rI   rJ   r     s   
!	r   c                   @  s   e Zd ZdZdZddddZdddd	Zd
dddZddddZddddZ	dddddZ
dddddZdddddZdS )rv   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   rA   r   r   r   r
   rL   c                 C  s   t dd S )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().)	TypeErrorrP   rI   rI   rJ   r   D  s    zWriteOnlyCollection.__iter__zSelect[Tuple[_T]]c                 C  s<   t | jjj| j }| jr&|j| j }| jr8|j| j }|S )zProduce a :class:`_sql.Select` construct that represents the
        rows within this instance-local :class:`_orm.WriteOnlyCollection`.

        )	r#   rA   rs   wherer   r   select_fromr   rl   )rH   stmtrI   rI   rJ   r#   K  s    zWriteOnlyCollection.selectr&   c                 C  s   t | j}|j}|j| jj }|jtjur4t	
di }|jD ],\}}||||j|}td|d||j< q>t| jjjf 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)Z	callable_)r   r   r   r   rA   rq   r   r   r   r   rG   Zsynchronize_pairsZ_get_attr_w_warn_on_nonedictr   r"   rs   values)rH   rB   r   r   rz   lrr   rI   rI   rJ   r"   W  s"    
zWriteOnlyCollection.insertr'   c                 C  s   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$   rA   rs   r   r   rP   rI   rI   rJ   r$     s    zWriteOnlyCollection.updater%   c                 C  s   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!   rA   rs   r   r   rP   rI   rI   rJ   r!     s    zWriteOnlyCollection.deleter   r@   r   c                 C  s   |  | 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   )rH   r   rI   rI   rJ   add_all  s    zWriteOnlyCollection.add_allr6   r   c                 C  s   |  |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   rI   rI   rJ   r[     s    zWriteOnlyCollection.addc                 C  s   |  | 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   rI   rI   rJ   r^     s    zWriteOnlyCollection.removeN)r`   ra   rb   rc   r   r   r#   r"   r$   r!   r   r[   r^   rI   rI   rI   rJ   rv   +  s   (		rv   N)Orc   
__future__r   typingr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   Zsqlalchemy.sqlr    r   r   r   r   baser   r   r   r   r   r   r   r    sqlr!   r"   r#   r$   Zsql.dmlr%   r&   r'   Zutil.typingr(   r)   Z_typingr*   r+   r,   collectionsr-   r.   r   r/   r0   rB   r1   r2   eventr3   Zsql.selectabler4   r5   r6   r8   ZHasCollectionAdapterZAttributeImplr>   Zclass_loggerZRelationshipPropertyZstrategy_forZAbstractRelationshipLoaderZ
Identifiedr   r   r   rv   rI   rI   rI   rJ   <module>   s   I
  '?