
    ,h                       S SK Jr  S SKrS SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S	S
K	J
r
  S	SK	Jr  S	SKJr  S	SKJr  S	SKJr  S	SKJr  SSKJr  SSKJr  SSKJr  \R,                  (       aH  S	SKJr  S	SKJr  S	SKJr  S	SKJr  S	SKJr  S	SKJr  S	SKJr  S	SKJr  S	SKJ r   SSK!J"r"  SSK#J$r$  SSK%J&r&   " S  S!\RN                  \   5      r( " S" S#\RN                  \   5      r)g)$    )annotationsN)Any)Dict)Optional)Tuple)Type)Union   )
Connection)Engine)ConnectionEventsTarget)DBAPIConnection)DBAPICursor)Dialect   )event)exc)Literal)_CoreMultiExecuteParams)_CoreSingleExecuteParams)_DBAPIAnyExecuteParams)_DBAPIMultiExecuteParams)_DBAPISingleExecuteParams)_ExecuteOptions)ExceptionContext)ExecutionContext)Result)ConnectionPoolEntry)
Executable)BindParameterc                    ^  \ rS rSrSrSr\r\      S%U 4S jj5       r	\SS.       S&S jj5       r
\R                  " S/ S	QS
 5                  S'S j5       r\R                  " S/ SQS 5                    S(S j5       r              S)S jr              S*S jr\R                  " SSS/S S9S+S j5       r      S,S jr      S-S jrS.S jrS+S jrS+S jrS+S jrS/S jr        S0S jr        S0S jrS1S  jrS1S! jr        S2S" jr        S2S# jrS$rU =r $ )3ConnectionEvents,   a
  Available events for
:class:`_engine.Connection` and :class:`_engine.Engine`.

The methods here define the name of an event as well as the names of
members that are passed to listener functions.

An event listener can be associated with any
:class:`_engine.Connection` or :class:`_engine.Engine`
class or instance, such as an :class:`_engine.Engine`, e.g.::

    from sqlalchemy import event, create_engine


    def before_cursor_execute(
        conn, cursor, statement, parameters, context, executemany
    ):
        log.info("Received statement: %s", statement)


    engine = create_engine("postgresql+psycopg2://scott:tiger@localhost/test")
    event.listen(engine, "before_cursor_execute", before_cursor_execute)

or with a specific :class:`_engine.Connection`::

    with engine.begin() as conn:

        @event.listens_for(conn, "before_cursor_execute")
        def before_cursor_execute(
            conn, cursor, statement, parameters, context, executemany
        ):
            log.info("Received statement: %s", statement)

When the methods are called with a `statement` parameter, such as in
:meth:`.after_cursor_execute` or :meth:`.before_cursor_execute`,
the statement is the exact SQL string that was prepared for transmission
to the DBAPI ``cursor`` in the connection's :class:`.Dialect`.

The :meth:`.before_execute` and :meth:`.before_cursor_execute`
events can also be established with the ``retval=True`` flag, which
allows modification of the statement and parameters to be sent
to the database.  The :meth:`.before_cursor_execute` event is
particularly useful here to add ad-hoc string transformations, such
as comments, to all executions::

    from sqlalchemy.engine import Engine
    from sqlalchemy import event


    @event.listens_for(Engine, "before_cursor_execute", retval=True)
    def comment_sql_calls(
        conn, cursor, statement, parameters, context, executemany
    ):
        statement = statement + " -- some comment"
        return statement, parameters

.. note:: :class:`_events.ConnectionEvents` can be established on any
   combination of :class:`_engine.Engine`, :class:`_engine.Connection`,
   as well
   as instances of each of those classes.  Events across all
   four scopes will fire off for a given instance of
   :class:`_engine.Connection`.  However, for performance reasons, the
   :class:`_engine.Connection` object determines at instantiation time
   whether or not its parent :class:`_engine.Engine` has event listeners
   established.   Event listeners added to the :class:`_engine.Engine`
   class or to an instance of :class:`_engine.Engine`
   *after* the instantiation
   of a dependent :class:`_engine.Connection` instance will usually
   *not* be available on that :class:`_engine.Connection` instance.
   The newly
   added listeners will instead take effect for
   :class:`_engine.Connection`
   instances created subsequent to those event listeners being
   established on the parent :class:`_engine.Engine` class or instance.

