OwlCyberSecurity - MANAGER
Edit File: events.cpython-312.pyc
� ̓�g� � �� � 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, rHd 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!ejN e � Z( G d"� d#ejN e � Z)y)$� )�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 �Z � � e Zd ZdZdZeZe d#� fd�� Zedd� d$d�� Z e j dg d�d � � d%d�� Z e j dg d�d � � d&d�� Z d'd�Z d(d�Z e j dd dgd� �� d)d�� Z d*d�Z d+d�Zd,d�Zd)d�Zd)d�Zd)d�Zd-d�Z d.d�Z d.d�Zd/d�Zd/d �Z d0d!�Z d0d"�Z� xZS )1�ConnectionEventsa 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 �d �� t �| � ||� }|�t |d� r|j � |S )N�_no_async_engine_events)�super�_accept_with�hasattrr% )�cls�target� identifier�default_dispatch� __class__s ��I/opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/engine/events.pyr'