B 4]1@s@dZddlmZddlmZGdddeZGdddeZdS) 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@s<eZdZdZeddZddZddZdd Zd d Z d S) PoolListenera Hooks into the lifecycle of connections in a :class:`.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:`.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. cCsddddg}tj||d}xH|D]@}tt|}t||d}|dk r t||s td||fq Wt|dr~t|d|j t|drt|d|j t|drt|d|j t|drt|d|j dS)z^Adapt a :class:`.PoolListener` to individual :class:`event.Dispatch` events. connect first_connectcheckoutcheckin)methodsNzPoolListener.%s is deprecated. The PoolListener class will be removed in a future release. Please transition to the @event interface, using @event.listens_for(Engine, '%s').) rZ as_interfacegetattrrmethods_equivalentwarn_deprecatedhasattrrlistenrrrr)clsselflistenerr methme_methls_methrH/opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/interfaces.py_adapt_listenerRs$         zPoolListener._adapt_listenercCsdS)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)r dbapi_con con_recordrrrrss zPoolListener.connectcCsdS)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 Nr)rrrrrrrs zPoolListener.first_connectcCsdS)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)rrrZ con_proxyrrrrszPoolListener.checkoutcCsdS)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 Nr)rrrrrrrs zPoolListener.checkinN) __name__ __module__ __qualname____doc__ classmethodrrrrrrrrrrs 8 !  rc@s~eZdZdZeddZddZddZdd Zd d Z d d Z dddZ ddZ ddZ ddZddZddZddZdS)ConnectionProxya7Allows 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:`.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 spddddddddd d d d g }x>|D]6}tt|}t|}t||s"td ||fq"Wfdd}t|d|fdd}t|d|ddfdd} t|d| jt|d| jt|d| j t|d| j t|d| j t|d| j t|d | j t|d | jt|d | jt|d | jdS)Nexecutecursor_executebeginrollbackcommit savepointrollback_savepointrelease_savepointbegin_twophaseprepare_twophaserollback_twophasecommit_twophasezConnectionProxy.%s is deprecated. The ConnectionProxy class will be removed in a future release. Please transition to the @event interface, using @event.listens_for(Engine, '%s').csdd}j|||f||S)Nc_s |||fS)Nr) clauseelement multiparamsparamsrrrexecute_wrapperszOConnectionProxy._adapt_listener..adapt_execute..execute_wrapper)r )connr,r-r.r/)rrr adapt_executesz6ConnectionProxy._adapt_listener..adapt_executeZbefore_executecsdd}||||||S)NcSs||fS)Nr)cursor statement parameterscontextrrrr/szVConnectionProxy._adapt_listener..adapt_cursor_execute..execute_wrapper)r!)r0r2r3r4r5 executemanyr/)rrradapt_cursor_executesz=ConnectionProxy._adapt_listener..adapt_cursor_executeZbefore_cursor_executec_sdS)Nr)argkwrrrdo_nothing_callback sz.do_nothing_callbackcsfdd}t|S)Ncs|f||dS)Nr)r0r8r9)r:fnrrgo szCConnectionProxy._adapt_listener..adapt_listener..go)rupdate_wrapper)r;r<)r:)r;radapt_listener sz7ConnectionProxy._adapt_listener..adapt_listener)r rrr r rrr"r#r$r%r&r'r(r)r*r+) rrrr rrrr1r7r>r)r:rrrs^          zConnectionProxy._adapt_listenercOs||f||S)z&Intercept high level execute() events.r)rr0r r,r-r.rrrr /szConnectionProxy.executecCs|||||S)z,Intercept low-level cursor execute() events.r)rr r2r3r4r5r6rrrr!4szConnectionProxy.cursor_executecCs|S)zIntercept begin() events.r)rr0r"rrrr";szConnectionProxy.begincCs|S)zIntercept rollback() events.r)rr0r#rrrr#@szConnectionProxy.rollbackcCs|S)zIntercept commit() events.r)rr0r$rrrr$EszConnectionProxy.commitNcCs ||dS)zIntercept savepoint() events.)namer)rr0r%r?rrrr%JszConnectionProxy.savepointcCs |||S)z&Intercept rollback_savepoint() events.r)rr0r&r?r5rrrr&Osz"ConnectionProxy.rollback_savepointcCs |||S)z%Intercept release_savepoint() events.r)rr0r'r?r5rrrr'Tsz!ConnectionProxy.release_savepointcCs||S)z"Intercept begin_twophase() events.r)rr0r(xidrrrr(YszConnectionProxy.begin_twophasecCs||S)z$Intercept prepare_twophase() events.r)rr0r)r@rrrr)^sz ConnectionProxy.prepare_twophasecCs |||S)z%Intercept rollback_twophase() events.r)rr0r*r@ is_preparedrrrr*csz!ConnectionProxy.rollback_twophasecCs |||S)z#Intercept commit_twophase() events.r)rr0r+r@rArrrr+hszConnectionProxy.commit_twophase)N)rrrrrrr r!r"r#r$r%r&r'r(r)r*r+rrrrrs! ^ rN)rrrobjectrrrrrrs