:param retval=False: Applies to the :meth:`.before_execute` and
  :meth:`.before_cursor_execute` events only.  When True, the
  user-defined event function must have a return value, which
  is a tuple of parameters that replace the given statement
  and parameters.  See those methods for a description of
  specific return arguments.


SomeEnginec                n   > [         TU ]  X5      nUc!  [        US5      (       a  UR                  5         U$ )N_no_async_engine_events)super_accept_withhasattrr&   )clstarget
identifierdefault_dispatch	__class__s       P/var/www/auris/envauris/lib/python3.13/site-packages/sqlalchemy/engine/events.pyr(   ConnectionEvents._accept_with   sA     !7/C#-)
 )
 **,    Fretvalc               0  ^	 UR                   UR                  UR                  penSUl        U(       d"  US:X  a  Um	U	4S jnUnO4US:X  a
  Um	U	4S jnUnO#U(       a  US;  a  [        R
                  " S5      eUR                  U5      R                  5         g )NTbefore_executec                $   > T" U UUUU5        XU4$ N )connclauseelementmultiparamsparamsexecution_optionsorig_fns        r/   wrap_before_execute5ConnectionEvents._listen.<locals>.wrap_before_execute   s)     %#) )v==r1   before_cursor_executec                $   > T" U UUUUU5        X#4$ r7   r8   )r9   cursor	statement
parameterscontextexecutemanyr>   s         r/   wrap_before_cursor_execute<ConnectionEvents._listen.<locals>.wrap_before_cursor_execute   s*     !"# %00r1   )r5   rA   zOnly the 'before_execute', 'before_cursor_execute' and 'handle_error' engine event listeners accept the 'retval=True' argument.)dispatch_targetr,   
_listen_fn_has_eventsr   ArgumentErrorwith_wrapperbase_listen)
r*   	event_keyr3   kwr+   r,   fnr?   rH   r>   s
            @r/   _listenConnectionEvents._listen   s     %%     
 "--
> )661 0
 +
 
 ##  	r"..0r1   z1.4)r9   r:   r;   r<   c                    U UUU4$ r7   r8   )r9   r:   r;   r<   r=   s        r/   <lambda>ConnectionEvents.<lambda>   s    	M
r1   r9   c                    g)a  Intercept high level execute() events, receiving uncompiled
SQL constructs and other objects prior to rendering into SQL.

This event is good for debugging SQL compilation issues as well
as early manipulation of the parameters being sent to the database,
as the parameter lists will be in a consistent format here.

This event can be optionally established with the ``retval=True``
flag.  The ``clauseelement``, ``multiparams``, and ``params``
arguments should be returned as a three-tuple in this case::

    @event.listens_for(Engine, "before_execute", retval=True)
    def before_execute(conn, clauseelement, multiparams, params):
        # do something with clauseelement, multiparams, params
        return clauseelement, multiparams, params

:param conn: :class:`_engine.Connection` object
:param clauseelement: SQL expression construct, :class:`.Compiled`
 instance, or string statement passed to
 :meth:`_engine.Connection.execute`.
:param multiparams: Multiple parameter sets, a list of dictionaries.
:param params: Single parameter set, a single dictionary.
:param execution_options: dictionary of execution
 options passed along with the statement, if any.  This is a merge
 of all options that will be used, including those of the statement,
 the connection, and those passed in to the method itself for
 the 2.0 style of execution.

 .. versionadded: 1.4

.. seealso::

    :meth:`.before_cursor_execute`

Nr8   )selfr9   r:   r;   r<   r=   s         r/   r5   ConnectionEvents.before_execute       r1   )r9   r:   r;   r<   resultc                    U UUUU4$ r7   r8   )r9   r:   r;   r<   r=   r\   s         r/   rV   rW   	  s    U
r1   c                    g)a  Intercept high level execute() events after execute.


:param conn: :class:`_engine.Connection` object
:param clauseelement: SQL expression construct, :class:`.Compiled`
 instance, or string statement passed to
 :meth:`_engine.Connection.execute`.
