ó
î%![c           @   sv   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 e f d „  ƒ  YZ	 d S(	   iÿÿÿÿN(   t   bases(   t   context(   t
   exceptions(   t   nodes(   t   utilt   CallSitec           B   sY   e  Z d  Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z e	 d „  ƒ Z
 d „  Z RS(   sS  Class for understanding arguments passed into a call site

    It needs a call context, which contains the arguments and the
    keyword arguments that were passed into a given call site.
    In order to infer what an argument represents, call
    :meth:`infer_argument` with the corresponding function node
    and the argument name.
    c         C   s   | j  } | j } t ƒ  |  _ |  j | ƒ |  _ |  j | ƒ |  _ g  |  j D] } | t j	 k	 rL | ^ qL |  _
 d „  |  j j ƒ  Dƒ |  _ d  S(   Nc         S   s.   i  |  ]$ \ } } | t  j k	 r | | “ q S(    (   R   t   Uninferable(   t   .0t   keyt   value(    (    s0   lib/python2.7/site-packages/astroid/arguments.pys
   <dictcomp>(   s   	 	(   t   argst   keywordst   sett   duplicated_keywordst   _unpack_argst   _unpacked_argst   _unpack_keywordst   _unpacked_kwargsR   R   t   positional_argumentst   itemst   keyword_arguments(   t   selft   callcontextR
   R   t   arg(    (    s0   lib/python2.7/site-packages/astroid/arguments.pyt   __init__   s    		c         C   s"   t  j | j | j ƒ } |  | ƒ S(   s/   Get a CallSite object from the given Call node.(   t
   contextmodt   CallContextR
   R   (   t   clst	   call_nodeR   (    (    s0   lib/python2.7/site-packages/astroid/arguments.pyt	   from_call,   s    c         C   s   t  |  j ƒ t  |  j ƒ k S(   sn  Check if in the current CallSite were passed *invalid* arguments

        This can mean multiple things. For instance, if an unpacking
        of an invalid object was passed, then this method will return True.
        Other cases can be when the arguments can't be inferred by astroid,
        for example, by passing objects which aren't known statically.
        (   t   lenR   R   (   R   (    (    s0   lib/python2.7/site-packages/astroid/arguments.pyt   has_invalid_arguments3   s    c         C   s   t  |  j ƒ t  |  j ƒ k S(   sf  Check if in the current CallSite were passed *invalid* keyword arguments

        For instance, unpacking a dictionary with integer keys is invalid
        (**{1:2}), because the keys must be strings, which will make this
        method to return True. Other cases where this might return True if
        objects which can't be inferred were passed.
        (   R   R   R   (   R   (    (    s0   lib/python2.7/site-packages/astroid/arguments.pyt   has_invalid_keywords=   s    c   	      C   s  i  } t  j ƒ  } x„| D]|\ } } | d  k r‹y t | j d | ƒ ƒ } Wn$ t j k
 rs t j | | <q n Xt	 | t
 j ƒ s™ t j | | <q n  xù | j D]á \ } } y t | j d | ƒ ƒ } Wn$ t j k
 rñ t j | | <q£ n Xt	 | t
 j ƒ st j | | <q£ n  t	 | j t j ƒ s?t j | | <q£ n  | j | k rwt j | | j <|  j j | j ƒ q£ n  | | | j <q£ Wq | | | <q W| S(   NR   (   R   t   InferenceContextt   Nonet   nextt   inferR   t   InferenceErrorR   R   t
   isinstanceR   t   DictR   t   ConstR	   t   sixt   string_typesR   t   add(	   R   R   t   valuesR   t   nameR	   t   inferredt   dict_keyt
   dict_value(    (    s0   lib/python2.7/site-packages/astroid/arguments.pyR   G   s>    c         C   sì   g  } t  j ƒ  } xÓ |  D]Ë } t | t j ƒ r× y t | j j d | ƒ ƒ } Wn' t j	 k
 ry | j
 t j ƒ q n X| t j k rŸ | j
 t j ƒ q n  t | d ƒ sÄ | j
 t j ƒ q n  | j | j ƒ q | j
 | ƒ q W| S(   NR   t   elts(   R   R!   R&   R   t   StarredR#   R	   R$   R   R%   t   appendR   R   t   hasattrt   extendR1   (   R
   R,   R   R   R.   (    (    s0   lib/python2.7/site-packages/astroid/arguments.pyR   n   s$    c            s¸  | |  j  k r9 t j d d |  d | d | d | ƒ‚ n  y |  j | j | ƒ SWn t k
 rd n Xt |  j ƒ t | j j ƒ k r¿ | j j	 s¿ t j d d |  d | d | d | ƒ‚ q¿ n  |  j t | j j ƒ  } |  j t | j j ƒ } | j j
 | ƒ d } t d „  | j j Dƒ ƒ ‰  ‡  f d	 †  |  j j ƒ  Dƒ } t | ƒ t | j j ƒ k  r«xH | j j D]7 } | j | k rm| j | j ƒ }	 | j |	 ƒ qmqmWn  | d k	 ré| d k rž| j d k rž| j d k	 rí| j }
 n | j j ƒ  }
 t |
 t j ƒ r?| j j ƒ  } | |
 j ƒ  k r?t |
 f ƒ Sn  | j d
 k rt |
 t j ƒ srt j |
 ƒ }
 n  t |
 f ƒ S| j d k ržt |
 f ƒ Sn  | j d k rº| d 8} n  y |  j | j | ƒ SWqét k
 råqéXn  | j j | k r¸|  j  ƒ  rCt j d d |  j d |  j! d |  d | d | d | ƒ‚ n  t j" d | j j# d | j j$ d | j ƒ } | j% g  | j ƒ  D]! \ } } t j& | ƒ | f ^ qƒƒ t | f ƒ S| j j	 | k rY|  j' ƒ  rt j d d |  j d |  j( d |  d | d | d | ƒ‚ n  t j) d | j j# d | j j$ d | j ƒ } | j% | ƒ t | f ƒ Sy | j j* | ƒ j | ƒ SWn t j+ k
 rŒn Xt j d d |  d | d | d | ƒ‚ d S(   sï   infer a function argument value according to the call context

        Arguments:
            funcnode: The function being called.
            name: The name of the argument whose value is being inferred.
            context: TODO
        s:   The arguments passed to {func!r}  have duplicate keywords.t	   call_sitet   funcR   R   sJ   Too many positional arguments passed to {func!r} that does not have *args.i    c         s   s   |  ] } | j  Vq d  S(   N(   R-   (   R   R   (    (    s0   lib/python2.7/site-packages/astroid/arguments.pys	   <genexpr>¥   s    c            s+   i  |  ]! \ } } | ˆ  k r | | “ q S(    (    (   R   R   R	   (   t
   kwonlyargs(    s0   lib/python2.7/site-packages/astroid/arguments.pys
   <dictcomp>§   s   	 	t   methodt   classmethodi   s‡   Inference failed to find values for all keyword arguments to {func!r}: {unpacked_kwargs!r} doesn't correspond to {keyword_arguments!r}.R   t   unpacked_kwargst   linenot
   col_offsett   parents‹   Inference failed to find values for all positional arguments to {func!r}: {unpacked_args!r} doesn't correspond to {positional_arguments!r}.R   t   unpacked_argss.   No value found for argument {name} to {func!r}N(   R9   R:   (   R9   R:   (,   R   R   R%   R   R$   t   KeyErrorR   R   R
   t   varargt   find_argnameR   R8   R   R-   t   popR3   R"   t   typet	   boundnodeR>   t   frameR&   R   t   ClassDeft   scopet	   metaclasst   iterR    t   Instancet
   IndexErrort   kwargR    R   R'   R<   R=   t   postinitt   const_factoryR   R   t   Tuplet   default_valuet	   NoDefault(   R   t   funcnodeR-   R   t
   positionalRA   t   argindext   kwargst   func_argR   RE   t   method_scopeRM   R   R	   R
   (    (   R8   s0   lib/python2.7/site-packages/astroid/arguments.pyt   infer_argument…   s˜    !			2		(   t   __name__t
   __module__t   __doc__R   R:   R   R   R    R   t   staticmethodR   RY   (    (    (    s0   lib/python2.7/site-packages/astroid/arguments.pyR      s   		
	
	'(
   R)   t   astroidR    R   R   R   R   R   t   objectR   (    (    (    s0   lib/python2.7/site-packages/astroid/arguments.pyt   <module>   s   