HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/__pycache__/visitors.cpython-310.pyc
o

���gߍ�@s�dZddlmZddlmZddlmZddlZddlZddl	Z	ddl	m
Z
ddl	mZddl	mZdd	l	m
Z
dd
l	mZddl	mZddl	mZdd
l	mZddl	mZddl	mZddl	mZddl	mZddl	mZddl	mZddl	mZddl	mZddlmZddlmZddlmZddlmZddl m!Z!ddl m"Z"ddl m#Z#er�ddl$m%Z%dd l&m'Z'e	js�es�dd!l(m)Z)dd"l(m*Z+ndd!l,m)Z)dd"l,m*Z+gd#�Z-Gd$d%�d%e"�Z.Gd&d'�d'�Z/Gd(d)�d)e�Z0eee1e0fZ2	Gd*d+�d+�Z3Gd,d-�d-e"�Z4Gd.d/�d/�Z5e0Z6ddd2d3�Z7e5j8Z8e7�Gd4d5�d5e3e/�Z9ed6e9d7�Z:ed8d9d7�Z;ee:gdfZ<Gd:d;�d;e"�Z=Gd<d=�d=e"e:�Z>ed>d?d7�Z?Gd@d?�d?ej@�ZAGdAdB�dBeA�ZBGdCdD�dDeB�ZCe/ZDeAZEeBZFeCZGejHfdedJdK�ZIedfdQdR��ZJedgdSdR��ZJdhdTdR�ZJedidUdV��ZKedjdWdV��ZKdkdXdV�ZKedidYdZ��ZLedld[dZ��ZLdkd\dZ�ZLedmd_d`��ZMedndad`��ZMedodbd`��ZMdpdcd`�ZMdS)qz5Visitor/traversal interface and library functions.