:param multiparams: Multiple parameter sets, a list of dictionaries.
:param params: Single parameter set, a single dictionary.
:param execution_options: dictionary of execution
 options passed along with the statement, if any.  This is a merge
 of all options that will be used, including those of the statement,
 the connection, and those passed in to the method itself for
 the 2.0 style of execution.

 .. versionadded: 1.4

:param result: :class:`_engine.CursorResult` generated by the
 execution.

Nr8   )rY   r9   r:   r;   r<   r=   r\   s          r/   after_executeConnectionEvents.after_execute  r[   r1   c                    g)a  Intercept low-level cursor execute() events before execution,
receiving the string SQL statement and DBAPI-specific parameter list to
be invoked against a cursor.

This event is a good choice for logging as well as late modifications
to the SQL string.  It's less ideal for parameter modifications except
for those which are specific to a target backend.

This event can be optionally established with the ``retval=True``
flag.  The ``statement`` and ``parameters`` arguments should be
returned as a two-tuple in this case::

    @event.listens_for(Engine, "before_cursor_execute", retval=True)
    def before_cursor_execute(
        conn, cursor, statement, parameters, context, executemany
    ):
        # do something with statement, parameters
        return statement, parameters

See the example at :class:`_events.ConnectionEvents`.

:param conn: :class:`_engine.Connection` object
:param cursor: DBAPI cursor object
:param statement: string SQL statement, as to be passed to the DBAPI
:param parameters: Dictionary, tuple, or list of parameters being
 passed to the ``execute()`` or ``executemany()`` method of the
 DBAPI ``cursor``.  In some cases may be ``None``.
:param context: :class:`.ExecutionContext` object in use.  May
 be ``None``.
:param executemany: boolean, if ``True``, this is an ``executemany()``
 call, if ``False``, this is an ``execute()`` call.

.. seealso::

    :meth:`.before_execute`

    :meth:`.after_cursor_execute`

Nr8   rY   r9   rC   rD   rE   rF   rG   s          r/   rA   &ConnectionEvents.before_cursor_execute0  r[   r1   c                    g)a  Intercept low-level cursor execute() events after execution.

:param conn: :class:`_engine.Connection` object
:param cursor: DBAPI cursor object.  Will have results pending
 if the statement was a SELECT, but these should not be consumed
 as they will be needed by the :class:`_engine.CursorResult`.
:param statement: string SQL statement, as passed to the DBAPI
:param parameters: Dictionary, tuple, or list of parameters being
 passed to the ``execute()`` or ``executemany()`` method of the
 DBAPI ``cursor``.  In some cases may be ``None``.
:param context: :class:`.ExecutionContext` object in use.  May
 be ``None``.
:param executemany: boolean, if ``True``, this is an ``executemany()``
 call, if ``False``, this is an ``execute()`` call.

Nr8   rb   s          r/   after_cursor_execute%ConnectionEvents.after_cursor_executea  r[   r1   z2.0branchc                
    U S4$ )NFr8   )r9   s    r/   rV   rW   |  s    4-r1   )	converterc                    g)a  Intercept the creation of a new :class:`_engine.Connection`.

This event is called typically as the direct result of calling
the :meth:`_engine.Engine.connect` method.

It differs from the :meth:`_events.PoolEvents.connect` method, which
refers to the actual connection to a database at the DBAPI level;
a DBAPI connection may be pooled and reused for many operations.
In contrast, this event refers only to the production of a higher level
:class:`_engine.Connection` wrapper around such a DBAPI connection.

It also differs from the :meth:`_events.PoolEvents.checkout` event
in that it is specific to the :class:`_engine.Connection` object,
not the
DBAPI connection that :meth:`_events.PoolEvents.checkout` deals with,
although
this DBAPI connection is available here via the
:attr:`_engine.Connection.connection` attribute.
But note there can in fact
be multiple :meth:`_events.PoolEvents.checkout`
events within the lifespan
of a single :class:`_engine.Connection` object, if that
:class:`_engine.Connection`
is invalidated and re-established.

:param conn: :class:`_engine.Connection` object.

.. seealso::

    :meth:`_events.PoolEvents.checkout`
    the lower-level pool checkout event
    for an individual DBAPI connection

