
'![c           @  s  d  Z  d d l m Z d d l Z d d l Z d d l m Z d d l Z d d l m	 Z	 m
 Z
 m Z m Z m Z m Z m 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 m Z d d l m Z d d	 l m Z m Z m Z m  Z  d d
 l! m" Z" d d l# m$ Z$ m% Z% m& Z& i d d 6d d 6d d 6d d 6d d 6d d 6Z' d   e j( e'  D Z) i d d 6d d 6d d 6d d 6d d 6d d 6Z* d Z+ d Z, d Z- d Z. e j/ d   Z0 d! Z1 d" e2 f d#     YZ3 e j4 d$ d% d& d' d d( d) d* d+ d, d- d. d/ g  Z5 d0 e5 f d1     YZ6 d2   Z7 d3   Z8 d4   Z9 d5 d6  Z: d7   Z; d8   Z< d9   Z= d: e2 f d;     YZ> d< e2 f d=     YZ? d> e2 f d?     YZ@ d@ e2 f dA     YZA dB e2 f dC     YZB dD   ZC dE   ZD dF   ZE dG e2 f dH     YZF dI dJ dK dL dM dN f ZG dO   ZH eI dP  ZJ eI eI eI eI dQ  ZK dR dS  ZL dT   ZM dU dV dW  ZN dX   ZO e jP rdY   ZQ n	 dZ   ZQ d[   ZR d\   ZS d]   ZT eI eI d^  ZU d_   ZV eU ZW eI eI d`  ZX d S(a   sV   some various utilities and helper classes, most of them used in the
