
    c&?                    ^   d Z ddlmZ ddlZddl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 ej        d	k    rdd
lmZ ndd
lmZ erddlmZ 	 ddlZddlmZmZmZmZmZmZ nV# e$ rN dZ G d d          Z G d d          Z G d d          Z G d d          Z G d d          Z	 	 	 d=d>dZY nw xY weW ej                    Ze                                Z dgd  e D             z   Z!d! e D             Z d""                    e           Z dZ#nd#Z dgZ!d$Z# G d% d&e          Z$ G d' d(e          Z% G d) d*e          Z& G d+ d,e&          Z' G d- d.e&          Z( G d/ d0e          Z) ej*        d1          Z+ ej*        d2          Z,d?d5Z-d?d6Z. G d7 d8e          Z/d@d<Z0dS )Az7Checker for spelling errors in comments and docstrings.    )annotationsN)Pattern)TYPE_CHECKING)nodes)BaseTokenChecker)only_required_for_messages)      )Literal)PyLinter)ChunkerEmailFilterFilter	URLFilterWikiWordFilterget_tokenizerc                      e Zd ZdS )r   N__name__
__module____qualname__     8lib/python3.11/site-packages/pylint/checkers/spelling.pyr   r   )           r   r   c                      e Zd ZdS )r   Nr   r   r   r   r   r   ,   r   r   r   c                      e Zd ZdS )r   Nr   r   r   r   r   r   /   r   r   r   c                      e Zd ZddZdS )r   wordstrreturnboolc                    t           N)NotImplementedErrorselfr   s     r   _skipzFilter._skip3   s    %%r   Nr   r    r!   r"   )r   r   r   r(   r   r   r   r   r   2   s(        	& 	& 	& 	& 	& 	&r   r   c                      e Zd ZdS )r   Nr   r   r   r   r   r   6   s        r   r   tag
str | Nonechunkerslist[Chunker] | Nonefilterslist[Filter] | Noner!   c                    t                      S r$   )r   )r+   r-   r/   s      r   r   r   9   s    
 xxr    c                    g | ]
}|d          S )r   r   .0ds     r   
<listcomp>r7   D   s    ///A1Q4///r   c                @    g | ]}|d           d|d         j          dS )r   z (   ))namer4   s     r   r7   r7   E   s3    444!$$!	$$$444r   z, nonez7 To make it work, install the 'python-enchant' package.c                      e Zd ZdZddZdS )	WordsWithDigitsFilterzSkips words with digits.r   r    r!   r"   c                4    t          d |D                       S )Nc              3  >   K   | ]}|                                 V  d S r$   )isdigit)r5   chars     r   	<genexpr>z.WordsWithDigitsFilter._skip.<locals>.<genexpr>R   s*      33d4<<>>333333r   )anyr&   s     r   r(   zWordsWithDigitsFilter._skipQ   s    33d333333r   Nr)   r   r   r   __doc__r(   r   r   r   r>   r>   N   s.        ""4 4 4 4 4 4r   r>   c                      e Zd ZdZddZdS )	WordsWithUnderscoreszSSkips words with underscores.

    They are probably function parameter names.
    r   r    r!   r"   c                
    d|v S )N_r   r&   s     r   r(   zWordsWithUnderscores._skip[   s    d{r   Nr)   rE   r   r   r   rH   rH   U   s2         
     r   rH   c                  &    e Zd ZU dZded<   d
dZd	S )RegExFilterzParent class for filters using regular expressions.

    This filter skips any words the match the expression
    assigned to the class attribute ``_pattern``.
    zPattern[str]_patternr   r    r!   r"   c                P    t          | j                            |                    S r$   )r"   rM   matchr&   s     r   r(   zRegExFilter._skiph   s     DM''--...r   Nr)   )r   r   r   rF   __annotations__r(   r   r   r   rL   rL   _   sB           / / / / / /r   rL   c                  2    e Zd ZdZ ej        d          ZdS )CamelCasedWordzFilter 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.
    z^([a-z]+(\d|[A-Z])(?:\w+)?)Nr   r   r   rF   recompilerM   r   r   r   rR   rR   l   s,          rz899HHHr   rR   c                  2    e Zd ZdZ ej        d          ZdS )SphinxDirectiveszFilter skipping over Sphinx Directives.
    This filter skips any words matching the following regular expression:

           ^(:([a-z]+)){1,2}:`([^`]+)(`)?

    That is, for example, :class:`BaseQuery`
    z^(:([a-z]+)){1,2}:`([^`]+)(`)?NrS   r   r   r   rW   rW   w   s,          rz;<<HHHr   rW   c                  .    e Zd ZU dZded<   d
dZddZd	S )ForwardSlashChunkerz[This chunker allows splitting words like 'before/after' into 'before' and
    'after'.
    r    _textr!   tuple[str, int]c                p   	 | j         st                      d| j         vr| j         }d| _        d| _         |dfS | j                             dd          \  }}|| _         d| _        |r6|r4|d                                         r|d                                         sd| _         d| _        | d| dfS |dfS )NT/r   r2   r9   )rZ   StopIteration_offsetsplitisalpha)r'   textpre_text	post_texts       r   nextzForwardSlashChunker.next   s    	: &#oo%$*$ z 
