ó
'![c           @  s%  d  Z  d d l m 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
 „  Z d „  Z e e d „ Z d e f d „  ƒ  YZ d e e j f d „  ƒ  YZ d e f d „  ƒ  YZ e d d d „ Z d S(   s{   
Visitor doing some postprocessing on the astroid tree.
Try to resolve definitions (namespace) dictionary, relationship...
iÿÿÿÿ(   t   print_functionN(   t   bases(   t
   exceptions(   t   manager(   t   modutils(   t   node_classes(   t   utilsc         C  s   t  S(   s@   Handler used by interfaces to handle suspicious interface nodes.(   t   True(   t   _(    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   _iface_hdlr   s    c         C  s_   t  d | ƒ y |  | ƒ SWn< t j k
 r> } t  | ƒ n t k
 rZ } t j ƒ  n Xd  S(   Ns   parsing %s...(   t   printR   t   AstroidBuildingExceptiont	   Exceptiont	   tracebackt	   print_exc(   t   funct   modnamet   exc(    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   _astroid_wrapper"   s    c         c  sß   y  t  j |  ƒ j d ƒ d } Wn t j k
 r7 d SX| rU | j ƒ  |  k	 rU d St ƒ  } t } x_ t j	 | ƒ D]N } | t
 j k r• t } qt n  | | k rt | | ƒ rt | j | ƒ | Vqt qt W| rÛ t j ƒ  ‚ n  d S(   sE   Return an iterator on interfaces implemented by the given class node.t   __implements__i    N(   R   t   Instancet   getattrR   t   NotFoundErrort   framet   sett   FalseR   t   unpack_infert   astroidt   YESR   t   addt   InferenceError(   t   nodet   heritedt   handler_funct
   implementst   foundt   missingt   iface(    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt
   interfaces,   s"     	t   IdGeneratorMixInc           B  s/   e  Z d  Z d d „ Z d d „ Z d „  Z RS(   s1   Mixin adding the ability to generate integer uid.i    c         C  s   | |  _  d  S(   N(   t   id_count(   t   selft   start_value(    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   __init__E   s    c         C  s   | |  _  d S(   s   init the id counter
        N(   R(   (   R)   R*   (    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   init_counterH   s    c         C  s   |  j  d 7_  |  j  S(   s"   generate a new identifier
        i   (   R(   (   R)   (    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   generate_idM   s    (   t   __name__t
   __module__t   __doc__R+   R,   R-   (    (    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyR'   B   s   t   Linkerc           B  sž   e  Z d  Z d e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 e Z
 e Z e Z e	 Z d „  Z e d	 „  ƒ Z d
 „  Z d „  Z d „  Z d „  Z RS(   s  Walk on the project tree and resolve relationships.

    According to options the following attributes may be
    added to visited nodes:

    * uid,
      a unique identifier for the node (on astroid.Project, astroid.Module,
      astroid.Class and astroid.locals_type). Only if the linker
      has been instantiated with tag=True parameter (False by default).

    * Function
      a mapping from locals names to their bounded value, which may be a
      constant like a string or an integer, or an astroid node
      (on astroid.Module, astroid.Class and astroid.Function).

    * instance_attrs_type
      as locals_type but for klass member attributes (only on astroid.Class)

    * implements,
      list of implemented interface _objects_ (only on astroid.Class nodes)
    i    c         C  s<   t  j |  ƒ t j j |  ƒ | |  _ | |  _ | |  _ d  S(   N(   R'   R+   R   t   LocalsVisitort   inherited_interfacest   tagt   project(   R)   R5   R3   R4   (    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyR+   k   s
    		c         C  s@   |  j  r |  j ƒ  | _ n  x | j D] } |  j | ƒ q% Wd S(   sc   visit an pyreverse.utils.Project node

         * optionally tag the node with a unique id
        N(   R4   R-   t   uidt   modulest   visit(   R)   R   t   module(    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   visit_projectu   s    	c         C  sC   |  j  r |  j ƒ  | _ n  x! | j ƒ  D] } |  j | ƒ q( Wd S(   s[   visit an astroid.Package node

         * optionally tag the node with a unique id
        N(   R4   R-   R6   t   valuesR8   (   R)   R   t   subelmt(    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   visit_package   s    	c         C  sM   t  | d ƒ r d St j t ƒ | _ g  | _ |  j rI |  j ƒ  | _ n  d S(   s¤   visit an astroid.Module node

         * set the locals_type mapping
         * set the depends mapping
         * optionally tag the node with a unique id
        t   locals_typeN(	   t   hasattrt   collectionst   defaultdictt   listR>   t   dependsR4   R-   R6   (   R)   R   (    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   visit_module‰   s    		c         C  s  t  | d ƒ r d St j t ƒ | _ |  j r@ |  j ƒ  | _ n  xB | j d t	 ƒ D]. } t
 | d g  ƒ } | j | ƒ | | _ qS Wt j t ƒ | _ x8 | j j ƒ  D]' } x | D] } |  j | | ƒ q´ Wq§ Wy t t | |  j ƒ ƒ | _ Wn t j k
 rd | _ n Xd S(   sÉ   visit an astroid.Class node

         * set the locals_type and instance_attrs_type mappings
         * set the implements list and build it
         * optionally tag the node with a unique id
        R>   Nt   recurst   specializations(    (   R?   R@   RA   RB   R>   R4   R-   R6   t	   ancestorsR   R   t   appendRF   t   instance_attrs_typet   instance_attrsR;   t   handle_assignattr_typeR&   R3   R"   R   R   (   R)   R   t   baseobjRF   t   assignattrst
   assignattr(    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   visit_classdef—   s"    	c         C  sD   t  | d ƒ r d St j t ƒ | _ |  j r@ |  j ƒ  | _ n  d S(   sƒ   visit an astroid.Function node

         * set the locals_type mapping
         * optionally tag the node with a unique id
        R>   N(   R?   R@   RA   RB   R>   R4   R-   R6   (   R)   R   (    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   visit_functiondef³   s
    	c         C  s  t  | d ƒ r d St | _ | j | j ƒ  k r@ | j ƒ  } n | j ƒ  } y© t  | d ƒ s² t | t j ƒ r€ |  j	 | ƒ q² t | t j
 ƒ r¢ |  j | ƒ q² |  j | ƒ n  | j | j } t | j ƒ  ƒ } t t | ƒ | Bƒ | j | j <Wn t j k
 rn Xd S(   sE   visit an astroid.AssignName node

        handle locals_type
        t   _handledNR>   (   R?   R   RQ   t   nameR   t   roott
   isinstanceR   t   ClassDefRO   t   FunctionDefRP   RD   R>   R   t   inferRB   R   (   R)   R   R   t   currentR;   (    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   visit_assignnameÄ   s$    	$c         C  sa   yF t  |  j ƒ  ƒ } t  | j |  j ƒ } t | | Bƒ | j |  j <Wn t j k
 r\ n Xd S(   sN   handle an astroid.assignattr node

        handle instance_attrs_type
        N(   R   RW   RI   t   attrnameRB   R   R   (   R   t   parentR;   RX   (    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyRK   æ   s    c         C  sT   | j  ƒ  j } x> | j D]3 } t j | d | ƒ } |  j | | d | ƒ q Wd S(   sJ   visit an astroid.Import node

        resolve module dependencies
        i    N(   RS   t   filet   namesR   t   is_relativet   _imported_module(   R)   R   t   context_fileRR   t   relative(    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   visit_importó   s    c         C  sè   | j  } | j ƒ  j } | d k	 r9 t j | | ƒ } n t } x¢ | j D]— } | d d k re qI n  d | | d f } | j d ƒ d k r¾ y t j	 | | ƒ } Wq¾ t
 k
 rº qI q¾ Xn  | | k rI |  j | | | ƒ qI qI Wd S(   sN   visit an astroid.ImportFrom node

        resolve module dependencies
        i    t   *s   %s.%st   .iÿÿÿÿN(   R   RS   R\   t   NoneR   R^   R   R]   t   findt   get_module_partt   ImportErrorR_   (   R)   R   t   basenameR`   Ra   RR   t   fullname(    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   visit_importfromý   s"    		
c         C  sE   t  j j |  j j ƒ } | | k r( d St j | | f ƒ rA d Sd S(   s9   return true if the module should be added to dependenciesi    i   (   t   ost   patht   dirnameR5   R   t   is_standard_module(   R)   t   context_namet   mod_patht   package_dir(    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   compute_module  s    c         C  s   | j  ƒ  } | j } | rD d d j | j d ƒ d  ƒ | f } n  |  j | | ƒ r™ t | d ƒ sq g  | _ n  | j } | | k r™ | j | ƒ q™ n  d S(   s7   Notify an imported module, used to analyze dependenciess   %s.%sRd   iÿÿÿÿRC   N(   RS   RR   t   joint   splitRs   R?   RC   RH   (   R)   R   Rq   Ra   R9   Rp   t	   mod_paths(    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyR_   !  s    		(   R.   R/   R0   R   R+   R:   R=   RD   RO   RP   t   link_projectt   link_modulet
   link_classt   link_functionRY   t   staticmethodRK   Rb   Rk   Rs   R_   (    (    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyR1   T   s"   
	
	
				"	
			t   Projectc           B  s>   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z RS(   s,   a project handle a set of modules / packagest    c         C  ss   | |  _  d  |  _ g  |  _ i  |  _ |  j j |  _ |  j j |  _ |  j j |  _ |  j j |  _ |  j j	 |  _	 d  S(   N(
   RR   Re   Rm   R7   t   localst   __getitem__t   __iter__R;   t   keyst   items(   R)   RR   (    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyR+   3  s    				c         C  s$   | |  j  | j <|  j j | ƒ d  S(   N(   R~   RR   R7   RH   (   R)   R   (    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt
   add_module>  s    c         C  s   |  j  | S(   N(   R~   (   R)   RR   (    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt
   get_moduleB  s    c         C  s   |  j  S(   N(   R7   (   R)   (    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   get_childrenE  s    c         C  s#   d |  j  t |  ƒ t |  j ƒ f S(   Ns   <Project %r at %s (%s modules)>(   RR   t   idt   lenR7   (   R)   (    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   __repr__H  s    (   R.   R/   R0   R+   Rƒ   R„   R…   Rˆ   (    (    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyR|   1  s   			s   no namet   CVSc   
      C  sf  t  j ƒ  } t | ƒ } xG|  D]?} t j j | ƒ sR t j | j d ƒ ƒ } n0 t j j	 | ƒ r| t j j
 | d ƒ } n | } | | j | ƒ } | d k r¦ q n  | j pµ | j | _ | j | ƒ | j }	 | j r | j d ƒ d k r xl t j t j j | j ƒ | ƒ D]F } | | j | ƒ } | d k s| j |	 k rJqn  | j | ƒ qWq q W| S(   s0   return a Project from a list of files or modulesRd   s   __init__.pyR+   iÿÿÿÿN(   R   t   AstroidManagerR|   Rl   Rm   t   existsR   t   file_from_modpathRu   t   isdirRt   t   ast_from_fileRe   R\   Rƒ   RR   t   packageRf   t   get_module_filesRn   (
   t   filest   func_wrappert   project_namet
   black_listt   astroid_managerR5   t	   somethingt   fpatht   astt	   base_name(    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   project_from_filesM  s,    	(   R‰   (   R0   t
   __future__R    R@   Rl   R   R   R   R   R   R   R   t   pylint.pyreverseR   R	   R   R   R&   t   objectR'   R2   R1   R|   Rš   (    (    (    s9   lib/python2.7/site-packages/pylint/pyreverse/inspector.pyt   <module>   s(   		
Ý