Ë
    ×[Ãib  ã                  ó®   — 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y)é    )ÚannotationsN)Úapp_ctxé   )Ú
SQLAlchemyc                  óJ   ‡ — 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``.
    c                ó@   •— t        ‰| �  di |¤Ž || _        i | _        y )N© )ÚsuperÚ__init__Ú_dbÚ_model_changes)ÚselfÚdbÚkwargsÚ	__class__s      €úP/var/www/timesheet/venv/lib/python3.12/site-packages/flask_sqlalchemy/session.pyr   zSession.__init__   s"   ø€ Ü‰ÑÑ"˜6Ò"ØˆŒØ?AˆÕó    c                ó�  •— |�|S | j                   j                  }|�0	 t        j                  |«      }t        |j                  |«      }|�|S |�t        ||«      }|�|S d|v r|d   S t        ‰| �8  d|||dœ|¤ŽS # t        j
                  $ r6}t        |t        «      r t        j                  j                  |«      |‚‚ d}~ww xY w)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%   zSession.get_bind   sÝ   ø€ ð& ÐØˆKà—(‘(×"Ñ"ˆàÐðÜŸ™ FÓ+�ô ' v×'9Ñ'9¸7ÓCˆFàÐ!Ø�àÐÜ& v¨wÓ7ˆFàÐ!Ø�à�7‰?Ø˜4‘=Ð ä‰wÑÐR v°fÀ4ÑRÈ6ÑRÐRøô) ×/Ñ/ò Ü˜f¤dÔ+Ü Ÿ*™*×7Ñ7¸Ó?ÀQÐFàûð	ús   ŸA< Á<CÂ1C Ã C)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__Ú__doc__r   r%   Ú__classcell__)r   s   @r   r   r      sZ   ø„ ñ	õBð  $Ø#Ø?Cð	/Sàð/Sð ð/Sð =ð	/Sð
 ð/Sð 
1÷/Sñ /Sr   r   c                ó„  — d}| �gt        | t        j                  «      r| }nJt        | t        j                  «      r0t        | j                  t        j                  «      r| j                  }|�Sd|j
                  j                  v r;|j
                  j                  d   }||vrt        j                  d|› d�«      ‚||   S y)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   r5   Úkeys       r   r#   r#   Q   s¬   € ð €EàÐÜ�fœbŸh™hÔ'Ø‰EÜ˜¤§¡Ô.´:¸f¿l¹lÌBÏHÉHÔ3UØ—L‘LˆEàÐ˜Z¨5¯>©>×+>Ñ+>Ñ>Ø�n‰n×!Ñ! *Ñ-ˆà�gÑÜ×.Ñ.Ø˜S˜EÐ!GÐHóð ð �s‰|Ðàr   c                 ó<   — 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_idr=   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#   r=   r
   r   r   ú<module>rI      sZ   ðÝ "ã ã Ý Ý Ý !à‡?‚?Ý%ô@Sˆf�n‰nô @SðFØ#ðà4ðð óô8-r   