o
    tBh'4                  	   @   s  d dl m Z  d dlmZ d dlmZmZmZmZmZm	Z	m
Z
mZmZ ddlmZmZ ddlmZ ddlmZmZ g d	ZG d
d deZe
e ZejZejZejZdZeeeedf f ZG dd de	ZG dd dZG dd de	Z	ddedede
e defddZ G dd deZ!dS )    )copy)Enum)	AnyCallable
CollectionDictList
NamedTupleOptionalTupleUnion   )inspectsnake_to_camel   )ast)NodeQUERY_DOCUMENT_KEYS)VisitorParallelVisitorVisitorActionvisitBREAKSKIPREMOVEIDLEc                   @   s   e Zd ZdZdZdZeZdS )VisitorActionEnumzkSpecial return values for the visitor methods.

    You can also use the values of this enum directly.
    TFN)__name__
__module____qualname____doc__r   r   Ellipsisr    r"   r"   o/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/graphql/language/visitor.pyr       s
    r   N.c                   @   sB   e Zd ZU dZeedee f  ed< eedee f  ed< dS )EnterLeaveVisitorz0Visitor with functions for entering and leaving..enterleaveN)r   r   r   r    r
   r   r   __annotations__r"   r"   r"   r#   r$   8   s   
 r$   c                       s   e Zd ZU dZeeeef\ZZZZee	e
f ed< d fddZdddZd	e	de
fd
dZ	dd	e	dedeedee f  fddZ  ZS )r   a  Visitor that walks through an AST.

    Visitors can define two generic methods "enter" and "leave". The former will be
    called when a node is entered in the traversal, the latter is called after visiting
    the node and its child nodes. These methods have the following signature::

        def enter(self, node, key, parent, path, ancestors):
            # The return value has the following meaning:
            # IDLE (None): no action
            # SKIP: skip visiting this node
            # BREAK: stop visiting altogether
            # REMOVE: delete this node
            # any other value: replace this node with the returned value
            return

        def leave(self, node, key, parent, path, ancestors):
            # The return value has the following meaning:
            # IDLE (None) or SKIP: no action
            # BREAK: stop visiting altogether
            # REMOVE: delete this node
            # any other value: replace this node with the returned value
            return

    The parameters have the following meaning:

    :arg node: The current node being visiting.
    :arg key: The index or key to this node from the parent node or Array.
    :arg parent: the parent immediately above this node, which may be an Array.
    :arg path: The key path to get to this node from the root node.
    :arg ancestors: All nodes and Arrays visited before reaching parent
        of this node. These correspond to array indices in ``path``.
        Note: ancestors includes arrays which contain the parent of visited node.

    You can also define node kind specific methods by suffixing them with an underscore
    followed by the kind of the node to be visited. For instance, to visit ``field``
    nodes, you would defined the methods ``enter_field()`` and/or ``leave_field()``,
    with the same signature as above. If no kind specific method has been defined
    for a given node, the generic method is called.
    enter_leave_mapreturnNc                    s   t    | j D ]C\}}|drq
|dd}t|dk r#d}n|\}}|dv rM|rMt|d }tt	|d}|rEt
|trEt|tsMtd| dq
dS )	z+Verify that all defined handlers are valid._r   r   N)r%   r&   r   zInvalid AST node kind: .)super__init_subclass____dict__items
startswithsplitlenr   getattrr   
isinstancetype
issubclassr   	TypeError)clsattrval	attr_kindkindnamenode_cls	__class__r"   r#   r-   m   s(   

zVisitor.__init_subclass__c                 C   s
   i | _ d S N)r(   )selfr"   r"   r#   __init__   s   
zVisitor.__init__r<   c                 C   s|   z| j | W S  ty=   t| d| d}|st| dd}t| d| d}|s/t| dd}t||}|| j |< | Y S w )>Given a node kind, return the EnterLeaveVisitor for that kind.enter_Nr%   leave_r&   )r(   KeyErrorr3   r$   )rB   r<   enter_fnleave_fnenter_leaver"   r"   r#   get_enter_leave_for_kind   s   

z Visitor.get_enter_leave_for_kindF
is_leaving.c                 C   s   |  |}|r
|jS |jS )zGet the visit function for the given node kind and direction.

        .. deprecated:: 3.2
           Please use ``get_enter_leave_for_kind`` instead. Will be removed in v3.3.
        )rK   r&   r%   )rB   r<   rL   rJ   r"   r"   r#   get_visit_fn   s   
zVisitor.get_visit_fn)r)   N)F)r   r   r   r    r   r   r   r   r   strr$   r'   r-   rC   rK   boolr
   r   r   rM   __classcell__r"   r"   r?   r#   r   ?   s   
 )
