o
    gߍ                     @  s  d Z ddlmZ ddlmZ ddlmZ ddlZddlZddl	Z	ddl	m
Z
 ddl	mZ ddl	mZ dd	l	mZ dd
l	mZ ddl	mZ ddl	mZ ddl	mZ ddl	mZ ddl	mZ ddl	mZ ddl	mZ ddl	mZ ddl	mZ ddl	mZ ddl	mZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl m"Z" ddl m#Z# erddl$m%Z% dd l&m'Z' e	jsesdd!l(m)Z) dd"l(m*Z+ ndd!l,m)Z) dd"l,m*Z+ g d#Z-G d$d% d%e"Z.G d&d' d'Z/G d(d) d)eZ0eee1e0f  Z2	 G d*d+ d+Z3G d,d- d-e"Z4G d.d/ d/Z5e0Z6ddd2d3Z7e5j8Z8e7  G d4d5 d5e3e/Z9ed6e9d7Z:ed8d9d7Z;ee:gdf Z<G d:d; d;e"Z=G d<d= d=e"e: Z>ed>d?d7Z?G d@d? d?ej@ZAG dAdB dBeAZBG dCdD dDeBZCe/ZDeAZEeBZFeCZGejHfdedJdKZIedfdQdRZJedgdSdRZJdhdTdRZJedidUdVZKedjdWdVZKdkdXdVZKedidYdZZLedld[dZZLdkd\dZZLedmd_d`ZMedndad`ZMedodbd`ZMdpdcd`ZMdS )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                   @     e Zd Zd
ddZd	S )_CompilerDispatchTypeselfr'   visitorr   kwreturnc                 K     d S N )_selfr-   r.   r/   r3   r3   Y/var/www/html/ecg_monitoring/venv/lib/python3.10/site-packages/sqlalchemy/sql/visitors.py__call__K       z_CompilerDispatchType.__call__N)r-   r'   r.   r   r/   r   r0   r   __name__
__module____qualname__r6   r3   r3   r3   r5   r,   J       r,   c                      s`   e Zd ZU dZdZded< ded< ejrdddZd fddZ	e
dddZddd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.   r   r/   r0   c                 K  r1   r2   r3   )r-   r.   r/   r3   r3   r5   _compiler_dispatchf   r7   zVisitable._compiler_dispatchNonec                   s    d| j v r	|   t   d S )Nr>   )__dict___generate_compiler_dispatchsuper__init_subclass__)cls	__class__r3   r5   rE   h   s   
zVisitable.__init_subclass__c                   sj   | j }d| jv r| j| _d S t|tstd| j dd| }t	
| d fdd}| | _| _d S )Nr@   z__visit_name__ on class z$ must be a string at the class levelvisit_%sr-   r'   r.   r   r/   r0   r=   c              
     sV   z |}W n t y" } z|j| |fi |W  Y d}~S d}~ww || fi |S )zLook 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getterr3   r5   r@      s    zAVisitable._generate_compiler_dispatch.<locals>._compiler_dispatch)r-   r'   r.   r   r/   r   r0   r=   )r>   rB   r@   r?   
isinstancer=   r   InvalidRequestErrorr9   operator
attrgetter)rF   
visit_namenamer@   r3   rN   r5   rC   m   s   


z%Visitable._generate_compiler_dispatchkeyc                 C  s   | S r2   r3   )rF   rV   r3   r3   r5   __class_getitem__      zVisitable.__class_getitem__)r.   r   r/   r   r0   r=   r0   rA   )rV   r   r0   r   )r9   r:   r;   __doc__	__slots____annotations__typingr   r@   rE   classmethodrC   rW   __classcell__r3   r3   rG   r5   r'   N   s   
 
%r'   c                   @  s   e Zd ZdZdZ	 dZ	 dZ	 dZ	 dZ	 dZ		 dZ
	 d	Zd
ZdZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZdZdZ	 dZ 	 dZ!	 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)+r9   r:   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_listr3   r3   r3   r5   r)      s    '


	
r)   c                   @  sD   e Zd ZU dZdZded< dZded< eddd	dddZ	dS )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_immutablezsqlalchemy.sql.traversals
omit_attrsr   Tuple[str, ...]r/   r   r0   Iterable[HasTraverseInternals]c                  sV   t jj}z| j}W n ty   g  Y S w |jj}tj	 fdd|| |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).

        c                 3  s6    | ]\}}}|vr|d ur||fi  V  qd S r2   r3   ).0attrnameobjrL   r/   r   r3   r5   	<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dispatchr3   r   r5   get_children  s   
z!HasTraverseInternals.get_childrenN)r   r   r/   r   r0   r   )
r9   r:   r;   rZ   r[   r\   r   r   preload_moduler   r3   r3   r3   r5   r     s   
 
r   c                   @  r+   )_InternalTraversalDispatchTyper-   objectr.   HasTraversalDispatchr0   r   c                 C  r1   r2   r3   )sr-   r.   r3   r3   r5   r6     r7   z'_InternalTraversalDispatchType.__call__N)r-   r   r.   r   r0   r   r8   r3   r3   r3   r5   r     r<   r   c                   @  sJ   e Zd ZU dZdZi Zded< dd	d
ZdddZdddZ	d ddZ
dS )!r   zcDefine infrastructure for classes that perform internal traversals

    .. versionadded:: 2.0

    r3   z2ClassVar[Dict[Union[InternalTraversal, str], str]]_dispatch_lookupvisit_symbolr)   r0   Callable[..., Any]c                 C  s   t | }t| |dS )ztGiven a method from :class:`.HasTraversalDispatch`, return the
        corresponding method on a subclass.

        N)r   getattr)r-   r   rU   r3   r3   r5   r     s   zHasTraversalDispatch.dispatchtargetr   internal_dispatchr   generate_dispatcher_namer=   r   c                 C  s>   z|j j| }W n ty   | |j ||}Y nw ||| S r2   )rH   rB   KeyErrorgenerate_dispatch)r-   r   r   r   
dispatcherr3   r3   r5   r     s   
z+HasTraversalDispatch.run_generated_dispatch
target_clsType[object]r   c                 C  s   |  ||}t||| |S r2   )_generate_dispatchersetattr)r-   r   r   r   r   r3   r3   r5   r     s
   z&HasTraversalDispatch.generate_dispatchmethod_namec           
      C  sz   g }|D ]\}}|  |}|d urt| }|||f qdddd |D  d }d| | d }	ttt|	i |S )Nz    return [
z, 
c                 s  s"    | ]\}}d |||f V  qdS )z!        (%r, self.%s, visitor.%s)Nr3   )r   r   rT   r3   r3   r5   r   1  s    
z<HasTraversalDispatch._generate_dispatcher.<locals>.<genexpr>z
    ]
zdef %s(self, visitor):

)r   r   appendjoinr   r   r   _exec_code_in_env)
r-   r   r   namesr   	visit_symrL   rT   code	meth_textr3   r3   r5   r   $  s(   

z)HasTraversalDispatch._generate_dispatcherN)r   r)   r0   r   )r   r   r   r   r   r=   r0   r   )r   r   r   r   r   r=   r0   r   )r   r   r   r=   r0   r   )r9   r:   r;   rZ   r[   r   r\   r   r   r   r   r3   r3   r3   r5   r     s   
 


r   r0   rA   c                  C  sT   t } tD ]#}|j}|dr'|dd}|j}|| vsJ || | |< | |< qd S )Ndp_visit_)r   r)   rU   
startswithreplacevalue)lookupsymrV   	visit_keysym_namer3   r3   r5   _generate_traversal_dispatchC  s   
r   c                   @  sZ   e Zd ZU dZejZded< ej	rddd	Z
dd
dddZdddZdd
dddZdS )ExternallyTraversibler3   zMapping[Any, Any]_annotationsvaluesr   r0   r   c                 C  r1   r2   r3   )r-   r   r3   r3   r5   	_annotateZ  r7   zExternallyTraversible._annotater   r   r   r/   r   Iterable[ExternallyTraversible]c                K  r1   r2   r3   r-   r   r/   r3   r3   r5   r   \  rX   z"ExternallyTraversible.get_childrenc                 K     t  )zclone this elementNotImplementedError)r-   r/   r3   r3   r5   _clone`  s   zExternallyTraversible._clonerA   c                K  r   )at  Reassign 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   r3   r3   r5   _copy_internalsd  s   z%ExternallyTraversible._copy_internalsN)r   r   r0   r   )r   r   r/   r   r0   r   )r/   r   r0   r   )r   r   r/   r   r0   rA   )r9   r:   r;   r[   r   
EMPTY_DICTr   r\   r]   r   r   r   r   r   r3   r3   r3   r5   r   S  s   
 