�)�annotations)�deque)�EnumN)�Any)�Callable)�cast)�ClassVar)�Dict)�Iterable)�Iterator)�List)�Mapping)�Optional)�overload)�Tuple)�Type)�
TYPE_CHECKING)�TypeVar)�Union�)�exc)�util)�langhelpers)�HAS_CYEXTENSION)�Literal)�Protocol)�Self�)�_AnnotationDict)�
ColumnElement)�prefix_anon_map)�cache_anon_map)	�iterate�traverse_using�traverse�cloned_traverse�replacement_traverse�	Visitable�ExternalTraversal�InternalTraversal�anon_mapc@�eZdZd
dd�Zd	S)�_CompilerDispatchType�selfr'�visitorr�kw�returncK�dS�N�)�_selfr-r.r/r3r3�B/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/visitors.py�__call__K�z_CompilerDispatchType.__call__N)r-r'r.rr/rr0r��__name__�
__module__�__qualname__r6r3r3r3r5r,J�r,cs`eZdZUdZdZded<ded<ejrddd�Zd�fdd�Z	e
ddd��Zddd�Z�Z
S)r'a,Base class for visitable objects.

    :class:`.Visitable` is used to implement the SQL compiler dispatch
    functions.    Other forms of traversal such as for cache key generation
    are implemented separately using the :class:`.HasTraverseInternals`
    interface.

    .. versionchanged:: 2.0  The :class:`.Visitable` class was named
       :class:`.Traversible` in the 1.4 series; the name is changed back
       to :class:`.Visitable` in 2.0 which is what it was prior to 1.4.

       Both names remain importable in both 1.4 and 2.0 versions.

    r3�str�__visit_name__r,�_original_compiler_dispatchr.rr/r0cKr1r2r3)r-r.r/r3r3r5�_compiler_dispatchfr7zVisitable._compiler_dispatch�Nonecs d|jvr	|��t���dS)Nr>)�__dict__�_generate_compiler_dispatch�super�__init_subclass__)�cls��	__class__r3r5rEhs
zVisitable.__init_subclass__csj|j}d|jvr|j|_dSt|t�st�d|j�d���d|}t	�
|��d�fdd
�}||_|_dS)Nr@z__visit_name__ on class z$ must be a string at the class level�visit_%sr-r'r.rr/r0r=c
sVz�|�}Wnty"}z|j||fi|��WYd}~Sd}~ww||fi|��S)zLook for an attribute named "visit_<visit_name>" on the
            visitor, and call it with the same kw params.

            N)�AttributeError�visit_unsupported_compilation)r-r.r/�meth�err��getterr3r5r@�s ��zAVisitable._generate_compiler_dispatch.<locals>._compiler_dispatch)r-r'r.rr/rr0r=)r>rBr@r?�
isinstancer=r�InvalidRequestErrorr9�operator�
attrgetter)rF�
visit_name�namer@r3rNr5rCms

�
�z%Visitable._generate_compiler_dispatch�keycCs|Sr2r3)rFrVr3r3r5�__class_getitem__��zVisitable.__class_getitem__)r.rr/rr0r=�r0rA)rVrr0r)r9r:r;�__doc__�	__slots__�__annotations__�typingrr@rE�classmethodrCrW�
__classcell__r3r3rGr5r'Ns

%r'c@s�eZdZdZdZ	dZ	dZ	dZ	dZ	dZ		dZ
	d	Zd
ZdZ
	dZ	d
Z	dZ	dZ	dZ	dZ	dZ	dZ	dZ	dZ	dZ	dZ	dZ	dZ	dZ	dZdZdZ	dZ 	dZ!	d Z"	d!Z#	d"Z$		d#Z%	d$Z&	d%Z'	d&Z(	d'Z)	d(Z*d)S)*r)a�Defines visitor symbols used for internal traversal.

    The :class:`.InternalTraversal` class is used in two ways.  One is that
    it can serve as the superclass for an object that implements the
    various visit methods of the class.   The other is that the symbols
    themselves of :class:`.InternalTraversal` are used within
    the ``_traverse_internals`` collection.   Such as, the :class:`.Case`
    object defines ``_traverse_internals`` as ::

        class Case(ColumnElement[_T]):
            _traverse_internals = [
                ("value", InternalTraversal.dp_clauseelement),
                ("whens", InternalTraversal.dp_clauseelement_tuples),
                ("else_", InternalTraversal.dp_clauseelement),
            ]

    Above, the :class:`.Case` class indicates its internal state as the
    attributes named ``value``, ``whens``, and ``else_``.    They each
    link to an :class:`.InternalTraversal` method which indicates the type
    of datastructure to which each attribute refers.

    Using the ``_traverse_internals`` structure, objects of type
    :class:`.InternalTraversible` will have the following methods automatically
    implemented:

    * :meth:`.HasTraverseInternals.get_children`

    * :meth:`.HasTraverseInternals._copy_internals`

    * :meth:`.HasCacheKey._gen_cache_key`

    Subclasses can also implement these methods directly, particularly for the
    :meth:`.HasTraverseInternals._copy_internals` method, when special steps
    are needed.

    .. versionadded:: 1.4

    �HC�HL�CE�FC�CTS�CL�CT�EO�WC�CO�S�SL�AN�B�O�T�PD�DO�CD�MD�AK�PO�DD�PS�TH�SJ�ME�SH�UK�DML_OV�DML_V�DML_MV�PA�IG�IS�M�MT�HT�ILN)+r9r:r;rZ�dp_has_cache_key�dp_has_cache_key_list�dp_clauseelement�)dp_fromclause_canonical_column_collection�dp_clauseelement_tuples�dp_clauseelement_list�dp_clauseelement_tuple�dp_executable_options�dp_with_context_options�dp_fromclause_ordered_set�	dp_string�dp_string_list�dp_anon_name�
dp_boolean�dp_operator�dp_type�
dp_plain_dict�dp_dialect_options�dp_string_clauseelement_dict�dp_string_multi_dict�dp_annotations_key�dp_plain_obj�dp_named_ddl_element�dp_prefix_sequence�dp_table_hint_list�dp_setup_join_tuple�dp_memoized_select_entities�dp_statement_hint_list�dp_unknown_structure�dp_dml_ordered_values�
dp_dml_values�dp_dml_multi_values�dp_propagate_attrs�	dp_ignore�dp_inspectable�dp_multi�
dp_multi_list�dp_has_cache_key_tuples�dp_inspectable_listr3r3r3r5r)�s�'


	
r)c@sDeZdZUdZdZded<dZded<e�d�dd	�ddd��Z	dS)�HasTraverseInternalsa�base for classes that have a "traverse internals" element,
    which defines all kinds of ways of traversing the elements of an object.

    Compared to :class:`.Visitable`, which relies upon an external visitor to
    define how the object is travered (i.e. the :class:`.SQLCompiler`), the
    :class:`.HasTraverseInternals` interface allows classes to define their own
    traversal, that is, what attributes are accessed and in what order.

    r3�_TraverseInternalsType�_traverse_internalsF�bool�
_is_immutablezsqlalchemy.sql.traversals��
omit_attrsr��Tuple[str, ...]r/rr0�Iterable[HasTraverseInternals]csVtjj}z|j}WntygYSw|jj}tj�	��fdd�|||d�D��S)a�Return immediate child :class:`.visitors.HasTraverseInternals`
        elements of this :class:`.visitors.HasTraverseInternals`.

        This is used for visit traversal.

        \**kw may contain flags that change the collection that is
        returned, for example to return a subset of items in order to
        cut down on larger traversals, or to return child items from a
        different context (such as schema-level collections instead of
        clause-level).

        c3s6�|]\}}}|�vr|dur||fi���VqdSr2r3)�.0�attrname�objrL�r/r�r3r5�	<genexpr>�s���z4HasTraverseInternals.get_children.<locals>.<genexpr>�!_generated_get_children_traversal)
r�	preloaded�sql_traversalsr�rJ�
_get_children�run_generated_dispatch�	itertools�chain�
from_iterable)r-r�r/�
traversals�traverse_internals�dispatchr3r�r5�get_children�s
���z!HasTraverseInternals.get_childrenN)r�r�r/rr0r�)
r9r:r;rZr[r\r�r�preload_moduler�r3r3r3r5r��s

�r�c@r+)�_InternalTraversalDispatchTyper-�objectr.�HasTraversalDispatchr0rcCr1r2r3)�sr-r.r3r3r5r6�r7z'_InternalTraversalDispatchType.__call__N)r-r�r.r�r0rr8r3r3r3r5r��r<r�c@sJeZdZUdZdZiZded<dd	d
�Zddd�Zddd�Z	d dd�Z
dS)!r�zcDefine infrastructure for classes that perform internal traversals

    .. versionadded:: 2.0

    r3z2ClassVar[Dict[Union[InternalTraversal, str], str]]�_dispatch_lookup�visit_symbolr)r0�Callable[..., Any]cCst|}t||d�S)ztGiven a method from :class:`.HasTraversalDispatch`, return the
        corresponding method on a subclass.

        N)r��getattr)r-r�rUr3r3r5r��szHasTraversalDispatch.dispatch�targetr��internal_dispatchr��generate_dispatcher_namer=rcCs>z|jj|}Wnty|�|j||�}Ynw|||�Sr2)rHrB�KeyError�generate_dispatch)r-r�r�r��
dispatcherr3r3r5r�s��
z+HasTraversalDispatch.run_generated_dispatch�
target_cls�Type[object]r�cCs|�||�}t|||�|Sr2)�_generate_dispatcher�setattr)r-r�r�r�r�r3r3r5r�s
�z&HasTraversalDispatch.generate_dispatch�method_namec
Cszg}|D]\}}|�|�}|durt|}|�||f�qdd�dd�|D��d}d||d}	ttt�|	i|��S)Nz
    return [
z, 
css"�|]\}}d|||fVqdS)z!        (%r, self.%s, visitor.%s)Nr3)r�r�rTr3r3r5r�1s���
�z<HasTraversalDispatch._generate_dispatcher.<locals>.<genexpr>z
    ]
zdef %s(self, visitor):
�
)r�r��append�joinrr�r�_exec_code_in_env)
r-r�r��namesr��	visit_symrLrT�code�	meth_textr3r3r5r�$s(
�
�����z)HasTraversalDispatch._generate_dispatcherN)r�r)r0r�)r�r�r�r�r�r=r0r)r�r�r�r�r�r=r0r�)r�r�r�r=r0r�)r9r:r;rZr[r�r\r�r�r�r�r3r3r3r5r��s




r�r0rAcCsTt}tD]#}|j}|�d�r'|�dd�}|j}||vsJ|��|||<||<qdS)N�dp_�visit_)r�r)rU�
startswith�replace�value)�lookup�symrV�	visit_key�sym_namer3r3r5�_generate_traversal_dispatchCs
��r�c@sZeZdZUdZejZded<ej	rddd	�Z
dd
�ddd�Zddd�Zdd
�ddd�Z
dS)�ExternallyTraversibler3zMapping[Any, Any]�_annotations�valuesrr0rcCr1r2r3)r-r�r3r3r5�	_annotateZr7zExternallyTraversible._annotater�r�r�r/r�Iterable[ExternallyTraversible]cKr1r2r3�r-r�r/r3r3r5r�\rXz"ExternallyTraversible.get_childrencK�t��)zclone this element��NotImplementedError)r-r/r3r3r5�_clone`szExternallyTraversible._clonerAcKr�)atReassign internal elements to be clones of themselves.

        Called during a copy-and-traverse operation on newly
        shallow-copied elements to create a deep copy.

        The given clone function should be used, which may be applying
        additional transformations to the element (i.e. replacement
        traversal, cloned traversal, annotations).

        r�r�r3r3r5�_copy_internalsds
