ó
MšV]c           @   sé   d  d l  m Z m Z d  d l m Z m Z m Z d  d l m Z d „  Z	 d e
 f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   abstractmethodt   abstractproperty(   t	   utf8_reprt   encodingt
   py_version(   t   split_linesc         G   s9   x2 t  r4 |  j }  |  d k s- |  j | k r |  Sq Wd S(   s;  
    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.

    :param node: The ancestors of this node will be checked.
    :param node_types: type names that are searched for.
    :type node_types: tuple of str
    N(   t   Truet   parentt   Nonet   type(   t   nodet
   node_types(    (    s)   lib/python2.7/site-packages/parso/tree.pyt   search_ancestor   s    			t
   NodeOrLeafc           B   s¤   e  Z d  Z d Z d Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d	 „  ƒ Z e d
 „  ƒ Z e e d „ ƒ Z RS(   s.   
    The base class for nodes and leaves.
    c         C   s)   |  } x | j  d k	 r$ | j  } q	 W| S(   s   
        Returns the root node of a parser tree. The returned node doesn't have
        a parent node like all the other nodes/leaves.
        N(   R   R   (   t   selft   scope(    (    s)   lib/python2.7/site-packages/parso/tree.pyt   get_root_node    s    c         C   sa   xZ t  |  j j ƒ D]F \ } } | |  k r y |  j j | d SWqY t k
 rU d SXq q Wd S(   s    
        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
        i   N(   t	   enumerateR   t   childrent
   IndexErrorR   (   R   t   it   child(    (    s)   lib/python2.7/site-packages/parso/tree.pyt   get_next_sibling*   s    c         C   sU   xN t  |  j j ƒ D]: \ } } | |  k r | d k r; d S|  j j | d Sq Wd S(   s­   
        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.
        i    i   N(   R   R   R   R   (   R   R   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyt   get_previous_sibling7   s
    c         C   sŸ   |  } x_ t  rg | j j } | j | ƒ } | d k rU | j } | j d k rd d Sq	 | | d } Pq	 Wx0 t  rš y | j d } Wqk t k
 r– | SXqk Wd S(   s‡   
        Returns the previous leaf in the parser tree.
        Returns `None` if this is the first element in the parser tree.
        i    i   iÿÿÿÿN(   R   R   R   t   indexR   t   AttributeError(   R   R
   t   cR   (    (    s)   lib/python2.7/site-packages/parso/tree.pyt   get_previous_leafD   s    			c         C   s©   |  } xi t  rq | j j } | j | ƒ } | t | ƒ d k r_ | j } | j d k rn d Sq	 | | d } Pq	 Wx0 t  r¤ y | j d } Wqu t k
 r  | SXqu Wd S(   s€   
        Returns the next leaf in the parser tree.
        Returns None if this is the last element in the parser tree.
        i   i    N(   R   R   R   R   t   lenR   R   (   R   R
   R   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyt   get_next_leaf[   s    			c         C   s   d S(   s†   
        Returns the starting position of the prefix as a tuple, e.g. `(3, 4)`.

        :return tuple of int: (line, column)
        N(    (   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyt	   start_posr   t    c         C   s   d S(   s   
        Returns the end position of the prefix as a tuple, e.g. `(3, 4)`.

        :return tuple of int: (line, column)
        N(    (   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyt   end_posz   R   c         C   s   d S(   s-  
        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)
        N(    (   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyt   get_start_pos_of_prefix‚   R   c         C   s   d S(   sO   
        Returns the first leaf of a node or itself if this is a leaf.
        N(    (   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyt   get_first_leaf   R   c         C   s   d S(   sN   
        Returns the last leaf of a node or itself if this is a leaf.
        N(    (   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyt   get_last_leaf“   R   c         C   s   d S(   sÇ   
        Returns the code that was input the input for the parser for this node.

        :param include_prefix: Removes the prefix (whitespace and comments) of
            e.g. a statement.
        N(    (   R   t   include_prefix(    (    s)   lib/python2.7/site-packages/parso/tree.pyt   get_code™   R   (    N(   t   __name__t
   __module__t   __doc__t	   __slots__R   R	   R   R   R   R   R   R   R   R    R    R!   R"   R#   R   R%   (    (    (    s)   lib/python2.7/site-packages/parso/tree.pyR      s   	
				t   Leafc           B   s†   e  Z d  Z d Z d d „ Z e d „  ƒ Z e j d	 „  ƒ Z d
 „  Z d „  Z	 d „  Z
 e d „ Z e d „  ƒ Z e d „  ƒ Z RS(   sƒ   
    Leafs are basically tokens with a better API. Leafs exactly know where they
    were defined and what text preceeds them.
    t   valueR   t   linet   columnt   prefixR   c         C   s(   | |  _  | |  _ | |  _ d  |  _ d  S(   N(   R+   R   R.   R   R   (   R   R+   R   R.   (    (    s)   lib/python2.7/site-packages/parso/tree.pyt   __init__ª   s
    				c         C   s   |  j  |  j f S(   N(   R,   R-   (   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR   º   s    c         C   s   | d |  _  | d |  _ d  S(   Ni    i   (   R,   R-   (   R   R+   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR   ¾   s    c         C   sI   |  j  ƒ  } | d  k rB t |  j ƒ } |  j t | ƒ d d f S| j S(   Ni   i    (   R   R   R   R.   R,   R   R    (   R   t   previous_leaft   lines(    (    s)   lib/python2.7/site-packages/parso/tree.pyR!   Ã   s
    c         C   s   |  S(   N(    (   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR"   Ë   s    c         C   s   |  S(   N(    (   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR#   Î   s    c         C   s   | r |  j  |  j S|  j Sd  S(   N(   R.   R+   (   R   R$   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR%   Ñ   s    c         C   si   t  |  j ƒ } |  j t | ƒ d } |  j | k rO |  j t | d ƒ } n t | d ƒ } | | f S(   Ni   iÿÿÿÿ(   R   R+   R,   R   R-   (   R   R1   t   end_pos_linet   end_pos_column(    (    s)   lib/python2.7/site-packages/parso/tree.pyR    ×   s    c         C   s2   |  j  } | s |  j } n  d t |  ƒ j | f S(   Ns   <%s: %s>(   R+   R	   R&   (   R   R+   (    (    s)   lib/python2.7/site-packages/parso/tree.pyt   __repr__â   s    	(   R+   R   R,   R-   R.   (   R&   R'   R(   R)   R/   t   propertyR   t   setterR!   R"   R#   R   R%   R    R   R4   (    (    (    s)   lib/python2.7/site-packages/parso/tree.pyR*   £   s   			t	   TypedLeafc           B   s   e  Z d Z d d „ Z RS(   R	   R   c         C   s)   t  t |  ƒ j | | | ƒ | |  _ d  S(   N(   t   superR7   R/   R	   (   R   R	   R+   R   R.   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR/   í   s    (   R	   (   R&   R'   R)   R/   (    (    (    s)   lib/python2.7/site-packages/parso/tree.pyR7   ê   s   t   BaseNodec           B   sŒ   e  Z d  Z d Z d Z d „  Z e d „  ƒ Z d „  Z	 e d „  ƒ Z
 d „  Z e d „ Z e d	 „ Z d
 „  Z d „  Z e d „  ƒ Z RS(   sd   
    The super class for all nodes.
    A node has children, a type and possibly a parent node.
    R   R   c         C   s   | |  _  d  |  _ d  S(   N(   R   R   R   (   R   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR/   ú   s    		c         C   s   |  j  d j S(   Ni    (   R   R   (   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR     s    c         C   s   |  j  d j ƒ  S(   Ni    (   R   R!   (   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR!   	  s    c         C   s   |  j  d j S(   Niÿÿÿÿ(   R   R    (   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR      s    c         C   sV   | r d j  d „  | Dƒ ƒ S| d j d t ƒ } | d j  d „  | d Dƒ ƒ Sd  S(   NR   c         s   s   |  ] } | j  ƒ  Vq d  S(   N(   R%   (   t   .0R   (    (    s)   lib/python2.7/site-packages/parso/tree.pys	   <genexpr>  s    i    R$   c         s   s   |  ] } | j  ƒ  Vq d  S(   N(   R%   (   R:   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pys	   <genexpr>  s    i   (   t   joinR%   t   False(   R   R   R$   t   first(    (    s)   lib/python2.7/site-packages/parso/tree.pyt   _get_code_for_children  s    c         C   s   |  j  |  j | ƒ S(   N(   R>   R   (   R   R$   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR%     s    c            sg   ‡  ‡ ‡ ‡ f d †  ‰  d ˆ k o9 ˆ j  d j k n sM t d ƒ ‚ n  ˆ  d t ˆ j  ƒ d ƒ S(   sx  
        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            s±   |  | k r_ ˆ j  |  } ˆ r3 ˆ | j k  r3 d  Sy | j ˆ ˆ ƒ SWq_ t k
 r[ | SXn  t |  | d ƒ } ˆ j  | } ˆ | j k rœ ˆ  |  | ƒ Sˆ  | d | ƒ Sd  S(   Ni   i   (   R   R   R   t   get_leaf_for_positionR   t   intR    (   t   lowert   uppert   elementR   (   t   binary_searcht   include_prefixest   positionR   (    s)   lib/python2.7/site-packages/parso/tree.pyRD   #  s    i   i    iÿÿÿÿs7   Please provide a position that exists within this node.(   i   i    (   R   R    t
   ValueErrorR   (   R   RF   RE   (    (   RD   RE   RF   R   s)   lib/python2.7/site-packages/parso/tree.pyR?     s    	&c         C   s   |  j  d j ƒ  S(   Ni    (   R   R"   (   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR"   ;  s    c         C   s   |  j  d j ƒ  S(   Niÿÿÿÿ(   R   R#   (   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR#   >  s    c         C   sv   |  j  ƒ  j d d ƒ j d d ƒ j ƒ  } t d k sK | j t d ƒ } n  d t |  ƒ j | |  j d |  j d f S(	   Ns   
t    s   i   t   replaces   <%s: %s@%s,%s>i    i   (	   R%   RI   t   stripR   t   encodeR   R	   R&   R   (   R   t   code(    (    s)   lib/python2.7/site-packages/parso/tree.pyR4   A  s
    *(   R   R   N(   R&   R'   R(   R)   R   R	   R/   R5   R   R!   R    R>   R   R%   R<   R?   R"   R#   R   R4   (    (    (    s)   lib/python2.7/site-packages/parso/tree.pyR9   ò   s   			!		t   Nodec           B   s&   e  Z d  Z d Z d „  Z d „  Z RS(   s+   Concrete implementation for interior nodes.R	   c         C   s#   t  t |  ƒ j | ƒ | |  _ d  S(   N(   R8   RM   R/   R	   (   R   R	   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR/   N  s    c         C   s   d |  j  j |  j |  j f S(   Ns
   %s(%s, %r)(   t	   __class__R&   R	   R   (   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR4   R  s    (   R	   (   R&   R'   R(   R)   R/   R4   (    (    (    s)   lib/python2.7/site-packages/parso/tree.pyRM   J  s   	t	   ErrorNodec           B   s   e  Z d  Z d Z d Z RS(   sÆ   
    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.
    t
   error_node(    (   R&   R'   R(   R)   R	   (    (    (    s)   lib/python2.7/site-packages/parso/tree.pyRO   V  s   t	   ErrorLeafc           B   s/   e  Z d  Z d Z d Z d d „ Z d „  Z RS(   s”   
    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`.
    t
   token_typet
   error_leafR   c         C   s)   t  t |  ƒ j | | | ƒ | |  _ d  S(   N(   R8   RQ   R/   RR   (   R   RR   R+   R   R.   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR/   h  s    c         C   s,   d t  |  ƒ j |  j t |  j ƒ |  j f S(   Ns   <%s: %s:%s, %s>(   R	   R&   RR   t   reprR+   R   (   R   (    (    s)   lib/python2.7/site-packages/parso/tree.pyR4   l  s    (   RR   (   R&   R'   R(   R)   R	   R/   R4   (    (    (    s)   lib/python2.7/site-packages/parso/tree.pyRQ   `  s
   N(   t   abcR    R   t   parso._compatibilityR   R   R   t   parso.utilsR   R   t   objectR   R*   R7   R9   RM   RO   RQ   (    (    (    s)   lib/python2.7/site-packages/parso/tree.pyt   <module>   s   	GX