Nr8   rY   r9   s     r/   engine_connectConnectionEvents.engine_connect{  r[   r1   c                    g)a8  Intercept when the :meth:`_engine.Connection.execution_options`
method is called.

This method is called after the new :class:`_engine.Connection`
has been
produced, with the newly updated execution options collection, but
before the :class:`.Dialect` has acted upon any of those new options.

Note that this method is not called when a new
:class:`_engine.Connection`
is produced which is inheriting execution options from its parent
:class:`_engine.Engine`; to intercept this condition, use the
:meth:`_events.ConnectionEvents.engine_connect` event.

:param conn: The newly copied :class:`_engine.Connection` object

:param opts: dictionary of options that were passed to the
 :meth:`_engine.Connection.execution_options` method.
 This dictionary may be modified in place to affect the ultimate
 options which take effect.

 .. versionadded:: 2.0 the ``opts`` dictionary may be modified
    in place.


.. seealso::

    :meth:`_events.ConnectionEvents.set_engine_execution_options`
    - event
    which is called when :meth:`_engine.Engine.execution_options`
    is called.


Nr8   )rY   r9   optss      r/    set_connection_execution_options1ConnectionEvents.set_connection_execution_options  r[   r1   c                    g)a  Intercept when the :meth:`_engine.Engine.execution_options`
method is called.

The :meth:`_engine.Engine.execution_options` method produces a shallow
copy of the :class:`_engine.Engine` which stores the new options.
That new
:class:`_engine.Engine` is passed here.
A particular application of this
method is to add a :meth:`_events.ConnectionEvents.engine_connect`
event
handler to the given :class:`_engine.Engine`
which will perform some per-
:class:`_engine.Connection` task specific to these execution options.

:param conn: The newly copied :class:`_engine.Engine` object

:param opts: dictionary of options that were passed to the
 :meth:`_engine.Connection.execution_options` method.
 This dictionary may be modified in place to affect the ultimate
 options which take effect.

 .. versionadded:: 2.0 the ``opts`` dictionary may be modified
    in place.

.. seealso::

    :meth:`_events.ConnectionEvents.set_connection_execution_options`
    - event
    which is called when :meth:`_engine.Connection.execution_options`
    is
    called.

Nr8   )rY   enginero   s      r/   set_engine_execution_options-ConnectionEvents.set_engine_execution_options  r[   r1   c                    g)a  Intercept when the :meth:`_engine.Engine.dispose` method is called.

The :meth:`_engine.Engine.dispose` method instructs the engine to
"dispose" of it's connection pool (e.g. :class:`_pool.Pool`), and
replaces it with a new one.  Disposing of the old pool has the
effect that existing checked-in connections are closed.  The new
pool does not establish any new connections until it is first used.

This event can be used to indicate that resources related to the
:class:`_engine.Engine` should also be cleaned up,
keeping in mind that the
:class:`_engine.Engine`
can still be used for new requests in which case
it re-acquires connection resources.

Nr8   )rY   rs   s     r/   engine_disposed ConnectionEvents.engine_disposed  r[   r1   c                    g)zLIntercept begin() events.

:param conn: :class:`_engine.Connection` object

Nr8   rk   s     r/   beginConnectionEvents.begin  r[   r1   c                    g)a  Intercept rollback() events, as initiated by a
:class:`.Transaction`.

Note that the :class:`_pool.Pool` also "auto-rolls back"
a DBAPI connection upon checkin, if the ``reset_on_return``
flag is set to its default value of ``'rollback'``.
To intercept this
rollback, use the :meth:`_events.PoolEvents.reset` hook.

:param conn: :class:`_engine.Connection` object

.. seealso::

    :meth:`_events.PoolEvents.reset`

Nr8   rk   s     r/   rollbackConnectionEvents.rollback  r[   r1   c                    g)a\  Intercept commit() events, as initiated by a
:class:`.Transaction`.

Note that the :class:`_pool.Pool` may also "auto-commit"
a DBAPI connection upon checkin, if the ``reset_on_return``
flag is set to the value ``'commit'``.  To intercept this
commit, use the :meth:`_events.PoolEvents.reset` hook.

