ó
'![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   Z d	 e f d
     YZ e j e j e j e j f Z d   Z d   Z d S(   s    Copyright (c) 2003-2010 LOGILAB S.A. (Paris, FRANCE).
 http://www.logilab.fr/ -- mailto:contact@logilab.fr

Raw metrics checker
i’’’’N(   t   ITokenChecker(   t   EmptyReportError(   t   BaseTokenChecker(   t   diff_string(   t   Tablec         C   só   | d } | s t     n  d | |  _ d } x d D] } | d } | | } t | d  | } | j | d  }	 |	 d k	 r t |	 |  }
 n d \ }	 }
 | | t |  d | t |	  |
 f 7} q6 W|  j t d | d d d d   d S(   s9   calculate percentage of code / doc / comment / empty
    t   total_liness   %s lines have been analyzedt   typet   numbert   %t   previoust
   differencet   codet	   docstringt   commentt   emptyt   _linesid   t   NCs   %.2ft   childrent   colsi   t   rheadersi   N(   R   R   R   R	   R
   (   R   R   R   R   (   R   R   (	   R   t   descriptiont   floatt   gett   NoneR   t   strt   appendR   (   t   sectt   statst	   old_statsR   t   linest	   node_typet   keyt   totalt   percentt   oldt   diff_str(    (    s:   lib/python2.7/site-packages/pylint/checkers/raw_metrics.pyt   report_raw_stats   s     


t   RawMetricsCheckerc           B   sV   e  Z d  Z e f Z d Z d Z i  Z d d e f f Z	 d   Z
 d   Z d   Z RS(   sć   does not check anything but gives some raw metrics :
    * total number of lines
    * total number of code lines
    * total number of docstring lines
    * total number of comments lines
    * total number of empty lines
    t   metricst   RP0701s   Raw metricsc         C   s   t  j |  |  d  |  _ d  S(   N(   R   t   __init__R   R   (   t   selft   linter(    (    s:   lib/python2.7/site-packages/pylint/checkers/raw_metrics.pyR(   E   s    c         C   s4   |  j  j d d d d d d d d d d  |  _ d S(   s   init statisticsR   i    t
   code_linest   empty_linest   docstring_linest   comment_linesN(   R*   t	   add_statsR   (   R)   (    (    s:   lib/python2.7/site-packages/pylint/checkers/raw_metrics.pyt   openI   s    c         C   sm   d } t  |  } xT | t |  k  rh t | |  \ } } } |  j d c | 7<|  j | c | 7<q Wd S(   s   update statsi    R   N(   t   listt   lent   get_typeR   (   R)   t   tokenst   it   lines_numbert	   line_type(    (    s:   lib/python2.7/site-packages/pylint/checkers/raw_metrics.pyt   process_tokensO   s    (    (   t   __name__t
   __module__t   __doc__R    t   __implements__t   namet   optionst   msgsR$   t   reportsR(   R0   R8   (    (    (    s:   lib/python2.7/site-packages/pylint/checkers/raw_metrics.pyR%   1   s   			c         C   sE  | } |  | d } |  | d } | } d	 } x¬ | t |   k  rÜ |  | d d | d k rÜ |  | d } |  | d } | d	 k rĻ | t j k r d } qĻ | t j k r· d } qĻ | t k rĘ qĻ d } n  | d 7} q1 W| d	 k rņ d } n6 | t |   k  r(|  | d t j k r(| d 7} n  | | d | d d | f S(
   s6   return the line type : docstring, comment, code, emptyi    i   i   R-   R.   R+   i   R,   N(   R   R2   t   tokenizet   STRINGt   COMMENTt   JUNKt   NEWLINE(   R4   t   start_indexR5   t   tok_typet   startt   posR7   (    (    s:   lib/python2.7/site-packages/pylint/checkers/raw_metrics.pyR3   [   s,    1				)c         C   s   |  j  t |    d S(   s/    required method to auto register this checker N(   t   register_checkerR%   (   R*   (    (    s:   lib/python2.7/site-packages/pylint/checkers/raw_metrics.pyt   registerv   s    (   R;   RA   t   pylint.interfacesR    t   pylint.exceptionsR   t   pylint.checkersR   t   pylint.reportersR   t   pylint.reporters.ureports.nodesR   R$   R%   t   NLt   INDENTRE   t	   ENDMARKERRD   R3   RK   (    (    (    s:   lib/python2.7/site-packages/pylint/checkers/raw_metrics.pyt   <module>   s   	(	