r   c                   @   sV   e Zd ZU dZeed< eed< eedf ed< e	ee
eef ef  ed< eed< dS )	StackzA stack for the visit function.in_arrayidx.keyseditsprevN)r   r   r   r    rO   r'   intr   r   r   r   rN   r   r"   r"   r"   r#   rQ      s   
 rQ   rootvisitorvisitor_keysr)   c                 C   s"  t | tstdt|  dt |tstdt| d|du r$t}d}d}| f}d}g }| }d}	d}
g }|j}|j}g }|j}|j}	 |d7 }|t|k}|oS|}|r|r\|d nd}	|
}|re| nd}
|r|rt	|}d	}|D ]\}}|| }|t
u s|tu r|| |d7 }qs|||< qst|}nt|}|D ]
\}}t||| q|j}|j}|j}|j}|j}n|
r|r|}	|
|	 }n
|| }	t|
|	d}|du rqE||	 t |trd}ndt |tstd
t| d||j}|r|jn|j}|r@|||	|
||}|tu s|du rnu|tu s|du r#|s"|  qEn|dur?||	|f |s?t |tr;|}n|  qEnd}|du rQ|rQ||	|f |r[|rZ|  n&t|||||}t |t}|rm|n||jd}d}g }|
r||
 |}
|snqF|r|d d S | S )a  Visit each node in an AST.

    :func:`~.visit` will walk through an AST using a depth-first traversal, calling the
    visitor's enter methods at each node in the traversal, and calling the leave methods
    after visiting that node and all of its child nodes.

    By returning different values from the enter and leave methods, the behavior of the
    visitor can be altered, including skipping over a sub-tree of the AST (by returning
    False), editing the AST by returning a value or None to remove the value, or to stop
    the whole traversal by returning :data:`~.BREAK`.

    When using :func:`~.visit` to edit an AST, the original AST will not be modified,
    and a new version of the AST with the changes applied will be returned from the
    visit function.

    To customize the node attributes to be used for traversal, you can provide a
    dictionary visitor_keys mapping node kinds to node attributes.
    zNot an AST Node: r+   zNot an AST Visitor: NFTr   r   zInvalid AST Node: r"   )r4   r   r7   r   r   r   appendpopr2   listr   r!   tupler   setattrrS   rT   rU   rR   rV   r3   rK   r<   r&   r%   r   r   rQ   get)rX   rY   rZ   stackrR   rT   rS   rU   nodekeyparentpathpath_appendpath_pop	ancestorsancestors_appendancestors_poprL   	is_editededit_offsetedit_key
edit_value	array_keyresultrJ   visit_fnr"   r"   r#   r      s   










Xr   c                       s<   e Zd ZdZdee f fddZdedefddZ	  Z
S )	r   zA Visitor which delegates to many visitors to run in parallel.

    Each visitor will be visited for each node before moving on.

    If a prior visitor edits a node, no following visitors will see that node.
    visitorsc                    s$   t    || _dgt| | _dS )z>Create a new visitor from the given list of parallel visitors.N)r,   rC   rs   r2   skipping)rB   rs   r?   r"   r#   rC   ;  s   
zParallelVisitor.__init__r<   r)   c              
      s   zj | W S  tyg   d}g  g jD ]}||\}}|s'|s%|r'd} | | q|rUdtdtdtt f fdd}dtdtdtt ffdd	}nd
 }}t	||}|j |< | Y S w )rD   FTrc   argsr)   c                    s|   j }t D ]4\}}|| s;|r;|| g|R  }|tu s!|du r&| ||< q|tu s.|du r3t||< q|d ur;|  S qd S )NFT)rt   	enumerater   r   rc   ru   rt   ifnrq   )
enter_listrB   r"   r#   r%   R  s   

z7ParallelVisitor.get_enter_leave_for_kind.<locals>.enterc                    s   j }t D ]:\}}|| s7|r6|| g|R  }|tu s!|du r&t||< q|d ur6|tur6|dur6|  S q|| | u rAd ||< qd S )NTF)rt   rv   r   r   rw   )
leave_listrB   r"   r#   r&   `  s    
z7ParallelVisitor.get_enter_leave_for_kind.<locals>.leaveN)
r(   rG   rs   rK   r\   r   r   r
   r   r$   )rB   r<   has_visitorrY   r%   r&   rJ   r"   )rz   r{   rB   r#   rK   A  s(   

 "

z(ParallelVisitor.get_enter_leave_for_kind)r   r   r   r    r   r   rC   rN   r$   rK   rP   r"   r"   r?   r#   r   3  s    r   rA   )"r   enumr   typingr   r   r   r   r   r	   r
   r   r   pyutilsr   r    r   r   r   __all__r   r   r   r   r   r   rN   VisitorKeyMapr$   r   rQ   r   r   r"   r"   r"   r#   <module>   s:    ,a
 
