ó
'![c           @   s†   d  Z  d d l j Z d d l Z d d l Z d d l Z d d l Z d „  Z d e	 f d „  ƒ  YZ
 d „  Z d d „ Z d „  Z d S(	   s^   Graph manipulation utilities.

(dot generation adapted from pypy/translator/tool/make_dot.py)
iÿÿÿÿNc         C   sG   t  j |  ƒ } t  j t  j |  ƒ ƒ } |  j d ƒ d } | | | f S(   sD   Transforms /some/path/foo.png into ('/some/path', 'foo.png', 'png').t   .iÿÿÿÿ(   t   ospt   basenamet   dirnamet   abspatht   split(   t   filenameR   t   storedirt   target(    (    s+   lib/python2.7/site-packages/pylint/graph.pyt   target_info_from_filename   s    t
   DotBackendc           B   sk   e  Z d  Z d	 d	 d	 d d d	 d „ Z d „  Z e e ƒ Z d	 d	 d	 d „ Z d „  Z	 d „  Z
 d „  Z RS(
   s   Dot File backend.s   utf-8t   dotc   	      C   s  | d  k r i  } n  | |  _ | |  _ g  |  _ d  |  _ |  j d t | ƒ ƒ | rj |  j d | ƒ n  | r„ |  j d | ƒ n  | rž |  j d | ƒ n  | rÚ | j ƒ  d k sÆ t d | ƒ ‚ |  j d	 | ƒ n  x* | j	 ƒ  D] } |  j d
 j
 | ƒ ƒ qç Wd  S(   Ns   digraph %s {s
   rankdir=%ss   ratio=%ss	   size="%s"s   utf-8s
   iso-8859-1t   latin1s   unsupported charset %ss   charset="%s"t   =(   s   utf-8s
   iso-8859-1R   (   t   Nonet	   graphnamet   renderert   linest   _sourcet   emitt   normalize_node_idt   lowert   AssertionErrort   itemst   join(	   t   selfR   t   rankdirt   sizet   ratiot   charsetR   t   additional_paramt   param(    (    s+   lib/python2.7/site-packages/pylint/graph.pyt   __init__   s&    					c         C   sA   |  j  d k r: |  j d ƒ d j |  j ƒ |  _  |  ` n  |  j  S(   s   returns self._sources   }
s   
N(   R   R   R   R   R   (   R   (    (    s+   lib/python2.7/site-packages/pylint/graph.pyt
   get_source3   s
    	c      
   C   sÃ  d d l  } |  j } | sF | r9 | j d ƒ r9 | } qF d | } n  | d k	 r° t | ƒ \ } } } | d k r› t j d | ƒ \ }	 }
 t j |	 ƒ q t	 j
 | | ƒ }
 nP d } t j d | ƒ \ }	 }
 t j d | ƒ \ } } t j |	 ƒ t j | ƒ t j |
 d d	 d
 ƒ}	 |	 j |  j ƒ |	 j ƒ  | d k r¿t j d k } | r‡| j |  j d d | d | |
 d | g	 d | ƒn( | j |  j d | |
 d | g d | ƒt j |
 ƒ n  | S(   s)  Generates a graph file.

        :param str outputfile: filename and path [defaults to graphname.png]
        :param str dotfile: filename and path [defaults to graphname.dot]
        :param str mapfile: filename and path

        :rtype: str
        :return: a path to the generated file
        iÿÿÿÿNs   .dots   %s.dotR   t   pngs   .pngt   wt   encodingt   utf8t   win32s   -Tcmapxs   -os   -Tt   shell(   t
   subprocessR   t   endswithR   R	   t   tempfilet   mkstempt   ost   closeR   R   t   codecst   opent   writet   sourcet   syst   platformt   callR   t   unlink(   R   t
   outputfilet   dotfilet   mapfileR(   t   nameR   t   _R   t   pdott   dot_sourcepatht   ppngt	   use_shell(    (    s+   lib/python2.7/site-packages/pylint/graph.pyt   generate=   s@    
		

c         C   s   |  j  j | ƒ d S(   s   Adds <line> to final output.N(   R   t   append(   R   t   line(    (    s+   lib/python2.7/site-packages/pylint/graph.pyR   m   s    c   	      K   su   g  | j  ƒ  D] \ } } d | | f ^ q } t | ƒ t | ƒ } } |  j d | | d j t | ƒ ƒ f ƒ d S(   sw   emit an edge from <name1> to <name2>.
        edge properties: see http://www.graphviz.org/doc/info/attrs.html
        s   %s="%s"s   %s -> %s [%s];s   , N(   R   R   R   R   t   sorted(	   R   t   name1t   name2t   propst   propt   valuet   attrst   n_fromt   n_to(    (    s+   lib/python2.7/site-packages/pylint/graph.pyt	   emit_edgeq   s    /c         K   s_   g  | j  ƒ  D] \ } } d | | f ^ q } |  j d t | ƒ d j t | ƒ ƒ f ƒ d S(   st   emit a node with given properties.
        node properties: see http://www.graphviz.org/doc/info/attrs.html
        s   %s="%s"s   %s [%s];s   , N(   R   R   R   R   RB   (   R   R9   RE   RF   RG   RH   (    (    s+   lib/python2.7/site-packages/pylint/graph.pyt	   emit_nodey   s    /N(   t   __name__t
   __module__t   __doc__R   R    R!   t   propertyR1   R?   R   RK   RL   (    (    (    s+   lib/python2.7/site-packages/pylint/graph.pyR
      s   		0		c         C   s   d |  S(   s)   Returns a suitable DOT node id for `nid`.s   "%s"(    (   t   nid(    (    s+   lib/python2.7/site-packages/pylint/graph.pyR   €   s    c         C   sY   |  s
 d Sg  } | d k r+ |  j ƒ  } n  x' | D] } t |  g  t ƒ  | | ƒ q2 W| S(   s·   given a dictionary representing an ordered graph (i.e. key are vertices
    and values is a list of destination vertices representing edges), return a
    list of detected cycles
    (    N(   R   t   keyst   _get_cyclest   set(   t
   graph_dictt   verticest   resultt   vertice(    (    s+   lib/python2.7/site-packages/pylint/graph.pyt
   get_cycles„   s    c   	      C   s  | | k r£ | g } x; | d d d … D]& } | | k r? Pn  | j  d | ƒ q) Wt | ƒ } | j | ƒ } | | | d | !} | | k rŸ | j | ƒ n  d S| j | ƒ yK xD |  | D]8 } | | k r¾ t |  | | | | ƒ | j | ƒ q¾ q¾ WWn t k
 rn X| j ƒ  d S(   s5   recursive function doing the real work for get_cyclesNiÿÿÿÿi    (   t   insertt   mint   indexR@   RS   t   addt   KeyErrort   pop(	   RU   t   patht   visitedRW   RX   t   cyclet   nodet
   start_fromR\   (    (    s+   lib/python2.7/site-packages/pylint/graph.pyRS   ’   s*    	(   RO   t   os.pathR`   R   R,   R2   R*   R.   R	   t   objectR
   R   R   RY   RS   (    (    (    s+   lib/python2.7/site-packages/pylint/graph.pyt   <module>   s   	e	