Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/sql/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/sql/__pycache__/visitors.cpython-311.pyc

�

�܋fD>���dZddlmZddlZddlmZddlmZgd�ZGd�d	e��Z	d
�Z
Gd�deje	e����Z
Gd
�de��ZGd�de��ZGd�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�
ClauseVisitor�CloningVisitor�ReplacingCloningVisitor�iterate�iterate_depthfirst�traverse_using�traverse�traverse_depthfirst�cloned_traverse�replacement_traversec�"��eZdZdZ�fd�Z�xZS)rarMetaclass 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���|dkrt|d��rt|��tt|���|||��dS)Nr�__visit_name__)�hasattr�_generate_dispatch�superr�__init__)�cls�clsname�bases�clsdict�	__class__s    ��N/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/sql/visitors.pyrzVisitableType.__init__BsT����k�!�!�g�c�3C�&D�&D�!��s�#�#�#�
�m�S�!�!�*�*�7�E�7�C�C�C�C�C�)�__name__�
__module__�__qualname__�__doc__r�
__classcell__)rs@rrr1sK��������� D�D�D�D�D�D�D�D�Dr rc�����d�jvrY�j}t|tjj��rt
jd|z�����fd�}n�fd�}d|_|�_	dSdS)zZReturn an optimized visit dispatch function for the cls
    for use by the compiler.

    r�visit_%sc���	�|��}||fi|��S#t$r4}tjtj|���|���Yd}~dSd}~wwxYw)N��replace_context)�AttributeErrorr�raise_r�UnsupportedCompilationError)�self�visitor�kw�meth�errr�getters     ��r�_compiler_dispatchz._generate_dispatch.<locals>._compiler_dispatchWs����,�!�6�'�?�?�D� �4��+�+��+�+�+��
&�����K��7���E�E�(+������������������s��
A�)A�Ac����d|jz}	t||��}||fi|��S#t$r4}tjtj|���|���Yd}~dSd}~wwxYw)Nr'r))r�getattrr+rr,rr-)r.r/r0�
visit_attrr1r2rs      �rr4z._generate_dispatch.<locals>._compiler_dispatchfs����'�$�*=�=�
�,�"�7�J�7�7�D� �4��+�+��+�+�+��
&�����K��7���E�E�(+������������������s�&�
A$�)A�A$z�Look for an attribute named "visit_" + self.__visit_name__
            on the visitor, and call it with the same kw params.
            N)
�__dict__r�
isinstancer�compat�string_types�operator�
attrgetterr$r4)r�
visit_namer4r3s`  @rrrIs�����
�3�<�'�'��'�
��j�$�+�":�;�;�	,��(��j�)@�A�A�F�	
,�	
,�	
,�	
,�	
,�	
,�	
,�

,�

,�

,�

,�

,�&��"�"4�����O(�'r c��eZdZdZdS)rz�Base class for visitable objects, applies the
    :class:`.visitors.VisitableType` metaclass.

    The :class:`.Visitable` class is essentially at the base of the
    :class:`_expression.ClauseElement` hierarchy.

    N)r!r"r#r$�r rrrxs���������r rc�d�eZdZdZiZd�Zd�Zd�Zej	d���Z
ed���Zd�Z
dS)	r	z�Base class for visitor objects which can traverse using
    the :func:`.visitors.traverse` function.

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

    c�f�|jD](}t|d|jzd��}|r||fi|��cS�)dS)Nr')�visitor_iteratorr6r)r.�objr0�vr1s     r�traverse_singlezClauseVisitor.traverse_single�s^���&�	'�	'�A��1�j�3�+=�=�t�D�D�D��
'��t�C���2���&�&�&�
'�	'�	'r c�,�t||j��S)zaTraverse the given expression structure, returning an iterator
        of all elements.

        )r�__traverse_options__�r.rDs  rrzClauseVisitor.iterate�s��
�s�D�5�6�6�6r c�8�t||j|j��S��2Traverse and visit the given expression structure.)rrH�
_visitor_dictrIs  rrzClauseVisitor.traverse�s����T�6��8J�K�K�Kr c��i}t|��D]2}|�d��rt||��||dd�<�3|S)N�visit_�)�dir�
startswithr6)r.�visitors�names   rrMzClauseVisitor._visitor_dict�sR������I�I�	9�	9�D����x�(�(�
9�%,�T�4�%8�%8���a�b�b��"���r c#�DK�|}|r|V�t|dd��}|�dSdS)z8Iterate through this visitor and each 'chained' visitor.�_nextN)r6)r.rEs  rrCzClauseVisitor.visitor_iterator�sM����
���	*��G�G�G���7�D�)�)�A��	*�	*�	*�	*�	*r c�H�t|j��d}||_|S)z�'Chain' an additional ClauseVisitor onto this ClauseVisitor.

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

        ���)�listrCrV)r.r/�tails   r�chainzClauseVisitor.chain�s%���D�)�*�*�2�.����
��r N)r!r"r#r$rHrFrrr�memoized_propertyrM�propertyrCr[r@r rr	r	�s�����������'�'�'�7�7�7�L�L�L�

��������*�*��X�*�����r r	c��eZdZdZd�Zd�ZdS)r
z�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.


    c� ���fd�|D��S)z`Apply cloned traversal to the given list of elements, and return
        the new list.

        c�:��g|]}��|����Sr@)r)�.0�xr.s  �r�
