HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/__pycache__/writeonly.cpython-310.pyc
o

���g!W�@s�dZddlmZddlmZddlmZddlmZddlmZddlmZddlm	Z	dd	lm
Z
dd
lmZddlmZddlm
Z
dd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!dd lm"Z"dd!l#m$Z$dd"l#m%Z%dd#l#m&Z&dd$l#m'Z'dd%l(m)Z)dd&l(m*Z*dd'l(m+Z+dd(l,m-Z-e�r1dd)lm.Z.dd*l/m0Z0dd+lm1Z1dd,lm2Z2dd-l3m4Z4dd.l3m5Z5dd/l6m7Z7dd0lm8Z8dd1l9m:Z:dd2l"m;Z;dd3l<m=Z=dd4l>m?Z?dd5l>m@Z@ed6ed7�ZAGd8d9�d9eeA�ZBGd:d;�d;ejCejD�ZEe!jFejGjHd<d=�Gd>d?�d?ejIe!jJ���ZKGd@dA�dA�ZLGdBdC�dCeeA�ZMGdDdE�dEeMeA�ZNdFS)Gz�Write-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�eZdZUdZded<ded<ded<ded<	d(d)dd�Zed*dd��Zed*dd��Zd+dd�Z	d,d d!�Z
d-d$d%�Zd-d&d'�ZdS).�WriteOnlyHistoryzDOverrides AttributeHistory to receive append/remove events directly.zutil.OrderedIdentitySet�unchanged_items�added_items�
deleted_items�bool�_reconcile_collectionN�attr�WriteOnlyAttributeImpl�state�InstanceState[_T]�passiver�apply_to�Optional[WriteOnlyHistory[_T]]�return�NonecCsr|r%|tj@rt�d|�d|�d���|j|_|j|_|j|_|j|_dSt�	�|_t�	�|_t�	�|_d|_dS)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�InvalidRequestErrorr9r:r;r=r �OrderedIdentitySet)�selfr>r@rBrC�rK�C/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/writeonly.py�__init__Us
��



zWriteOnlyHistory.__init__�List[_T]cCst|j�|j��S�N)�listr:�unionr9�rJrKrKrL�added_plus_unchangedpsz%WriteOnlyHistory.added_plus_unchangedcCst|j�|j��|j��SrO)rPr:rQr9r;rRrKrKrL�	all_itemsts
��zWriteOnlyHistory.all_items�attributes.HistorycCs`|jr|j�|j�}|j�|j�}|j�|�}n|j|j|j}}}t�t|�t|�t|��SrO)	r=r:�
differencer9r;�intersectionr�HistoryrP)rJ�added�deleted�	unchangedrKrKrL�
as_history|s
�zWriteOnlyHistory.as_history�index�Union[int, slice]�Union[List[_T], _T]cCst|j�|SrO)rPr:)rJr]rKrKrL�indexed�szWriteOnlyHistory.indexed�valuer6cCs|j�|�dSrO)r:�add�rJrarKrKrL�	add_added�szWriteOnlyHistory.add_addedcCs*||jvr
|j�|�dS|j�|�dSrO)r:�remover;rbrcrKrKrL�add_removed�s
zWriteOnlyHistory.add_removedrO)
r>r?r@rArBrrCrDrErF)rErN)rErU)r]r^rEr_)rar6rErF)
�__name__�
__module__�__qualname__�__doc__�__annotations__rM�propertyrSrTr\r`rdrfrKrKrKrLr8Ms 
�


