
    Mh?                        d dl mZmZ d dlmZmZmZmZ d dlm	Z	 ddde
ddfd	Z G d
 d          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          ZdS )    )abstractmethodabstractproperty)ListOptionalTupleUnion)split_linesnode
NodeOrLeaf
node_typesreturnOptional[BaseNode]c                 @    | j         }||j        |v r|S |j         }|dS )an  
    Recursively looks at the parents of a node and returns the first found node
    that matches ``node_types``. Returns ``None`` if no matching node is found.

    This function is deprecated, use :meth:`NodeOrLeaf.search_ancestor` instead.

    :param node: The ancestors of this node will be checked.
    :param node_types: type names that are searched for.
    Nparenttype)r
   r   ns      J/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/parso/tree.pysearch_ancestorr      s7     	A
-6ZHH - 4    c                   B   e Zd ZU dZdZeed<   	 ded<   	 d Zd Zd Z	d	 Z
d
 Zedeeef         fd            Zedeeef         fd            Zed             Zed             Zed             Zedd            ZdeddfdZdddeeeef                  defdZdS )r   z.
    The base class for nodes and leaves.
    r   r   r   r   c                 4    | }|j         |j         }|j         |S )z
        Returns the root node of a parser tree. The returned node doesn't have
        a parent node like all the other nodes/leaves.
        r   )selfscopes     r   get_root_nodezNodeOrLeaf.get_root_node(   s'    
 l&LE l&r   c                     | j         }|dS t          |j                  D ]3\  }}|| u r*	 | j         j        |dz            c S # t          $ r Y  dS w xY w4dS )z
        Returns the node immediately following this node in this parent's
        children list. If this node does not have a next sibling, it is None
        N   )r   	enumeratechildren
IndexErrorr   r   ichilds       r   get_next_siblingzNodeOrLeaf.get_next_sibling2   s    
 >4 "&/22 	  	 HAu}} ;/A6666!      444  	  	 s   A
AAc                     | j         }|dS t          |j                  D ])\  }}|| u r |dk    r dS | j         j        |dz
           c S *dS )z
        Returns the node immediately preceding this node in this parent's
        children list. If this node does not have a previous sibling, it is
        None.
        Nr   r   )r   r   r    r"   s       r   get_previous_siblingzNodeOrLeaf.get_previous_siblingC   sv     >4 "&/22 	3 	3HAu}}6644{+AE2222 	3 	3r   c                     | j         dS | }	 |j         j        }|                    |          }|dk    r|j         }|j         dS n||dz
           }nE	 	 |j        d         }n# t          $ r |cY S w xY w")z
        Returns the previous leaf in the parser tree.
        Returns `None` if this is the first element in the parser tree.
        NTr   r   )r   r    indexAttributeErrorr   r
   cr#   s       r   get_previous_leafzNodeOrLeaf.get_previous_leafT   s    
 ;4		$AAAvv{;&4 ' Qx			}R(!   	s   A" "A10A1c                 
   | j         dS | }	 |j         j        }|                    |          }|t          |          dz
  k    r|j         }|j         dS n||dz            }nU	 	 |j        d         }n# t          $ r |cY S w xY w")z
        Returns the next leaf in the parser tree.
        Returns None if this is the last element in the parser tree.
        NTr   r   )r   r    r*   lenr+   r,   s       r   get_next_leafzNodeOrLeaf.get_next_leafn   s    
 ;4		$AACFFQJ{;&4 ' Qx			}Q'!   	s   $A2 2B Br   c                     dS )z
        Returns the starting position of the prefix as a tuple, e.g. `(3, 4)`.

        :return tuple of int: (line, column)
        N r   s    r   	start_poszNodeOrLeaf.start_pos         r   c                     dS )z
        Returns the end position of the prefix as a tuple, e.g. `(3, 4)`.

        :return tuple of int: (line, column)
        Nr3   r4   s    r   end_poszNodeOrLeaf.end_pos   r6   r   c                     dS )a-  
        Returns the start_pos of the prefix. This means basically it returns
        the end_pos of the last prefix. The `get_start_pos_of_prefix()` of the
        prefix `+` in `2 + 1` would be `(1, 1)`, while the start_pos is
        `(1, 2)`.

        :return tuple of int: (line, column)
        Nr3   r4   s    r   get_start_pos_of_prefixz"NodeOrLeaf.get_start_pos_of_prefix   r6   r   c                     dS )zO
        Returns the first leaf of a node or itself if this is a leaf.
        Nr3   r4   s    r   get_first_leafzNodeOrLeaf.get_first_leaf   r6   r   c                     dS )zN
        Returns the last leaf of a node or itself if this is a leaf.
        Nr3   r4   s    r   get_last_leafzNodeOrLeaf.get_last_leaf   r6   r   Tc                     dS )z
        Returns the code that was the input for the parser for this node.

        :param include_prefix: Removes the prefix (whitespace and comments) of
            e.g. a statement.
        Nr3   r   include_prefixs     r   get_codezNodeOrLeaf.get_code   r6   r   r   c                 @    | j         }||j        |v r|S |j         }|dS )a  
        Recursively looks at the parents of this node or leaf and returns the
        first found node that matches ``node_types``. Returns ``None`` if no
        matching node is found.

        :param node_types: type names that are searched for.
        Nr   )r   r   r
   s      r   r   zNodeOrLeaf.search_ancestor   s9     {yJ&&;D  tr      )indentrE   c          	         |ddnIt          |t                    rdd|z  n,t          |t                    rd|nt          d|          ddt          dt          d	t
          d
