ó
'![c           @   s˜   d  Z  d d l Z d d l Z d d l m Z d d l m Z d d l m Z i d d	 6d
 d d i d d 6f d 6Z	 d e f d „  ƒ  YZ
 d „  Z d S(   sH   Check source code is ascii only or has an encoding declaration (PEP 263)iÿÿÿÿN(   t   IRawChecker(   t   BaseChecker(   t
   OPTION_RGXs   %st   fixmes5   Used when a warning note as FIXME or XXX is detected.t   W0511sA   Cannot decode using encoding "%s", unexpected byte at position %ds   invalid-encoded-datasS   Used when a source line cannot be decoded using the specified source file encoding.i   i    t
   maxversiont   W0512t   EncodingCheckerc           B   sf   e  Z d  Z e Z d Z e Z d i d d 6d d 6d d
 6d d 6f f Z d „  Z	 d „  Z
 d „  Z RS(   sW   checks for:
    * warning notes in the code like FIXME, XXX
    * encoding issues.
    t   miscellaneoust   notest   csvt   types   <comma separated values>t   metavart   FIXMEt   XXXt   TODOt   defaultsA   List of note tags to take in consideration, separated by a comma.t   helpc         C   sK  x( |  j  j D] } | | k r Pq q Wd S| j | ƒ } | sD d S| | k rt j | ƒ } | rys | j d ƒ j d d ƒ \ } }	 g  |	 j d ƒ D] }
 |
 j ƒ  j ƒ  ^ q™ } t | ƒ t |  j  j ƒ @r× d SWqt	 k
 r|  j
 d d | j d ƒ j ƒ  d | ƒd SXqn  |  j
 d d | | j d ƒ j ƒ  d | ƒd S(	   s•  
        Add the message 'fixme' in case a note is found in the line.

        :param notes: regular expression object matching any notes
                      (XXX, TODO, FIXME) behind a '#'
        :type notes: re.pattern object
        :param lineno: line number
        :type lineno: int
        :param line: line to be checked
        :type line: str
        :param module_last_lineno: last line number of the module as parsed by astroid
                                   (may be different from real last line number in case
                                    commented lines exist at the end of the module)
        :type module_last_lineno: int
        Ni   t   =t   ,s   bad-inline-optiont   argst   lineR   (   t   configR	   t   searchR   t   groupt   splitt   stript   uppert   sett
   ValueErrort   add_messaget   startt   rstrip(   t   selfR	   t   linenoR   t   module_last_linenot   notet   matcht   disable_option_matcht   _t   valuet   _valt   values(    (    s3   lib/python2.7/site-packages/pylint/checkers/misc.pyt   _check_note>   s(    !.c         C   s²   y t  j | | ƒ SWn— t k
 rO } |  j d d | d | | j d f ƒn_ t k
 r­ } | j d ƒ r® d | k r® | | k r® |  j d d | d d j | ƒ ƒq® n Xd  S(	   Ns   invalid-encoded-dataR   R   i   t   #t   codings   syntax-errors/   Cannot decode using encoding "{}", bad encoding(   t   sixt	   text_typet   UnicodeDecodeErrorR   R   t   LookupErrort
   startswitht   format(   R!   R"   R   t   file_encodingt   ex(    (    s3   lib/python2.7/site-packages/pylint/checkers/misc.pyt   _check_encodingp   s    c      
   C   sÓ   |  j  j r1 t j d d j |  j  j ƒ ƒ } n d } | j rL | j } n d } | j ƒ  o } xe t | ƒ D]W \ } } |  j	 | d | | ƒ } | d k	 rn | rn |  j
 | | d | | j ƒ qn qn WWd QXd S(   sV   inspect the source file to find encoding problem or fixmes like
        notes
        s   .*?#\s*(%s)(:*\s*.*)t   |t   asciii   N(   R   R	   t   ret   compilet   joint   NoneR4   t   streamt	   enumerateR6   R+   t   tolineno(   R!   t   moduleR	   t   encodingR=   R"   R   (    (    s3   lib/python2.7/site-packages/pylint/checkers/misc.pyt   process_module~   s    	(   R   R   R   (   t   __name__t
   __module__t   __doc__R    t   __implements__t   namet   MSGSt   msgst   optionsR+   R6   RB   (    (    (    s3   lib/python2.7/site-packages/pylint/checkers/misc.pyR   ,   s   	2	c         C   s   |  j  t |  ƒ ƒ d S(   s-   required method to auto register this checkerN(   t   register_checkerR   (   t   linter(    (    s3   lib/python2.7/site-packages/pylint/checkers/misc.pyt   register“   s    (   s   %sR   s5   Used when a warning note as FIXME or XXX is detected.(   i   i    (   RE   R9   R.   t   pylint.interfacesR    t   pylint.checkersR   t   pylint.utilsR   RH   R   RM   (    (    (    s3   lib/python2.7/site-packages/pylint/checkers/misc.pyt   <module>   s     g