:param conn: :class:`_engine.Connection` object
Nr8   rk   s     r/   commitConnectionEvents.commit  r[   r1   c                    g)zIntercept savepoint() events.

:param conn: :class:`_engine.Connection` object
:param name: specified name used for the savepoint.

Nr8   )rY   r9   names      r/   	savepointConnectionEvents.savepoint$  r[   r1   c                    g)zIntercept rollback_savepoint() events.

:param conn: :class:`_engine.Connection` object
:param name: specified name used for the savepoint.
:param context: not used

Nr8   rY   r9   r   rF   s       r/   rollback_savepoint#ConnectionEvents.rollback_savepoint,  r[   r1   c                    g)zIntercept release_savepoint() events.

:param conn: :class:`_engine.Connection` object
:param name: specified name used for the savepoint.
:param context: not used

Nr8   r   s       r/   release_savepoint"ConnectionEvents.release_savepoint8  r[   r1   c                    g)zzIntercept begin_twophase() events.

:param conn: :class:`_engine.Connection` object
:param xid: two-phase XID identifier

Nr8   rY   r9   xids      r/   begin_twophaseConnectionEvents.begin_twophaseD  r[   r1   c                    g)z{Intercept prepare_twophase() events.

:param conn: :class:`_engine.Connection` object
:param xid: two-phase XID identifier
Nr8   r   s      r/   prepare_twophase!ConnectionEvents.prepare_twophaseL  r[   r1   c                    g)zIntercept rollback_twophase() events.

:param conn: :class:`_engine.Connection` object
:param xid: two-phase XID identifier
:param is_prepared: boolean, indicates if
 :meth:`.TwoPhaseTransaction.prepare` was called.

Nr8   rY   r9   r   is_prepareds       r/   rollback_twophase"ConnectionEvents.rollback_twophaseS  r[   r1   c                    g)zIntercept commit_twophase() events.

:param conn: :class:`_engine.Connection` object
:param xid: two-phase XID identifier
:param is_prepared: boolean, indicates if
 :meth:`.TwoPhaseTransaction.prepare` was called.

Nr8   r   s       r/   commit_twophase ConnectionEvents.commit_twophase_  r[   r1   r8   )r+   z;Union[ConnectionEventsTarget, Type[ConnectionEventsTarget]]r,   strreturnzEOptional[Union[ConnectionEventsTarget, Type[ConnectionEventsTarget]]])rP   z'event._EventKey[ConnectionEventsTarget]r3   boolrQ   r   r   None)r9   r   r:   r   r;   r   r<   r   r=   r   r   zNOptional[Tuple[Executable, _CoreMultiExecuteParams, _CoreSingleExecuteParams]])r9   r   r:   r   r;   r   r<   r   r=   r   r\   zResult[Any]r   r   )r9   r   rC   r   rD   r   rE   r   rF   Optional[ExecutionContext]rG   r   r   z,Optional[Tuple[str, _DBAPIAnyExecuteParams]])r9   r   rC   r   rD   r   rE   r   rF   r   rG   r   r   r   )r9   r   r   r   )r9   r   ro   Dict[str, Any]r   r   )rs   r   ro   r   r   r   )rs   r   r   r   )r9   r   r   r   r   r   )r9   r   r   r   rF   r   r   r   )r9   r   r   r   r   r   )r9   r   r   r   r   r   r   r   )!__name__
__module____qualname____firstlineno____doc___target_class_docr   _dispatch_targetclassmethodr(   rS   r   _legacy_signaturer5   r_   rA   re   rl   rp   rt   rw   rz   r}   r   r   r   r   r   r   r   r   __static_attributes____classcell__)r.   s   @r/   r"   r"   ,   s   Qf %- K    
O	    
 	:1::1 	:1
 :1 
:1 :1x :	
	,, ", -	,
 ), +,
,	,\ D	

 " -	
 ) +  

>// / 	/
 +/ ,/ / 
6/b  	
 + ,  
4 !-G""H$$&4$	$L##$2#	#J$$
		&)	48					&)	48			