<listcomp>z3CloningVisitor.copy_and_process.<locals>.<listcomp>�s%���0�0�0�Q��
�
�a� � �0�0�0r r@)r.�list_s` r�copy_and_processzCloningVisitor.copy_and_process�s���
1�0�0�0�%�0�0�0�0r c�8�t||j|j��SrK)rrHrMrIs  rrzCloningVisitor.traverse�s#�����*�D�,>�
�
�	
r N)r!r"r#r$rerr@r rr
r
�s<��������1�1�1�
�
�
�
�
r r
c��eZdZdZd�Zd�ZdS)rz�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.

    c��dS)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.
        Nr@)r.�elems  r�replacezReplacingCloningVisitor.replace�s	���tr c�:���fd�}t|�j|��S)rLc�R���jD]}|�|��}|�|cS�dS)N)rCrj)rirE�er.s   �rrjz1ReplacingCloningVisitor.traverse.<locals>.replace�sA����*�
�
���I�I�d�O�O���=��H�H�H�!�
�
r )rrH)r.rDrjs`  rrz ReplacingCloningVisitor.traverse�s3���	�	�	�	�	�$�C��)B�G�L�L�Lr N)r!r"r#r$rjrr@r rrr�sA�����������	M�	M�	M�	M�	Mr rc�$�|jdi|��}|s|gSt��}t|g��}|rP|���}|�|��|jdi|��D]}|�|���|�Pt	|��S)arTraverse the given expression structure, returning an iterator.

    Traversal is configured to be breadth-first.

    The central API feature used by the :func:`.visitors.iterate` and
    :func:`.visitors.iterate_depthfirst` functions 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.

    r@)�get_childrenr�popleft�append�iter)rD�opts�children�	traversal�stack�t�cs       rrr�s���, �s��'�'�$�'�'�H����u�����I��3�%�L�L�E�
���M�M�O�O������������'�'�$�'�'�	�	�A��L�L��O�O�O�O�	��
�	�?�?�r c�$�|jdi|��}|s|gSt|g��}t��}|rP|���}|�|��|jdi|��D]}|�|���|�Pt|��S)a�Traverse the given expression structure, returning an iterator.

    Traversal is configured to be depth-first.

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

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

    .. seealso::

        :func:`.visitors.iterate` - includes a general overview of iteration.

    r@)ror�pop�
appendleftrqrr)rDrsrtrvrurwrxs       rr
r
s���  �s��'�'�$�'�'�H����u���3�%�L�L�E����I�
���I�I�K�K�����Q�������'�'�$�'�'�	�	�A��L�L��O�O�O�O�	��
�	�?�?�r c�`�|D]*}|�|jd��}|r||���+|S)aeVisit 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` or :func:`.visitors.traverse_depthfirst`
    functions.

    :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` or
     :func:`.visitors.iterate_depthfirst` functions.

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

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

    .. seealso::

        :func:`.traverse`

        :func:`.traverse_depthfirst`

    N)�getr)�iteratorrDrS�targetr1s     rrr5sD��8�����|�|�F�1�4�8�8���	��D��L�L�L���Jr c�@�tt||��||��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.

    )rr�rDrsrSs   rrrXs ��<�'�#�t�,�,�c�8�<�<�<r c�@�tt||��||��S)a/traverse and visit the given expression structure using the
    depth-first iterator.

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

    Usage is the same as that of :func:`.visitors.traverse` function.


    )rr
r�s   rrrys!���,�S�$�7�7��h�G�G�Gr c������i�t|�dg���������fd��|��|��}d�|S)a�Clone the given expression structure, allowing modifications by
    visitors.

    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 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_onc���|�vr|St|���vr]|���x�t|��<}|jdd�i|����|jd��}|r||���t|��S)N�cloner@)�id�_clone�_copy_internalsr}r)rir0�newelemr1r��clonedr�rSs    ����rr�zcloned_traverse.<locals>.clone�s�����7�?�?��K��$�x�x�v�%�%�-1�[�[�]�]�:��r�$�x�x� �7�'��'�:�:�e�:�r�:�:�:��|�|�G�$:�D�A�A���"��D��M�M�M��"�T�(�(�#�#r N)�setr})rDrsrSr�r�r�s  `@@@rrr�sn������6�F��$�(�(�9�b�)�)�*�*�G�
$�
$�
$�
$�
$�
$�
$�
$����e�C�j�j���E��Jr c�|�����i�d�|�dg��D�������fd��|�	�|fi|��}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�,�h|]}t|����Sr@)r�)rarbs  r�	<setcomp>z'replacement_traverse.<locals>.<setcomp>�s��6�6�6��r�!�u�u�6�6�6r r�c���t|���vs	d|jvr|S�|��}|�$��t|����|S|�vr(|���x�|<}|jdd�i|���|S)N�no_replacement_traverser�r@)r��_annotations�addr�r�)rir0r�r�r�rjr�s   ����rr�z#replacement_traverse.<locals>.clone�s�����t�H�H����(�D�,=�=�=��K��g�d�m�m�G��"����B�w�K�K�(�(�(����v�%�%�-1�[�[�]�]�:�F�4�L�7�+�G�+�>�>�%�>�2�>�>�>��d�|�#r N)r})rDrsrjr�r�r�s  `@@@rrr�s~������0�F�6�6�d�h�h�y�"�5�5�6�6�6�G�$�$�$�$�$�$�$�$�"���e�C� � �4� � ���E��Jr )r$�collectionsrr<�rr�__all__�typerr�with_metaclass�objectrr	r
rrr
rrrrrr@r r�<module>r�s�����$����������������������
�
�
�� D�D�D�D�D�D�D�D�D�0,4�,4�,4�^�����#��#�M�6�:�:����7�7�7�7�7�F�7�7�7�t
�
�
�
�
�]�
�
�
�2M�M�M�M�M�n�M�M�M�<!�!�!�H���< � � �F=�=�=�BH�H�H�-�-�-�`/�/�/�/�/r 

Hacked By AnonymousFox1.0, Coded By AnonymousFox