r   _ET)bound_CEzColumnElement[Any]c                   @  s   e Zd Zd	ddZdS )
_CloneCallableTypeelementr   r/   r   r0   c                 K  r1   r2   r3   r-   r   r/   r3   r3   r5   r6   |  r7   z_CloneCallableType.__call__N)r   r   r/   r   r0   r   r8   r3   r3   r3   r5   r   {  r<   r   c                   @  r+   )_TraverseTransformCallableTyper   r   r/   r   r0   Optional[_ET]c                 K  r1   r2   r3   r   r3   r3   r5   r6     r7   z'_TraverseTransformCallableType.__call__N)r   r   r/   r   r0   r  r8   r3   r3   r3   r5   r     r<   r   _ExtTr(   c                   @  s   e Zd ZU dZdZi Zded< ded< d%ddZd&ddZe	d'ddZ
e	d(ddZ
d)ddZ
d*ddZed+ddZd,d"d#Zd$S )-r(   zBase 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_nextzDict[str, Any]__traverse_options__zOptional[ExternalTraversal]r  r   r'   r/   r   r0   c                 K  s:   | j D ]}t|d|j d }|r||fi |  S qd S )NrI   )visitor_iteratorr   r>   )r-   r   r/   vrL   r3   r3   r5   traverse_single  s   
z!ExternalTraversal.traverse_singleOptional[ExternallyTraversible]Iterator[ExternallyTraversible]c                 C  s   t || jS )zaTraverse the given expression structure, returning an iterator
        of all elements.

        )r"   r  r-   r   r3   r3   r5   r"     s   zExternalTraversal.iterateLiteral[None]rA   c                 C  r1   r2   r3   r  r3   r3   r5   r$        zExternalTraversal.traverser   c                 C  r1   r2   r3   r  r3   r3   r5   r$        c                 C     t || j| jS 2Traverse and visit the given expression structure.)r$   r  r  r  r3   r3   r5   r$     s   %Dict[str, _TraverseCallableType[Any]]c                 C  s6   i }t | D ]}|drt| |||dd  < q|S )Nr      )dirr   r   )r-   visitorsrU   r3   r3   r5   _memoized_attr__visitor_dict  s   
