o
    gW@                     @   s  d 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mZ zddlZddlmZmZmZmZmZmZ W n4 eyx   dZG d	d
 d
ZG dd dZG dd dZG dd dZG dd dZ	d1ddZY nw edure 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$e%d(Z&d)e'd*e'fd+d,Z(G d-d. d.e	Z)d/d0 Z*dS )2z8Checker for spelling errors in comments and docstrings.
    N)Pattern)nodes)BaseTokenChecker)check_messages)IAstroidCheckerITokenChecker)ChunkerEmailFilterFilter	URLFilterWikiWordFilterget_tokenizerc                   @      e Zd ZdS )r	   N__name__
__module____qualname__ r   r   V/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/pylint/checkers/spelling.pyr	   7       r	   c                   @   r   )r   Nr   r   r   r   r   r   :   r   r   c                   @   r   )r   Nr   r   r   r   r   r   =   r   r   c                   @   s   e Zd Zdd ZdS )r
   c                 C   s   t N)NotImplementedErrorselfwordr   r   r   _skipA   s   zFilter._skipN)r   r   r   r   r   r   r   r   r
   @   s    r
   c                   @   r   )r   Nr   r   r   r   r   r   D   r   r   c                 C   s   t  S r   )r
   )tagchunkersfiltersr   r   r   r   G   s   r    c                 C   s   g | ]}|d  qS )r   r   .0dr   r   r   
<listcomp>P   s    r#   c                 C   s&   g | ]}|d   d|d j  dqS )r   z (   ))namer    r   r   r   r#   Q   s   & 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.c                 C   s   |D ]	}|  r dS qdS )NTF)isdigit)r   r   charr   r   r   r   ]   s
   zWordsWithDigitsFilter._skipNr   r   r   __doc__r   r   r   r   r   r)   Z   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   j   s   zWordsWithUnderscores._skipNr,   r   r   r   r   r.   d   s    r.   c                   @   s,   e Zd ZU dZee ed< def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``.

    _patternreturnc                 C   s   t | j|S r   )boolr1   matchr   r   r   r   r   x   s   zRegExFilter._skipN)	r   r   r   r-   r   str__annotations__r3   r   r   r   r   r   r0   n   s   
 r0   c                   @      e Zd ZdZe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   r-   recompiler1   r   r   r   r   r8   |   s    r8   c                   @   r7   )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}:`([^`]+)(`)?Nr9   r   r   r   r   r<      s    r<   c                   @   s    e Zd ZdZdd Zdd ZdS )ForwardSlashChunkerz[
    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   next   s.   


zForwardSlashChunker.nextc                 C   sf   	 d| j vr| j dfS | j dd\}}|r|s	 t |d  r(|d  s+t |d | | _ q)NTr>   r   r$   r?    )r@   rC   rD   rA   )r   rF   rG   r   r   r   _next   s   

zForwardSlashChunker._nextN)r   r   r   r-   rH   rJ   r   r   r   r   r=      s    r=   z!(\s|^)(`{1,2})([^`]+)(\2)([^`]|$)liner2   c                 C   s   dt fdd}t|| S )zAlter line so code flanked in backticks is ignored.

    Pyenchant automatically strips backticks when parsing tokens,
    so this cannot be done at the individual filter level.r2   c                 S   s   |  d|  d S )Nr$      )group)	match_objr   r   r   -replace_code_but_leave_surrounding_characters   s   zW_strip_code_flanked_in_backticks.<locals>.replace_code_but_leave_surrounding_characters)r5   CODE_FLANKED_IN_BACKTICK_REGEXsub)rK   rO   r   r   r    _strip_code_flanked_in_backticks   s   rR   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
 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d)d* Zed+d,ejd-d.fd/d0Zed+d,ejd-d.fd1d2Zed+d,ejd-d.fd3d4ZeZd5d6 Zd.S )7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-dictr   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_   ra   zspelling-private-dict-filez<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 and the beginning of a comment and should not be checked.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 dd | jj	dD | _
