§
    'ê[fb  ã                  ó–   — d dl mZ d dlZd dlZd dlmZ d dl	m
Z d dlmZ ej        rddlmZ  G d„ dej        ¦  «        Zdd„Zdd„ZdS )é    )ÚannotationsN)Úapp_ctxé   )Ú
SQLAlchemyc                  ó8   ‡ — e Zd ZdZdˆ fd„Z	 	 	 ddˆ fd„Zˆ xZS )ÚSessiona�  A SQLAlchemy :class:`~sqlalchemy.orm.Session` class that chooses what engine to
    use based on the bind key associated with the metadata associated with the thing
    being queried.

    To customize ``db.session``, subclass this and pass it as the ``class_`` key in the
    ``session_options`` to :class:`.SQLAlchemy`.

    .. versionchanged:: 3.0
        Renamed from ``SignallingSession``.
    Údbr   Úkwargsút.AnyÚreturnÚNonec                óV   •—  t          ¦   «         j        di |¤Ž || _        i | _        d S )N© )ÚsuperÚ__init__Ú_dbÚ_model_changes)Úselfr	   r
   Ú	__class__s      €úL/var/www/piapp/venv/lib/python3.11/site-packages/flask_sqlalchemy/session.pyr   zSession.__init__   s5   ø€ Ø�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"ØˆŒØ?AˆÔÐÐó    NÚmapperút.Any | NoneÚclauseÚbindú.sa.engine.Engine | sa.engine.Connection | Noneú'sa.engine.Engine | sa.engine.Connectionc                óž  •— |�|S | j         j        }|�|	 t          j        |¦  «        }nM# t          j        $ r;}t          |t          ¦  «        r t          j	         
                    |¦  «        |‚‚ d}~ww xY wt          |j        |¦  «        }|�|S |�t          ||¦  «        }|�|S d|v r|d         S  t          ¦   «         j        d|||dœ|¤ŽS )aÞ  Select an engine based on the ``bind_key`` of the metadata associated with
        the model or table being queried. If no bind key is set, uses the default bind.

        .. versionchanged:: 3.0.3
            Fix finding the bind for a joined inheritance model.

        .. versionchanged:: 3.0
            The implementation more closely matches the base SQLAlchemy implementation.

        .. versionchanged:: 2.1
            Support joining an external transaction.
        N)r   r   r   r   )r   ÚenginesÚsaÚinspectÚsa_excÚNoInspectionAvailableÚ
isinstanceÚtypeÚsa_ormÚexcÚUnmappedClassErrorÚ_clause_to_engineÚlocal_tabler   Úget_bind)	r   r   r   r   r
   r   ÚeÚenginer   s	           €r   r+   zSession.get_bind   sþ   ø€ ð& ÐØˆKà”(Ô"ˆàÐðÝœ FÑ+Ô+��øÝÔ/ð ð ð Ý˜f¥dÑ+Ô+ð GÝ œ*×7Ò7¸Ñ?Ô?ÀQÐFàøøøøð	øøøõ ' vÔ'9¸7ÑCÔCˆFàÐ!Ø�àÐÝ& v¨wÑ7Ô7ˆFàÐ!Ø�à�7ˆ?ˆ?Ø˜4”=Ð à�u‰wŒwÔÐR v°fÀ4ÐRÐRÈ6ÐRÐRÐRs   •* ªA4¹6A/Á/A4)r	   r   r
   r   r   r   )NNN)
r   r   r   r   r   r   r
   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r+   Ú__classcell__)r   s   @r   r   r      s†   ø€ € € € € ð	ð 	ðBð Bð Bð Bð Bð Bð  $Ø#Ø?Cð	/Sð /Sð /Sð /Sð /Sð /Sð /Sð /Sð /Sð /Sð /Sr   r   r   úsa.ClauseElement | Noner   ú't.Mapping[str | None, sa.engine.Engine]r   úsa.engine.Engine | Nonec                óT  — d}| �]t          | t          j        ¦  «        r| }n@t          | t          j        ¦  «        r&t          | j        t          j        ¦  «        r| j        }|�Dd|j        j        v r6|j        j        d         }||vrt          j        d|› d�¦  «        ‚||         S dS )zeIf the clause is a table, return the engine associated with the table's
    metadata's bind key.
    NÚbind_keyz
Bind key 'z&' is not in 'SQLALCHEMY_BINDS' config.)	r$   r    ÚTableÚ
UpdateBaseÚtableÚmetadataÚinfor"   ÚUnboundExecutionError)r   r   r:   Úkeys       r   r)   r)   Q   s½   € ð €EàÐÝ�f�bœhÑ'Ô'ð 	!ØˆEˆEÝ˜¥¤Ñ.Ô.ð 	!µ:¸f¼lÍBÌHÑ3UÔ3Uð 	!Ø”LˆEàÐ˜Z¨5¬>Ô+>Ð>Ð>ØŒnÔ! *Ô-ˆà�gÐÐÝÔ.ØH˜SÐHÐHÐHñô ð ð �sŒ|Ðàˆ4r   Úintc                 óB   — t          t          j        ¦   «         ¦  «        S )zJGet the id of the current Flask application context for the session scope.)Úidr   Ú_get_current_objectr   r   r   Ú_app_ctx_idrC   m   s   € å�gÔ)Ñ+Ô+Ñ,Ô,Ð,r   )r   r3   r   r4   r   r5   )r   r?   )Ú
__future__r   ÚtypingÚtÚ
sqlalchemyr    Úsqlalchemy.excr'   r"   Úsqlalchemy.ormÚormr&   Úflask.globalsr   ÚTYPE_CHECKINGÚ	extensionr   r   r)   rC   r   r   r   ú<module>rN      sð   ðØ "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð à Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !à„?ð &Ø%Ð%Ð%Ð%Ð%Ð%ð@Sð @Sð @Sð @Sð @SˆfŒnñ @Sô @Sð @SðFð ð ð ð8-ð -ð -ð -ð -ð -r   