main pylint class
i(   t   print_functionN(   t   cleandoc(   t   dirnamet   basenamet   splitextt   existst   isdirt   joint   normpath(   t   zip(   t   nodest   Module(   t   modutils(   t   IRawCheckert   ITokenCheckert	   UNDEFINEDt
   implements(   t   Section(   t   InvalidMessageErrort   UnknownMessageErrort   EmptyReportErrort   infot   It
   conventiont   Ct   refactort   Rt   warningt   Wt   errort   Et   fatalt   Fc         C  s   i  |  ] \ } } | |  q S(    (    (   t   .0t   kt   v(    (    s+   lib/python2.7/site-packages/pylint/utils.pys
   <dictcomp>D   s   	 i    i   i   i   i   i   t   EWRCIFs   \s*#.*\bpylint:\s*([^;]+);{0,1}t   FRt   WarningScopec           B  s   e  Z d  Z d Z RS(   s   line-based-msgs   node-based-msg(   t   __name__t
   __module__t   LINEt   NODE(    (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR&   \   s   t   _MsgBaset   msg_idt   symbolt   msgt   categoryt
   confidencet   abspatht   patht   modulet   objt   linet   columnt   Messagec           B  s    e  Z d  Z d   Z d   Z RS(   s<   This class represent a message to be issued by the reportersc      	   C  s.   t  j |  | | | | d t | d | |  S(   Ni    (   R+   t   __new__t	   MSG_TYPES(   t   clsR,   R-   t   locationR.   R0   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR8   h   s    c         C  s   | j  t t |  j |      S(   s   Format the message according to the given template.

        The template format is the one of the format method :
        cf. http://docs.python.org/2/library/string.html#formatstrings
        (   t   formatt   dictR	   t   _fields(   t   selft   template(    (    s+   lib/python2.7/site-packages/pylint/utils.pyR<   m   s    (   R'   R(   t   __doc__R8   R<   (    (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR7   f   s   	c         C  s   |  j    } d g  } } xk | r t | t  r= | j } n | j t | d d   y | j j    } Wq t k
 r d } q Xq W| j	   | d j
 |  f S(   s5   return the module name and the frame id in the modulet    t   names   <lambda>t   .N(   t   framet
   isinstanceR   RC   t   appendt   getattrt   parentt   AttributeErrort   Nonet   reverseR   (   t   nodeRE   R3   R4   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   get_module_and_frameidx   s    	
c         C  s)   |  j    }  |  t k r |  St j |   S(   N(   t   upperR9   t   MSG_TYPES_LONGt   get(   t   cid(    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   category_id   s    c         O  sQ   y# |  j  | p t j   | |  SWn' t k
 rL |  j  t j   | |  SXd S(   sA   return decoded line from encoding or decode with default encodingN(   t   decodet   syst   getdefaultencodingt   LookupError(   R5   t   encodingt   argst   kwargs(    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   safe_decode   s    #t   strictc         C  sU   y t  j | p t j    } Wn& t k
 rG t  j t j    } n X| |  |  S(   N(   t   codecst	   getreaderRU   RV   RW   (   t   streamRX   t   errorst
   reader_cls(    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   decoding_stream   s
    c         C  s   t  |  | d d j S(   s4   return lambda function for tokenize with safe decodeR`   t   replace(   Rb   t   readline(   R_   RX   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   _decoding_readline   s    c         C  s{   |  j    i } | j } t j d k  r^ |  j d  k	 rK t | |  j  } n  t t j	 |   St t j |   SWd  QXd  S(   Ni   i    (   i   i    (
   R_   Rd   RU   t   version_infot   file_encodingRK   Re   t   listt   tokenizet   generate_tokens(   R3   R_   Rd   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   tokenize_module   s    	c         C  s   t  |  t t f  r! t j } n	 t j } i  } t |  d k rW | \ } } } } nJ t |  d k r{ | \ } } } n& | \ } } t j d | t	  d  } | j d |  t |  | | | | |  S(   Ni   i   sG   [pylint 0.26] description of message %s doesn't include a symbolic namet   scope(   R   R   R   R&   R)   R*   t   lent   warningst   warnt   DeprecationWarningRK   t
   setdefaultt   MessageDefinition(   t   checkert   msgidt	   msg_tuplet   default_scopet   optionsR.   R-   t   descr(    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   build_message_def   s    		Rr   c           B  s/   e  Z d d d d   Z d   Z e d  Z RS(   c
   
      C  s   | |  _  t |  d k r. t d |   n  | d t k r[ t d | d | f   n  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _	 | |  _
 |	 p g  |  _ d  S(   Ni   s   Invalid message id %ri    s   Bad message type %s in %r(   Rs   Rm   R   R9   Rt   R.   Rx   R-   Rl   t
   minversiont
   maxversiont	   old_names(
   R?   Rs   Rt   R.   Rx   R-   Rl   Rz   R{   R|   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   __init__   s    								c         C  sN   |  j  d k	 r% |  j  t j k r% t S|  j d k	 rJ |  j t j k rJ t St S(   sC   return True if message may be emitted using the current interpreterN(   Rz   RK   RU   Rf   t   FalseR{   t   True(   R?   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   may_be_emitted   s
    !!c         C  s  |  j  } | r& | d |  j j 7} n  |  j } |  j rQ d |  j |  j f } n	 |  j } |  j sl |  j r-g  } |  j r | j d d j	 g  |  j D] } t
 |  ^ q   n  |  j r | j d d j	 g  |  j D] } t
 |  ^ q   n  d j	 |  } | r| d | 7} q-| d | 7} n  t d	 j	 | j    d
 d } | d k r{| j   d } d | | | f Sd | | f S(   s/   return the help string for the given message ids(    This message belongs to the %s checker.s   %s (%s)s   < %sRD   s   >= %ss    or s*    It can't be emitted when using Python %s.s4    This message can't be emitted when using Python %s.t    t   indents     s   %si    s   :%s: *%s*
%ss   :%s:
%s(   Rx   Rs   RC   R.   R-   Rt   Rz   R{   RG   R   t   strt   _normalize_textt   splitt
   splitlines(   R?   t
   checkerreft   desct   titleRt   t   restrt   n(    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   format_help   s.    					9	9!N(   R'   R(   RK   R}   R   R~   R   (    (    (    s+   lib/python2.7/site-packages/pylint/utils.pyRr      s   	t   MessagesHandlerMixInc           B  s   e  Z d  Z d   Z d   Z d d e d  Z d d e d  Z d d e d  Z	 d   Z
 d e d  Z d d d	  Z d d d e d
  Z d d  Z e d d   Z RS(   s[   a mix-in class containing all the messages related methods for the main
    lint class
    c         C  s   i  |  _  d |  _ d  S(   Ni    (   t   _msgs_statet
   msg_status(   R?   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR}      s    	c         c  s;   x4 |  j  | j   D] } x | j D] } | Vq$ Wq Wd  S(   N(   t	   _checkerst   lowert   msgs(   R?   Rs   t   known_checkerRt   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   _checker_messages  s    t   packagec      
   C  s)   |  j  | d t d | d | d | d S(   s$   don't output message of the given idt   enableRl   R5   t   ignore_unknownN(   t   _set_msg_statusR~   (   R?   Rt   Rl   R5   R   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   disable  s    c      
   C  s)   |  j  | d t d | d | d | d S(   s    reenable message of the given idR   Rl   R5   R   N(   R   R   (   R?   Rt   Rl   R5   R   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR     s    c         C  s  | d
 k s t   | d k rl x' t D] } |  j | | | | |  q% W| rh |  j rh |  j d  n  d  St |  } | d  k	 r x3 |  j j j	 |  D] } |  j | | | |  q Wd  S| j
   |  j k r:|  j } xW |  j | j
   D]B }	 x9 |	 j D]. } | | j k r |  j | | | |  q q Wq Wd  S| j
   j d  rv| re|  j |  n |  j |  d  Sy |  j j |  }
 Wn t k
 r| rd  S  n X| d k r7|  j j |
 | |  | r|  j d d | d |
 j |
 j f q|
 j d	 k r|  j d	 d | d |
 j |
 j f qn |  j } | | |
 j <g  t t j |   D]! \ } } | rc|  j |  ^ qc|  j _ g  t t j |   D]! \ } } | s|  j |  ^ q|  j _ d  S(   NR   R3   t   allt   python3t   rps   locally-enabledR5   RY   s   locally-disabled(   R   R3   (   t   AssertionErrorR9   R   t   _python3_porting_modeR   RS   RK   t
   msgs_storet   _msgs_by_categoryRQ   R   R   R   t   _alternative_namest
   startswitht   enable_reportt   disable_reportt   check_message_idR   t
   file_statet   set_msg_statust   add_messageR-   Rt   R   t   sortedt   sixt	   iteritemst   _message_symbolt   configR   (   R?   Rt   R   Rl   R5   R   t   _msgidt   catidR   Rs   R.   R   t   midt   val(    (    s+   lib/python2.7/site-packages/pylint/utils.pyR     sX    	!	@c         C  s0   y |  j  j |  j SWn t k
 r+ | SXd S(   s   Get the message symbol of the given message id

        Return the original message id if the message does not
        exist.
        N(   R   R   R-   R   (   R?   Rt   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR   L  s    c         C  sb   |  j  j r% | j |  j  j k r% t Sy | |  j j | k rB t SWn t t f k
 r] t	 SXd S(   s:   Returns the scope at which a message was enabled/disabled.N(   R   R0   RC   t   MSG_STATE_CONFIDENCER   t   _module_msgs_statet   MSG_STATE_SCOPE_MODULEt   KeyErrort	   TypeErrort   MSG_STATE_SCOPE_CONFIGRK   (   R?   Rt   R5   R0   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   get_message_state_scopeW  s    !c         C  s   |  j  j r. | r. | j |  j  j k r. t Sn  y |  j j |  j } Wn t k
 r` | } n X| d k r |  j	 j
 | t  Sy |  j j | | SWn! t k
 r |  j	 j
 | t  SXd S(   s   return true if the message associated to the given message id is
        enabled

        msgid may be either a numeric or symbolic message id.
        N(   R   R0   RC   R~   R   R   Rt   R   RK   R   RQ   R   R   R   R   (   R?   t	   msg_descrR5   R0   Rt   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   is_message_enabledb  s    
c      
   C  s  |  j  j |  } | j } | j p' | } | d t k r | j t j k r | d k rk t	 d |   n  | d k	 r t	 d | | | f   q q | j t j
 k r | d k r t	 d |   q q n  | d k r | d k	 r | j } n  t | d  r| j }	 n d }	 |  j | | |  sY|  j j |  j | | |  | | | | |  d St | d }
 |  j t | d O_ |  j |
 c d 7<|  j d |  j |
 c d 7<y |  j d	 | c d 7<Wn" t k
 rd |  j d	 | <n X| j } | r| | ;} n  | d k r3|  j d
 } } |  j } n! t |  \ } } | j   j } | j |  j j d
  } |  j j  t! | | | | | | | pd |	 pd f | |   d S(   s*  Adds a message given by ID or name.

        If provided, the message string is expanded using args

        AST checkers should must the node argument (but may optionally
        provide line if the line number is different), raw and token checkers
        must provide the line argument.
        i    s&   Message %s must provide line, got Nones7   Message %s must only provide line, got line=%s, node=%ss&   Message %s must provide Node, got Nonet
   col_offsetNi   t	   by_modulet   by_msgRB   ("   R   R   Rt   R-   t   _SCOPE_EXEMPTRl   R&   R)   RK   R   R*   t
   fromlinenot   hasattrR   R   R   t   handle_ignored_messageR   R9   R   t   MSG_TYPES_STATUSt   statst   current_nameR   R.   t   current_fileRN   t   roott   fileRc   t   reportert   path_strip_prefixt   handle_messageR7   (   R?   R   R5   RM   RY   R0   t   msg_infoRt   R-   R   t   msg_catR.   R3   R4   R1   R2   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR   y  s\    						c   	      C  s  | s t  j } n  t d d | t d d | t d d | t d d | t d d | i  } xe|  j   D]W} | j d k r%| j rx | j   D]{ \ } } | d k r d } n d | j   } t | d | t d	 t	 |  d | t
 | d |  t d d | q Wqqu | j } yM | | d
 c | j   7<| | d j | j  | | d c | j 7<Wqu t k
 ri t | j    d
 6t | j  d 6t | j  d 6| | <qu Xqu Wt d d | t d d | t d d | t d d | t d d | t d d | t d d | t d d | t d d | t d d | t d d | x9 t t j |   D]" \ } } |  j | | d | qWd S(   s*   output a full documentation in ReST formats"   Pylint global options and switchesR   s"   ----------------------------------RB   s,   Pylint provides global options and switches.t   masters   General optionss
   %s optionst   ~Rw   R   t   reportss%   Pylint checkers' options and switchess%   -------------------------------------s2   Pylint checkers can provide three set of features:s'   * options that control their execution,s   * messages that they can raise,s!   * reports that they can generate.s3   Below is a list of all checkers and their features.R_   N(   RU   t   stdoutt   printt   get_checkersRC   Rw   t   options_by_sectionRK   t
   capitalizeRm   t   _rest_format_sectiont   options_and_valuest   updateR   R   R   Rh   R=   R   R   R   t   _print_checker_doc(	   R?   R_   t
   by_checkerRs   t   sectionRw   R   RC   R   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   print_full_documentation  sT    			"c         C  s  | s t  j } n  | j d  } | j d  } | j d  } | j d  } | j d  } d |  j d d  j   } | r t d	 | d
 | n  t | d
 | t d t |  d
 | t d d
 | | r t d | d
 | n  t d |  d
 | t d d
 | | rpd } t | d
 | t d t |  d
 | t t |  d
 | t d d
 | n  | rd } t | d
 | t d t |  d
 | t | d |  t d d
 | n  | rod } t | d
 | t d t |  d
 | xZ t
 t j |  d d   D]: \ }	 }
 t |  |	 |
  }
 t |
 j d t  d
 | qWt d d
 | n  | rd } t | d
 | t d t |  d
 | x& | D] } t d | d  d
 | qWt d d
 | n  t d d
 | d S(   si   Helper method for print_full_documentation.

        Also used by doc/exts/pylint_extensions.py.
        t   docR3   R   Rw   R   s
   %s checkert   _R   s   .. _%s:
R   R   RB   s#   This checker is provided by ``%s``.s'   Verbatim name of the checker is ``%s``.t   Documentationt   ^t   Optionst   Messagest   keyc         S  s   t  j |  d d  |  d f S(   Ni    i   (   t
   _MSG_ORDERt   index(   t   kv(    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   <lambda>  s    R   t   Reportss   :%s: %si   N(   RU   R   RQ   Rc   R   R   Rm   R   R   RK   R   R   R   Ry   R   R~   (   t   checker_nameR   R_   R   R3   R   Rw   R   R   Rt   R.   t   report(    (    s+   lib/python2.7/site-packages/pylint/utils.pyR     s\     N(   R'   R(   RA   R}   R   RK   R~   R   R   R   R   R   R   R   R   R   t   staticmethodR   (    (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR      s   		<	D4t	   FileStatec           B  sG   e  Z d  Z d d  Z d   Z d   Z d   Z d   Z d   Z	 RS(   s;   Hold internal state specific to the currently analyzed filec         C  s:   | |  _  i  |  _ i  |  _ t j t  |  _ i  |  _ d  S(   N(   t	   base_nameR   t   _raw_module_msgs_statet   collectionst   defaultdictt   sett   _ignored_msgst   _suppression_mapping(   R?   t   modname(    (    s+   lib/python2.7/site-packages/pylint/utils.pyR}   -  s
    			c         C  sn   x3 t  j |  j  D] \ } } | j   |  j | <q W|  j j   } i  |  _ i  |  _ |  j | | |  d S(   s9   Walk the AST to collect block level options line numbers.N(   R   R   R   t   copyR   R   t   _collect_block_lines(   R?   R   t   module_nodeR.   t   linest
   orig_state(    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   collect_block_lines4  s    		c         C  s  x' | j    D] } |  j | | |  q W| j } | j } t | t j t j t j f  ry | j	 ry | j	 d j } n | } xvt
 j |  D]e\ } }	 xVt |	 j    D]B\ }
 } |
 } | |
 k s | |
 k  r q n  | j |  j t j k r&|
 | k rt } n  | j |
  \ } } n |
 } | } x t | | d  D] } | |  j j | d  k rmqFn  | |	 k r|	 | } | } n  | s| |  j | | f <n  y | |  j | | <WqFt k
 ri | | 6|  j | <qFXqFW|	 |
 =q Wq Wd S(   s`   Recursively walk (depth first) AST to collect block level options
        line numbers.
        i    i   N(    (   t   get_childrenR   R   t   tolinenoRF   R
   R   t   ClassDeft   FunctionDeft   bodyR   R   Rh   t   itemsR   Rl   R&   R*   R   t   block_ranget   rangeR   RQ   R   R   (   R?   R   RM   t	   msg_statet   childt   firstt   lastt   firstchildlinenoRt   R   t   linenot   statet   original_linenot   first_t   last_R5   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR   =  s@    		!		
	c         C  sY   | d k s t   y | |  j | j | <Wn( t k
 rT i | | 6|  j | j <n Xd S(   s@   Set status (enabled/disable) for a given message at a given linei    N(   R   R   Rt   R   (   R?   R.   R5   t   status(    (    s+   lib/python2.7/site-packages/pylint/utils.pyR   v  s
    c         C  sX   | t  k rT y1 |  j | | f } |  j | | f j |  WqT t k
 rP qT Xn  d S(   s  Report an ignored message.

        state_scope is either MSG_STATE_SCOPE_MODULE or MSG_STATE_SCOPE_CONFIG,
        depending on whether the message was disabled locally in the module,
        or globally. The other arguments are the same as for add_message.
        N(   R   R   R   t   addR   (   R?   t   state_scopeRt   R5   RM   RY   R0   t	   orig_line(    (    s+   lib/python2.7/site-packages/pylint/utils.pyR   ~  s    c         c  s   xy t  j |  j  D]e \ } } xV t  j |  D]E \ } } | r/ | | f |  j k r/ d | | j |  f f Vq/ q/ Wq WxW t |  j j    D]@ \ \ } } } x+ | D]# } d | | j |  | f f Vq Wq Wd  S(   Ns   useless-suppressions   suppressed-message(   R   R   R   R   t   get_msg_display_stringRh   R   (   R?   R   R   R   R5   R   t   from_(    (    s+   lib/python2.7/site-packages/pylint/utils.pyt"   iter_spurious_suppression_messages  s    (N(
   R'   R(   RA   RK   R}   R   R   R   R   R  (    (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR   *  s   			9		t   MessagesStorec           B  se   e  Z d  Z d   Z e d    Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z RS(
   sw   The messages store knows information about every possible message but has
    no particular state during analysis.
    c         C  s(   i  |  _  i  |  _ t j t  |  _ d  S(   N(   t	   _messagesR   R   R   Rh   R   (   R?   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR}     s    		c         C  s   t  j |  j  S(   s    The list of all active messages.(   R   t
   itervaluesR  (   R?   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   messages  s    c         C  sI   |  j  |  } | j j | | f  |  j | |  |  j | |  d S(   s   Register the old ID and symbol for a warning that was renamed.

        This allows users to keep using the old ID/symbol in suppressions.
        N(   R   R|   RG   t   _register_alternative_name(   R?   t   old_idt
   old_symbolt
   new_symbolR.   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   add_renamed_message  s    c         C  sE  d } x8t t j | j   D]\ } } t | | |  } | j |  j k sa | j |  j k rw t	 d | j   n  | d k	 r | | j
 d d !k r t	 d | | f   n  | j
 d d !} | |  j | j <|  j | | j
  x7 | j D], \ } } |  j | |  |  j | |  q W|  j | j
 d j | j
  q Wd S(   s.  register a dictionary of messages

        Keys are message ids, values are a 2-uple with the message type and the
        message itself

        message ids should be a string of len 4, where the two first characters
        are the checker id and the two last the message id in this checker
        s$   Message symbol %r is already definedi   i   s=   Inconsistent checker part in message id %r (expected 'x%sxx')i    N(   RK   R   R   R   R   Ry   R-   R  R   R   Rt   R  R|   R   RG   (   R?   Rs   t   chkidRt   Ru   R.   R  R  (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   register_messages  s"    	%$"c         C  s   | |  j  k r5 |  j  | | k r5 t d |   n  | |  j k r |  j | | k r t d t |  d k r | d t k r d n d | f   n  | |  j | <d S(   s   helper for register_message()s$   Message symbol %r is already defineds    Message %s %r is already definedi   i    t   ids   alternate nameN(   R  R   R   Rm   R9   (   R?   R.   RC   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR    s    ""+c         C  sp   | d j    r | j   } n  x: |  j |  j f D]& } y | | SWq2 t k
 rW q2 Xq2 Wt d |   d S(   s   returns the Message object for this message.

        msgid may be either a numeric or symbolic id.

        Raises UnknownMessageError if the message id is not defined.
        i   s   No such message id %sN(   t   isdigitRO   R   R  R   R   (   R?   Rt   t   source(    (    s+   lib/python2.7/site-packages/pylint/utils.pyR     s    c         C  s   t  |  j |  j  S(   s   Generates a user-consumable representation of a message.

        Can be just the message ID or the ID and the symbol.
        (   t   reprR   R-   (   R?   Rt   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR    s    c         C  so   xh | D]` } y- t  |  j |  j d t   t  d  Wq t k
 rf } t  |  t  d  q q Xq Wd S(   s7   display help messages for the given message identifiersR   RB   N(   R   R   R   R   R   (   R?   t   msgidsRt   t   ex(    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   help_message  s    

c         C  sh   t  t j |  j  d d   } x6 | D]. } | j   s@ q( n  t | j d t   q( Wt d  d S(   s6   output full messages list documentation in ReST formatR   c         S  s   |  j  S(   N(   Rt   (   R.   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR     s    R   RB   N(   R   R   R  R  R   R   R   R~   (   R?   R   R.   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   list_messages  s    !(   R'   R(   RA   R}   t   propertyR  R  R  R  R   R  R$  R%  (    (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR    s   		
					t   ReportsHandlerMixInc           B  sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   sq   a mix-in class containing all the reports and stats manipulation
    related methods for the main lint class
    c         C  s   t  j t  |  _ i  |  _ d  S(   N(   R   R   Rh   t   _reportst   _reports_state(   R?   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR}     s    c         C  s   t  |  j  S(   s]    Return a list of reports, sorted in the order
        in which they must be called.
        (   Rh   R(  (   R?   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   report_order  s    c         C  s-   | j    } |  j | j | | | f  d S(   s   register a report

        reportid is the unique identifier for the report
        r_title the report's title
        r_cb the method to call to make the report
        checker is the checker defining the report
        N(   RO   R(  RG   (   R?   t   reportidt   r_titlet   r_cbRs   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   register_report  s    c         C  s   | j    } t |  j | <d S(   s"   disable the report of the given idN(   RO   R   R)  (   R?   R+  (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR   '  s    c         C  s   | j    } t |  j | <d S(   s"   disable the report of the given idN(   RO   R~   R)  (   R?   R+  (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR   ,  s    c         C  s   |  j  j | t  S(   sX   return true if the report associated to the given identifier is
        enabled
        (   R)  RQ   R   (   R?   R+  (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   report_is_enabled1  s    c   	      C  s   t  d d |  j d  } x |  j   D] } x |  j | D]q \ } } } |  j |  s_ q; n  t  |  } y | | | |  Wn t k
 r q; n X| | _ | j |  q; Wq' W| S(   s   render registered reportst   Reports   %s statements analysed.t	   statement(   R   R   R*  R(  R/  R   t	   report_idRG   (	   R?   R   t	   old_statst   sectRs   R+  R,  R-  t   report_sect(    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   make_reports7  s    	c         K  sf   x\ t  j |  D]K \ } } | d d k r9 | d  } n  | |  j k sN t  | |  j | <q W|  j S(   sv   add some stats entries to the statistic dictionary
        raise an AssertionError if there is a key conflict
        iR   (   R   R   R   R   (   R?   RZ   R   t   value(    (    s+   lib/python2.7/site-packages/pylint/utils.pyt	   add_statsH  s    (   R'   R(   RA   R}   R*  R.  R   R   R/  R6  R8  (    (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR'    s   							c         C  s(   x! | D] } | j  |   r t Sq Wt S(   sI  Determines if the basename is matched in a regex blacklist

    :param str base_name: The basename of the file
    :param list black_list_re: A collection of regex patterns to match against.
        Successful matches are blacklisted.

    :returns: `True` if the basename is blacklisted, `False` otherwise.
    :rtype: bool
    (   t   matchR   R~   (   R   t   black_list_ret   file_pattern(    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   _basename_in_blacklist_reS  s    
c           s"     f d   } t  j |  d | S(   Nc           s   t  j |  |  p   S(   N(   R   t   check_modpath_has_init(   R2   t   parts(   t   is_namespace(    s+   lib/python2.7/site-packages/pylint/utils.pyt   _is_package_cbc  s    t   is_package_cb(   R   t   modpath_from_file_with_callback(   t   filenameR?  R@  (    (   R?  s+   lib/python2.7/site-packages/pylint/utils.pyt   _modpath_from_fileb  s    c         C  s  g  } g  } x|  D]} t  j j |  | k r7 q n  t t  j j |  |  rX q n  t |  r y d j t j |   } Wn' t k
 r t	 t |   d } n Xt
 |  r t | d  } qF| } nu | } y. t j | j d   } | d k rw n  Wn> t t f k
 rE} | j i d d 6| d 6| d 6 q n Xt |  } | p[| j d  }	 y t j |	 d t j }
 Wn# t k
 rt } t
 |  } n Xt j |
  } t j |
  } | s | j i | d 6| d	 6t d
 6| d 6| d 6 n  | j d  p| d k o+t |  d k } | s@| s@| r x t j t |  | d | D] } | | k rwq_n  t t |  |  rq_n  t | |  } d j |  } | j i | d 6| d	 6t d
 6| d 6| d 6 q_Wq q W| | f S(   s   take a list of files/modules/packages and return the list of tuple
    (file, module name) which have to be actually checked
    RD   i    s   __init__.pyR   R   t   modR#  R2   RC   t   isargt   basepathR   s	   .__init__R}   t   list_allN(   t   osR2   R   R<  R   R   R   t   modpath_from_filet   ImportErrorR   R   t   file_from_modpathR   RK   t   SyntaxErrorRG   R   t   file_info_from_modpathRU   R~   R?  t   is_directoryR   t   endswitht   get_module_filesR   RD  (   t   files_or_modulest
   black_listR:  t   resultR`   t	   somethingR   t   filepathR#  t   modpartst   specR?  RO  t   has_initt   subfilepatht   modpatht
   submodname(    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   expand_modulesi  sd    	
"t   PyLintASTWalkerc           B  s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C  s:   d |  _  t j t  |  _ t j t  |  _ | |  _ d  S(   Ni    (   t   nbstatementsR   R   Rh   t   visit_eventst   leave_eventst   linter(   R?   Rb  (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR}     s    	c         C  sA   t  | d  s t Sx' | j D] } |  j j |  r t Sq Wt S(   Nt   checks_msgs(   R   R   Rc  Rb  R   R~   (   R?   t   methodt   msg_desc(    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   _is_method_enabled  s    c         C  s[  t    } t    } |  j } |  j } x t |  D] } | d } | d k rS q1 n  | j d  r t | |  } |  j |  r | | j |  | j |  q q1 | j d  r1 t | |  }	 |  j |	  r | | j |	  | j |  q q1 q1 Wt | d d  }
 |
 rWxC t
 j D]5 } | j j   } | | k r| | j |
  qqWn  d S(   s=   walk to the checker's dir and collect visit and leave methodsi   t   defaultt   visit_t   leave_t   visit_defaultN(   R   R`  Ra  t   dirR   RH   Rf  RG   R  RK   R
   t   ALL_NODE_CLASSESR'   R   (   R?   Rs   t   vcidst   lcidst   visitst   leavest   memberRR   t   v_metht   l_methRj  R:   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   add_checker  s0    				
c         C  s   | j  j j   } d } d } |  j j | d  } |  j j | d  } | j rc |  j d 7_ n  x | po d D] } | |  qp Wx! | j   D] } |  j	 |  q Wx | p d D] } | |  q Wd S(	   sv   call visit events of astroid checkers for the given node, recurse on
        its children, then leave events.
        i   N(    (    (    (    (    (    (
   t	   __class__R'   R   R`  RQ   Ra  t   is_statementR_  R   t   walk(   R?   t   astroidRR   R`  Ra  t   cbR  (    (    s+   lib/python2.7/site-packages/pylint/utils.pyRw    s    	(   R'   R(   R}   Rf  Rt  Rw  (    (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR^    s   			s   .pys   .pycs   .pyos   .pyws   .sos   .dllc         C  s  i  } x	t  j |  D] } t |  \ } } | | k s | d k rL q n  | t k rd | d k s | r t t | |   r y t j t | |   } WnC t k
 r q qt	 k
 r } t
 d | | f d t j qXt | d  r| j |   d | | <qq q Wd S(   s   load all module and package in the given directory, looking for a
    'register' function in each one, used to register pylint checkers
    t   __pycache__R}   s   Problem importing module %s: %sR   t   registeri   N(   RI  t   listdirR   t   PY_EXTSR   R   R   t   load_module_from_filet
   ValueErrorRK  R   RU   t   stderrR   R{  (   Rb  t	   directoryt   importedRC  t   baset	   extensionR3   t   exc(    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   register_plugins  s"    c         C  s   y  t  |  j | j d d   SWn t k
 r3 n XxT |  j j D]F } x= | j D]2 } | d | k rQ t  | j | j d d   SqQ WqA W| S(   s   Retrieve an option defined by the given *checker* or
    by all known option providers.

    It will look in the list of all options providers
    until the given *option* will be found.
    If the option wasn't found, the *default* value will be returned.
    t   -R   i    (   RH   R   Rc   RJ   Rb  t   options_providersRw   (   Rs   t   optionRg  t   providerRw   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   get_global_option  s     $c           sV     f d   } i | d 6t  d 6| d 6d d 6| d 6t  d 6} |  rR |  | d <n  | S(	   Nc           s$     r  t  j j   | f  n  d  S(   N(   RU   R  t   write(   R  t   optnameRY   (   t   deprecation_msg(    s+   lib/python2.7/site-packages/pylint/utils.pyt   _warn_deprecated,  s    t   helpt   hidet   typet   callbackt   actiont
   deprecatedt	   shortname(   R   (   R  t   opt_typet   help_msgR  R  R  (    (   R  s+   lib/python2.7/site-packages/pylint/utils.pyt   deprecated_option+  s    
t   ,c         C  s2   g  |  j  |  D] } | j   r | j   ^ q S(   s%  return a list of stripped string by splitting the string given as
    argument on `sep` (',' by default). Empty string are discarded.

    >>> _splitstrip('a, b, c   ,  4,,')
    ['a', 'b', 'c', '4']
    >>> _splitstrip('a')
    ['a']
    >>> _splitstrip('a,
b,
c,')
    ['a', 'b', 'c']

    :type string: str or unicode
    :param string: a csv line

    :type sep: str or unicode
    :param sep: field separator, default to the comma (',')

    :rtype: str or unicode
    :return: the unquoted string (or the input string if it wasn't quoted)
    (   R   t   strip(   t   stringt   sept   word(    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   _splitstrip=  s    c         C  sH   |  s
 |  S|  d d k r' |  d }  n  |  d d k rD |  d  }  n  |  S(   s   remove optional quotes (simple or double) from the string

    :type string: str or unicode
    :param string: an optionally quoted string

    :rtype: str or unicode
    :return: the unquoted string (or the input string if it wasn't quoted)
    i    s   "'i   i(    (   R  (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   _unquoteT  s    	iP   RB   c      	   C  s(   d j  t j |  d | d | d |  S(   s'   Wrap the text on the given line length.s   
t   widtht   initial_indentt   subsequent_indent(   R   t   textwrapt   wrap(   t   textt   line_lenR   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR   f  s    c         C  s#   t  |  t t f  r |  St |   S(   N(   RF   Rh   t   tupleR  (   R7  (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt
   _check_csvl  s    c         C  s&   t  |  t  r |  j |  St |   S(   N(   RF   t   unicodet   encodeR   (   R  RX   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   _encodes  s    c         C  s
   t  |   S(   N(   R   (   R  R   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR  y  s    c         C  s=   |  p t  | d d   }  |  s9 d d  l } | j   }  n  |  S(   NRX   i(   RH   RK   t   localet   getpreferredencoding(   RX   R_   R  (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   _get_encoding|  s
    c         C  s=   g  |  j    D] } | j   ^ q } d d t j j |  S(   s   return string as a comments   # s   %s# (   R   R  RI  t   linesepR   (   R  R5   R   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   _comment  s    %c           s   t  | t t f  r7 d j   f d   | D  } n t  | t  rh d j d   | j   D  } np t | d  r | j } nU   j d  d k r | r d n d } n+ t  | t	 j
  r | j   r d	 | } n  | S(
   s5   return the user input's value from a 'compiled' valueR  c         3  s   |  ] } t    |  Vq d  S(   N(   t   _format_option_value(   R!   t   item(   t   optdict(    s+   lib/python2.7/site-packages/pylint/utils.pys	   <genexpr>  s    c         s  s%   |  ] \ } } d  | | f Vq d S(   s   %s:%sN(    (   R!   R"   R#   (    (    s+   lib/python2.7/site-packages/pylint/utils.pys	   <genexpr>  s    R9  R  t   ynt   yest   nos   '%s'(   RF   Rh   R  R   R=   R   R   t   patternRQ   R   t   string_typest   isspace(   R  R7  (    (   R  s+   lib/python2.7/site-packages/pylint/utils.pyR    s    ""c         C  s_   t  | |   } | r7 t t t |  |  d |  n  t d | d |  t |  | |  d S(   s.   format an options section using the INI formatR   s   [%s]N(   R  R   R  R  t   _ini_format(   R_   R   Rw   RX   R   (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   _ini_format_section  s
    "c         C  sC  x<| D]4\ } } } t  | |  } | j d  } | r{ t | d d d d } t d |   t t | |  d |  n t d |   | d k r t d | d |  q t | |  j   } t j d t	 |   r!d	 d
 t
 |  } | j d   t	 |  j d  D  } | d  } n  t d | | f d |  q Wd S(   s#   format options using the INI formatR  R  iO   R   s   # R   s   #%s=s   ^([\w-]+,)+[\w-]+$s   
 R   c         s  s   |  ] } | d  Vq d S(   R  N(    (   R!   t   x(    (    s+   lib/python2.7/site-packages/pylint/utils.pys	   <genexpr>  s    R  is   %s=%sN(   R  RQ   R   R   R  RK   R  t   reR9  R   Rm   R   R   (   R_   Rw   RX   R  R  R7  R  t	   separator(    (    s+   lib/python2.7/site-packages/pylint/utils.pyR    s"    "c   	      C  sF  t  | |   } | r< t d | d t |  f d |  n  | r} t t t | d d d d |  d |  t d |   n  x | D] \ } } } | j d  } t d	 | d |  | r t | d d d d
 } t t | |  d |  n  | r t t | |  |  } t d |   t d | j d d  d |  q q Wd S(   s8   format an options section using as ReST formatted outputs   %s
%st   'R   R  iO   R   RB   R  s   :%s:s     s     Default: ``%s``s   `` s   ```` ``N(   R  R   Rm   R  R   RQ   R  Rc   (	   R_   R   Rw   RX   R   R  R  R7  R  (    (    s+   lib/python2.7/site-packages/pylint/utils.pyR     s     '+(Y   RA   t
   __future__R    R]   R   t   inspectR   RI  t   os.pathR   R   R   R   R   R   R   R  RU   Ri   Rn   R  R   t	   six.movesR	   Rx  R
   R   R   t   pylint.interfacesR   R   R   R   t   pylint.reporters.ureports.nodesR   t   pylint.exceptionsR   R   R   R9   R   RP   R   R   R   R   R   t   compilet
   OPTION_RGXR   t   objectR&   t
   namedtupleR+   R7   RN   RS   R[   Rb   Re   Rk   Ry   Rr   R   R   R  R'  R<  RD  R]  R^  R}  R  RK   R  R  R  R  R   R  t   PY2R  R  R  R  R  R  t   format_sectionR   (    (    (    s+   lib/python2.7/site-packages/pylint/utils.pyt   <module>#   s   4"

					
	7 3ptE			FL										