%(
7;
	


%(
7;
	
 
r1   r"   c                     \ rS rSrSrSr\r\SS.       SS jj5       r	\      SS j5       r
    SS jr          SS	 jr          SS
 jr        SS jr          SS jr            SS jrSrg)DialectEventsil  a  event interface for execution-replacement functions.

These events allow direct instrumentation and replacement
of key dialect functions which interact with the DBAPI.

.. note::

    :class:`.DialectEvents` hooks should be considered **semi-public**
    and experimental.
    These hooks are not for general use and are only for those situations
    where intricate re-statement of DBAPI mechanics must be injected onto
    an existing dialect.  For general-use statement-interception events,
    please use the :class:`_events.ConnectionEvents` interface.

.. seealso::

    :meth:`_events.ConnectionEvents.before_cursor_execute`

    :meth:`_events.ConnectionEvents.before_execute`

    :meth:`_events.ConnectionEvents.after_cursor_execute`

    :meth:`_events.ConnectionEvents.after_execute`

r$   Fr2   c               J    UR                   nSUl        UR                  5         g )NT)rJ   rL   rO   )r*   rP   r3   rQ   r+   s        r/   rS   DialectEvents._listen  s#     **!r1   c                   [        U[        5      (       a3  [        U[        5      (       a  [        $ [        U[        5      (       a  U$ g [        U[        5      (       a  UR
                  $ [        U[        5      (       a  U$ [        U[        5      (       a  US:X  a  [        R                  " S5      e[        US5      (       a  UR                  5         g g )Nhandle_errorzThe handle_error() event hook as of SQLAlchemy 2.0 is established on the Dialect, and may only be applied to the Engine as a whole or to a specific Dialect as a whole, not on a per-Connection basis.r&   )
isinstancetype
issubclassr   r   dialectr   r   InvalidRequestErrorr)   r&   )r*   r+   r,   s      r/   r(   DialectEvents._accept_with  s     fd##&&))FG,, -''>>!((M
++
n0L))1  V677**,r1   c                    g)a  Intercept all exceptions processed by the
:class:`_engine.Dialect`, typically but not limited to those
emitted within the scope of a :class:`_engine.Connection`.

.. versionchanged:: 2.0 the :meth:`.DialectEvents.handle_error` event
   is moved to the :class:`.DialectEvents` class, moved from the
   :class:`.ConnectionEvents` class, so that it may also participate in
   the "pre ping" operation configured with the
   :paramref:`_sa.create_engine.pool_pre_ping` parameter. The event
   remains registered by using the :class:`_engine.Engine` as the event
   target, however note that using the :class:`_engine.Connection` as
   an event target for :meth:`.DialectEvents.handle_error` is no longer
   supported.

This includes all exceptions emitted by the DBAPI as well as
within SQLAlchemy's statement invocation process, including
encoding errors and other statement validation errors.  Other areas
in which the event is invoked include transaction begin and end,
result row fetching, cursor creation.

Note that :meth:`.handle_error` may support new kinds of exceptions
and new calling scenarios at *any time*.  Code which uses this
event must expect new calling patterns to be present in minor
releases.

To support the wide variety of members that correspond to an exception,
as well as to allow extensibility of the event without backwards
incompatibility, the sole argument received is an instance of
:class:`.ExceptionContext`.   This object contains data members
representing detail about the exception.

Use cases supported by this hook include:

* read-only, low-level exception handling for logging and
  debugging purposes
* Establishing whether a DBAPI connection error message indicates
  that the database connection needs to be reconnected, including
  for the "pre_ping" handler used by **some** dialects
* Establishing or disabling whether a connection or the owning
  connection pool is invalidated or expired in response to a
  specific exception
* exception re-writing

The hook is called while the cursor from the failed operation
(if any) is still open and accessible.   Special cleanup operations
can be called on this cursor; SQLAlchemy will attempt to close
this cursor subsequent to this hook being invoked.

As of SQLAlchemy 2.0, the "pre_ping" handler enabled using the
:paramref:`_sa.create_engine.pool_pre_ping` parameter will also
participate in the :meth:`.handle_error` process, **for those dialects
that rely upon disconnect codes to detect database liveness**. Note
that some dialects such as psycopg, psycopg2, and most MySQL dialects
make use of a native ``ping()`` method supplied by the DBAPI which does
not make use of disconnect codes.

.. versionchanged:: 2.0.0 The :meth:`.DialectEvents.handle_error`
   event hook participates in connection pool "pre-ping" operations.
   Within this usage, the :attr:`.ExceptionContext.engine` attribute
   will be ``None``, however the :class:`.Dialect` in use is always
   available via the :attr:`.ExceptionContext.dialect` attribute.

.. versionchanged:: 2.0.5 Added :attr:`.ExceptionContext.is_pre_ping`
   attribute which will be set to ``True`` when the
   :meth:`.DialectEvents.handle_error` event hook is triggered within
   a connection pool pre-ping operation.

.. versionchanged:: 2.0.5 An issue was repaired that allows for the
   PostgreSQL ``psycopg`` and ``psycopg2`` drivers, as well as all
   MySQL drivers, to properly participate in the
   :meth:`.DialectEvents.handle_error` event hook during
   connection pool "pre-ping" operations; previously, the
   implementation was non-working for these drivers.


A handler function has two options for replacing
the SQLAlchemy-constructed exception into one that is user
defined.   It can either raise this new exception directly, in
which case all further event listeners are bypassed and the
exception will be raised, after appropriate cleanup as taken
place::

    @event.listens_for(Engine, "handle_error")
    def handle_exception(context):
        if isinstance(
            context.original_exception, psycopg2.OperationalError
        ) and "failed" in str(context.original_exception):
            raise MySpecialException("failed operation")

.. warning::  Because the
   :meth:`_events.DialectEvents.handle_error`
   event specifically provides for exceptions to be re-thrown as
   the ultimate exception raised by the failed statement,
   **stack traces will be misleading** if the user-defined event
   handler itself fails and throws an unexpected exception;
   the stack trace may not illustrate the actual code line that
   failed!  It is advised to code carefully here and use
   logging and/or inline debugging if unexpected exceptions are
   occurring.

Alternatively, a "chained" style of event handling can be
used, by configuring the handler with the ``retval=True``
modifier and returning the new exception instance from the
function.  In this case, event handling will continue onto the
next handler.   The "chained" exception is available using
:attr:`.ExceptionContext.chained_exception`::

    @event.listens_for(Engine, "handle_error", retval=True)
    def handle_exception(context):
        if (
            context.chained_exception is not None
            and "special" in context.chained_exception.message
        ):
            return MySpecialException(
                "failed", cause=context.chained_exception
            )

Handlers that return ``None`` may be used within the chain; when
a handler returns ``None``, the previous exception instance,
if any, is maintained as the current exception that is passed onto the
next handler.

When a custom exception is raised or returned, SQLAlchemy raises
this new exception as-is, it is not wrapped by any SQLAlchemy
object.  If the exception is not a subclass of
:class:`sqlalchemy.exc.StatementError`,
certain features may not be available; currently this includes
the ORM's feature of adding a detail hint about "autoflush" to
exceptions raised within the autoflush process.

:param context: an :class:`.ExceptionContext` object.  See this
 class for details on all available members.


.. seealso::

    :ref:`pool_new_disconnect_codes`

Nr8   )rY   exception_contexts     r/   r   DialectEvents.handle_error  r[   r1   c                    g)a  Receive connection arguments before a connection is made.

This event is useful in that it allows the handler to manipulate the
cargs and/or cparams collections that control how the DBAPI
``connect()`` function will be called. ``cargs`` will always be a
Python list that can be mutated in-place, and ``cparams`` a Python
dictionary that may also be mutated::

    e = create_engine("postgresql+psycopg2://user@host/dbname")


    @event.listens_for(e, "do_connect")
    def receive_do_connect(dialect, conn_rec, cargs, cparams):
        cparams["password"] = "some_password"

The event hook may also be used to override the call to ``connect()``
entirely, by returning a non-``None`` DBAPI connection object::

    e = create_engine("postgresql+psycopg2://user@host/dbname")


    @event.listens_for(e, "do_connect")
    def receive_do_connect(dialect, conn_rec, cargs, cparams):
        return psycopg2.connect(*cargs, **cparams)

.. seealso::

    :ref:`custom_dbapi_args`

Nr8   )rY   r   conn_reccargscparamss        r/   
do_connectDialectEvents.do_connectA  r[   r1   c                    g)zReceive a cursor to have executemany() called.

Return the value True to halt further events from invoking,
and to indicate that the cursor execution has already taken
place within the event handler.

Nr8   rY   rC   rD   rE   rF   s        r/   do_executemanyDialectEvents.do_executemanyg  r[   r1   c                    g)zReceive a cursor to have execute() with no parameters called.

Return the value True to halt further events from invoking,
and to indicate that the cursor execution has already taken
place within the event handler.

Nr8   )rY   rC   rD   rF   s       r/   do_execute_no_params"DialectEvents.do_execute_no_paramsv  r[   r1   c                    g)zReceive a cursor to have execute() called.