t          ffd |           S )a  
        Returns a formatted dump of the parser tree rooted at this node or leaf. This is
        mainly useful for debugging purposes.

        The ``indent`` parameter is interpreted in a similar way as :py:func:`ast.dump`.
        If ``indent`` is a non-negative integer or string, then the tree will be
        pretty-printed with that indent level. An indent level of 0, negative, or ``""``
        will only insert newlines. ``None`` selects the single line representation.
        Using a positive integer indent indents that many spaces per level. If
        ``indent`` is a string (such as ``"\t"``), that string is used to indent each
        level.

        :param indent: Indentation style as described above. The default indentation is
            4 spaces, which yields a pretty-printed dump.

        >>> import parso
        >>> print(parso.parse("lambda x, y: x + y").dump())
        Module([
            Lambda([
                Keyword('lambda', (1, 0)),
                Param([
                    Name('x', (1, 7), prefix=' '),
                    Operator(',', (1, 8)),
                ]),
                Param([
                    Name('y', (1, 10), prefix=' '),
                ]),
                Operator(':', (1, 11)),
                PythonNode('arith_expr', [
                    Name('x', (1, 13), prefix=' '),
                    Operator('+', (1, 15), prefix=' '),
                    Name('y', (1, 17), prefix=' '),
                ]),
            ]),
            EndMarker('', (1, 18)),
        ])
        NF T z,expect 'indent' to be int, str or None, got r
   rE   	top_levelr   c                    d}t          |           j        }t          | t                    r}|| | dz  }t          | t                    r|| j        dz  }n"t          | t                    r|| j         dz  }|| j        d| j        z  }| j	        r|d| j	        z  }|dz  }nt          | t                    r_|| | dz  }t          | t                    r|| j         dz  }|dz  }r|dz  }| j        D ]}| ||z   d	          z  }|| d
z  }nt          d|           |sr|dz  }n|dz  }|S )NrG   (, z	, prefix=)[
F)rE   rI   z])zunsupported node encountered: z,
)r   __name__
isinstanceLeaf	ErrorLeaf
token_type	TypedLeafvaluer5   prefixBaseNodeNoder    	TypeError)	r
   rE   rI   result	node_typer$   _format_dumpindent_stringnewlines	         r   r]   z%NodeOrLeaf.dump.<locals>._format_dump   s   FT

+I$%% KV1Y1111dI.. 16666FFi00 10000FTZ??T^???; :9$+999F#D(++ KV1Y1111dD)) 10000F# #dNF!] b bEll5-9O[`aaaaFFV---'   I I IJJJ # #eOFFdNFMr   )rG   T)rQ   intstrrZ   r   bool)r   rE   r]   r^   r_   s     @@@r   dumpzNodeOrLeaf.dump   s    L >GMM$$ 	WG&LMM$$ 	WG"MMU6UUVVV"	 "	z "	3 "	 "	X[ "	 "	 "	 "	 "	 "	 "	 "	H |D!!!r   NT)rP   
__module____qualname____doc__	__slots__ra   __annotations__r   r%   r'   r.   r1   r   r   r`   r5   r8   r   r:   r<   r>   rB   r   r   r   rc   r3   r   r   r   r      s          I
III !   
       "3 3 3"  4  4 5c?     sCx       ^   ^
   ^
    ^3 3G     ;< V" V" V"huS#X7 V" V" V" V" V" V" V"r   c            	           e Zd ZU dZdZeed<   ddedeeef         deddfd	Z	e
deeef         fd
            Zej        deeef         ddfd            Zd Zd Zd ZddZe
