관리-도구
편집 파일: events.cpython-38.pyc
U -?�f� � @ s� d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d l m Z d dl mZ d dlm Z d d lmZ d dlmZ d dlmZ ddlmZ ddlmZ ddlmZ ej�r`d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm Z ddl!m"Z" ddl#m$Z$ ddl%m&Z& G d d!� d!ej'e �Z(G d"d#� d#ej'e �Z)dS )$� )�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 s e Zd ZdZdZeZedddd�� fdd��Zed d �ddd dd�dd��Z e �dddddgdd� �ddddddd�d d!��Ze �dddddd"gd#d� �dddddd$dd%�d&d'��Z dd(dd)d*dd+d,�d-d.�Zdd(dd)d*ddd,�d/d0�Ze jd1dd2gd3d� d4�ddd5�d6d7��Zdd8dd9�d:d;�Zd<d8dd=�d>d?�Zd<dd@�dAdB�Zddd5�dCdD�Zddd5�dEdF�Zddd5�dGdH�ZddddI�dJdK�ZdddddL�dMdN�ZdddddL�dOdP�Zdd ddQ�dRdS�Zdd ddQ�dTdU�Zdd dddV�dWdX�Zdd dddV�dYdZ�Z� ZS )[�ConnectionEventsaH 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. � SomeEnginez;Union[ConnectionEventsTarget, Type[ConnectionEventsTarget]]�strzEOptional[Union[ConnectionEventsTarget, Type[ConnectionEventsTarget]]]��target� identifier�returnc s, t � �||�}|d kr(t|d�r(|�� |S )N�_no_async_engine_events)�super�_accept_with�hasattrr'