r8cs�eZdZUdZded<dZded<dZded<dZded<dZded<dZ	ded	<d
Z
ded<eZd
ed<ded<da�fdd�Z
ejfdbd%d&�Ze	'	'dcddd,d-��Ze	'	'dcded/d-��Ze	'	'dcdfd2d-��Zd3ejfdfd4d-�Zejdgd6d7��Zejdgd8d9��Z	3dhdid@dA�Z	3dhdidBdC�ZdjdEdF�Zd3ejd3ddfdkdJdK�ZdldOdP�ZdmdQdR�ZejfdndTdU�ZejfdodWdX�Z dpdYdZ�Z!ejfdqd[d\�Z"ejfdqd]d^�Z#ejfdqd_d`�Z$�Z%S)rr?Tr<�uses_objectsF�default_accepts_scalar_loader�supports_population�_supports_dynamic_iteration�
collection�dynamicrKr0�order_byzType[WriteOnlyHistory[Any]]�collection_history_clszType[WriteOnlyCollection[Any]]�query_class�class_�#Union[Type[Any], AliasedClass[Any]]�key�str�dispatch�"_Dispatch[QueryableAttribute[Any]]�
target_mapper�
Mapper[_T]�kwrcs<t�j||d|fi|��||_t|_|rt|�|_dSdSrO)�superrMr|�WriteOnlyCollectionru�tuplers)rJrvrxrzr|rsr~��	__class__rKrLrM�s	�zWriteOnlyAttributeImpl.__init__r@�InstanceState[Any]�dict_r*rBrrE�8Union[util.OrderedIdentitySet, WriteOnlyCollection[Any]]cCs&|tj@s
|�|tj�jS|�||�SrO)rrG�_get_collection_history�PASSIVE_NO_INITIALIZEr:ru)rJr@r�rBrKrKrL�get�s
��zWriteOnlyAttributeImpl.get.�	user_data�
Literal[None]� Literal[PassiveFlag.PASSIVE_OFF]r.cC�dSrOrK�rJr@r�r�rBrKrKrL�get_collection��z%WriteOnlyAttributeImpl.get_collectionr-cCr�rOrKr�rKrKrLr��r��$Optional[_AdaptedCollectionProtocol]�IUnion[Literal[LoaderCallableStatus.PASSIVE_NO_RESULT], CollectionAdapter]cCr�rOrKr�rKrKrLr��s	NcCs:|tj@s|�||�j}t|�S|�||�}|j}t|�SrO)rrGr�r:rS�DynamicCollectionAdapter)rJr@r�r�rB�data�historyrKrKrLr��s

��attributes.AttributeEventTokencC�t�|tj�SrO)rr+�	OP_APPENDrRrKrKrL�
_append_token��z$WriteOnlyAttributeImpl._append_tokencCr�rO)rr+�	OP_REMOVErRrKrKrL�
_remove_token�r�z$WriteOnlyAttributeImpl._remove_tokenra�	initiator�Optional[AttributeEventToken]�collection_history�Optional[WriteOnlyHistory[Any]]rFcCsl|dur
|�||�}|�|�|jjD]}||||p|j�}q|jr2|dur4|�t�|�|d�dSdSdS�NT)	�_modified_eventrdrz�appendr��trackparent�sethasparentr�instance_state�rJr@r�rar�r��fnrKrKrL�fire_append_event�s
�z(WriteOnlyAttributeImpl.fire_append_eventcCsd|dur
|�||�}|�|�|jr |dur |�t�|�|d�|jjD]}||||p-|j�q$dS)NF)	r�rfr�r�rr�rzrer�r�rKrKrL�fire_remove_event
s
�z(WriteOnlyAttributeImpl.fire_remove_event�WriteOnlyHistory[Any]cCsH|j|jvr|�||tj�|j|j<|�||t�d||j<|j|jSr�)rx�committed_statertr�PASSIVE_NO_FETCHr�r)rJr@r�rKrKrLr� s�
z&WriteOnlyAttributeImpl._modified_event�	check_old�pop�_adaptc	Cs�|r
|j|jur
dS|r|durdS|}	t|	�}
|jr2|js't�d|�d���t�|j|||d��}|�	||�}|js?|j
}n|�|j
�}|�|
�}
t�|
��
|
�}|�
|
�}|
D]}||vri|j|||d|d�qY|D]}|j|||d|d�qldS)NzCollection "zV" does not support implicit iteration; collection replacement operations can't be used�rB)r�)�parent_tokenrP�has_identityrprrHr �IdentitySetr�r�r:rQrWrVr�r�)rJr@r�rar�rBr�r�r��iterable�
new_values�old_collectionr��	constants�	additions�removals�memberrKrKrL�set/sT
���

����zWriteOnlyAttributeImpl.set�args�kwargsr
cOst��rO��NotImplementedError)rJr�r�rKrKrLr!lszWriteOnlyAttributeImpl.deletecC�td��)Nz7Dynamic attributes don't support collection population.r�)rJr@r�rarKrKrL�set_committed_valueos�z*WriteOnlyAttributeImpl.set_committed_valuerUcCs|�||�}|��SrO)r�r\�rJr@r�rB�crKrKrL�get_historyvsz"WriteOnlyAttributeImpl.get_history�$List[Tuple[InstanceState[Any], Any]]cCs|�||�}dd�|jD�S)NcSsg|]	}t�|�|f�qSrK)rr�)�.0�xrKrKrL�
<listcomp>�sz:WriteOnlyAttributeImpl.get_all_pending.<locals>.<listcomp>)r�rTr�rKrKrL�get_all_pendingsz&WriteOnlyAttributeImpl.get_all_pendingcCsP|j|jvr
|j|j}n|�||tj�}|jr&|tj@r&|j||||d�S|S)N)rC)rxr�rtrr�r��INIT_OK)rJr@rBr�rKrKrLr��s��z.WriteOnlyAttributeImpl._get_collection_historycC� ||ur|�||||�dSdSrO)r��rJr@r�rar�rBrKrKrLr����zWriteOnlyAttributeImpl.appendcCr�rO)r�r�rKrKrLre�r�zWriteOnlyAttributeImpl.removecCs|j|||||d�dS)Nr�)rer�rKrKrLr��szWriteOnlyAttributeImpl.pop)rvrwrxryrzr{r|r}rsr0r~r)r@r�r�r*rBrrEr�)..)
r@r�r�r*r�r�rBr�rEr.)
r@r�r�r*r�r-rBrrEr.)
r@r�r�r*r�r�rBrrEr�)rEr�rO)r@r�r�r*rarr�r�r�r�rErF)r@r�r�r*rEr�)r@r�r�r*rarr�r�rBrr�rr�r<r�r<rErF)r�rr�rrEr
)r@r�r�r*rarrEr
)r@r�r�r*rBrrErU)r@r�r�r*rBrrEr�)r@r�rBrrEr�)r@r�r�r*rarr�r�rBrrErF)&rgrhrirmrkrnrorprqrrrsr8rtrMr�PASSIVE_OFFr�rr�r �memoized_propertyr�r�r�r�r�r�r!r�r�r�r�r�r�r�rer��
__classcell__rKrKr�rLr?�sp
�
������
�
=
�
�
	���r?�
write_only)�lazyc@seZdZeZddd�ZdS)	�WriteOnlyLoader�mapper�Mapper[Any]rErFc	Cs\d|_|jr|jjtjtjfvrt�d|j��t	j
|j|d|j|jj|jj
|jjd�dS)NTztOn relationship %s, 'dynamic' loaders cannot be used with many-to-one/one-to-one relationships and/or uselist=False.)�	useobject�
impl_classr|rsru)�is_class_level�uselist�parent_property�	directionr�	ONETOMANY�
MANYTOMANYrrHr�_register_attributer�r�rsru)rJr�rKrKrL�init_class_attribute�s&���
�z$WriteOnlyLoader.init_class_attributeN)r�r�rErF)rgrhrir?r�r�rKrKrKrLr��sr�c@sLeZdZUdZded<ddd�Zddd	�Zddd�Zddd�Zddd�Z	dS)r�z9simplified CollectionAdapter for internal API consistency�Collection[Any]r�cCs
||_dSrO)r�)rJr�rKrKrLrM��
z!DynamicCollectionAdapter.__init__rE�
Iterator[Any]cC�
t|j�SrO)�iterr�rRrKrKrL�__iter__�r�z!DynamicCollectionAdapter.__iter__rFcCr�rOrKrRrKrKrL�_reset_empty��z%DynamicCollectionAdapter._reset_empty�intcCr�rO)�lenr�rRrKrKrL�__len__�r�z DynamicCollectionAdapter.__len__r<cCsdSr�rKrRrKrKrL�__bool__�r�z!DynamicCollectionAdapter.__bool__N)r�r�)rEr�)rErF)rEr�)rEr<)
rgrhrirjrkrMr�r�r�r�rKrKrKrLr��s




