ó
’›V]c           @   s<  d  d l  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 „  Z d „  Z e d	 „ Z d
 „  Z d „  Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d e f d „  ƒ  YZ e d „  ƒ Z d d „ Z  d „  Z! d S(   iÿÿÿÿN(   t   chain(   t   contextmanager(   t   tree(   t   unicode(   t   get_parent_scopec         C   sZ   d |  k s d |  k r t  St j j t j d d ƒ } t t j t j	 | ƒ d |  ƒ ƒ S(   Ns   dist-packagess   site-packagest   libt   pythons   \d.\d(
   t   Falset   ost   patht   joint   syst   prefixt   boolt   ret   matcht   escape(   R	   t	   base_path(    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyt   is_stdlib_path   s    c         C   s…   t  j  |  ƒ } g  } x` |  j D]U } t | t j ƒ rR t  j  | ƒ } | | _ n t | ƒ } | | _ | j | ƒ q W| | _ | S(   sO   
    Much, much faster than copy.deepcopy, but just for parser tree nodes.
    (   t   copyt   childrent
   isinstanceR   t   Leaft   parentt   deep_ast_copyt   append(   t   objt   new_objt   new_childrent   childt	   new_child(    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyR      s    		c         C   s±  | j  } | j d k r8 d d l m } | j |  j ƒ S| j d k sg | | j d | j d f k r | j d k rƒ |  j | ƒ S|  j | ƒ S| j  } | j j | ƒ } | rº | } n
 | d } | j d k r+| } x4 t	 r| d 8} | j | }	 |	 j d k rÜ PqÜ qÜ W| j | d | d !}
 n | j d }	 | j d | !}
 |	 d	 k rk|
 d }	 |
 d }
 n  |  j |	 ƒ } d d
 l
 m } x  |
 D] } | |  | | ƒ } q‘W| S(   s®  
    Creates a "call" node that consist of all ``trailer`` and ``power``
    objects.  E.g. if you call it with ``append``::

        list([]).append(3) or None

    You would get a node with the content ``list([]).append`` back.

    This generates a copy of the original ast node.

    If you're using the leaf, e.g. the bracket `)` it will return ``list([])``.

    We use this function for two purposes. Given an expression ``bar.foo``,
    we may want to
      - infer the type of ``foo`` to offer completions after foo
      - infer the type of ``bar`` to be able to jump to the definition of foo
    The option ``cut_own_trailer`` must be set to true for the second purpose.
    t   fstringiÿÿÿÿ(   t   compiledt   traileri    t   atomi   t
   error_nodet   await(   t   eval_trailer(   R   t   typet   jedi.evaluateR    t   get_string_context_sett	   evaluatorR   t	   eval_nodet   indext   Truet   jedi.evaluate.syntax_treeR%   (   t   contextt   leaft   cut_own_trailerR!   R    t   powerR+   t   cutt   startt   baset   trailerst   valuesR%   (    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyt   evaluate_call_of_leaf/   s>    	/		
	

c         C   s  |  j  } | j d k s8 |  | j d | j d f k rO | j d k rK | S|  S| j  } | j j | ƒ } t j | ƒ } t | j ƒ | _ g  | j | d )| j d k r| } x. t rá | d 8} | j | j d k r´ Pq´ q´ Wt j d | j | ƒ } | j  | _  | S| S(   sp  
    Creates a "call" node that consist of all ``trailer`` and ``power``
    objects.  E.g. if you call it with ``append``::

        list([]).append(3) or None

    You would get a node with the content ``list([]).append`` back.

    This generates a copy of the original ast node.

    If you're using the leaf, e.g. the bracket `)` it will return ``list([])``.
    R!   i    iÿÿÿÿR"   i   R#   R1   (	   R   R&   R   R+   R   t   listR,   R   t   Node(   R/   R!   R1   R+   t	   new_powerR3   t   transformed(    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyt   call_of_leafm   s(    	/		
c         C   s\   y |  j  } Wn+ t k
 r: |  j d k r3 |  g Sg  Sn Xt t j d „  | Dƒ ƒ ƒ Sd  S(   Nt   namec         s   s   |  ] } t  | ƒ Vq d  S(   N(   t   get_names_of_node(   t   .0t   c(    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pys	   <genexpr>¡   s    (   R   t   AttributeErrorR&   R8   R    t   from_iterable(   t   nodeR   (    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyR>   ˜   s    c            sb   t  t j ˆ  j ƒ  j ƒ  ƒ ƒ } | s^ ‡  f d †  } g  | D] } | | ƒ r= | ^ q= } n  | S(   sZ   
    Returns a dictionary with name parts as keys and their call paths as
    values.
    c            s=   t  |  ƒ } | r- | j d k r- | j } n  | ˆ  d  f k S(   Nt
   async_stmt(   R   R&   R   t   None(   R=   t   parent_scope(   t   module(    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyt   is_module_scope_name°   s    (   R8   R    RB   t   get_used_namesR6   (   RG   t
   all_scopest   namesRH   t   n(    (   RG   s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyt   get_module_names¤   s
    !(c         c   s+   |  j  } | | | <z	 d  VWd  | | =Xd  S(   N(   t   predefined_names(   R.   t
   flow_scopet   dctt
   predefined(    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyt   predefine_names»   s
    	
	c         C   sU   |  j  j j j d k r' t t f } n	 t f } |  j ƒ  oT t |  j d d  ƒ | ƒ S(   Ni   t   default(
   R)   t   environmentt   version_infot   majorR   t   bytest   is_compiledR   t   get_safe_valueRE   (   R.   t   str_classes(    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyt	   is_stringÅ   s    	c         C   s   t  |  ƒ p t |  ƒ S(   N(   t	   is_numberR[   (   R.   (    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyt
   is_literalÍ   s    c         C   s)   |  j  d d  ƒ } t | | ƒ r% | Sd  S(   NRS   (   RY   RE   R   (   R.   t   acceptt   value(    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyt   _get_safe_value_or_noneÑ   s    c         C   s   t  |  t ƒ S(   N(   R`   t   int(   R.   (    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyt   get_int_or_none×   s    c         C   s   t  |  t t f ƒ S(   N(   R`   RW   R   (   R.   (    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyt   get_str_or_noneÛ   s    c         C   s   t  |  t t f ƒ d  k	 S(   N(   R`   Ra   t   floatRE   (   R.   (    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyR\   ß   s    t   SimpleGetItemNotFoundc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyRe   ã   s   c          g   s/   y	 d  VWn |  k
 r* } t  | ƒ ‚ n Xd  S(   N(   Re   (   t   exception_classest   e(    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyt   reraise_getitem_errorsç   s    	c         C   sø   d } g  } xß |  d D]Ó } | d	 k rH | sê | t  | j ƒ 7} qê q | j d k rœ x> | j d  d  d … D]# } | j | ƒ | | k rn Pqn qn Wq Pq | j d k rË | j | ƒ | | k rê Pqê q | d k ré | sê g  } qê q Pq W| | f S(
   Ni    i   t   .s   ...t   dotted_namei   R=   t   ,(   Rk   s   ...(   t   lenR_   R&   R   R   (   t   nodest   is_import_fromt
   until_nodet   levelRK   RC   RL   (    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyt   parse_dotted_namesï   s,    c         G   s   |  j  | d  ƒ j | d ƒ S(   Niÿÿÿÿ(   t   import_modulet   py__getattribute__(   R)   RK   (    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyt   contexts_from_qualified_names  s    ("   R   R   R   R   t	   itertoolsR    t
   contextlibR   t   parso.pythonR   t   jedi._compatibilityR   t   jedi.parser_utilsR   R   R   R   R7   R<   R>   RM   RR   R[   R]   R`   Rb   Rc   R\   t	   ExceptionRe   Rj   RE   Rs   Rv   (    (    (    s4   lib/python2.7/site-packages/jedi/evaluate/helpers.pyt   <module>   s2   		>	+		
						