ó
'![c           @   s.  d  Z  d d l Z d d l Z d d l Z y> d d l Z d d l m Z m Z m Z m	 Z	 m
 Z
 m Z Wn= e k
 r§ d Z d d  d „  ƒ  YZ d d! d „  ƒ  YZ n Xd d l Z d d l m Z m Z d d	 l m Z d d
 l m Z d d l m Z e d k	 rˆe j ƒ  Z e j ƒ  Z d g g  e D] Z e d ^ q+Z g  e D]! Z d e d e d j f ^ qIZ d j e ƒ Z d Z  n d Z d g Z d Z  d e f d „  ƒ  YZ! d e f d „  ƒ  YZ" d e f d „  ƒ  YZ# d e f d „  ƒ  YZ$ d e f d „  ƒ  YZ% d e f d „  ƒ  YZ& d „  Z' d S("   s8   Checker for spelling errors in comments and docstrings.
iÿÿÿÿN(   t   get_tokenizert   Chunkert   Filtert   EmailFiltert	   URLFiltert   WikiWordFilterR   c           B   s   e  Z d  „  Z RS(   c         C   s
   t  ‚ d  S(   N(   t   NotImplementedError(   t   selft   word(    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyt   _skip"   s    (   t   __name__t
   __module__R	   (    (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyR   !   s   R   c           B   s   e  Z RS(    (   R
   R   (    (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyR   %   s   (   t   ITokenCheckert   IAstroidChecker(   t   BaseTokenChecker(   t   check_messages(   t   safe_decodet    i    s   %s (%s)i   s   , t   nones3    To make it working install python-enchant package.t   WordsWithDigigtsFilterc           B   s   e  Z d  Z d „  Z RS(   s   Skips words with digits.
    c         C   s%   x | D] } | j  ƒ  r t Sq Wt S(   N(   t   isdigitt   Truet   False(   R   R   t   char(    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyR	   A   s    (   R
   R   t   __doc__R	   (    (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyR   =   s   t   WordsWithUnderscoresc           B   s   e  Z d  Z d „  Z RS(   sS   Skips words with underscores.

    They are probably function parameter names.
    c         C   s
   d | k S(   Nt   _(    (   R   R   (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyR	   M   s    (   R
   R   R   R	   (    (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyR   H   s   t   CamelCasedWordc           B   s&   e  Z d  Z e j d ƒ Z d „  Z RS(   sÈ   Filter skipping over camelCasedWords.
    This filter skips any words matching the following regular expression:

           ^([a-z]\w+[A-Z]+\w+)

    That is, any words that are camelCasedWords.
    s   ^([a-z]+([\d]|[A-Z])(?:\w+)?)c         C   s   t  |  j j | ƒ ƒ S(   N(   t   boolt   _patternt   match(   R   R   (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyR	   [   s    (   R
   R   R   t   ret   compileR   R	   (    (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyR   Q   s   t   SphinxDirectivesc           B   s&   e  Z d  Z e j d ƒ Z d „  Z RS(   sÉ   Filter skipping over Sphinx Directives.
    This filter skips any words matching the following regular expression:

           ^:([a-z]+):`([^`]+)(`)?

    That is, for example, :class:`BaseQuery`
    s   ^:([a-z]+):`([^`]+)(`)?c         C   s   t  |  j j | ƒ ƒ S(   N(   R   R   R   (   R   R   (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyR	   j   s    (   R
   R   R   R   R    R   R	   (    (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyR!   _   s   t   ForwardSlashChunkderc           B   s    e  Z d  Z d „  Z d „  Z RS(   s[   
    This chunker allows splitting words like 'before/after' into 'before' and 'after'
    c         C   sâ   xÛ t  rÝ |  j s t ƒ  ‚ n  d |  j k rR |  j } d |  _ d |  _ | d f S|  j j d d ƒ \ } } | |  _ d |  _ | s¯ | s¯ | d j ƒ  s¯ | d j ƒ  rÓ d |  _ d |  _ | d | d f S| d f SWd  S(   Nt   /i    R   i   iÿÿÿÿ(   R   t   _textt   StopIterationt   _offsett   splitt   isalpha(   R   t   textt   pre_textt	   post_text(    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyt   nextr   s"    					
		"		c         C   s¢   x’ t  r” d |  j k r% |  j d f S|  j j d d ƒ \ } } | sN | rR Pn  | d j ƒ  st | d j ƒ  r€ t ƒ  ‚ n  | d | |  _ q Wt ƒ  ‚ d  S(   NR#   i    i   iÿÿÿÿt    (   R   R$   R'   R(   R%   (   R   R*   R+   (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyt   _next…   s    	"(   R
   R   R   R,   R.   (    (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyR"   n   s   	t   SpellingCheckerc           B   s}  e  Z d  Z e e f Z d Z i d1 d 6d2 d	 6d3 d 6Z d i d d 6d d 6d d 6e d 6d e	 e
 f d 6f d i d d 6d d 6d d 6d d 6f d i d d 6d d 6d d 6d d 6f d i d  d 6d! d 6d" d 6d# d 6f d$ i d% d 6d& d 6d' d 6d( d 6f f Z d) „  Z d* „  Z d+ „  Z d, „  Z e d ƒ d- „  ƒ Z e d ƒ d. „  ƒ Z e d ƒ d/ „  ƒ Z e Z d0 „  Z RS(4   s)   Check spelling in comments and docstringst   spellingsE   Wrong spelling of a word '%s' in a comment:
%s
%s
Did you mean: '%s'?s   wrong-spelling-in-comments5   Used when a word in comment is not spelled correctly.t   C0401sG   Wrong spelling of a word '%s' in a docstring:
%s
%s
Did you mean: '%s'?s   wrong-spelling-in-docstrings7   Used when a word in docstring is not spelled correctly.t   C0402s$   Invalid characters %r in a docstrings   invalid-characters-in-docstrings;   Used when a word in docstring cannot be checked by enchant.t   C0403s   spelling-dictR   t   defaultt   choicet   types   <dict name>t   metavart   choicess7   Spelling dictionary name. Available dictionaries: %s.%st   helps   spelling-ignore-wordst   strings   <comma separated words>s9   List of comma separated words that should not be checked.s   spelling-private-dict-files   <path to file>sE   A path to a file that contains private dictionary; one word per line.s   spelling-store-unknown-wordst   nt   yns   <y_or_n>s‰   Tells whether to store unknown words to indicated private dictionary in --spelling-private-dict-file option instead of raising a message.s   max-spelling-suggestionsi   t   intt   Ns9   Limits count of emitted suggestions for spelling mistakesc         C   s[  t  |  _ d  |  _ t d  k r" d  S|  j j } | s8 d  Sg  |  j j j d ƒ D] } | j	 ƒ  ^ qN |  _
 |  j
 j d d g ƒ |  j j r¬ t j j |  j j ƒ |  j _ n  |  j j rî t j | |  j j ƒ |  _ t |  j j d ƒ |  _ n t j | ƒ |  _ |  j j rt ƒ  |  _ n  t | d t g d t t t t t t t g ƒ|  _ t  |  _ d  S(   Nt   ,t   paramt   pylintt   at   chunkerst   filters(!   R   t   initializedt   Nonet   private_dict_filet   enchantt   configt   spelling_dictt   spelling_ignore_wordsR'   t   stript   ignore_listt   extendt   spelling_private_dict_filet   ost   patht
   expandusert   DictWithPWLt   opent   Dictt   spelling_store_unknown_wordst   sett   unknown_wordsR    R"   R   R   R   R   R   R   R!   t	   tokenizerR   (   R   t	   dict_namet   w(    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyRT   À   s<    		1			c         C   s   |  j  r |  j  j ƒ  n  d  S(   N(   RG   t   close(   R   (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyR\   ê   s    	c         C   sV  | } | j  ƒ  j d ƒ r4 | j  ƒ  d } t } n t } x|  j | j  ƒ  ƒ D]þ\ } } t j rt | j ƒ  } n | j ƒ  } | |  j	 k sP | |  j	 k r¤ qP n  | j d ƒ rÜ t
 | ƒ d k rÜ | d } | d } n  y4 |  j j | ƒ r÷ wP n  |  j j | ƒ rwP n  Wn6 t j j k
 rH|  j d d	 | d
 | f ƒqP n X|  j j rŽ| |  j k rN|  j j d | ƒ |  j j | ƒ qNqP |  j j | ƒ }	 |	 |  j j 3t j d | | ƒ }
 |
 rÝ|
 j d d } n | j | ƒ } | rÿ| d 7} n  d | d t
 | ƒ } |  j | d	 | d
 | | | d j d j |	 ƒ ƒ f ƒqP Wd  S(   Nt   #i   s   u's   u"s   r's   r"i   s   invalid-characters-in-docstringt   linet   argss   %s
s   (\W|^)(%s)(\W|$)i    R-   t   ^s   '{0}'s   ' or '(   s   u's   u"s   r's   r"(   RL   t
   startswithR   R   RY   t   sixt   PY2t   lowert   casefoldRM   t   lenRJ   t   checkRH   t   errorst   Errort   add_messageRI   RV   RX   RG   t   writet   addt   suggestt   max_spelling_suggestionsR   t   searcht   regst   indext   formatt   join(   R   t   msgidR^   t   line_numt   original_linet   starts_with_commentR   R   t   lower_cased_wordt   suggestionst   mt   colt	   indicator(    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyt   _check_spellingî   sP    	"	!

c         C   s’   |  j  s d  Sx~ | D]v \ } } \ } } } } | t j k r | d k r_ | j d ƒ r_ q n  | j d ƒ rt q n  |  j d | | ƒ q q Wd  S(   Ni   s   #!/s	   # pylint:s   wrong-spelling-in-comment(   RE   t   tokenizet   COMMENTRa   R}   (   R   t   tokenst   tok_typet   tokent	   start_rowR   (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyt   process_tokens.  s    	"	c         C   s   |  j  s d  S|  j | ƒ d  S(   N(   RE   t   _check_docstring(   R   t   node(    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyt   visit_module>  s    	c         C   s   |  j  s d  S|  j | ƒ d  S(   N(   RE   R…   (   R   R†   (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyt   visit_classdefD  s    	c         C   s   |  j  s d  S|  j | ƒ d  S(   N(   RE   R…   (   R   R†   (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyt   visit_functiondefJ  s    	c         C   s‹   | j  } | s d S| j d } t j rM | j ƒ  j } t | | d ƒ } n  x7 t | j ƒ  ƒ D]# \ } } |  j	 d | | | ƒ q` Wd S(   s&   check the node has any spelling errorsNi   t   replaces   wrong-spelling-in-docstring(
   t   doct   linenoRb   Rc   t   roott   file_encodingR   t	   enumeratet
   splitlinesR}   (   R   R†   t	   docstringt
   start_linet   encodingt   idxR^   (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyR…   R  s    			(   sE   Wrong spelling of a word '%s' in a comment:
%s
%s
Did you mean: '%s'?s   wrong-spelling-in-comments5   Used when a word in comment is not spelled correctly.(   sG   Wrong spelling of a word '%s' in a docstring:
%s
%s
Did you mean: '%s'?s   wrong-spelling-in-docstrings7   Used when a word in docstring is not spelled correctly.(   s$   Invalid characters %r in a docstrings   invalid-characters-in-docstrings;   Used when a word in docstring cannot be checked by enchant.(   R
   R   R   R   R   t   __implements__t   namet   msgst   dict_choicest   dictst   instrt   optionsRT   R\   R}   R„   R   R‡   Rˆ   R‰   t   visit_asyncfunctiondefR…   (    (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyR/   ’   sV         





	*		@	c         C   s   |  j  t |  ƒ ƒ d S(   s.   required method to auto register this checker N(   t   register_checkerR/   (   t   linter(    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyt   registerc  s    (    (    ((   R   RP   R~   R   RH   t   enchant.tokenizeR    R   R   R   R   R   t   ImportErrorRF   Rb   t   pylint.interfacesR   R   t   pylint.checkersR   t   pylint.checkers.utilsR   t   pylint.utilsR   t   Brokert   brt
   list_dictsR™   t   dR˜   R–   Rs   Rš   R   R   R   R!   R"   R/   RŸ   (    (    (    s7   lib/python2.7/site-packages/pylint/checkers/spelling.pyt   <module>   s@   2$.			$Ñ