Return the value True to halt further events from invoking,
and to indicate that the cursor execution has already taken
place within the event handler.

Nr8   r   s        r/   
do_executeDialectEvents.do_execute  r[   r1   c                    g)a  Receive the setinputsizes dictionary for possible modification.

This event is emitted in the case where the dialect makes use of the
DBAPI ``cursor.setinputsizes()`` method which passes information about
parameter binding for a particular statement.   The given
``inputsizes`` dictionary will contain :class:`.BindParameter` objects
as keys, linked to DBAPI-specific type objects as values; for
parameters that are not bound, they are added to the dictionary with
``None`` as the value, which means the parameter will not be included
in the ultimate setinputsizes call.   The event may be used to inspect
and/or log the datatypes that are being bound, as well as to modify the
dictionary in place.  Parameters can be added, modified, or removed
from this dictionary.   Callers will typically want to inspect the
:attr:`.BindParameter.type` attribute of the given bind objects in
order to make decisions about the DBAPI object.

After the event, the ``inputsizes`` dictionary is converted into
an appropriate datastructure to be passed to ``cursor.setinputsizes``;
either a list for a positional bound parameter execution style,
or a dictionary of string parameter keys to DBAPI type objects for
a named bound parameter execution style.

The setinputsizes hook overall is only used for dialects which include
the flag ``use_setinputsizes=True``.  Dialects which use this
include python-oracledb, cx_Oracle, pg8000, asyncpg, and pyodbc
dialects.

