Ë
    ÛÍ:jÝ&  ã                  óz  — 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" er0d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d$e¬%«      Z/ G d&„ d'ee/   «      Z0 G d(„ d)e«      Z1ejd                  jg                  d*¬+«       G d,„ d-e «      «       Z4 G d.„ d/ee/   «      Z5 G d0„ d1e5e/   ee/   «      Z6d4d2„Z7y3)5zâ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)Úoverload)Ú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                  ó*   — e Zd Z	 d	 	 	 	 	 	 	 	 	 dd„Zy)ÚDynamicCollectionHistoryNc                ój  — |r_t        ||«      j                  d«      }t        j                  |«      | _        |j
                  | _        |j                  | _        d| _        y t        j                  «       | _        t        j                  «       | _        t        j                  «       | _        d| _        y )NFT)ÚAppenderQueryÚ	autoflushr   ÚOrderedIdentitySetÚunchanged_itemsÚadded_itemsÚdeleted_itemsÚ_reconcile_collection)ÚselfÚattrÚstateÚpassiveÚapply_toÚcolls         úk/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/sqlalchemy/orm/dynamic.pyÚ__init__z!DynamicCollectionHistory.__init__>   s�   € ñ Ü   uÓ-×7Ñ7¸Ó>ˆDÜ#'×#:Ñ#:¸4Ó#@ˆDÔ Ø'×3Ñ3ˆDÔØ!)×!7Ñ!7ˆDÔØ)-ˆDÕ&ä!%×!8Ñ!8Ó!:ˆDÔÜ#×6Ñ6Ó8ˆDÔÜ#'×#:Ñ#:Ó#<ˆDÔ Ø).ˆDÕ&ó    ©N)
r2   ÚDynamicAttributeImplr3   úInstanceState[_T]r4   r   r5   z&Optional[DynamicCollectionHistory[_T]]ÚreturnÚNone)Ú__name__Ú
__module__Ú__qualname__r8   © r9   r7   r(   r(   =   s=   „ ð <@ð/à"ð/ð !ð/ð ð	/ð
 9ð/ð 
ô/r9   r(   c                  óP   — e Zd ZU dZee   Zded<   	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zy)r;   TzType[AppenderMixin[Any]]Úquery_classNc                óö   — t        j                  j                  | ||d |fi |¤Ž || _        |rt	        |«      | _        |st        | _        y t        |j                  «       v r|| _        y t        |«      | _        y r:   )r   ÚAttributeImplr8   Útarget_mapperÚtupleÚorder_byr*   rD   ÚAppenderMixinÚmroÚmixin_user_query)r1   Úclass_ÚkeyÚdispatchrG   rI   rD   Úkws           r7   r8   zDynamicAttributeImpl.__init__W   sr   € ô 	× Ñ ×)Ñ)Ø�&˜#˜t Xñ	
Ø13ò	
ð +ˆÔÙÜ! (›OˆDŒMÙÜ,ˆDÕÜ˜kŸo™oÓ/Ñ/Ø*ˆDÕä/°Ó<ˆDÕr9   r:   )rM   z#Union[Type[Any], AliasedClass[Any]]rN   ÚstrrO   z"_Dispatch[QueryableAttribute[Any]]rG   z
Mapper[_T]rI   r   rD   z!Optional[Type[AppenderMixin[_T]]]rP   r   r=   r>   )	r?   r@   rA   Ú_supports_dynamic_iterationr(   r   Úcollection_history_clsÚ__annotations__r8   rB   r9   r7   r;   r;   R   sq   … Ø"&ÐØ5°cÑ:ÐØ)Ó)ð :>ð=à3ð=ð ð=ð 5ð	=ð
 "ð=ð *ð=ð 7ð=ð ð=ð 
ô=r9   r;   Údynamic)Úlazyc                  ó   — e Zd ZeZy)Ú
DynaLoaderN)r?   r@   rA   r;   Ú
impl_classrB   r9   r7   rX   rX   o   s   „ à%�Jr9   rX   c                  ó  ‡ — e Zd ZU dZdZded<   ded<   	 	 	 	 	 	 dˆ fd„Zedd„«       Zej                  dd	„«       Zdd
„Z
erdd„Zedd„«       Zedd„«       Zdd„Zdd„Z	 d	 	 	 d d„Zd!d„Zd"d„Zd!d„Zd"d„Zd"d„Zˆ xZS )#rJ   zTA mixin that expects to be mixing in a Query class with
    AbstractAppender.


    NzOptional[Type[Query[_T]]]rD   zTuple[ColumnElement[Any], ...]Ú_order_by_clausesc                óh   •— t        j                  | |j                  d «       t        ‰| �  ||«       y r:   )r   r8   rG   Úsuper)r1   r2   r3   Ú	__class__s      €r7   r8   zAppenderMixin.__init__~   s1   ø€ ô 	�‰ØØ×ÑØô	