Qw"&*"2"23":":Hi"DJDL4 4  |++--4 !|++--	4  
 "00Y00!33Q;r   tuple[str, Literal[0]]c                *   	 d| j         vr	| j         dfS | j                             dd          \  }}|r|snP|d                                         r|d                                         st                      |dz   |z   | _         t                      )NTr]   r   r9   r^    )rZ   ra   rb   r_   )r'   rd   re   s      r   _nextzForwardSlashChunker._next   s    	4$*$ %z1}$"&*"2"23":":Hi 9 B<'')) &11E1E1G1G &#oo%!C)3DJ	4 oor   N)r!   r[   )r!   rg   )r   r   r   rF   rP   rf   rj   r   r   r   rY   rY      sS           JJJ   .
 
 
 
 
 
r   rY   z!(\s|^)(`{1,2})([^`]+)(\2)([^`]|$)z#(\s|^)(type\: ignore\[[^\]]+\])(.*)liner    c                @    dd}t                               ||           S )zAlter line so code flanked in back-ticks is ignored.

    Pyenchant automatically strips back-ticks when parsing tokens,
    so this cannot be done at the individual filter level.
    	match_objre.Match[str]r!   r    c                X    |                      d          |                      d          z   S )Nr9      grouprm   s    r   -replace_code_but_leave_surrounding_characterszW_strip_code_flanked_in_backticks.<locals>.replace_code_but_leave_surrounding_characters   s%    q!!IOOA$6$666r   rm   rn   r!   r    )CODE_FLANKED_IN_BACKTICK_REGEXsub)rk   rt   s     r    _strip_code_flanked_in_backticksrx      s5    7 7 7 7 *--5t  r   c                @    dd}t                               ||           S )zAlter line so mypy rule name is ignored.

    Pyenchant parses anything flanked by spaces as an individual token,
    so this cannot be done at the individual filter level.
    rm   rn   r!   r    c                X    |                      d          |                      d          z   S )Nr9   r	   rq   rs   s    r   2replace_rule_name_but_leave_surrounding_charactersz]_strip_mypy_ignore_directive_rule.<locals>.replace_rule_name_but_leave_surrounding_characters   s'     q!!IOOA$6$666r   ru   ) MYPY_IGNORE_DIRECTIVE_RULE_REGEXrw   )rk   r{   s     r   !_strip_mypy_ignore_directive_ruler}      s5    7 7 7 7
 ,//:D  r   c                  6   e Zd ZdZdZddddZddd	d
ede de dfddddddfddddddfddddddfddddd dfd!d"ddd#dffZ	d:d&Z
d;d+Zd<d.Z ed/          d=d2            Z ed/          d>d4            Z ed/          d?d6            ZeZd@d8Zd9S )ASpellingCheckerz*Check spelling in comments and docstrings.spelling)zEWrong spelling of a word '%s' in a comment:
%s
%s
Did you mean: '%s'?wrong-spelling-in-commentz5Used when a word in comment is not spelled correctly.)zGWrong spelling of a word '%s' in a docstring:
%s
%s
Did you mean: '%s'?wrong-spelling-in-docstringz7Used when a word in docstring is not spelled correctly.)z$Invalid characters %r in a docstringinvalid-characters-in-docstringz;Used when a word in docstring cannot be checked by enchant.)C0401C0402C0403zspelling-dictr2   choicez<dict name>z2Spelling dictionary name. Available dictionaries: .)defaulttypemetavarchoiceshelpzspelling-ignore-wordsstringz<comma separated words>z9List of comma separated words that should not be checked.)r   r   r   r   zspelling-private-dict-filepathz<path to file>zIA path to a file that contains the private dictionary; one word per line.zspelling-store-unknown-wordsnynz<y or n>zTells whether to store unknown words to the private dictionary (see the --spelling-private-dict-file option) instead of raising a message.zmax-spelling-suggestions   intNz:Limits count of emitted suggestions for spelling mistakes.z"spelling-ignore-comment-directivesz2fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy:zList of comma separated words that should be considered directives if they appear at the beginning of a comment and should not be checked.r!   Nonec                   d| _         t          d S | j        j        j        }|sd S d | j        j        j                            d          D             | _        | j                            ddg           d | j        j        j	                            d          D             | _
        | j        j        j        r*t          j        || j        j        j                  | _        nt          j        |          | _        | j        j        j        rt                      | _        t#          |t$          gt&          t(          t*          t,          t.          t0          t2          g          | _        d| _         d S )	NFc                6    g | ]}|                                 S r   stripr5   ws     r   r7   z(SpellingChecker.open.<locals>.<listcomp>2  s-     
 
 
AGGII
 
 
r   ,parampylintc                6    g | ]}|                                 S r   r   r   s     r   r7   z(SpellingChecker.open.<locals>.<listcomp>9  s0     .
 .
 .
 GGII.
 .
 .
r   )r-   r/   T)initializedenchantlinterconfigspelling_dictspelling_ignore_wordsra   ignore_listextend"spelling_ignore_comment_directivesignore_comment_directive_listspelling_private_dict_fileDictWithPWLDictspelling_store_unknown_wordssetunknown_wordsr   rY   r   r   r   r>   rH   rR   rW   	tokenizer)r'   	dict_names     r   openzSpellingChecker.open*  sn     	FK&4	 	F
 
#{1GMMcRR
 
 

 	( 3444.
 .
['JPPQTUU.
 .
 .
*
 ;8 	9!(!44;-H" "D ")i!8!8D;: 	1+.55D&)*%$ 
 
 
  r   msgidr    rk   line_numc                   |}	 t          j        d|          j        d         d         }n# t          t          f$ r d}Y nw xY w|                                                    d          rad|vr]|                                dd          }| j        D ]6}|                    d|z             r|t          |          dz   d          } n7d}nd}t          |          }t          |          }|                     |                                          D ]7\  }}	|	|z  }	|                                }
|| j        v s	|
| j        v r2|                    d	          r't          |          d
k    r|d
d          }|
d
d          }
	 | j                            |
          r| j                            |          rn3# t           j        j        $ r |                     d||f           Y w xY w| j        j        j        rv|
| j        vrkt1          | j        j        j        dd          5 }|                    |
 d           d d d            n# 1 swxY w Y   | j                            |
           `| j                            |          }|| j        j        j        d = ||	d          }t          j        d| d|          }|r|j        d
         d         }n|                    |          }||	z  }|r|dz  }d|z  dt          |          z  z   }d                    |          }|||d| df}|                     |||           9d S )Nz^\s+r   r9   #	docstringri   TF)zu'zu"zr'zr"   r   )rk   argsazutf-8)encoding