deeef         fd            Zd ZdS )rR   z
    Leafs are basically tokens with a better API. Leafs exactly know where they
    were defined and what text preceeds them.
    )rV   linecolumnrW   rW   rG   rV   r5   r   Nc                 B    || _         	 || _        || _        	 d | _        d S N)rV   r5   rW   r   )r   rV   r5   rW   s       r   __init__zLeaf.__init__(  s6    
	 #	 +/	 	r   c                     | j         | j        fS rn   rk   rl   r4   s    r   r5   zLeaf.start_pos8  s    y$+%%r   c                 :    |d         | _         |d         | _        d S )Nr   r   rq   r   rV   s     r   r5   zLeaf.start_pos<  s    !H	Ahr   c                     |                                  }|0t          | j                  }| j        t	          |          z
  dz   dfS |j        S )Nr   r   )r.   r	   rW   rk   r0   r8   )r   previous_leafliness      r   r:   zLeaf.get_start_pos_of_prefixA  sN    ..00 ,,E9s5zz)A-q00$$r   c                     | S rn   r3   r4   s    r   r<   zLeaf.get_first_leafI      r   c                     | S rn   r3   r4   s    r   r>   zLeaf.get_last_leafL  rx   r   Tc                 2    |r| j         | j        z   S | j        S rn   )rW   rV   r@   s     r   rB   zLeaf.get_codeO  s!     	;++:r   c                     t          | j                  }| j        t          |          z   dz
  }| j        |k    r| j        t          |d                   z   }nt          |d                   }||fS )Nr   r)   )r	   rV   rk   r0   rl   )r   rv   end_pos_lineend_pos_columns       r   r8   zLeaf.end_posU  sg    DJ''y3u::-19$$![3uRy>>9NN r^^N^++r   c                 X    | j         }|s| j        }dt          |           j        d|dS )N<: >)rV   r   rP   rs   s     r   __repr__zLeaf.__repr__`  s7    
 	IE!$ZZ000%%%88r   rG   rd   )rP   re   rf   rg   rh   ra   ri   r   r`   ro   propertyr5   setterr:   r<   r>   rB   r8   r   r3   r   r   rR   rR      sV          6IKKK c eCHo s TX      &5c? & & & X& uS#X 4    % % %        ,sCx , , , X,9 9 9 9 9r   rR   c                   $     e Zd ZdZd fd	Z xZS )rU   r   rG   c                 \    t                                          |||           || _        d S rn   superro   r   )r   r   rV   r5   rW   	__class__s        r   ro   zTypedLeaf.__init__j  s*    	6222			r   r   )rP   re   rf   rh   ro   __classcell__r   s   @r   rU   rU   g  sB        I         r   rU   c                       e Zd ZdZdZdee         ddfdZede	e
e
f         fd            Zd Zede	e
e
f         fd	            Zd
 ZddZddZd Zd Zd ZdS )rX   zd
    The super class for all nodes.
    A node has children, a type and possibly a parent node.
    )r    r    r   Nc                 >    || _         	 d | _        	 |D ]	}| |_        