z%ExternallyTraversible._copy_internalsN)r�rr0r)r�r�r/rr0r�)r/rr0r)r�r�r/rr0rA)r9r:r;r[r�
EMPTY_DICTr�r\r]rr�r�r�r�r3r3r3r5r�Ss

�
�r��_ET)�bound�_CEzColumnElement[Any]c@seZdZd	dd�ZdS)
�_CloneCallableType�elementr�r/rr0cKr1r2r3�r-r�r/r3r3r5r6|r7z_CloneCallableType.__call__N)r�r�r/rr0r�r8r3r3r3r5r�{r<r�c@r+)�_TraverseTransformCallableTyper�r�r/rr0�
Optional[_ET]cKr1r2r3r�r3r3r5r6�r7z'_TraverseTransformCallableType.__call__N)r�r�r/rr0rr8r3r3r3r5rr<r�_ExtTr(c@s�eZdZUdZdZiZded<ded<d%dd
�Zd&dd�Ze	d'dd��Z
e	d(dd��Z
d)dd�Z
d*dd�Zed+dd��Z
d,d"d#�Zd$S)-r(z�Base class for visitor objects which can traverse externally using
    the :func:`.visitors.traverse` function.

    Direct usage of the :func:`.visitors.traverse` function is usually
    preferred.

    )�
