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: //home/arjun/.local/lib/python3.10/site-packages/sqlalchemy/orm/__pycache__/dynamic.cpython-310.pyc
o

���gX&�@sdZddlmZddlmZddlmZddlmZddlmZddlmZddlm	Z	dd	lm
Z
dd
lmZddlmZddlm
Z
d
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZddlmZddl m!Z!er�d
dlm"Z"d
dl#m$Z$d
dlm%Z%d
dlm&Z&d
dl'm(Z(d
d lm)Z)dd!l*m+Z+dd"l,m-Z-ed#ed$�Z.Gd%d&�d&ee.�Z/Gd'd(�d(e�Z0ej1j2d)d*�Gd+d,�d,e��Z3Gd-d.�d.ee.�Z4Gd/d0�d0e4e.ee.�Z5d8d5d6�Z6d7S)9z�Dynamic collection API.

Dynamic collections act like Query() objects for read operations and support
basic add/delete mutation.

.. legacy:: the "dynamic" loader is a legacy feature, superseded by the
 "write_only" loader.


�)�annotations)�Any)�Iterable)�Iterator)�List)�Optional)�Tuple)�Type)�
TYPE_CHECKING)�TypeVar)�Union�)�
attributes)�exc)�
relationships)�util)�PassiveFlag)�Query)�object_session)�AbstractCollectionWriter)�WriteOnlyAttributeImpl)�WriteOnlyHistory)�WriteOnlyLoader�)�result)�QueryableAttribute)�Mapper)�_RelationshipOrderByArg)�Session)�
InstanceState)�AliasedClass)�	_Dispatch)�
ColumnElement�_T)�boundc@seZdZ	dddd
�ZdS)�DynamicCollectionHistoryN�attr�DynamicAttributeImpl�state�InstanceState[_T]�passiver�apply_to�&Optional[DynamicCollectionHistory[_T]]�return�NonecCsb|rt||��d�}t�|�|_|j|_|j|_d|_dSt��|_t��|_t��|_d|_dS)NFT)�
AppenderQuery�	autoflushr�OrderedIdentitySet�unchanged_items�added_items�
deleted_items�_reconcile_collection)�selfr&r(r*r+�coll�r8�I/home/arjun/.local/lib/python3.10/site-packages/sqlalchemy/orm/dynamic.py�__init__>s




z!DynamicCollectionHistory.__init__�N)
r&r'r(r)r*rr+r,r-r.)�__name__�
__module__�__qualname__r:r8r8r8r9r%=s�r%c@s0eZdZUdZeeZded<	dddd�ZdS)r'TzType[AppenderMixin[Any]]�query_classN�class_�#Union[Type[Any], AliasedClass[Any]]�key�str�dispatch�"_Dispatch[QueryableAttribute[Any]]�
target_mapper�
Mapper[_T]�order_byr�!Optional[Type[AppenderMixin[_T]]]�kwrr-r.cKsbtjj|||d|fi|��||_|rt|�|_|st|_dSt|�	�vr*||_dSt
|�|_dSr;)r�
AttributeImplr:rF�tuplerHr/r?�
AppenderMixin�mro�mixin_user_query)r6r@rBrDrFrHr?rJr8r8r9r:Ws

��


zDynamicAttributeImpl.__init__r;)r@rArBrCrDrErFrGrHrr?rIrJrr-r.)	r<r=r>�_supports_dynamic_iterationr%r�collection_history_cls�__annotations__r:r8r8r8r9r'Rs
	�r'�dynamic)�lazyc@seZdZeZdS)�
DynaLoaderN)r<r=r>r'�
impl_classr8r8r8r9rUosrUcs�eZdZUdZdZded<ded<d5�fd
d�Zed6dd��Zej	d7dd��Zd8dd�Z
er3d9dd�Zd:dd�Z
d;d!d"�Z	d<d=d%d&�Zd>d)d*�Zd?d-d.�Zd>d/d0�Zd?d1d2�Zd?d3d4�Z�ZS)@rMzTA mixin that expects to be mixing in a Query class with
    AbstractAppender.


    NzOptional[Type[Query[_T]]]r?zTuple[ColumnElement[Any], ...]�_order_by_clausesr&r'r(r)r-r.cs"t�||jd�t��||�dSr;)rr:rF�super)r6r&r(��	__class__r8r9r:~s�zAppenderMixin.__init__�Optional[Session]cCs>t|j�}|dur|jr|j|vr|��t�|j�sdS|Sr;)r�instancer0�flush�orm_util�has_identity�r6�sessr8r8r9�session�s