r�c@sHeZdZUdZesdZded<ded<ddd�Zddd�Zddd�Z	dS)�AbstractCollectionWriterzsVirtual collection which includes append/remove methods that synchronize
    into the attribute event system.

    rKr6�instancezTuple[FromClause, ...]�	_from_objr>r?r@rAcCs�|��}tr
|s
J�||_||_t|�}|j|jj}|jdur*|j�	�|jf|_
nd|_
|j|dd�f|_|jj
rA|jj
|_dSd|_dS)NrKF)�alias_secondary)�objrr�r>r�_propsrx�	secondaryr��__clause_element__r��_with_parent�_where_criteriars�_order_by_clauses)rJr>r@r�r��proprKrKrLrM�s

�
z!AbstractCollectionWriter.__init__�iterator�Iterable[_T]rErFcCs0|D]}|j�t�|j�t�|j�|d�qdSrO)r>r�rr�r��
instance_dict)rJr��itemrKrKrL�
_add_all_impls

��z&AbstractCollectionWriter._add_all_implr�cCs&|j�t�|j�t�|j�|d�dSrO)r>rerr�r�r��rJr�rKrKrL�_remove_impl"s

�z%AbstractCollectionWriter._remove_implN)r>r?r@rA�r�r�rErF�r�r6rErF)
rgrhrirjr�	__slots__rkrMr�r�rKrKrKrLr��s


!	r�c@sdeZdZdZdZddd�Zd dd	�Zd!dd�Zd"dd�Zd#dd�Z	d$dd�Z
d%dd�Zd%dd�ZdS)&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�rEr
cCr�)Nz�WriteOnly 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().)�	TypeErrorrRrKrKrLr�Ds�zWriteOnlyCollection.__iter__�Select[Tuple[_T]]cCs<t|jj�j|j�}|jr|j|j�}|jr|j|j�}|S)z�Produce a :class:`_sql.Select` construct that represents the
        rows within this instance-local :class:`_orm.WriteOnlyCollection`.

        )	r#r>r|�wherer�r��select_fromr�rs)rJ�stmtrKrKrLr#KszWriteOnlyCollection.selectr&cCs�t|j�}|j}|j|jj}|jtjurt	�
d��i}|jD]\}}|�|||j
|�}td|d�||j<qt|jj�jdi|��S)aNFor 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.


        z�Write 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_rK)rr�r�r�r>rxr�rr�rrH�synchronize_pairs�_get_attr_w_warn_on_none�dictrr"r|�values)rJr@r�r�r��l�rr�rKrKrLr"Ws"
��zWriteOnlyCollection.insertr'cC�t|jj�j|j�S)z�Produce a :class:`_dml.Update` which will refer to rows in terms
        of this instance-local :class:`_orm.WriteOnlyCollection`.

        )r$r>r|rr�rRrKrKrLr$�zWriteOnlyCollection.updater%cCr)z�Produce a :class:`_dml.Delete` which will refer to rows in terms
        of this instance-local :class:`_orm.WriteOnlyCollection`.

        )r!r>r|rr�rRrKrKrLr!�rzWriteOnlyCollection.deleter�r�rFcC�|�|�dS)z�Add 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�)rJr�rKrKrL�add_all��zWriteOnlyCollection.add_allr�r6cCs|�|g�dS)z�Add 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.

        Nrr�rKrKrLrb�szWriteOnlyCollection.addcCr)z�Remove 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�rKrKrLre�rzWriteOnlyCollection.removeN)rEr
)rEr)rEr&)rEr')rEr%rr)
rgrhrirjrr�r#r"r$r!rrbrerKrKrKrLr�+s



(


		r�N)Orj�
__future__r�typingrrrrrrr	r
rrr
rrrr�sqlalchemy.sqlr�rrrr�baserrrrrrrr �sqlr!r"r#r$�sql.dmlr%r&r'�util.typingr(r)�_typingr*r+r,�collectionsr-r.r�r/r0r@r1r2�eventr3�sql.selectabler4r5r6r8�HasCollectionAdapter�
AttributeImplr?�class_logger�RelationshipProperty�strategy_for�AbstractRelationshipLoader�
Identifiedr�r�r�r�rKrKrKrL�<module>s�
I�'?