_visitor_dict�_nextzDict[str, Any]�__traverse_options__zOptional[ExternalTraversal]rr�r'r/rr0cKs:|jD]}t|d|jd�}|r||fi|��SqdS)NrI)�visitor_iteratorr�r>)r-r�r/�vrLr3r3r5�traverse_single�s
��z!ExternalTraversal.traverse_single�Optional[ExternallyTraversible]�Iterator[ExternallyTraversible]cCst||j�S)zaTraverse the given expression structure, returning an iterator
        of all elements.

        )r"r�r-r�r3r3r5r"�szExternalTraversal.iterate�
Literal[None]rAcCr1r2r3rr3r3r5r$��zExternalTraversal.traverser�cCr1r2r3rr3r3r5r$��cC�t||j|j�S��2Traverse and visit the given expression structure.)r$rrrr3r3r5r$�s�%Dict[str, _TraverseCallableType[Any]]cCs6i}t|�D]}|�d�rt||�||dd�<q|S)Nr��)�dirr�r�)r-�visitorsrUr3r3r5�_memoized_attr__visitor_dict�s
�z.ExternalTraversal._memoized_attr__visitor_dict�Iterator[ExternalTraversal]ccs(�|}|r|Vt|dd�}|sdSdS)z8Iterate through this visitor and each 'chained' visitor.rN)r�)r-rr3r3r5r�s��z"ExternalTraversal.visitor_iteratorr-rr.cCst|j�d}||_|S)z�'Chain' an additional ExternalTraversal onto this ExternalTraversal

        The chained visitor will receive all visit events after this one.

        ���)�listrr)r-r.�tailr3r3r5r��szExternalTraversal.chainN)r�r'r/rr0r)r�r	r0r