| jjrDtj| jj| j_| jjr\t|| jj| _t| jjdd	d
| _nt|| _| jjrjt | _t|tgtttttttgd| _d| _ d S )NFc                 S      g | ]}|  qS r   stripr!   wr   r   r   r#   .      z(SpellingChecker.open.<locals>.<listcomp>,parampylintc                 S   rh   r   ri   rk   r   r   r   r#   5  rm   azutf-8)encoding)r   r   T)initializedprivate_dict_fileenchantconfigspelling_dictspelling_ignore_wordsrC   ignore_listextend"spelling_ignore_comment_directivesignore_comment_directive_listspelling_private_dict_fileospath
expanduserDictWithPWLopenDictspelling_store_unknown_wordssetunknown_wordsr   r=   r	   r   r   r)   r.   r8   r<   	tokenizer)r   	dict_namer   r   r   r   $  sR   


zSpellingChecker.openc                 C   s   | j r
| j   d S d S r   )rt   close)r   r   r   r   r   [  s   zSpellingChecker.closec              	   C   sB  |}zt d|jd d }W n ttfy   d}Y nw | drLd|vrL| dd  }| jD ]}|d| rH|t|d d  } nq3d}nd}t	|}| 
| D ]\}}	|	|7 }	| }
|| jv so|
| jv rpqY|d	rt|d
kr|d
d  }|
d
d  }
z| j|
rW qY| j|rW qYW n tjjy   | jd||fd Y qYw | jjr|
| jvr| j|
 d | j|
 qY| j|}|| jjd = ||	d  }t d| d|}|r|jd
 d }n||}||	7 }|r|d7 }d| dt|  }d|}|||d| df}| j|||d qYd S )Nz	^[^\S]\s*r   r$   #	docstringrI   TF)zu'zu"zr'zr"   rW   )rK   args
z(\W|^)(z)(\W|$)^z' or '')r:   searchregs
IndexErrorAttributeErrorrj   
startswithr|   lenrR   r   casefoldry   rw   checkru   errorsErroradd_messagerv   r   r   rt   writeaddsuggestmax_spelling_suggestionsindexjoin)r   msgidrK   line_numoriginal_lineinitial_spaceiter_directivestarts_with_commentr   word_start_atlower_cased_wordsuggestionsline_segmentr4   col	indicatorall_suggestionr   r   r   r   _check_spelling_  sp   



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:rU   )rs   tokenizeCOMMENTr   r   )r   tokenstok_typetoken	start_rowr/   r   r   r   process_tokens  s   

zSpellingChecker.process_tokensrV   noder2   Nc                 C      | j sd S | | d S r   rs   _check_docstringr   r   r   r   r   visit_module     zSpellingChecker.visit_modulec                 C   r   r   r   r   r   r   r   visit_classdef  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$   rV   )doclineno	enumerate
splitlinesr   )r   r   r   
start_lineidxrK   r   r   r   r     s   
z SpellingChecker._check_docstring)r   r   r   r-   r   r   __implements__r&   msgsdict_choicesdictsinstroptionsr   r   r   r   r   r   Moduler   ClassDefr   FunctionDefr   visit_asyncfunctiondefr   r   r   r   r   rS      s    

?7KrS   c                 C   s   |  t|  dS )z-required method to auto register this checkerN)register_checkerrS   )linterr   r   r   register  s   r   )NNN)+r-   r~   r:   r   typingr   astroidr   pylint.checkersr   pylint.checkers.utilsr   pylint.interfacesr   r   ru   enchant.tokenizer   r	   r
   r   r   r   ImportErrorBrokerbr
list_dictsr   r   r   r   r)   r.   r0   r8   r<   r=   r;   rP   r5   rR   rS   r   r   r   r   r   <module>   sX   $



)  