ô
 	‰Ñ˜˜uÕ%r9   c                óÈ   — t        | j                  «      }|�*|j                  r| j                  |v r|j                  «        t	        j
                  | j                  «      sy |S r:   )r   Úinstancer+   ÚflushÚorm_utilÚhas_identity©r1   Úsesss     r7   ÚsessionzAppenderMixin.sessionˆ   sJ   € ä˜dŸm™mÓ,ˆØÐ §¢°4·=±=ÀDÑ3HØ�J‰JŒLÜ×$Ñ$ T§]¡]Ô3ØàˆKr9   c                ó   — || _         y r:   )re   )r1   rf   s     r7   rf   zAppenderMixin.session’   s	   € àˆ�	r9   c           
     ój  — | j                   }|�€t        j                  | j                  «      }|j                  r+t        j                  dt        j                  |«      z  «       t        j                  t        j                  | j                  j                  j                  g«      t        | j                  j!                  t        j                  | j                  «      t"        j$                  «      j&                  «      d¬«      j)                  «       S | j+                  |«      j-                  «       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)rf   r   Úinstance_stater`   Údetachedr   Úwarnrb   Ú	state_strr   ÚIteratorResultÚSimpleResultMetaDatar2   rM   r?   ÚiterÚ_get_collection_historyr   ÚPASSIVE_NO_INITIALIZEr.   ÚscalarsÚ	_generateÚ_iter)r1   re   r3   s      r7   ru   zAppenderMixin._iter–   sì   € Ø�|‰|ˆØ‰<Ü×-Ñ-¨d¯m©mÓ<ˆEØ�~Š~Ü—	‘	ðCô  ×)Ñ)¨%Ó0ñ2ôô ×(Ñ(Ü×+Ñ+¨T¯Y©Y×-=Ñ-=×-FÑ-FÐ,GÓHÜØ—I‘I×5Ñ5Ü"×1Ñ1°$·-±-Ó@Ü#×9Ñ9ó÷ "‘kó	ð *.ô	÷ ‰g‹ið	ð —>‘> $Ó'×-Ñ-Ó/Ð/r9   c                 ó   — y r:   rB   )r1   s    r7   Ú__iter__zAppenderMixin.__iter__±   s   � r9   c                 ó   — y r:   rB   ©r1   Úindexs     r7   Ú__getitem__zAppenderMixin.__getitem__³   s   € Ø-0r9   c                 ó   — y r:   rB   ry   s     r7   r{   zAppenderMixin.__getitem__¶   s   € Ø58r9   c                ó
  — | j                   }|€V| j                  j                  t        j                  | j
                  «      t        j                  «      j                  |«      S | j                  |«      j                  |«      S r:   )rf   r2   rq   r   rj   r`   r   rr   Úindexedrt   r{   )r1   rz   re   s      r7   r{   zAppenderMixin.__getitem__¹   si   € Ø�|‰|ˆØˆ<Ø—9‘9×4Ñ4Ü×)Ñ)¨$¯-©-Ó8Ü×1Ñ1ó÷ ‰g�e‹nðð
 —>‘> $Ó'×3Ñ3°EÓ:Ð:r9   c                ó  — | j                   }|€Zt        | j                  j                  t	        j
                  | j                  «      t        j                  «      j                  «      S | j                  |«      j                  «       S r:   )rf   Úlenr2   rq   r   rj   r`   r   rr   r.   rt   Úcountrd   s     r7   r�   zAppenderMixin.countÃ   sk   € Ø�|‰|ˆØˆ<ÜØ—	‘	×1Ñ1Ü×-Ñ-¨d¯m©mÓ<Ü×5Ñ5ó÷ ‘+ó	ð ð —>‘> $Ó'×-Ñ-Ó/Ð/r9   c                óÚ  — | j                   }|€Pt        |«      }|€Ct        j                  dt	        j
                  |«      ›d| j                  j                  ›d�«      ‚| j                  r(| j                  | j                  j                  |¬«      }n%|j                  | j                  j                  «      }| j                  |_        | j                  |_        | j                  |_        |S )NzParent instance zh is not bound to a Session, and no contextual session is established; lazy load operation of attribute 'z' cannot proceed)rf   )r`   r   Úorm_excÚDetachedInstanceErrorrb   Úinstance_strr2   rN   rD   rG   ÚqueryÚ_where_criteriaÚ	_from_objr[   )r1   re   r`   r†   s       r7   rt   zAppenderMixin._generateÏ   sÂ   € ð —=‘=ˆØˆ<Ü! (Ó+ˆDØˆ|Ü×3Ò3ô  ×,Ñ,¨XÕ6¸¿	¹	¿»ðGóð ð ×ÒØ×$Ñ$ T§Y¡Y×%<Ñ%<ÀdÐ$ÓK‰Eà—J‘J˜tŸy™y×6Ñ6Ó7ˆEà $× 4Ñ 4ˆÔØŸ.™.ˆŒØ"&×"8Ñ"8ˆÔàˆr9   c                ó&   — | j                  |«       y)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©r1   Úiterators     r7   Úadd_allzAppenderMixin.add_allì   s   € ð 	×Ñ˜8Õ$r9   c                ó(   — | j                  |g«       y)ap  Add 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Š   ©r1   Úitems     r7   ÚaddzAppenderMixin.addú   s   € ð 	×Ñ˜D˜6Õ"r9   c                ó&   — | j                  |«       y)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Œ   s     r7   ÚextendzAppenderMixin.extend  s   € ð 	×Ñ˜8Õ$r9   c                ó(   — | j                  |g«       y)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�   s     r7   ÚappendzAppenderMixin.append  s   € ð 	×Ñ˜D˜6Õ"r9   c                ó&   — | j                  |«       y)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�   s     r7   ÚremovezAppenderMixin.remove  s   € ð 	×Ñ˜$Õr9   )r2   r;   r3   r<   r=   r>   )r=   úOptional[Session])rf   r    r=   r>   )r=   z1Union[result.ScalarResult[_T], result.Result[_T]])r=   zIterator[_T])rz   Úintr=   r%   )rz   Úslicer=   zList[_T])rz   zUnion[int, slice]r=   zUnion[_T, List[_T]])r=   r›   r:   )re   rš   r=   z	Query[_T])r�   zIterable[_T]r=   r>   )r‘   r%   r=   r>   )r?   r@   rA   Ú__doc__rD   rT   r8   Úpropertyrf   Úsetterru   r   rw   r	   r{   r�   rt   rŽ   r’   r”   r–   r™   Ú__classcell__)r^   s   @r7   rJ   rJ   t   sÌ   ø… ñð .2€KÐ*Ó1Ø5Ó5ð&Ø(ð&Ø1Bð&à	õ&ð òó ðð ‡^�^òó ðó0ñ2 ã/àÚ0ó Ø0àÚ8ó Ø8ó;ó
