e7 d Z ddlmZ ddlZddlmZ ddlmZ g dZ G d d e Z d
Z
G d d ej e e Z
G d
de Z G d de Z G d de Zd Zd Zd Zd Zd Zd Zd ZdS )a@ Visitor/traversal interface and library functions.
SQLAlchemy schema and expression constructs rely on a Python-centric
version of the classic "visitor" pattern as the primary way in which
they apply functionality. The most common use of this pattern
is statement compilation, where individual expression classes match
up to rendering methods that produce a string result. Beyond this,
the visitor system is also used to inspect expressions for various
information and patterns, as well as for the purposes of applying
transformations to expressions.
Examples of how the visit system is used can be seen in the source code
of for example the ``sqlalchemy.sql.util`` and the ``sqlalchemy.sql.compiler``
modules. Some background on clause adaption is also at
http://techspot.zzzeek.org/2008/01/23/expression-transformations/ .
)dequeN )exc)util)
VisitableType Visitable
ClauseVisitorCloningVisitorReplacingCloningVisitoriterateiterate_depthfirsttraverse_usingtraversetraverse_depthfirstcloned_traversereplacement_traversec " e Zd ZdZ fdZ xZS )r ar Metaclass which assigns a ``_compiler_dispatch`` method to classes
having a ``__visit_name__`` attribute.
The ``_compiler_dispatch`` attribute becomes an instance method which
looks approximately like the following::
def _compiler_dispatch (self, visitor, **kw):
'''Look for an attribute named "visit_" + self.__visit_name__
on the visitor, and call it with the same kw params.'''
visit_attr = 'visit_%s' % self.__visit_name__
return getattr(visitor, visit_attr)(self, **kw)
Classes having no ``__visit_name__`` attribute will remain unaffected.
c |dk rt | d rt | t t | ||| d S )Nr __visit_name__)hasattr_generate_dispatchsuperr __init__)clsclsnamebasesclsdict __class__s k/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib64/python3.11/site-packages/sqlalchemy/sql/visitors.pyr zVisitableType.__init__B sT k!!gc3C&D&D!s###
mS!!**7E7CCCCC )__name__
__module____qualname____doc__r
__classcell__)r s @r r r 1 sK D D D D D D D D Dr r c d j v rY j }t |t j j rt
j d|z fd}n fd}d|_ | _ dS dS )zZReturn an optimized visit dispatch function for the cls
for use by the compiler.
r visit_%sc | } || fi |S # t $ r4}t j t j | | Y d }~d S d }~ww xY w)Nreplace_context)AttributeErrorr raise_r UnsupportedCompilationError)selfvisitorkwmetherrr getters r _compiler_dispatchz._generate_dispatch.