
%![c           @   s!  d  Z  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 d l m Z d d	 l m Z d d
 l m Z d d l m Z e j d  Z e j d  Z d   Z d   Z d Z i d d 6d d 6e j rd n d d 6d d 6d d 6d d 6d d 6d  d! 6d" d# 6d$ d% 6d& d' 6d( d) 6d* d+ 6Z d,   e j   D Z d-   e j   D Z i d. d 6d/ d 6d0 d1 6d d2 6Z i e j d 6e j d 6e j  d1 6e j! d2 6Z" d3   Z# d4   e j$ _% d5   e j& _% d6   e j' _% d7   e j( _% d8   e j) _% i d9   d 6d:   d 6d;   d 6d<   d 6d=   d 6d>   d 6d?   d 6d@   d! 6dA   d# 6dB   d% 6dC   d' 6dD   d) 6Z* e j+ dZ k re j, e* d+ <n  x. e- e* j    D] \ Z. Z/ e/ e* e. dG <qWe j0 dH    Z1 e1 e j( _2 dI   Z3 dJ   Z4 e j0 dK    Z5 e5 e j$ _2 e5 e j& _2 e j0 dL    Z6 e6 e j7 _2 e6 e j8 _2 dM   Z9 e j: d d d dN   Z; e; e j< _= e; e j> _= d d d dO  Z? e? e j$ _= e? e j& _= d d d dP  Z@ e@ e jA _= e@ e jB _= dQ   ZC d d d dR  ZD eD e jE _= e j: d d d dS   ZF d d d dT  ZG eF e jH _= eG e jI _= eF e jJ _= dU   ZK e j: d d d dV   ZL eL e jM _= dW   ZN e j: d d d dX   ZO eO e jP _= e j0 d d d dY   ZQ eQ e jR _= d S([   sc   this module contains a set of functions to handle python protocols for nodes
where it makes sense.
iN(   t	   arguments(   t   bases(   t   context(   t
   exceptions(   t
   decorators(   t   node_classes(   t   helpers(   t   nodes(   t   utilt   raw_buildingt   objectsc         C   s   d |  d S(   Nt   __ri   (    (   t   name(    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   _reflected_name    s    c         C   s   d |  d S(   Nt   __ii   (    (   R   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   _augmented_name#   s    s   contextlib.contextmanagert   __add__t   +t   __sub__t   -t   __div__t   __truediv__t   /t   __floordiv__s   //t   __mul__t   *t   __pow__s   **t   __mod__t   %t   __and__t   &t   __or__t   |t   __xor__t   ^t
   __lshift__s   <<t
   __rshift__s   >>t
   __matmul__t   @c         C   s%   i  |  ] \ } } t  |  |  q S(    (   R   (   t   .0t   keyt   value(    (    s0   lib/python2.7/site-packages/astroid/protocols.pys
   <dictcomp>8   s   	c         C   s)   i  |  ] \ } } t  |  | d   q S(   t   =(   R   (   R'   R(   R)   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pys
   <dictcomp><   s   	t   __pos__t   __neg__t
   __invert__t   ~t   notc         C   s#   t  | } | |   } t j |  S(   N(   t   _UNARY_OPERATORSR   t   const_factory(   t   objt   opt   funcR)   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   _infer_unary_opM   s    
c         C   s   t  t |  j  |  S(   N(   R5   t   tuplet   elts(   t   selfR3   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   <lambda>R   s    c         C   s   t  |  j |  S(   N(   R5   R7   (   R8   R3   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR9   S   s    c         C   s   t  t |  j  |  S(   N(   R5   t   setR7   (   R8   R3   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR9   T   s    c         C   s   t  |  j |  S(   N(   R5   R)   (   R8   R3   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR9   U   s    c         C   s   t  t |  j  |  S(   N(   R5   t   dictt   items(   R8   R3   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR9   V   s    c         C   s   |  | S(   N(    (   t   at   b(    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR9   Z   s    c         C   s   |  | S(   N(    (   R=   R>   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR9   [   s    c         C   s   |  | S(   N(    (   R=   R>   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR9   \   s    c         C   s   |  | S(   N(    (   R=   R>   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR9   ]   s    c         C   s   |  | S(   N(    (   R=   R>   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR9   ^   s    c         C   s   |  | S(   N(    (   R=   R>   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR9   _   s    c         C   s   |  | S(   N(    (   R=   R>   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR9   `   s    c         C   s   |  | @S(   N(    (   R=   R>   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR9   a   s    c         C   s   |  | BS(   N(    (   R=   R>   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR9   b   s    c         C   s   |  | AS(   N(    (   R=   R>   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR9   c   s    c         C   s   |  | >S(   N(    (   R=   R>   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR9   d   s    c         C   s   |  | ?S(   N(    (   R=   R>   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR9   e   s    i   i   R*   c         c   s   t  j t  } t | t  j  r y` t | } y! t  j | |  j | j   VWn. t k
 rg | Vn t k
 r t	 j
 Vn XWq t k
 r | Vq Xn1 t |  j t j  r | d k r t	 j
 Vn | Vd  S(   NR   (   R   t   Constt   NotImplementedt
   isinstancet   BIN_OP_IMPLR1   R)   t	   TypeErrort	   ExceptionR   t   Uninferablet   sixt   string_types(   R8   t   opnodet   operatort   otherR   t   _t   not_implementedt   impl(    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   const_infer_binary_opo   s    
!!c   	      C   s   |  j  d |  } g  } d   |  j D } xE | D]= } t j | |  } | d  k rb t j } n  | j |  q2 W| | j | _ | S(   Nt   parentc         s   s$   |  ] } | t  j k	 r | Vq d  S(   N(   R   RE   (   R'   t   elt(    (    s0   lib/python2.7/site-packages/astroid/protocols.pys	   <genexpr>   s    (	   t	   __class__R7   R   t
   safe_infert   NoneR   RE   t   appendR)   (	   R8   RH   RJ   R   t   nodeR7   t   filtered_eltsRP   t   infered(    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   _multiply_seq_by_int   s    c         c   sn   xg |  D]_ } | t  j k r* t j   Vq x9 | j |  D]( } | t  j k	 rW | Vq: t j   Vq: Wq Wd  S(   N(   R   RE   R   t   Unknownt   infer(   R7   R   RP   t   inferred(    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   _filter_uninferable_nodes   s    c   
      c   s2  t  j t  } t | |  j  r | d k r |  j d |  } t t |  j |   } | t t | j |   7} | | _ | Vn t | t  j  r | d k r t | j t	  s | Vd  St
 |  | | |  VnZ t | t j  r)| d k r)t j |  }	 |	 st j Vq.t
 |  | |	 |  Vn | Vd  S(   NR   RO   R   (   R   R?   R@   RA   RQ   t   listR\   R7   R)   t   intRX   R   t   InstanceR   t   class_instance_as_indexR   RE   (
   R8   RH   RI   RJ   R   t   methodRL   RU   R7   t   as_index(    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   tl_infer_binary_op   s$    	c         C   s   | j  |  |  S(   N(   t   infer_call_result(   R8   RH   RI   RJ   R   Ra   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   instance_class_infer_binary_op   s    c   
   	   c   s@  | } | j  d  } x#|  D]} | t j k r8 q n  t | d  sM q n  y | j   } Wn t k
 rs q n Xx | D] } t j |  } y | j | |  } Wn# t	 t
 j t
 j f k
 r q{ n X| s | Vq{ | t j k r Pq{ y/ x( t | j |  | |  D] }	 |	 VqWWq{ t
 j k
 r3Pq{ Xq{ Wq Wd S(   s;   recursive function to resolve multiple assignments on loopsi    t   iteredN(   t   popR   RE   t   hasattrRf   RC   R   R?   t   getitemt   AttributeErrorR   t   AstroidTypeErrort   AstroidIndexErrort   _resolve_looppartRZ   t   InferenceError(
   t   partst   asspathR   t   indext   partRf   t   stmtt
   index_nodet   assignedR[   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyRm      s:    c      
   c   s
  t  |  t j  s$ t |  d t  rN t t d |  d | d | d |    n  | d  k r x |  j j	 |  D]= } t  | t j
 t j f  rm x | j D] } | Vq Wqm qm Wn. x+ t |  j j	 |  | |  D] } | Vq Wt t d |  d | d | d |    d  S(   Nt   is_asyncRU   t   unknownt   assign_pathR   (   RA   R   t   AsyncFort   getattrt   Falset   StopIterationR;   RS   t   iterRZ   t   Tuplet   ListR7   Rm   (   R8   RU   R   Rp   t   lstt   itemR[   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   for_assigned_stmts   s    $	c      	   C   s   | d  k r g  } n  y |  j j |  } Wn9 t k
 rf t j t j d d |  d | d |  n X| j d |  |  j	 j
 d |  d | d |  S(   Ns6   Tried to retrieve a node {node!r} which does not existRU   Rx   R   i    Rp   (   RS   R7   Rq   t
   ValueErrorR   t   reraiseR   Rn   t   insertRO   t   assigned_stmts(   R8   RU   R   Rp   Rq   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   sequence_assigned_stmts  s    	c         C   s   |  j  j d |  d |  S(   NRU   R   (   RO   R   (   R8   RU   R   Rp   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   assend_assigned_stmts   s    c         c   s  |  j  p |  j p |  j s' t j Vd  S|  j  r t |  j  d d d   | k r |  j j } |  j j j	   } t
 | t j  o | j d k } | s | d k r | Vd  S| d k r t j |  j j j    Vd  Sn  | r#| j r#t j | j  } x% | j |  j | |  D] } | VqWd  S| |  j k rSt j d  } |  | _ | Vd  S| |  j k rt j i   }	 |  |	 _ |	 Vd  SyC t j |  } x% |  j |  j |  D] }
 |
 VqWt j VWn t j k
 rt j Vn Xd  S(   Ni    R   t	   metaclasst   classmethodRa   (    (   t   argst   varargt   kwargR   RE   Rz   RS   RO   t   typet   scopeRA   R   t   ClassDefR   R_   t   framet   callcontextR    t   CallSitet   infer_argumentR1   t
   contextmodt   copy_contextt   default_valueRZ   R   t	   NoDefault(   R8   R   R   t   functypet   clst   is_metaclasst	   call_siteR)   R   R   R[   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   _arguments_infer_argname&  sF    (!				c         C   se   | j  rR | j  } t j |  } d  | _  t j |  } | j |  j | j |  St	 |  | j |  S(   N(
   R   R   R   RS   R    R   R   RO   R   R   (   R8   RU   R   Rp   R   R   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   arguments_assigned_stmtsV  s    			c      
   c   sk   | s |  j  Vd  Sx+ t |  j  j |  | |  D] } | Vq1 Wt t d |  d | d | d |    d  S(   NRU   Rw   Rx   R   (   R)   t   _resolve_asspartRZ   R|   R;   (   R8   RU   R   Rp   R[   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   assign_assigned_stmtsc  s    %	c         c   s@   x9 t  |  | | |  D]" } | d  k r3 t j Vq | Vq Wd  S(   N(   R   RS   R   RE   (   R8   RU   R   Rp   R[   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   assign_annassigned_stmtsp  s    c         c   s   | } | j  d  } x |  D] } t | d  r t j |  } y | j | |  } Wn t j t j f k
 rw d SX| s | Vq | t j	 k r d Sy/ x( t
 | j |  | |  D] } | Vq WWq t j k
 r d SXq q Wd S(   s2   recursive function to resolve multiple assignmentsi    Ri   N(   Rg   Rh   R   R?   Ri   R   Rk   Rl   R   RE   R   RZ   Rn   (   Ro   Rp   R   Rq   Rr   Rt   Ru   R[   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyR   |  s&    c      
   c   sq   xC t  j |  j  D]/ } t | t j  r= t j |  } n  | Vq Wt t	 d |  d | d | d |    d  S(   NRU   Rw   Rx   R   (
   R   t   unpack_inferR   RA   R   R   R
   t   ExceptionInstanceR|   R;   (   R8   RU   R   Rp   Ru   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   excepthandler_assigned_stmts  s    	c         #   s  y t  | j d |   } Wn t j k
 r3 d  SXt | t j  rN| j     j s\ d  SxX   j j	 D]F } t  | j |   } t | t	 j
  ri | j   t k r Pq qi qi Wd  S  j t	 j  } t    f d   | D d   } | r| j s#t	 j d   } | | _ | j | _ | VqKx% | j j d |  D] } | Vq9Wqn t | t j  ry t  | j d d |  }	 Wn t j t j f k
 rd  SXt |	 t j  sd  S| j st j d | g  | _ n  x" |	 j |  |  D] }
 |
 VqWn  d  S(   NR   c         3   s'   |  ] } | j      k r | Vq d  S(   N(   R   (   R'   RU   (   R4   (    s0   lib/python2.7/site-packages/astroid/protocols.pys	   <genexpr>  s    t	   __enter__R   (   t   nextRZ   R   Rn   RA   R   t	   GeneratorRO   R   R   t   FunctionDeft   qnamet   _CONTEXTLIB_MGRt   nodes_of_classt   YieldRS   R)   R?   t   linenoR_   t   igetattrt   AttributeInferenceErrort   BoundMethodR   R   t   CallContextRd   (   R8   t   mgrR   R[   t   decorator_nodet	   decoratort   possible_yield_pointst   yield_pointt   constt   entert   result(    (   R4   s0   lib/python2.7/site-packages/astroid/protocols.pyt   _infer_context_manager  sH    						c         #   s~  t    f d   |  j D  } | d k rP x%t |  | |  D] } | Vq> Wnx t |  | |  D] } | } x | D] } t | d  s t j d d |  d   d | d |  n  y | j | } Wqv t k
 rt	 j
 t j d d |  d   d | d |  qv t k
 rEt	 j
 t j d	 d |  d   d | d |  qv Xqv W| Vqc Wt t d |  d
   d | d |    d S(   s[  Infer names and other nodes from a *with* statement.

    This enables only inference for name binding in a *with* statement.
    For instance, in the following code, inferring `func` will return
    the `ContextManager` class, not whatever ``__enter__`` returns.
    We are doing this intentionally, because we consider that the context
    manager result is whatever __enter__ returns and what it is binded
    using the ``as`` keyword.

        class ContextManager(object):
            def __enter__(self):
                return 42
        with ContextManager() as f:
            pass

        # ContextManager().infer() will return ContextManager
        # f.infer() will return 42.

    Arguments:
        self: nodes.With
        node: The target of the assignment, `as (a, b)` in `with foo as (a, b)`.
        context: TODO
        asspath: TODO
    c         3   s'   |  ] \ } } |   k r | Vq d  S(   N(    (   R'   R   t   vars(   RU   (    s0   lib/python2.7/site-packages/astroid/protocols.pys	   <genexpr>  s    R7   s0   Wrong type ({targets!r}) for {node!r} assignmentRU   t   targetsRx   R   sC   Tried to infer a nonexistent target with index {index} in {node!r}.s2   Tried to unpack an non-iterable value in {node!r}.Rw   N(   R   R<   RS   R   Rh   R   Rn   R7   t
   IndexErrorR   R   RC   R|   R;   (   R8   RU   R   Rp   R   R   R2   Rq   (    (   RU   s0   lib/python2.7/site-packages/astroid/protocols.pyt   with_assigned_stmts  s6    	c         c   sg  |  j    } t | t j t j f  sQ t j d d |  d | d | d |  n  t | t j  rc| j } | j d } t	 d   | j
 t j  D  d k r t j d	 d |  d
 | d | d |  n  | d k r t j   } n  y t | j |   } Wn t j k
 rt j Vd SX| t j k s>t | d  rJt j Vd St j | j  } t | j  t | j  k rt j d d |  d
 | d | d | d |  n  x t | j  D] \ }	 }
 t |
 t j  s| j   qn  t j t | j |	   } xT | D]L } t | t j  s4| j   qn  t j   } | | _ |  | _ | VPqWqWn  d S(   so   
    Arguments:
        self: nodes.Starred
        node: TODO
        context: TODO
        asspath: TODO
    sD   Statement {stmt!r} enclosing {node!r} must be an Assign or For node.RU   Rs   Rw   R   i    c         s   s   |  ] } d  Vq d S(   i   N(    (   R'   RU   (    (    s0   lib/python2.7/site-packages/astroid/protocols.pys	   <genexpr>,  s    i   s>   Too many starred arguments in the  assignment targets {lhs!r}.R   NR7   s=   More targets, {targets!r}, than values to unpack, {values!r}.t   values(   t	   statementRA   R   t   Assignt   ForR   Rn   R)   R   t   sumR   t   StarredRS   R   t   InferenceContextR   RZ   R   RE   Rh   t   collectionst   dequeR7   t   lent	   enumeratet   popleftt   reversedRg   R   RO   (   R8   RU   R   Rp   Rs   R)   t   lhst   rhsR7   Rq   t	   left_nodet   lhs_eltst
   right_nodet   packed(    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   starred_assigned_stmts  sT    		(	

		(   i   i   (S   t   __doc__R   RI   t   operator_modt   sysRF   t   astroidR    R   R   R   R   R   R   R   R   R   t   lazy_importR	   R
   R   R   R   t   PY2t   BIN_OP_METHODR<   t   REFLECTED_BIN_OP_METHODt   AUGMENTED_OP_METHODRS   t   UNARY_OP_METHODt   post   negt   invertt   not_R0   R5   R~   t   infer_unary_opR   t   SetR?   t   DictRB   t   version_infot   matmulR]   t   _KEYt   _IMPLt   yes_if_nothing_inferredRN   t   infer_binary_opRX   R\   Rc   Re   R_   R   Rm   t   raise_if_nothing_inferredR   R   R   t   ComprehensionR   R   t
   AssignNamet
   AssignAttrR   R   t	   ArgumentsR   R   R   t	   AnnAssignt	   AugAssignR   R   t   ExceptHandlerR   R   t   WithR   R   (    (    (    s0   lib/python2.7/site-packages/astroid/protocols.pyt   <module>   s   		






	









			&	0
		19D