Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/sqlalchemy/__pycache__/events.cpython-39.pyc
Ðазад
a _�h}� � @ s� d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m Z dd lmZ G d d� dej �ZG dd � d ej �ZG dd� dej �ZG dd� dej �ZdS )zCore event interfaces.� )�event)�exc)�util)�Connectable)�Dialect)�Engine)�Pool)�SchemaEventTargetc @ sX e Zd ZdZdZeZdd� Zdd� Zdd� Z d d � Z dd� Zd d� Zdd� Z dd� ZdS )� DDLEventsa� Define event listeners for schema objects, that is, :class:`.SchemaItem` and other :class:`.SchemaEventTarget` subclasses, including :class:`_schema.MetaData`, :class:`_schema.Table`, :class:`_schema.Column`. :class:`_schema.MetaData` and :class:`_schema.Table` support events specifically regarding when CREATE and DROP DDL is emitted to the database. Attachment events are also provided to customize behavior whenever a child schema element is associated with a parent, such as, when a :class:`_schema.Column` is associated with its :class:`_schema.Table`, when a :class:`_schema.ForeignKeyConstraint` is associated with a :class:`_schema.Table`, etc. Example using the ``after_create`` event:: from sqlalchemy import event from sqlalchemy import Table, Column, Metadata, Integer m = MetaData() some_table = Table('some_table', m, Column('data', Integer)) def after_create(target, connection, **kw): connection.execute("ALTER TABLE %s SET name=foo_%s" % (target.name, target.name)) event.listen(some_table, "after_create", after_create) DDL events integrate closely with the :class:`.DDL` class and the :class:`.DDLElement` hierarchy of DDL clause constructs, which are themselves appropriate as listener callables:: from sqlalchemy import DDL event.listen( some_table, "after_create", DDL("ALTER TABLE %(table)s SET name=foo_%(table)s") ) The methods here define the name of an event as well as the names of members that are passed to listener functions. For all :class:`.DDLEvent` events, the ``propagate=True`` keyword argument will ensure that a given event handler is propagated to copies of the object, which are made when using the :meth:`_schema.Table.tometadata` method:: from sqlalchemy import DDL event.listen( some_table, "after_create", DDL("ALTER TABLE %(table)s SET name=foo_%(table)s"), propagate=True ) new_table = some_table.tometadata(new_metadata) The above :class:`.DDL` object will also be associated with the :class:`_schema.Table` object represented by ``new_table``. .. seealso:: :ref:`event_toplevel` :class:`.DDLElement` :class:`.DDL` :ref:`schema_ddl_sequences` ZSomeSchemaClassOrObjectc K s dS )a� Called before CREATE statements are emitted. :param target: the :class:`_schema.MetaData` or :class:`_schema.Table` object which is the target of the event. :param connection: the :class:`_engine.Connection` where the CREATE statement or statements will be emitted. :param \**kw: additional keyword arguments relevant to the event. The contents of this dictionary may vary across releases, and include the list of tables being generated for a metadata-level event, the checkfirst flag, and other elements used by internal events. :func:`.event.listen` also accepts the ``propagate=True`` modifier for this event; when True, the listener function will be established for any copies made of the target object, i.e. those copies that are generated when :meth:`_schema.Table.tometadata` is used. N� ��self�target� connection�kwr r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/sqlalchemy/events.py� before_createe s zDDLEvents.before_createc K s dS )a� Called after CREATE statements are emitted. :param target: the :class:`_schema.MetaData` or :class:`_schema.Table` object which is the target of the event. :param connection: the :class:`_engine.Connection` where the CREATE statement or statements have been emitted. :param \**kw: additional keyword arguments relevant to the event. The contents of this dictionary may vary across releases, and include the list of tables being generated for a metadata-level event, the checkfirst flag, and other elements used by internal events. :func:`.event.listen` also accepts the ``propagate=True`` modifier for this event; when True, the listener function will be established for any copies made of the target object, i.e. those copies that are generated when :meth:`_schema.Table.tometadata` is used. Nr r r r r �after_create{ s zDDLEvents.after_createc K s dS )a� Called before DROP statements are emitted. :param target: the :class:`_schema.MetaData` or :class:`_schema.Table` object which is the target of the event. :param connection: the :class:`_engine.Connection` where the DROP statement or statements will be emitted. :param \**kw: additional keyword arguments relevant to the event. The contents of this dictionary may vary across releases, and include the list of tables being generated for a metadata-level event, the checkfirst flag, and other elements used by internal events. :func:`.event.listen` also accepts the ``propagate=True`` modifier for this event; when True, the listener function will be established for any copies made of the target object, i.e. those copies that are generated when :meth:`_schema.Table.tometadata` is used. Nr r r r r �before_drop� s zDDLEvents.before_dropc K s dS )a� Called after DROP statements are emitted. :param target: the :class:`_schema.MetaData` or :class:`_schema.Table` object which is the target of the event. :param connection: the :class:`_engine.Connection` where the DROP statement or statements have been emitted. :param \**kw: additional keyword arguments relevant to the event. The contents of this dictionary may vary across releases, and include the list of tables being generated for a metadata-level event, the checkfirst flag, and other elements used by internal events. :func:`.event.listen` also accepts the ``propagate=True`` modifier for this event; when True, the listener function will be established for any copies made of the target object, i.e. those copies that are generated when :meth:`_schema.Table.tometadata` is used. Nr r r r r � after_drop� s zDDLEvents.after_dropc C s dS )a Called before a :class:`.SchemaItem` is associated with a parent :class:`.SchemaItem`. :param target: the target object :param parent: the parent to which the target is being attached. :func:`.event.listen` also accepts the ``propagate=True`` modifier for this event; when True, the listener function will be established for any copies made of the target object, i.e. those copies that are generated when :meth:`_schema.Table.tometadata` is used. Nr �r r �parentr r r �before_parent_attach� s zDDLEvents.before_parent_attachc C s dS )a Called after a :class:`.SchemaItem` is associated with a parent :class:`.SchemaItem`. :param target: the target object :param parent: the parent to which the target is being attached. :func:`.event.listen` also accepts the ``propagate=True`` modifier for this event; when True, the listener function will be established for any copies made of the target object, i.e. those copies that are generated when :meth:`_schema.Table.tometadata` is used. Nr r r r r �after_parent_attach� s zDDLEvents.after_parent_attachc C s dS )zUinternal event hook used for primary key naming convention updates. Nr )r �const�colr r r �'_sa_event_column_added_to_pk_constraint� s z1DDLEvents._sa_event_column_added_to_pk_constraintc C s dS )a Called for each unit of 'column info' retrieved when a :class:`_schema.Table` is being reflected. Currently, this event may only be applied to the :class:`_schema.Table` class directly:: from sqlalchemy import Table @event.listens_for(Table, 'column_reflect') def receive_column_reflect(inspector, table, column_info): # receives for all Table objects that are reflected Or applied using the :paramref:`_schema.Table.listeners` parameter:: t1 = Table( "my_table", autoload_with=some_engine, listeners=[ ('column_reflect', receive_column_reflect) ] ) A future release will allow it to be associated with a specific :class:`_schema.MetaData` object as well. The dictionary of column information as returned by the dialect is passed, and can be modified. The dictionary is that returned in each element of the list returned by :meth:`.reflection.Inspector.get_columns`: * ``name`` - the column's name, is applied to the :paramref:`_schema.Column.name` parameter * ``type`` - the type of this column, which should be an instance of :class:`~sqlalchemy.types.TypeEngine`, is applied to the :paramref:`_schema.Column.type` parameter * ``nullable`` - boolean flag if the column is NULL or NOT NULL, is applied to the :paramref:`_schema.Column.nullable` parameter * ``default`` - the column's server default value. This is normally specified as a plain string SQL expression, however the event can pass a :class:`.FetchedValue`, :class:`.DefaultClause`, or :func:`_expression.text` object as well. Is applied to the :paramref:`_schema.Column.server_default` parameter .. versionchanged:: 1.1.6 The :meth:`.DDLEvents.column_reflect` event allows a non string :class:`.FetchedValue`, :func:`_expression.text`, or derived object to be specified as the value of ``default`` in the column dictionary. The event is called before any action is taken against this dictionary, and the contents can be modified; the following additional keys may be added to the dictionary to further modify how the :class:`_schema.Column` is constructed: * ``key`` - the string key that will be used to access this :class:`_schema.Column` in the ``.c`` collection; will be applied to the :paramref:`_schema.Column.key` parameter. Is also used for ORM mapping. See the section :ref:`mapper_automated_reflection_schemes` for an example. * ``quote`` - force or un-force quoting on the column name; is applied to the :paramref:`_schema.Column.quote` parameter. * ``info`` - a dictionary of arbitrary data to follow along with the :class:`_schema.Column`, is applied to the :paramref:`_schema.Column.info` parameter. :func:`.event.listen` also accepts the ``propagate=True`` modifier for this event; when True, the listener function will be established for any copies made of the target object, i.e. those copies that are generated when :meth:`_schema.Table.to_metadata` is used. Nr )r Z inspector�tableZcolumn_infor r r �column_reflect� s zDDLEvents.column_reflectN)�__name__� __module__�__qualname__�__doc__�_target_class_docr �_dispatch_targetr r r r r r r r r r r r r s Mr c @ st e Zd ZdZdZeZedd� �Zdd� Z dd� Z d d � Zdd� Zd d� Z dd� Zdd� Zdd� Zdd� Zdd� ZdS )� PoolEventsa� Available events for :class:`_pool.Pool`. The methods here define the name of an event as well as the names of members that are passed to listener functions. e.g.:: from sqlalchemy import event def my_on_checkout(dbapi_conn, connection_rec, connection_proxy): "handle an on checkout event" event.listen(Pool, 'checkout', my_on_checkout) In addition to accepting the :class:`_pool.Pool` class and :class:`_pool.Pool` instances, :class:`_events.PoolEvents` also accepts :class:`_engine.Engine` objects and the :class:`_engine.Engine` class as targets, which will be resolved to the ``.pool`` attribute of the given engine or the :class:`_pool.Pool` class:: engine = create_engine("postgresql://scott:tiger@localhost/test") # will associate with engine.pool event.listen(engine, 'checkout', my_on_checkout) ZSomeEngineOrPoolc C s@ t |t�r(t|t�rtS t|t�r<|S nt |t�r8|jS |S d S �N)� isinstance�type� issubclassr r �pool��clsr r r r �_accept_withU s zPoolEvents._accept_withc C s dS )a� Called at the moment a particular DBAPI connection is first created for a given :class:`_pool.Pool`. This event allows one to capture the point directly after which the DBAPI module-level ``.connect()`` method has been used in order to produce a new DBAPI connection. :param dbapi_connection: a DBAPI connection. :param connection_record: the :class:`._ConnectionRecord` managing the DBAPI connection. Nr �r �dbapi_connection�connection_recordr r r �connecta s zPoolEvents.connectc C s dS )a� Called exactly once for the first time a DBAPI connection is checked out from a particular :class:`_pool.Pool`. The rationale for :meth:`_events.PoolEvents.first_connect` is to determine information about a particular series of database connections based on the settings used for all connections. Since a particular :class:`_pool.Pool` refers to a single "creator" function (which in terms of a :class:`_engine.Engine` refers to the URL and connection options used), it is typically valid to make observations about a single connection that can be safely assumed to be valid about all subsequent connections, such as the database version, the server and client encoding settings, collation settings, and many others. :param dbapi_connection: a DBAPI connection. :param connection_record: the :class:`._ConnectionRecord` managing the DBAPI connection. Nr r. r r r � first_connectp s zPoolEvents.first_connectc C s dS )aG Called when a connection is retrieved from the Pool. :param dbapi_connection: a DBAPI connection. :param connection_record: the :class:`._ConnectionRecord` managing the DBAPI connection. :param connection_proxy: the :class:`._ConnectionFairy` object which will proxy the public interface of the DBAPI connection for the lifespan of the checkout. If you raise a :class:`~sqlalchemy.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. .. seealso:: :meth:`_events.ConnectionEvents.engine_connect` - a similar event which occurs upon creation of a new :class:`_engine.Connection`. Nr )r r/ r0 Zconnection_proxyr r r �checkout� s zPoolEvents.checkoutc C s dS )a� Called 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.) :param dbapi_connection: a DBAPI connection. :param connection_record: the :class:`._ConnectionRecord` managing the DBAPI connection. Nr r. r r r �checkin� s zPoolEvents.checkinc C s dS )ab Called before the "reset" action occurs for a pooled connection. This event represents when the ``rollback()`` method is called on the DBAPI connection before it is returned to the pool. The behavior of "reset" can be controlled, including disabled, using the ``reset_on_return`` pool argument. The :meth:`_events.PoolEvents.reset` event is usually followed by the :meth:`_events.PoolEvents.checkin` event is called, except in those cases where the connection is discarded immediately after reset. :param dbapi_connection: a DBAPI connection. :param connection_record: the :class:`._ConnectionRecord` managing the DBAPI connection. .. seealso:: :meth:`_events.ConnectionEvents.rollback` :meth:`_events.ConnectionEvents.commit` Nr r. r r r �reset� s zPoolEvents.resetc C s dS )a8 Called when a DBAPI connection is to be "invalidated". This event is called any time the :meth:`._ConnectionRecord.invalidate` method is invoked, either from API usage or via "auto-invalidation", without the ``soft`` flag. The event occurs before a final attempt to call ``.close()`` on the connection occurs. :param dbapi_connection: a DBAPI connection. :param connection_record: the :class:`._ConnectionRecord` managing the DBAPI connection. :param exception: the exception object corresponding to the reason for this invalidation, if any. May be ``None``. .. versionadded:: 0.9.2 Added support for connection invalidation listening. .. seealso:: :ref:`pool_connection_invalidation` Nr �r r/ r0 � exceptionr r r � invalidate� s zPoolEvents.invalidatec C s dS )a� Called when a DBAPI connection is to be "soft invalidated". This event is called any time the :meth:`._ConnectionRecord.invalidate` method is invoked with the ``soft`` flag. Soft invalidation refers to when the connection record that tracks this connection will force a reconnect after the current connection is checked in. It does not actively close the dbapi_connection at the point at which it is called. .. versionadded:: 1.0.3 Nr r6 r r r �soft_invalidate� s zPoolEvents.soft_invalidatec C s dS )a Called when a DBAPI connection is closed. The event is emitted before the close occurs. The close of a connection can fail; typically this is because the connection is already closed. If the close operation fails, the connection is discarded. The :meth:`.close` event corresponds to a connection that's still associated with the pool. To intercept close events for detached connections use :meth:`.close_detached`. .. versionadded:: 1.1 Nr r. r r r �close� s zPoolEvents.closec C s dS )z�Called when a DBAPI connection is "detached" from a pool. This event is emitted after the detach occurs. The connection is no longer associated with the given connection record. .. versionadded:: 1.1 Nr r. r r r �detach s zPoolEvents.detachc C s dS )aG Called when a detached DBAPI connection is closed. The event is emitted before the close occurs. The close of a connection can fail; typically this is because the connection is already closed. If the close operation fails, the connection is discarded. .. versionadded:: 1.1 Nr )r r/ r r r �close_detached s zPoolEvents.close_detachedN)r r r! r"