0ð #'ðàðð 
óó:%ó#ó%ó#÷ r9   rJ   c                  ó   — e Zd ZdZy)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@   rA   r�   rB   r9   r7   r*   r*   $  s   „ òr9   r*   c                óJ   — d| j                   z   }t        |t        | fd| i«      S )zAReturn a new class with AppenderQuery functionality layered over.ÚAppenderrD   )r?   ÚtyperJ   )ÚclsÚnames     r7   rL   rL   /  s)   € à˜Ÿ™Ñ$€DÜ�”} cÐ*¨]¸CÐ,@ÓAÐAr9   N)r¥   r   r=   ztype[AppenderMixin[Any]])8r�   Ú
__future__r   Útypingr   r   r   r   r   r	   r
   r   r   r   r   Ú r   r   rƒ   r   r   rb   Úbaser   r†   r   rf   r   Ú	writeonlyr   r   r   r   Úenginer   r   Úmapperr   r   r    r3   r!   r"   Úeventr#   Úsql.elementsr$   r%   r(   r;   ÚRelationshipPropertyÚstrategy_forrX   rJ   r*   rL   rB   r9   r7   ú<module>r²      sÿ   ðñ	õ #å Ý Ý Ý Ý Ý Ý Ý Ý  Ý Ý å Ý Ý Ý Ý Ý Ý #Ý /Ý -Ý 'Ý &Ý Ý áÝ$ÝÝ6Ý Ý$Ý"Ý!Ý,áˆT˜Ô€ô/Ð/°Ñ3ô /ô*=Ð1ô =ð: ×#Ñ#×0Ñ0°iÐ0Ó@ô&�ó &ó Að&ôm Ð,¨RÑ0ô m ô`�M "Ñ% u¨R¡yô ôBr9   