Uh<ZdZddlmZddlmZGddeZGddeZdS) aDeprecated core event interfaces. .. deprecated:: 0.7 As of SQLAlchemy 0.7, the new event system described in :ref:`event_toplevel` replaces the extension/proxy/listener system, providing a consistent interface to all events without the need for subclassing. )event)utilc@eZdZdZedZdZdZdZdZ dS) PoolListenera Hooks into the lifecycle of connections in a :class:`_pool.Pool`. .. deprecated:: 0.7 :class:`.PoolListener` is deprecated and will be removed in a future release. Please refer to :func:`.event.listen` in conjunction with the :class:`_events.PoolEvents` listener interface. Usage:: class MyListener(PoolListener): def connect(self, dbapi_con, con_record): '''perform connect operations''' # etc. # create a new pool with a listener p = QueuePool(..., listeners=[MyListener()]) # add a listener after the fact p.add_listener(MyListener()) # usage with create_engine() e = create_engine("url://", listeners=[MyListener()]) All of the standard connection :class:`~sqlalchemy.pool.Pool` types can accept event listeners for key connection lifecycle events: creation, pool check-out and check-in. There are no events fired when a connection closes. For any given DB-API connection, there will be one ``connect`` event, `n` number of ``checkout`` events, and either `n` or `n - 1` ``checkin`` events. (If a ``Connection`` is detached from its pool via the ``detach()`` method, it won't be checked back in.) These are low-level events for low-level objects: raw Python DB-API connections, without the conveniences of the SQLAlchemy ``Connection`` wrapper, ``Dialect`` services or ``ClauseElement`` execution. If you execute SQL through the connection, explicitly closing all cursors and other resources is recommended. Events also receive a ``_ConnectionRecord``, a long-lived internal ``Pool`` object that basically represents a "slot" in the connection pool. ``_ConnectionRecord`` objects have one public attribute of note: ``info``, a dictionary whose contents are scoped to the lifetime of the DB-API connection managed by the record. You can use this shared storage area however you like. There is no need to subclass ``PoolListener`` to handle events. Any class that implements one or more of these methods can be used as a pool listener. The ``Pool`` will inspect the methods provided by a listener object and add the listener to one or more internal event queues based on its capabilities. In terms of efficiency and function call overhead, you're much better off only providing implementations for the hooks you'll be using. cPgd}tj||}|D]Z}tt|}t||d}|0tj||stjd|d|d[t |drtj|d|j t |drtj|d|j t |d rtj|d |j t |d rtj|d |j dSdS) z^Adapt a :class:`.PoolListener` to individual :class:`event.Dispatch` events. )connect first_connectcheckoutcheckin)methodsNz PoolListener.z is deprecated. The PoolListener class will be removed in a future release. Please transition to the @event interface, using @event.listens_for(Engine, '').rr r r ) r as_interfacegetattrrmethods_equivalentwarn_deprecatedhasattrrlistenrr r r )clsselflistenerr methme_methls_meths /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/sqlalchemy/interfaces.py_adapt_listenerzPoolListener._adapt_listenerRsZFEE$Xw???  DlD11Ghd33G"4+B,,"$$BFtttM 8Y ' ' < Ly(*: ; ; ; 8_ - - H L0F G G G 8Z ( ( > Lz8+< = = = 8Y ' ' < Ly(*: ; ; ; ; ; < <cdS)a(Called once for each new DB-API connection or Pool's ``creator()``. dbapi_con A newly connected raw DB-API connection (not a SQLAlchemy ``Connection`` wrapper). con_record The ``_ConnectionRecord`` that persistently manages the connection Nr dbapi_con con_records rrzPoolListener.connectsrcdS)aCalled exactly once for the first DB-API connection. dbapi_con A newly connected raw DB-API connection (not a SQLAlchemy ``Connection`` wrapper). con_record The ``_ConnectionRecord`` that persistently manages the connection Nrrs rr zPoolListener.first_connectr"rcdS)aCCalled when a connection is retrieved from the Pool. dbapi_con A raw DB-API connection con_record The ``_ConnectionRecord`` that persistently manages the connection con_proxy The ``_ConnectionFairy`` which manages the connection for the span of the current checkout. If you raise an ``exc.DisconnectionError``, the current connection will be disposed and a fresh connection retrieved. Processing of all checkout listeners will abort and restart using the new connection. Nr)rr r! con_proxys rr zPoolListener.checkoutr"rcdS)aCalled when a connection returns to the pool. Note that the connection may be closed, and may be None if the connection has been invalidated. ``checkin`` will not be called for detached connections. (They do not return to the pool.) dbapi_con A raw DB-API connection con_record The ``_ConnectionRecord`` that persistently manages the connection Nrrs rr zPoolListener.checkinr"rN) __name__ __module__ __qualname____doc__ classmethodrrr r r rrrrrsw77r<<[<@           &      rrcreZdZdZedZdZdZdZdZ dZ dd Z d Z d Z d Zd ZdZdZdS)ConnectionProxya>Allows interception of statement execution by Connections. .. deprecated:: 0.7 :class:`.ConnectionProxy` is deprecated and will be removed in a future release. Please refer to :func:`.event.listen` in conjunction with the :class:`_events.ConnectionEvents` listener interface. Either or both of the ``execute()`` and ``cursor_execute()`` may be implemented to intercept compiled statement and cursor level executions, e.g.:: class MyProxy(ConnectionProxy): def execute(self, conn, execute, clauseelement, *multiparams, **params): print "compiled statement:", clauseelement return execute(clauseelement, *multiparams, **params) def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): print "raw statement:", statement return execute(cursor, statement, parameters, context) The ``execute`` argument is a function that will fulfill the default execution behavior for the operation. The signature illustrated in the example should be used. The proxy is installed into an :class:`~sqlalchemy.engine.Engine` via the ``proxy`` argument:: e = create_engine('someurl://', proxy=MyProxy()) c gd}|D]W}tt|}t|}tj||stjd|d|dXfd}t j|d|fd}t j|d|d fd } t j|d | jt j|d | jt j|d | j t j|d| j t j|d| j t j|d| j t j|d| j t j|d| jt j|d| jt j|d| jdS)N) executecursor_executebeginrollbackcommit savepointrollback_savepointrelease_savepointbegin_twophaseprepare_twophaserollback_twophasecommit_twophasezConnectionProxy.z is deprecated. The ConnectionProxy class will be removed in a future release. Please transition to the @event interface, using @event.listens_for(Engine, 'r c0d}j|||g|Ri|S)Nc |||fSNr) clauseelement multiparamsparamss rexecute_wrapperzOConnectionProxy._adapt_listener..adapt_execute..execute_wrappers$k699r)r/)connr>r?r@rArs r adapt_executez6ConnectionProxy._adapt_listener..adapt_executesL : : :$8#o}7BFL rbefore_executec>d}||||||S)Nc ||fSr=r)cursor statement parameterscontexts rrAzVConnectionProxy._adapt_listener..adapt_cursor_execute..execute_wrappers  *,,r)r0)rBrGrHrIrJ executemanyrArs radapt_cursor_executez=ConnectionProxy._adapt_listener..adapt_cursor_executes> - - -**  rbefore_cursor_executecdSr=r)argkws rdo_nothing_callbackz.do_nothing_callback s Drc<fd}tj|S)Nc"|g|Ri|dSr=r)rBrOrPrQfns rgozCConnectionProxy._adapt_listener..adapt_listener..go s,4,9s999b99999r)rupdate_wrapper)rTrUrQs` radapt_listenerz7ConnectionProxy._adapt_listener..adapt_listener s7 : : : : : :&r2.. .rr1r2r3r4r5r6r7r8r9r:)rr-rrrrrr1r2r3r4r5r6r7r8r9r:) rrrr rrrrCrLrWrQs ` @rrzConnectionProxy._adapt_listeners      Dot44Gh--G*7G<< $$BFtttM       T+];;;       T24HIII    / / / / /  T7NN8>$B$BCCC T:~~h6G'H'HIII T8^^HO%D%DEEE T;x7I(J(JKKK  N86 7 7      N85 6 6    "NN83J$K$K     $nnX5N&O&O       N85 6 6    #^^H4L%M%M     rc||g|Ri|S)z&Intercept high level execute() events.r)rrBr/r>r?r@s rr/zConnectionProxy.execute/s$w}={===f===rc|||||S)z,Intercept low-level cursor execute() events.r)rr/rGrHrIrJrKs rr0zConnectionProxy.cursor_execute4s wvy*g>>>rc|S)zIntercept begin() events.r)rrBr1s rr1zConnectionProxy.begin;suwwrc|S)zIntercept rollback() events.r)rrBr2s rr2zConnectionProxy.rollback@sxzzrc|S)zIntercept commit() events.r)rrBr3s rr3zConnectionProxy.commitEsvxxrNc||S)zIntercept savepoint() events.)namer)rrBr4r^s rr4zConnectionProxy.savepointJsyd####rc|||S)z&Intercept rollback_savepoint() events.r)rrBr5r^rJs rr5z"ConnectionProxy.rollback_savepointOs"!$000rc|||S)z%Intercept release_savepoint() events.r)rrBr6r^rJs rr6z!ConnectionProxy.release_savepointTs! w///rc||S)z"Intercept begin_twophase() events.r)rrBr7xids rr7zConnectionProxy.begin_twophaseYs~c"""rc||S)z$Intercept prepare_twophase() events.r)rrBr8rbs rr8z ConnectionProxy.prepare_twophase^s $$$rc|||S)z%Intercept rollback_twophase() events.r)rrBr9rb is_prepareds rr9z!ConnectionProxy.rollback_twophasecs! k222rc|||S)z#Intercept commit_twophase() events.r)rrBr:rbres rr:zConnectionProxy.commit_twophasehssK000rr=)r'r(r)r*r+rr/r0r1r2r3r4r5r6r7r8r9r:rrrr-r-s  D[ [ [[ z>>> ???   $$$$ 111 000 ### %%% 333 11111rr-N)r*rrobjectrr-rrrris  S S S S S 6S S S l}1}1}1}1}1f}1}1}1}1}1r