z(\W|^)(z)(\W|$)^z' or '') rT   searchregs
IndexErrorAttributeErrorr   
startswithr   lenrx   r}   r   casefoldr   r   checkr   errorsErroradd_messager   r   r   r   r   r   writeaddsuggestmax_spelling_suggestionsindexjoin)r'   r   rk   r   original_lineinitial_spaceiter_directivestarts_with_commentr   word_start_atlower_cased_wordfsuggestionsline_segmentrO   col	indicatorall_suggestionr   s                      r   _check_spellingzSpellingChecker._check_spellingX  s5   	Igt449!<Q?MMN+ 	 	 	MMM	::<<""3'' 	(Ku,D 	(::<<#D #'"D  ??3#788 ^!4!4q!8 ; ;<DE #'"'/55066#'>>$**,,#?#? 9	B 9	BD-]*M#}} t'' +;t?O+O  788 8SYY] 8ABBx#3ABB#7 %++,<== 
 %++D11 >'     5HD7 !    	 {!> B#4+== =*E!(   9 #3 7 7 78889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 &**+;<<< #088>> 2 K M MN#MNN3	":T":":":LII 3*Q-*CC&,,T22C}$& 1HC 3Y3T?;	!){!;!;mY8MN8M8M8MN  XD AAAAs9	B 9	Bs9   &+ A AF9F99-G)(G)'II	I	tokenslist[tokenize.TokenInfo]c                    | j         sd S |D ]d\  }}\  }}}}|t          j        k    rI|dk    r|                    d          r7|                    d          rM|                     d||           ed S )Nr9   z#!/z	# pylint:r   )r   tokenizeCOMMENTr   r   )r'   r   tok_typetoken	start_rowrJ   s         r   process_tokenszSpellingChecker.process_tokens  s     	F 6< 	T 	T1He^iQ8++ T> e&6&6u&=&= ##K00 $$%@%SSS	T 	Tr   r   nodenodes.Modulec                0    |                      |           d S r$   _check_docstringr'   r   s     r   visit_modulezSpellingChecker.visit_module      d#####r   nodes.ClassDefc                0    |                      |           d S r$   r   r   s     r   visit_classdefzSpellingChecker.visit_classdef  r   r   *nodes.FunctionDef | nodes.AsyncFunctionDefc                0    |                      |           d S r$   r   r   s     r   visit_functiondefz!SpellingChecker.visit_functiondef  s     	d#####r   Jnodes.FunctionDef | nodes.AsyncFunctionDef | nodes.ClassDef | nodes.Modulec                    | j         sdS |j        sdS |j        dz   }t          |j        j                                                  D ]\  }}|                     d|||z               dS )z*Check if the node has any spelling errors.Nr9   r   )r   doc_nodelineno	enumeratevalue