�r�rr0rA�r�r�r0r��r�r	r0r	)r0r)r0r)r-rr.r(r0r)r9r:r;rZr[rr\rr"rr$r�propertyrr�r3r3r3r5r(�s 


	


c@sDeZdZdZdZddd�Zeddd��Zeddd��Zddd�ZdS)�CloningExternalTraversalz�Base class for visitor objects which can traverse using
    the :func:`.visitors.cloned_traverse` function.

    Direct usage of the :func:`.visitors.cloned_traverse` function is usually
    preferred.


    r3�list_�List[ExternallyTraversible]r0cs�fdd�|D�S)z`Apply cloned traversal to the given list of elements, and return
        the new list.

        csg|]}��|��qSr3)r$�r��x�r-r3r5�
<listcomp>�sz=CloningExternalTraversal.copy_and_process.<locals>.<listcomp>r3)r-r r3r$r5�copy_and_process�sz)CloningExternalTraversal.copy_and_processr�rrAcCr1r2r3rr3r3r5r$�r
z!CloningExternalTraversal.traverser�cCr1r2r3rr3r3r5r$�rr	cCrr)r%rrrr3r3r5r$�s
�N)r r!r0r!rrr)r9r:r;rZr[r&rr$r3r3r3r5r�s	
	rc@sDeZdZdZdZddd�Zeddd
��Zeddd
��Zddd
�ZdS)�ReplacingExternalTraversalz�Base class for visitor objects which can traverse using
    the :func:`.visitors.replacement_traverse` function.

    Direct usage of the :func:`.visitors.replacement_traverse` function is
    usually preferred.

    r3�elemr�r0r	cCsdS)aReceive pre-copied elements during a cloning traversal.

        If the method returns a new element, the element is used
        instead of creating a simple copy of the element.  Traversal
        will halt on the newly returned element if it is re-encountered.
        Nr3)r-r(r3r3r5r�s	z"ReplacingExternalTraversal.replacer�rrAcCr1r2r3rr3r3r5r$
r
z#ReplacingExternalTraversal.traversecCr1r2r3rr3r3r5r$rcsd
�fdd�}t|�j|�S)rr�r�r/rr0r	cs0�jD]}tt|��|�}|dur|SqdSr2)rrr'r�)r�r/r�er$r3r5r�s
�z4ReplacingExternalTraversal.traverse.<locals>.replaceN)r�r�r/rr0r	)r&r)r-r�r�r3r$r5r$sN)r(r�r0r	rrr)r9r:r;rZr[r�rr$r3r3r3r5r'�s
r'r�r	�opts�Mapping[str, Any]r
ccst�|durdS|V|jdi|��}|sdSt|g�}|r8|��}|D]}|V|�|jdi|���q#|sdSdS)aHTraverse the given expression structure, returning an iterator.

    Traversal is configured to be breadth-first.

    The central API feature used by the :func:`.visitors.iterate`
    function is the
    :meth:`_expression.ClauseElement.get_children` method of
    :class:`_expression.ClauseElement` objects.  This method should return all
    the :class:`_expression.ClauseElement` objects which are associated with a
    particular :class:`_expression.ClauseElement` object. For example, a
    :class:`.Case` structure will refer to a series of
    :class:`_expression.ColumnElement` objects within its "whens" and "else\_"
    member variables.

    :param obj: :class:`_expression.ClauseElement` structure to be traversed

    :param opts: dictionary of iteration options.   This dictionary is usually
     empty in modern usage.

    Nr3)r�r�popleftr�)r�r*�children�stack�
t_iterator�tr3r3r5r"0s�
�r"�iteratorr�rr�(Mapping[str, _TraverseCallableType[Any]]cCr1r2r3�r1r�rr3r3r5r#Y�r#cCr1r2r3r3r3r3r5r#ar4cCs(|D]}|�|jd�}|r||�q|S)a�Visit the given expression structure using the given iterator of
    objects.

    :func:`.visitors.traverse_using` is usually called internally as the result
    of the :func:`.visitors.traverse` function.

    :param iterator: an iterable or sequence which will yield
     :class:`_expression.ClauseElement`
     structures; the iterator is assumed to be the
     product of the :func:`.visitors.iterate` function.

    :param obj: the :class:`_expression.ClauseElement`
     that was used as the target of the
     :func:`.iterate` function.

    :param visitors: dictionary of visit functions.  See :func:`.traverse`
     for details on this dictionary.

    .. seealso::

        :func:`.traverse`


    N)�getr>)r1r�rr�rLr3r3r5r#is�cCr1r2r3�r�r*rr3r3r5r$�r4r$cCr1r2r3r6r3r3r5r$�r4cCstt||�||�S)aTraverse and visit the given expression structure using the default
    iterator.

     e.g.::

        from sqlalchemy.sql import visitors

        stmt = select(some_table).where(some_table.c.foo == "bar")


        def visit_bindparam(bind_param):
            print("found bound value: %s" % bind_param.value)


        visitors.traverse(stmt, {}, {"bindparam": visit_bindparam})

    The iteration of objects uses the :func:`.visitors.iterate` function,
    which does a breadth-first traversal using a stack.

    :param obj: :class:`_expression.ClauseElement` structure to be traversed

    :param opts: dictionary of iteration options.   This dictionary is usually
     empty in modern usage.

    :param visitors: dictionary of visit functions.   The dictionary should
     have strings as keys, each of which would correspond to the
     ``__visit_name__`` of a particular kind of SQL expression object, and
     callable functions  as values, each of which represents a visitor function
     for that kind of object.

    )r#r"r6r3r3r5r$�s$cCr1r2r3r6r3r3r5r%�r4r%cCr1r2r3r6r3r3r5r%�r4cs\i�t��dg���d��fdd�}d����fd
d��|dur*�|fd
|i���}d�|S)aClone the given expression structure, allowing modifications by
    visitors for mutable objects.

    Traversal usage is the same as that of :func:`.visitors.traverse`.
    The visitor functions present in the ``visitors`` dictionary may also
    modify the internals of the given structure as the traversal proceeds.

    The :func:`.cloned_traverse` function does **not** provide objects that are
    part of the :class:`.Immutable` interface to the visit methods (this
    primarily includes :class:`.ColumnClause`, :class:`.Column`,
    :class:`.TableClause` and :class:`.Table` objects). As this traversal is
    only intended to allow in-place mutation of objects, :class:`.Immutable`
    objects are skipped. The :meth:`.Immutable._clone` method is still called
    on each object to allow for objects to replace themselves with a different
    object based on a clone of their sub-internals (e.g. a
    :class:`.ColumnClause` that clones its subquery to return a new
    :class:`.ColumnClause`).

    .. versionchanged:: 2.0  The :func:`.cloned_traverse` function omits
       objects that are part of the :class:`.Immutable` interface.

    The central API feature used by the :func:`.visitors.cloned_traverse`
    and :func:`.visitors.replacement_traverse` functions, in addition to the
    :meth:`_expression.ClauseElement.get_children`
    function that is used to achieve
    the iteration, is the :meth:`_expression.ClauseElement._copy_internals`
    method.
    For a :class:`_expression.ClauseElement`
    structure to support cloning and replacement
    traversals correctly, it needs to be able to pass a cloning function into
    its internal members in order to make copies of them.

    .. seealso::

        :func:`.visitors.traverse`

        :func:`.visitors.replacement_traverse`

    �stop_onr�r�r0c�t|���Sr2)r%�r�)r*rr3r5�deferred_copy_internals�z0cloned_traverse.<locals>.deferred_copy_internalsr(r/rcs�|�vr|St|��vrQd|vr'ttt|d|��}|dur'|�t|�<|S|jdd�i|���t|�<}|jdd�i|��|jsQ��|jd�}|rQ||��t|�S)Nr��cloner3)	�idrrr�r�r�r�r5r>)r(r/�newelemrL)r<�clonedr7rr3r5r<
s"� zcloned_traverse.<locals>.cloneNr:r�r(r�r/rr0r�)�setr5)r�r*rr:r3)r<r?r*r7rr5r%�s-���r��#_TraverseTransformCallableType[Any]cCr1r2r3�r�r*r�r3r3r5r&3r4r&cCr1r2r3rCr3r3r5r&;r4cCr1r2r3rCr3r3r5r&Cr4csbi�dd���dg�D��d��fdd�}d����fdd
��|dur-�|fd|i���}d�|S)a]Clone the given expression structure, allowing element
    replacement by a given replacement function.

    This function is very similar to the :func:`.visitors.cloned_traverse`
    function, except instead of being passed a dictionary of visitors, all
    elements are unconditionally passed into the given replace function.
    The replace function then has the option to return an entirely new object
    which will replace the one given.  If it returns ``None``, then the object
    is kept in place.

    The difference in usage between :func:`.visitors.cloned_traverse` and
    :func:`.visitors.replacement_traverse` is that in the former case, an
    already-cloned object is passed to the visitor function, and the visitor
    function can then manipulate the internal state of the object.
    In the case of the latter, the visitor function should only return an
    entirely different object, or do nothing.

    The use case for :func:`.visitors.replacement_traverse` is that of
    replacing a FROM clause inside of a SQL structure with a different one,
    as is a common use case within the ORM.

    cSsh|]}t|��qSr3)r=r"r3r3r5�	<setcomp>hsz'replacement_traverse.<locals>.<setcomp>r7r�r�r0cr8r2)r&r9)r*r�r3r5r:jr;z5replacement_traverse.<locals>.deferred_copy_internalsr(r/rcs�t|��vsd|jvr
|S�|�}|dur��t|��|St|�}|�vrPd|vr:|d|�}|dur:|�|<|S|jdi|���|<}|jdd�i|���|S)N�no_replacement_traverser�r<r3)r=r��addr�r�)r(r/r>�id_elem)r<r?r�r7r3r5r<os"
z#replacement_traverse.<locals>.cloneNr:rr@)r5)r�r*r�r:r3)r<r?r*r�r7r5r&Ks���rY)r�r	r*r+r0r
)r1r�r�rrr2r0rA)r1r�r�r�rr2r0r�)r1r�r�r	rr2r0r	)r�rr*r+rr2r0rA)r�r�r*r+rr2r0r�)r�r	r*r+rr2r0r	)r�r�r*r+rr2r0r�)r�rr*r+r�rBr0rA)r�r�r*r+r�rBr0r�)r�r�r*r+r�rBr0r�)r�r	r*r+r�rBr0r	)NrZ�
__future__r�collectionsr�enumrr�rRr]rrrrr	r
rrr
rrrrrrr�rrr�util._has_cyr�util.typingrrr�
annotationr�elementsr�_py_utilr r!r*�sqlalchemy.cyextension.util�__all__r,r'r)r=r�r�r�r��ExtendedInternalTraversalr�r�r�r�r��_TraverseCallableTyper�rr�
MemoizedSlotsr(rr'�Traversible�
ClauseVisitor�CloningVisitor�ReplacingCloningVisitorr�r"r#r$r%r&r3r3r3r5�<module>s�

J
4O
!J'2�)
$
'
[