.. note::

    For use with pyodbc, the ``use_setinputsizes`` flag
    must be passed to the dialect, e.g.::

        create_engine("mssql+pyodbc://...", use_setinputsizes=True)

    .. seealso::

          :ref:`mssql_pyodbc_setinputsizes`

.. versionadded:: 1.2.9

.. seealso::

    :ref:`cx_oracle_setinputsizes`

Nr8   )rY   
inputsizesrC   rD   rE   rF   s         r/   do_setinputsizesDialectEvents.do_setinputsizes  s    j 	r1   r8   N)rP   zevent._EventKey[Dialect]r3   r   rQ   r   r   r   )r+   z3Union[Engine, Type[Engine], Dialect, Type[Dialect]]r,   r   r   z'Optional[Union[Dialect, Type[Dialect]]])r   r   r   zOptional[BaseException])
r   r   r   r   r   zTuple[Any, ...]r   r   r   zOptional[DBAPIConnection])
rC   r   rD   r   rE   r   rF   r   r   Optional[Literal[True]])rC   r   rD   r   rF   r   r   r   )
rC   r   rD   r   rE   r   rF   r   r   r   )r   zDict[BindParameter[Any], Any]rC   r   rD   r   rE   r   rF   r   r   r   )r   r   r   r   r   r   r   r   r   rS   r(   r   r   r   r   r   r   r   r8   r1   r/   r   r   l  s   4 %
 	
 +
  	
 
 
  

  
  C  
1	 4M!1M	 M^$$ &$ 	$
  $ 
#$L  -	
 " 
!	!	.1	<L		 	  .	
 " 
!515 5 	5
 +5 "5 
5r1   r   )*
__future__r   typingr   r   r   r   r   r	   baser   r   
interfacesr   r   r   r    r   r   util.typingr   TYPE_CHECKINGr   r   r   r   r   r   r   r   r\   r   poolr   sqlr   sql.elementsr    Eventsr"   r   r8   r1   r/   <module>r      s    #          . ' #    !	34245+,,* ,}u||$:; }@YELL) Yr1   