
%![c        
   @   s0  d  Z  d d l Z d d l 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 e	 j   Z e e
 j  Z e j d k Z e e j j  Z e j e  Z d   Z d	   Z d
   Z e   Z e d  Z d   Z  e  e j! _" d   Z# d   Z$ d d  Z& d d d  Z' d d d d  Z( d   Z) d d  Z* d   Z+ d   Z, d   Z- d   Z. d d d  Z/ d   Z0 d e f d     YZ1 e1   Z2 i  Z3 d d  Z4 e4   d   Z5 e6 e5  e j7 _8 e j9 e j: j e j: j   Z; e j< e j j j e; _= e; e j> _8 e2 j? e j> j8 e j:  e j< e j j j Z@ e jA e j: e jB eC d  eC eD  e jE e jF e jG e jH e jI f
 ZJ xn eJ D]f ZK eK j e@ k re j9 eK j eK j   ZL e j< e j j j eL _= e2 j? eL eK  eL e@ eK j <qqWd S(   s   this module contains a set of functions to create astroid trees from scratch
(build_* functions) or from living object (object_build_* functions)
iN(   t   bases(   t   manager(   t   node_classes(   t   nodest   javac         C   sC   t  |  d d   } | oB t j |  oB | j d k oB |  j d k S(   Nt   __self__t   _iot   io(   t   getattrt   Nonet   inspectt   ismodulet   __name__t
   __module__(   t   membert   member_self(    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   _io_discrepancy#   s
    c         C   s   | | _  |  j |  d  S(   N(   t   namet   add_local_node(   t   parentt   nodeR   (    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   _attach_local_node+   s    	c         C   sm   | j  } t | d d  } | s% d Sg  | j D] } | j ^ q/ } t | | | j  } | g |  j d <d S(   sF   Add a __class__ member to the given func node, if we can determine it.R   Nt	   __class__(   R   R   R	   t	   __bases__R   t   build_classt   __doc__t   instance_attrs(   t   funcR   t
   python_clst   cls_namet   ancestort	   cls_basest	   ast_klass(    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   _add_dunder_class0   s    	c         C   s)   t  j   } | | _ t |  | |  d S(   sd   create a dummy node and register it in the locals of the given
    node with the specified name
    N(   R   t	   EmptyNodet   objectR   (   R   R   t   runtime_objectt   enode(    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   attach_dummy_node>   s    	c         C   s   |  j  d  k	 o |  j  t k	 S(   N(   R#   R	   t   _marker(   t   self(    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   _has_underlying_objectF   s    c         C   s/   | |  j  k r+ t |  t j |  |  n  d S(   sd   create a Const node and register it in the locals of the given
    node with the specified name
    N(   t   special_attributesR   R   t   const_factory(   R   R   t   value(    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   attach_const_nodeK   s    c         C   s/   t  j | | d f g  } t |  | |  d S(   si   create a ImportFrom node and register it in the locals of the given
    node with the specified name
    N(   R   t
   ImportFromR	   R   (   R   t   modnamet
   membernamet	   from_node(    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   attach_import_nodeR   s    c         C   s.   t  j |  | d t } t | _ d | _ | S(   s+   create and initialize a astroid Module nodet   pure_pythonN(   R   t   Modulet   Falset   packageR	   R   (   R   t   docR   (    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   build_moduleZ   s    		c         C   sU   t  j |  |  } x< | D]4 } t  j   } | | _ | j j |  | | _ q W| S(   s-   create and initialize a astroid ClassDef node(   R   t   ClassDeft   NameR   R    t   appendR   (   R   t	   basenamesR7   R   t   baset   basenode(    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyR   b   s    	c         C   s  | p	 g  | p g  } } t  j |  |  } t  j   | _ } g  | _ xD | D]< } | j j t  j    | | j d _ | | j d _ qN Wg  | _ x7 | D]/ } | j j t  j	 |   | | j d _ q Wd | _ d | _ | | _ | r t |  n  | S(   s0   create and initialize a astroid FunctionDef nodeiN(   R   t   FunctionDeft	   Argumentst   argsR;   R:   R   R   t   defaultsR+   R	   t   kwargt   varargt   register_arguments(   R   RA   RB   R7   R   t   argsnodet   argt   default(    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   build_functionm   s$    					c         C   s)   t  j |  g  | D] } | d f ^ q  S(   s<   create and initialize an astroid ImportFrom import statementN(   R   R.   R	   (   t   fromnamet   namesR   (    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   build_from_import   s    c         C   s   | d k rk |  j j } |  j j r@ |  j |  j j |  j  n  |  j j rk |  j |  j j |  j  qk n  xF | D]> } t | t j  r |  j | j |  qr t	 |  | j
  qr Wd S(   s{   add given arguments to local

    args is a list that may contains nested lists
    (i.e. def func(a, (b, c, d)): ...)
    N(   R	   RA   RD   t	   set_localRC   t
   isinstanceR   R:   R   RE   t   elts(   R   RA   RG   (    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyRE      s    c         C   s5   g  | j  D] } | j ^ q
 } t |  | | d | S(   s(   create astroid for a living class objectt	   localname(   R   R   t   _base_class_object_build(   R   R   RP   R=   R<   (    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   object_build_class   s    c         C   s   t  j |  \ } } } } | d k	 r7 | j |  n  | d k	 rS | j |  n  t t | d d  pk | | | | j  } |  j | |  d S(   s+   create astroid for a living function objectR   N(   R
   t
   getargspecR	   R;   RI   R   R   R   (   R   R   RP   RA   t   varargst   varkwRB   R   (    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   object_build_function   s    c         C   s   t  |  | g  |  S(   s2   create astroid for a living data descriptor object(   RQ   (   R   R   R   (    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   object_build_datadescriptor   s    c         C   sT   t  t | d d  p | d | j } d | j _ |  j | |  t | |  d S(   s4   create astroid for a living method descriptor objectR   R7   N(   RI   R   R	   R   RA   R   R!   (   R   R   RP   R   (    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   object_build_methoddescriptor   s
    c   
      C   s   t  | p t | d d  p | | | j  } t | t  | _ |  j | |  y( t | t	  rp |   j
 } n t  Wn nU XxQ | j   D]C \ } } t j   }	 | |	 _ | |	 _ d |	 _ |	 g | j | <q W| S(   sb   create astroid for a living class object, with a given set of base names
    (e.g. ancestors)
    R   i   N(   R   R   R	   R   RN   t   typet	   _newstyleR   t
   issubclasst	   Exceptiont   __dict__t	   TypeErrort   itemsR   R"   R#   R   t   linenoR   (
   R   R   R<   R   RP   t   klasst   instdictt	   item_namet   objt   valnode(    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyRQ      s"    
			c         C   s   y t  j |  } Wn t k
 r, d  } n Xt | d d   } | d  k rs t | t  s` t  t |  | |  n; | t | d d   k r t	 |  | |  n t
 |  | |  d  S(   Nt   co_filenamet   __file__(   t   sixt   get_function_codet   AttributeErrorR	   R   RN   R#   t   AssertionErrorRX   R&   RV   (   R   R   R   t   modulet   codet   filename(    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   _build_from_function   s    
t   InspectBuilderc           B   s8   e  Z d  Z d   Z d d d  Z d   Z d   Z RS(   s   class for building nodes from living object

    this is actually a really minimal representation, including only Module,
    FunctionDef and ClassDef nodes and some others as guessed.
    c         C   s   i  |  _  d  |  _ d  S(   N(   t   _doneR	   t   _module(   R(   (    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   __init__   s    	c         C   s   | |  _  | d k r! | j } n  y t | | j  } Wn t k
 rV t |  } n X| ro t j j |  n | | _	 | _ | | _
 t j |  t | d  | _ i  |  _ |  j | |  | S(   s   build astroid from a living module (i.e. using inspect)
        this is used when there is no python source code available (either
        because it's a built-in module or because the .py is not available)
        t   __path__N(   Rr   R	   R   R8   R   Rj   t   ost   patht   abspatht   fileR   t   MANAGERt   cache_modulet   hasattrR6   Rq   t   object_build(   R(   Rl   R/   Rv   R   (    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   inspect_build   s    	(		c         C   s  | |  j  k r |  j  | S| |  j  | <xst |  D]e} y t | |  } Wn! t k
 rp t | |  q4 n Xt j |  r t j |  } n  t j	 |  r t
 | | | |  j  q4 t j |  rt |  r |  j | | |  r q4 n  t | | |  q4 t j |  r|  j | | |  r.q4 n  | |  j  k r{|  j  | } | | j j | d  k r| j | |  qn" t | | |  } |  j | |  | d k r| j d k r|  j  |  j | _ qq4 t j |  rt | t  st  t | | |  q4 t j |  r?t | t  s,t  t | | |  q4 t | t  rat | | |  q4 t j  |  rt
 | | | |  j  q4 t | | |  q4 Wd S(   s~   recursive method which create a partial ast from real objects
         (only function, class, and method are handled)
        R   (    N(!   Rq   t   dirR   Rj   R&   R
   t   ismethodRh   t   get_method_functiont
   isfunctionRo   Rr   t	   isbuiltinR   t   imported_memberRX   t   isclasst   localst   getR   RR   R|   R   R	   t   ismethoddescriptorRN   R#   Rk   t   isdatadescriptorRW   t
   _CONSTANTSR-   t	   isroutine(   R(   R   Rd   R   R   t
   class_node(    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyR|     sR    c         C   s  y t  | d d	  } Wn t j d  d	 } n X| d	 k r | d
 k s] | t k ro t ro t j j j	 } q t
 | | |  t Sn  i d d 6d d 6j | |  } | |  j j	 k ry t  t j | |  Wn' t t f k
 r t
 | | |  n Xt | | |  t St S(   s1   verify this is not an imported class or handle itR   s:   unexpected error while building astroid from living objectt   __new__t   __subclasshook__t   gtk_gtkt   gtkR   R   N(   R   R   (   R   R	   t   _LOGt	   exceptiont	   _BUILTINSt   _JYTHONRh   t   movest   builtinsR   R&   t   TrueR   Rr   t   syst   modulest   KeyErrorRj   R2   R5   (   R(   R   R   R   R/   t	   real_name(    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyR   F  s.    

N(   R   R   R   Rs   R	   R}   R|   R   (    (    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyRp      s
   		5c         C   s   |  d k r. d d l m } t j |  }  n  x t j j   D] \ } } | t d  k rt t	 d  } |  | _
 n@ | t t  k r t	 d  } |  | _
 n |  j | j  d } | t t t t f k r | | _ q> | t | <q> Wd S(   s*   astroid boot strapping the builtins modulei(   R   t   NoneTypet   NotImplementedTypei    N(   R	   t	   six.movesR   t   Astroid_BUILDERR}   R   t	   CONST_CLSR_   RY   R   R   t   NotImplementedR   R   t   dictt   listt   sett   tuplet   _proxiedt   _CONST_PROXY(   t   astroid_builtinR   t   clst   node_clst   proxy(    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   _astroid_bootstrappingr  s    c         C   s   t  |  j j S(   N(   R   R,   R   (   t   const(    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   _set_proxied  s    (    (M   R   R
   t   loggingRu   R   t   typesRh   t   astroidR    R   R   R   t   AstroidManagerRy   R   R   R   R   R   t   varsR   R   R   t	   getLoggerR   R   R   R   R!   R#   R'   R&   R)   R"   t   has_underlying_objectR-   R2   R	   R8   R   RI   RL   RE   RR   RV   RW   RX   RQ   Ro   Rp   R   R   R   R   t   propertyt   ConstR   R9   t   GeneratorTypet   _GeneratorTypet   astroid_cacheR   t	   GeneratorR|   t	   _builtinst   GetSetDescriptorTypet   MemberDescriptorTypeRY   R   t   FunctionTypet
   MethodTypet   BuiltinFunctionTypet
   ModuleTypet   TracebackTypet   BUILTIN_TYPESt   _typeR   (    (    (    s3   lib/python2.7/site-packages/astroid/raw_building.pyt   <module>   sr   															