zAppenderMixin.sessionrbrcCs
||_dSr;)ra)r6rbr8r8r9rb�s
�1Union[result.ScalarResult[_T], result.Result[_T]]cCs~|j}|dur8t�|j�}|jrt�dt�|��t	j
t	�|jj
jg�t|j�t�|j�tj�j�dd���S|�|���S)Nz�Instance %s is detached, dynamic relationship cannot return a correct result.   This warning will become a DetachedInstanceError in a future release.T)�_source_supports_scalars)rbr�instance_stater\�detachedr�warnr^�	state_strr�IteratorResult�SimpleResultMetaDatar&r@r<�iter�_get_collection_historyr�PASSIVE_NO_INITIALIZEr3�scalars�	_generate�_iter)r6rar(r8r8r9rp�s.��
���	�zAppenderMixin._iter�Iterator[_T]cCsdSr;r8)r6r8r8r9�__iter__�szAppenderMixin.__iter__�indexr�Union[_T, List[_T]]cCs<|j}|dur|j�t�|j�tj��|�S|�	|��
|�Sr;)rbr&rlrrer\rrm�indexedro�__getitem__)r6rsrar8r8r9rv�s
��zAppenderMixin.__getitem__�intcCs:|j}|durt|j�t�|j�tj�j	�S|�
|���Sr;)rb�lenr&rlrrer\rrmr3ro�countr`r8r8r9ry�s
��zAppenderMixin.countra�	Query[_T]cCs~|j}|durt|�}|durt�dt�|�|jjf��|jr*|j|jj	|d�}n|�
|jj	�}|j|_|j|_|j
|_
|S)Nz�Parent instance %s is not bound to a Session, and no contextual session is established; lazy load operation of attribute '%s' cannot proceed)rb)r\r�orm_exc�DetachedInstanceErrorr^�instance_strr&rBr?rF�query�_where_criteria�	_from_objrW)r6rar\r~r8r8r9ro�s ��zAppenderMixin._generate�iterator�Iterable[_T]cC�|�|�dS)a~Add an iterable of items to this :class:`_orm.AppenderQuery`.

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

        This method is provided to assist in delivering forwards-compatibility
        with the :class:`_orm.WriteOnlyCollection` collection class.

        .. versionadded:: 2.0

        N��
_add_all_impl�r6r�r8r8r9�add_all�szAppenderMixin.add_all�itemr#cC�|�|g�dS)apAdd an item to this :class:`_orm.AppenderQuery`.

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

        This method is provided to assist in delivering forwards-compatibility
        with the :class:`_orm.WriteOnlyCollection` collection class.

        .. versionadded:: 2.0

        Nr��r6r�r8r8r9�add�szAppenderMixin.addcCr�)z�Add an iterable of items to this :class:`_orm.AppenderQuery`.

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

        Nr�r�r8r8r9�extend�zAppenderMixin.extendcCr�)z�Append an item to this :class:`_orm.AppenderQuery`.

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

        Nr�r�r8r8r9�appendszAppenderMixin.appendcCr�)z�Remove an item from this :class:`_orm.AppenderQuery`.

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

        N)�_remove_implr�r8r8r9�remover�zAppenderMixin.remove)r&r'r(r)r-r.)r-r[)rbrr-r.)r-rc)r-rq)rsrr-rt)r-rwr;)rar[r-rz)r�r�r-r.)r�r#r-r.)r<r=r>�__doc__r?rRr:�propertyrb�setterrpr
rrrvryror�r�r�r�r��
__classcell__r8r8rYr9rMts*

	




�



		rMc@seZdZdZdS)r/z�A dynamic query that supports basic collection storage operations.

    Methods on :class:`.AppenderQuery` include all methods of
    :class:`_orm.Query`, plus additional methods used for collection
    persistence.


    N)r<r=r>r�r8r8r8r9r/sr/�clsrr-�type[AppenderMixin[Any]]cCsd|j}t|t|fd|i�S)zAReturn a new class with AppenderQuery functionality layered over.�Appenderr?)r<�typerM)r��namer8r8r9rO)s
rON)r�rr-r�)7r��
__future__r�typingrrrrrrr	r
rr�rrr{rrr^�baserr~rrbr�	writeonlyrrrr�enginerr�mapperrrrr(rr �eventr!�sql.elementsr"r#r%r'�RelationshipProperty�strategy_forrUrMr/rOr8r8r8r9�<module>sV+