z.ExternalTraversal._memoized_attr__visitor_dictIterator[ExternalTraversal]c                 c  s(    | }|r|V  t |dd}|sdS dS )z8Iterate through this visitor and each 'chained' visitor.r  N)r   )r-   r  r3   r3   r5   r    s   z"ExternalTraversal.visitor_iteratorr-   r  r.   c                 C  s   t | jd }||_| S )z'Chain' an additional ExternalTraversal onto this ExternalTraversal

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

        )listr  r  )r-   r.   tailr3   r3   r5   r     s   zExternalTraversal.chainN)r   r'   r/   r   r0   r   )r   r	  r0   r
  r   r  r0   rA   r   r   r0   r   r   r	  r0   r	  )r0   r  )r0   r  )r-   r  r.   r(   r0   r  )r9   r:   r;   rZ   r[   r  r\   r  r"   r   r$   r  propertyr  r   r3   r3   r3   r5   r(     s    
 

	


c                   @  sD   e Zd ZdZdZdddZedddZedddZdddZdS )CloningExternalTraversalzBase 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]r0   c                   s    fdd|D S )z`Apply cloned traversal to the given list of elements, and return
        the new list.

        c                   s   g | ]}  |qS r3   )r$   r   xr-   r3   r5   
<listcomp>  s    z=CloningExternalTraversal.copy_and_process.<locals>.<listcomp>r3   )r-   r   r3   r$  r5   copy_and_process  s   z)CloningExternalTraversal.copy_and_processr   r  rA   c                 C  r1   r2   r3   r  r3   r3   r5   r$     r  z!CloningExternalTraversal.traverser   c                 C  r1   r2   r3   r  r3   r3   r5   r$     r  r	  c                 C  r  r  )r%   r  r  r  r3   r3   r5   r$     s   
N)r   r!  r0   r!  r  r  r  )r9   r:   r;   rZ   r[   r&  r   r$   r3   r3   r3   r5   r    s    	
	r  c                   @  sD   e Zd ZdZdZdddZedddZedddZdddZdS )ReplacingExternalTraversalzBase 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   r0   r	  c                 C  s   dS )a  Receive 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(  r3   r3   r5   r     s   	z"ReplacingExternalTraversal.replacer   r  rA   c                 C  r1   r2   r3   r  r3   r3   r5   r$     r  z#ReplacingExternalTraversal.traversec                 C  r1   r2   r3   r  r3   r3   r5   r$     r  c                   s   d
 fdd}t | j|S )r  r   r   r/   r   r0   r	  c                   s0    j D ]}tt|| }|d ur|  S qd S r2   )r  r   r'  r   )r   r/   r  er$  r3   r5   r     s   
z4ReplacingExternalTraversal.traverse.<locals>.replaceN)r   r   r/   r   r0   r	  )r&   r  )r-   r   r   r3   r$  r5   r$     s   N)r(  r   r0   r	  r  r  r  )r9   r:   r;   rZ   r[   r   r   r$   r3   r3   r3   r5   r'    s    
r'  r   r	  optsMapping[str, Any]r
  c                 c  st    | du rdS | V  | j di |}|sdS t|g}|r8| }|D ]}|V  ||j di | q#|sdS dS )aH  Traverse 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tr3   r3   r5   r"   0  s   
r"   iteratorr   r  r  (Mapping[str, _TraverseCallableType[Any]]c                 C  r1   r2   r3   r1  r   r  r3   r3   r5   r#   Y     r#   c                 C  r1   r2   r3   r3  r3   r3   r5   r#   a  r4  c                 C  s(   | D ]}| |jd}|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>   )r1  r   r  r   rL   r3   r3   r5   r#   i  s   c                 C  r1   r2   r3   r   r*  r  r3   r3   r5   r$     r4  r$   c                 C  r1   r2   r3   r6  r3   r3   r5   r$     r4  c                 C  s   t t| || |S )a  Traverse 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"   r6  r3   r3   r5   r$     s   $c                 C  r1   r2   r3   r6  r3   r3   r5   r%     r4  r%   c                 C  r1   r2   r3   r6  r3   r3   r5   r%     r4  c                   s\   i t dg dfdd}d fd
d | dur* | fd|i} d | S )a  Clone 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   r0   c                      t |  S r2   )r%   r   )r*  r  r3   r5   deferred_copy_internals     z0cloned_traverse.<locals>.deferred_copy_internalsr(  r/   r   c                   s   | v r| S t | vrQd|v r'ttt |d | }|d ur'|t | < |S | jdd i| t | < }|jdd i| | jsQ|jd }|rQ|| t |  S )Nr   cloner3   )	idr   r   r   r   r   r   r5  r>   )r(  r/   newelemrL   )r<  clonedr7  r  r3   r5   r<    s"    zcloned_traverse.<locals>.cloneNr:  r  r(  r   r/   r   r0   r   )setr5  )r   r*  r  r:  r3   )r<  r?  r*  r7  r  r5   r%     s   -r   #_TraverseTransformCallableType[Any]c                 C  r1   r2   r3   r   r*  r   r3   r3   r5   r&   3  r4  r&   c                 C  r1   r2   r3   rC  r3   r3   r5   r&   ;  r4  c                 C  r1   r2   r3   rC  r3   r3   r5   r&   C  r4  c                   sb   i dd  dg D dfdd}d fdd | dur- | fd|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.

    c                 S  s   h | ]}t |qS r3   )r=  r"  r3   r3   r5   	<setcomp>h  s    z'replacement_traverse.<locals>.<setcomp>r7  r   r   r0   c                   r8  r2   )r&   r9  )r*  r   r3   r5   r:  j  r;  z5replacement_traverse.<locals>.deferred_copy_internalsr(  r/   r   c                   s   t | v sd| jv r| S | }|d urt | |S t | }|vrPd|v r:|d | }|d ur:||< |S | jdi | |< }|jdd i| | S )Nno_replacement_traverser   r<  r3   )r=  r   addr   r   )r(  r/   r>  id_elem)r<  r?  r   r7  r3   r5   r<  o  s"   
z#replacement_traverse.<locals>.cloneNr:  r  r@  )r5  )r   r*  r   r:  r3   )r<  r?  r*  r   r7  r5   r&   K  s   rY   )r   r	  r*  r+  r0   r
  )r1  r   r   r  r  r2  r0   rA   )r1  r   r   r   r  r2  r0   r   )r1  r   r   r	  r  r2  r0   r	  )r   r  r*  r+  r  r2  r0   rA   )r   r   r*  r+  r  r2  r0   r   )r   r	  r*  r+  r  r2  r0   r	  )r   r   r*  r+  r  r2  r0   r   )r   r  r*  r+  r   rB  r0   rA   )r   r   r*  r+  r   rB  r0   r   )r   r   r*  r+  r   rB  r0   r   )r   r	  r*  r+  r   rB  r0   r	  )NrZ   
__future__r   collectionsr   enumr   r   rR   r]   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r    r   r   r   util._has_cyr   util.typingr   r   r   
annotationr   elementsr   _py_utilr    r!   r*   sqlalchemy.cyextension.util__all__r,   r'   r)   r=   r   r   r   r   ExtendedInternalTraversalr   r   r   r   r   _TraverseCallableTyper   r   r  MemoizedSlotsr(   r  r'  TraversibleClauseVisitorCloningVisitorReplacingCloningVisitorr   r"   r#   r$   r%   r&   r3   r3   r3   r5   <module>   s   
J  4O
!J'2)
$
'
[