
    2hb                        S SK Jr  S SKrS SKrS SKJr  S SK	J
r  S SKJr  \R                  (       a  SSKJr   " S S\R"                  5      r      S
S jrSS	 jrg)    )annotationsN)app_ctx   )
SQLAlchemyc                  \   ^  \ rS rSrSrSU 4S jjr   S         SU 4S jjjrSrU =r$ )	Session   as  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``.
c                @   > [         TU ]  " S0 UD6  Xl        0 U l        g )N )super__init___db_model_changes)selfdbkwargs	__class__s      P/var/www/auris/envauris/lib/python3.13/site-packages/flask_sqlalchemy/session.pyr   Session.__init__   s     "6"?A    c                  > Ub  U$ U R                   R                  nUb2   [        R                  " U5      n[        UR                  U5      nUb  U$ Ub  [        X%5      nUb  U$ SU;   a  US   $ [        TU ]8  " SXUS.UD6$ ! [        R
                   a;  n[        U[        5      (       a   [        R                  R                  U5      Uee SnAff = f)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)mapperclausebindr   )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'   Session.get_bind   s    & K((""F+ 'v'9'97CF!&v7F!7?4= wRv4R6RR) // fd++ **77?QF	s   B C6CC)r   r   )r   r   r   t.AnyreturnNone)NNN)
r   t.Any | Noner   r.   r   z.sa.engine.Engine | sa.engine.Connection | Noner   r+   r,   z'sa.engine.Engine | sa.engine.Connection)	__name__
__module____qualname____firstlineno____doc__r   r'   __static_attributes____classcell__)r   s   @r   r   r      sZ    	B  $#?C	/S/S /S =	/S
 /S 
1/S /Sr   r   c                   SnU bv  [        U [        R                  5      (       a  U nOT[        U [        R                  5      (       a5  [        U R                  [        R                  5      (       a  U R                  nUbV  SUR
                  R                  ;   a<  UR
                  R                  S   nX1;  a  [        R                  " SU S35      eX   $ g)z]If 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fbhh''E..:fllBHH3U3ULLEZ5>>+>+>>nn!!*-..SE!GH  |r   c                 >    [        [        R                  " 5       5      $ )zJGet the id of the current Flask application context for the session scope.)idr   _get_current_objectr   r   r   _app_ctx_idrB   m   s    g))+,,r   )r   zsa.ClauseElement | Noner   z't.Mapping[str | None, sa.engine.Engine]r,   zsa.engine.Engine | None)r,   int)
__future__r   typingt
sqlalchemyr   sqlalchemy.excr#   r   sqlalchemy.ormormr"   flask.globalsr   TYPE_CHECKING	extensionr   r   r%   rB   r   r   r   <module>rN      sZ    "     !??%@Sfnn @SF#4 8-r   