o
    b3                     @   sh  d Z ddlZddlZddlZzddlZddlmZmZmZm	Z	m
Z
mZ W n ey=   dZG dd dZG dd dZY nw ddlmZmZ dd	lmZ dd
lmZ edurwe Ze Zdgdd eD  Zdd eD ZdeZdZndZdgZdZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZ dd Z!dS ) z8Checker for spelling errors in comments and docstrings.
    N)get_tokenizerChunkerFilterEmailFilter	URLFilterWikiWordFilterc                   @   s   e Zd Zdd ZdS )r   c                 C   s   t N)NotImplementedErrorselfword r   W/var/www/secure340b-portal/env/lib/python3.10/site-packages/pylint/checkers/spelling.py_skip'   s   zFilter._skipN)__name__
__module____qualname__r   r   r   r   r   r   &   s    r   c                   @   s   e Zd ZdS )r   N)r   r   r   r   r   r   r   r   *   s    r   )ITokenCheckerIAstroidChecker)BaseTokenChecker)check_messages c                 C   s   g | ]}|d  qS )r   r   .0dr   r   r   
<listcomp>5   s    r   c                 C   s"   g | ]}d |d |d j f qS )z%s (%s)r      )namer   r   r   r   r   6   s   " z, nonez3 To make it working install python-enchant package.c                   @      e Zd ZdZdd ZdS )WordsWithDigigtsFilterzSkips words with digits.
    c                 C   s   |D ]	}|  r dS qdS )NTF)isdigit)r   r   charr   r   r   r   C   s
   zWordsWithDigigtsFilter._skipNr   r   r   __doc__r   r   r   r   r   r    ?   s    r    c                   @   r   )WordsWithUnderscoreszSSkips words with underscores.

    They are probably function parameter names.
    c                 C   s   d|v S )N_r   r
   r   r   r   r   P   s   zWordsWithUnderscores._skipNr#   r   r   r   r   r%   J   s    r%   c                   @   "   e Zd ZdZedZd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+)?)c                 C      t | j|S r   bool_patternmatchr
   r   r   r   r   ^      zCamelCasedWord._skipNr   r   r   r$   recompiler,   r   r   r   r   r   r(   T   s    
r(   c                   @   r'   )SphinxDirectiveszFilter skipping over Sphinx Directives.
    This filter skips any words matching the following regular expression:

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

    That is, for example, :class:`BaseQuery`
    z^:([a-z]+):`([^`]+)(`)?c                 C   r)   r   r*   r
   r   r   r   r   m   r.   zSphinxDirectives._skipNr/   r   r   r   r   r2   b   s    
r2   c                   @   s    e Zd ZdZdd Zdd ZdS )ForwardSlashChunkderz[
    This chunker allows splitting words like 'before/after' into 'before' and 'after'
    c                 C   s   	 | j st d| j vr| j }d| _d| _ |dfS | j dd\}}|| _ d| _|r8|r8|d  r8|d  sFd| _ d| _|d | dfS |dfS )NT/r   r   r   )_textStopIteration_offsetsplitisalpha)r   textpre_text	post_textr   r   r   nextv   s.   


zForwardSlashChunkder.nextc                 C   sf   	 d| j vr| j dfS | j dd\}}|r|s	 t |d  r(|d  s+t |d | | _ q)NTr4   r   r   r5    )r6   r9   r:   r7   )r   r<   r=   r   r   r   _next   s   

zForwardSlashChunkder._nextN)r   r   r   r$   r>   r@   r   r   r   r   r3   q   s    r3   c                
   @   s   e Zd ZdZeefZdZddddZddd	d
e	de
ef 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d%d& Zed'd(d) Zed'd*d+ Zed'd,d- ZeZd.d/ Zd0S )1SpellingCheckerz)Check spelling in comments and docstringsZ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.)ZC0401ZC0402ZC0403zspelling-dictr   choicez<dict name>z8Spelling dictionary name. Available dictionaries: %s.%s.)defaulttypemetavarchoiceshelpzspelling-ignore-wordsstringz<comma separated words>z9List of comma separated words that should not be checked.)rF   rG   rH   rJ   zspelling-private-dict-filez<path to file>zEA path to a file that contains private dictionary; one word per line.zspelling-store-unknown-wordsnZynz<y_or_n>zTells whether to store unknown words to indicated private dictionary in --spelling-private-dict-file option instead of raising a message.zmax-spelling-suggestions   intNz:Limits count of emitted suggestions for spelling mistakes.c              
   C   s   d| _ d | _td u rd S | jj}|sd S dd | jjdD | _| jddg | jj	r7t
j| jj	| j_	| jj	rMt|| jj	| _t| jj	d| _nt|| _| jjr[t | _t|tgtttttttgd| _d	| _ d S )
NFc                 S   s   g | ]}|  qS r   )strip)r   wr   r   r   r      s    z(SpellingChecker.open.<locals>.<listcomp>,paramZpylinta)ZchunkersfiltersT)initializedprivate_dict_fileenchantconfigspelling_dictZspelling_ignore_wordsr9   ignore_listextendZspelling_private_dict_fileospath
expanduserZDictWithPWLopenDictspelling_store_unknown_wordssetunknown_wordsr   r3   r   r   r   r    r%   r(   r2   	tokenizer)r   Z	dict_namer   r   r   r`      sH   
zSpellingChecker.openc                 C   s   | j r
| j   d S d S r   )rW   close)r   r   r   r   rf     s   zSpellingChecker.closec                 C   s  |}|  dr|  dd  }d}nd}| |  D ]\}}| }|| jv s/|| jv r0q|drGt|dkrG|dd  }|dd  }z| j|rPW q| j|rXW qW n tj	j
ym   | jd||fd Y qw | jjr|| jvr| jd	|  | j| q| j|}	|	| jjd = td
| |}
|
r|
jd d }n||}|r|d7 }d| dt|  }| j|||||dd|	fd qd S )N#r   TF)zu'zu"zr'zr"   rD   )lineargsz%s
z(\W|^)(%s)(\W|$)r   r?   ^z'{}'z' or ')rP   
startswithre   casefoldr[   lenrZ   checkrX   errorsErrorZadd_messagerY   rb   rd   rW   writeaddZsuggestZmax_spelling_suggestionsr0   searchregsindexformatjoin)r   msgidri   line_numZoriginal_lineZstarts_with_commentr   r&   Zlower_cased_wordZsuggestionsmcolZ	indicatorr   r   r   _check_spelling  s`   

zSpellingChecker._check_spellingc                 C   s^   | j sd S |D ]%\}}\}}}}|tjkr,|dkr|drq|dr%q| d|| qd S )Nr   z#!/z	# pylint:rB   )rV   tokenizeCOMMENTrl   r}   )r   tokenstok_typetokenZ	start_rowr&   r   r   r   process_tokensa  s   

zSpellingChecker.process_tokensrC   c                 C      | j sd S | | d S r   rV   _check_docstringr   noder   r   r   visit_modulep     zSpellingChecker.visit_modulec                 C   r   r   r   r   r   r   r   visit_classdefv  r   zSpellingChecker.visit_classdefc                 C   r   r   r   r   r   r   r   visit_functiondef|  r   z!SpellingChecker.visit_functiondefc                 C   sD   |j }|sdS |jd }t| D ]\}}| d|||  qdS )z&check the node has any spelling errorsNr   rC   )doclineno	enumerate
splitlinesr}   )r   r   	docstring
start_lineidxri   r   r   r   r     s   
z SpellingChecker._check_docstringN)r   r   r   r$   r   r   Z__implements__r   Zmsgsdict_choicesdictsinstroptionsr`   rf   r}   r   r   r   r   r   Zvisit_asyncfunctiondefr   r   r   r   r   rA      sv    
61D


rA   c                 C   s   |  t|  dS )z.required method to auto register this checker N)Zregister_checkerrA   )Zlinterr   r   r   register  s   r   )"r$   r]   r~   r0   rX   Zenchant.tokenizer   r   r   r   r   r   ImportErrorZpylint.interfacesr   r   Zpylint.checkersr   Zpylint.checkers.utilsr   ZBrokerbrZ
list_dictsr   r   rx   r   r    r%   r(   r2   r3   rA   r   r   r   r   r   <module>   sB   $

) x