d S rn   )r    r   )r   r    r$   s      r   ro   zBaseNode.__init__v  s@     	 +/	  	  	 EELL	  	 r   c                 &    | j         d         j        S Nr   )r    r5   r4   s    r   r5   zBaseNode.start_pos  s    }Q))r   c                 @    | j         d                                         S r   )r    r:   r4   s    r   r:   z BaseNode.get_start_pos_of_prefix  s    }Q77999r   c                 &    | j         d         j        S Nr)   )r    r8   r4   s    r   r8   zBaseNode.end_pos  s    }R ((r   c                     |rd                     d |D                       S |d                             d          }|d                     d |dd          D                       z   S )NrG   c              3   >   K   | ]}|                                 V  d S rn   rB   .0r-   s     r   	<genexpr>z2BaseNode._get_code_for_children.<locals>.<genexpr>  s*      ::A1::<<::::::r   r   F)rA   c              3   >   K   | ]}|                                 V  d S rn   r   r   s     r   r   z2BaseNode._get_code_for_children.<locals>.<genexpr>  s*      "F"FA1::<<"F"F"F"F"F"Fr   r   )joinrB   )r   r    rA   firsts       r   _get_code_for_childrenzBaseNode._get_code_for_children  st     	G77::::::::QK(((>>E277"F"F!"""F"F"FFFFFr   Tc                 8    |                      | j        |          S rn   )r   r    r@   s     r   rB   zBaseNode.get_code  s    **4=.IIIr   Fc                       fddcxk    r j         d         j        k    sn t          d           dt           j                   dz
            S )ax  
        Get the :py:class:`parso.tree.Leaf` at ``position``

        :param tuple position: A position tuple, row, column. Rows start from 1
        :param bool include_prefixes: If ``False``, ``None`` will be returned if ``position`` falls
            on whitespace or comments before a leaf
        :return: :py:class:`parso.tree.Leaf` at ``position``, or ``None``
        c                 *   | |k    rEj         |          }s|j        k     rd S 	 |                              S # t          $ r |cY S w xY wt	          | |z   dz            }j         |         }|j        k    r | |          S  |dz   |          S )N   r   )r    r5   get_leaf_for_positionr+   r`   r8   )lowerupperelementr*   binary_searchinclude_prefixespositionr   s       r   r   z5BaseNode.get_leaf_for_position.<locals>.binary_search  s    ~~-.'  Hw7H,H,H4#"88CSTTT% # # #"NNN# !+,,EmE*G7?**$}UE222$}UQY666s   ; A
	A
)r   r   r)   z7Please provide a position that exists within this node.r   r   )r    r8   
ValueErrorr0   )r   r   r   r   s   ```@r   r   zBaseNode.get_leaf_for_position  s    	7 	7 	7 	7 	7 	7 	7 	7& (????dmB&7&?????VWWW}QDM 2 2Q 6777r   c                 @    | j         d                                         S r   )r    r<   r4   s    r   r<   zBaseNode.get_first_leaf  s    }Q..000r   c                 @    | j         d                                         S r   )r    r>   r4   s    r   r>   zBaseNode.get_last_leaf  s    }R ..000r   c           	         |                                                      dd                              dd                                          }dt          |           j        d|d| j        d         d| j        d	         d
	S )NrO   rH   r   r   @r   ,r   r   )rB   replacestripr   rP   r5   )r   codes     r   r   zBaseNode.__repr__  s    }}&&tS1199$DDJJLL$ZZ   $$$q(9(9(94>!;L;L;LN 	Nr   rd   )F)rP   re   rf   rg   rh   r   r   ro   r   r   r`   r5   r:   r8   r   rB   r   r<   r>   r   r3   r   r   rX   rX   o  s*         I j!1  d         *5c? * * * X*: : : )sCx ) ) ) X)G G GJ J J J8 8 8 8@1 1 11 1 1N N N N Nr   rX   c                   ,     e Zd ZdZdZ fdZd Z xZS )rY   z+Concrete implementation for interior nodes.r   c                 X    t                                          |           || _        d S rn   r   )r   r   r    r   s      r   ro   zNode.__init__  s&    """			r   c                 @    | j         j        d| j        d| j        dS )NrK   rL   rM   )r   rP   r   r    r4   s    r   r   zNode.__repr__  s&    #~666			4===QQr   )rP   re   rf   rg   rh   ro   r   r   r   s   @r   rY   rY     sY        55I    R R R R R R Rr   rY   c                       e Zd ZdZdZdZdS )	ErrorNodez
    A node that contains valid nodes/leaves that we're follow by a token that
    was invalid. This basically means that the leaf after this node is where
    Python would mark a syntax error.
    r3   
error_nodeN)rP   re   rf   rg   rh   r   r3   r   r   r   r     s$         
 IDDDr   r   c                   2     e Zd ZdZdZdZd fd	Zd Z xZS )rS   z
    A leaf that is either completely invalid in a language (like `$` in Python)
    or is invalid at that position. Like the star in `1 +* 1`.
    )rT   
error_leafrG   c                 \    t                                          |||           || _        d S rn   )r   ro   rT   )r   rT   rV   r5   rW   r   s        r   ro   zErrorLeaf.__init__  s*    	6222$r   c           	      |    dt          |           j        d| j        dt          | j                  d| j        d	S )Nr   r   :rL   r   )r   rP   rT   reprrV   r5   r4   s    r   r   zErrorLeaf.__repr__  sD     $ZZ   $///4
3C3C3C3CT^^^U 	Ur   r   )	rP   re   rf   rg   rh   r   ro   r   r   r   s   @r   rS   rS     si           ID% % % % % %U U U U U U Ur   rS   N)abcr   r   typingr   r   r   r   parso.utilsr	   ra   r   r   rR   rU   rX   rY   r   rS   r3   r   r   <module>r      s   0 0 0 0 0 0 0 0 / / / / / / / / / / / / # # # # # #, S =Q    $D" D" D" D" D" D" D" D"ND9 D9 D9 D9 D9: D9 D9 D9N       RN RN RN RN RNz RN RN RNj	R 	R 	R 	R 	R8 	R 	R 	R       U U U U U U U U U Ur   