ó
î%![c           @   s  d  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 e j j j Z d   Z d   Z d d  Z d d  Z d d  Z d d  Z d   Z d   Z d   Z d   Z d S(   s   
Various helper utilities.
i˙˙˙˙N(   t   bases(   t   context(   t
   exceptions(   t   manager(   t   nodes(   t   raw_building(   t   scoped_nodes(   t   utilc         C   s   t  j |   } | | _ | S(   N(   R   t   build_classt   parent(   t   cls_namet   builtinst   proxy(    (    s.   lib/python2.7/site-packages/astroid/helpers.pyt   _build_proxy_class   s    	c         C   s    t  |  t j  r9 |  j   j t k r0 d } q d } nZ t  |  t j  rf t j	 r] d } q d } n- t  |  t j
  r t j	 r d } q d } n  t | |  S(   Nt   builtin_function_or_methodt   functiont   instancemethodt   method(   t
   isinstanceR   t   Lambdat   roott   namet   BUILTINSR    t   BoundMethodt   sixt   PY2t   UnboundMethodR   (   R   R   R
   (    (    s.   lib/python2.7/site-packages/astroid/helpers.pyt   _function_type!   s    								c         c   só   t  j   } | j t } | p( t j   } xÁ |  j d |  D]­ } t | t j	  r | j
 r | j   } | r | Vq> q n  | j d  d Vq> t | t j t j f  rŔ t | |  Vq> t | t j  ră t d |  Vq> | j Vq> Wd  S(   NR   t   typei    t   module(   R   t   AstroidManagert   astroid_cacheR   t
   contextmodt   InferenceContextt   inferR   R   t   ClassDeft   newstylet	   metaclasst   getattrR   R    R   R   t   ModuleR   t   _proxied(   t   nodeR   t   astroid_managerR   t   inferredR%   (    (    s.   lib/python2.7/site-packages/astroid/helpers.pyt   _object_type4   s     		c         C   sb   y t  t |  |   } Wn t j k
 r3 t j SXt |  d k sM | rT t j St |  d S(   sU  Obtain the type of the given node

    This is used to implement the ``type`` builtin, which means that it's
    used for inferring type calls, as well as used in a couple of other places
    in the inference.
    The node will be inferred first, so this function can support all
    sorts of objects, as long as they support inference.
    i   i    (   t   setR,   R   t   InferenceErrorR   t   Uninferablet   lent   list(   R)   R   t   types(    (    s.   lib/python2.7/site-packages/astroid/helpers.pyt   object_typeI   s    
c         C   sy   y" |  j  d |  } t |  } Wn t j k
 r9 d SXy t |  d SWn& t j k
 rc d St k
 rt | SXd S(   sĄ   Return the inferred value for the given node.

    Return None if inference failed or if there is some ambiguity (more than
    one node has been inferred).
    R   N(   R"   t   nextR   R.   t   Nonet   StopIteration(   R)   R   t   inferitt   value(    (    s.   lib/python2.7/site-packages/astroid/helpers.pyt
   safe_infer\   s    
c         C   s   y |  j  SWn t k
 r n Xxb |  j D]W } t | d | } t | t j  ss | |  k ss t | d | r) t |  _  t Sq) Wt	 |  _  t	 S(   s=   Return true if all base classes of a class could be inferred.R   (
   t   _all_bases_knownt   AttributeErrorR    R9   R   R   R#   t   has_known_basest   Falset   True(   t   klassR   t   baset   result(    (    s.   lib/python2.7/site-packages/astroid/helpers.pyR<   p   s    		c         C   s   t  t t |  | f   s' t j  n  t  |  j | j g  sC t Sy |  | j   d  k SWn t j k
 rz t j  n Xd  S(   Ni˙˙˙˙(	   t   allt   mapR<   R   t   _NonDeducibleTypeHierarchyR$   R=   t   mrot   MroError(   t   type1t   type2(    (    s.   lib/python2.7/site-packages/astroid/helpers.pyt   _type_check   s    c         C   s   t  | |   S(   s(   Check if *type1* is a subtype of *typ2*.(   RI   (   RG   RH   (    (    s.   lib/python2.7/site-packages/astroid/helpers.pyt
   is_subtype   s    c         C   s   t  |  |  S(   s+   Check if *type2* is a supertype of *type1*.(   RI   (   RG   RH   (    (    s.   lib/python2.7/site-packages/astroid/helpers.pyt   is_supertype   s    c         C   sĂ   t  j   } t  j d |  g  | _ y x} |  j d d | D]f } t | t j  s[ q= n  xE | j |  d | D]. } t | t	 j
  rq t | j t  rq | Sqq Wq= WWn t j k
 rž n Xd S(   sę   Get the value as an index for the given instance.

    If an instance provides an __index__ method, then it can
    be used in some scenarios where an integer is expected,
    for instance when multiplying or subscripting a list.
    t   argst	   __index__R   N(   R    R!   t   CallContextt   callcontextt   igetattrR   R    R   t   infer_call_resultR   t   ConstR8   t   intR   R.   R5   (   R)   R   R+   RA   (    (    s.   lib/python2.7/site-packages/astroid/helpers.pyt   class_instance_as_index   s    (   t   __doc__R   t   astroidR    R   R    R   R   R   R   R   R   t   movesR   t   __name__R   R   R   R5   R,   R3   R9   R<   RI   RJ   RK   RT   (    (    (    s.   lib/python2.7/site-packages/astroid/helpers.pyt   <module>
   s(   					