splitlinesr   )r'   r   
start_lineidxrk   s        r   r   z SpellingChecker._check_docstring  s      	F} 	F[1_
"4=#6#A#A#C#CDD 	X 	XIC  !>jSVFVWWWW	X 	Xr   N)r!   r   )r   r    rk   r    r   r   r!   r   )r   r   r!   r   )r   r   r!   r   )r   r   r!   r   )r   r   r!   r   )r   r   r!   r   )r   r   r   rF   r;   msgsdict_choicesdictsinstroptionsr   r   r   r   r   r   r   visit_asyncfunctiondefr   r   r   r   r   r      s       44D


 D*  (';+0; ;38; ; 
	
 $ 4S	 	
 )+1	 		
 +%%	 	
 'T	 	
 1O 4-	 
	
i?GB+  +  +  + \PB PB PB PBdT T T T   =>>$ $ $ ?>$   =>>$ $ $ ?>$   =>>$ $ $ ?>$
 /X X X X X Xr   r   r   r   r   c                J    |                      t          |                      d S r$   )register_checkerr   )r   s    r   registerr    s$    
OF3344444r   )NNN)r+   r,   r-   r.   r/   r0   r!   r   )rk   r    r!   r    )r   r   r!   r   )1rF   
__future__r   rT   sysr   r   typingr   astroidr   pylint.checkersr   pylint.checkers.utilsr   version_infor   typing_extensionspylint.lintr   r   enchant.tokenizer   r   r   r   r   r   ImportErrorBrokerbr
list_dictsr   r   r   r   r>   rH   rL   rR   rW   rY   rU   rv   r|   rx   r}   r   r  r   r   r   <module>r     s  
 > = " " " " " " 				 



                          , , , , , , < < < < < <v *)))))) %$$$$$$"NNN                    G                     & & & & & & & &        )-'+      '6  
F			BMMOOE4//////L44e444EIIeEEEE4LEE4 4 4 4 4F 4 4 4    6   
/ 
/ 
/ 
/ 
/& 
/ 
/ 
/: : : : :[ : : :	= 	= 	= 	= 	={ 	= 	= 	=( ( ( ( (' ( ( (V ",,P!Q!Q #-2:.T#U#U        "FX FX FX FX FX& FX FX FXR5 5 5 5 5 5s   A) )AB<;B<