B
    0°zf[&  ã               @   sÚ   d Z ddlZddlZddlZyddlmZ W n" ek
rN   e dej	¡ZY nX dZ
dZdZdZd	d
dœZd	d
dddddddddddddddddœZd	d
ddddddœZdd	iZeeeedœZd%d!d"„ZG d#d$„ d$ƒZdS )&zˆCheck Python docstrings validate as reStructuredText (RST).

This is a plugin for the tool flake8 tool for checking Python
source code.
é    N)Úpy_ext_sig_reai  ^ ([\w.]+::)?            # explicit module name
              ([\w.]+\.)?            # module and/or class name(s)
              (\w+)  \s*             # thing name
              (?: \((.*)\)           # optional: arguments
               (?:\s* -> \s* (.*))?  #           return annotation
              )? $                   # and nothing more
              z0.2.7ZRSTi„  i‡  é   é   )z2Possible title underline, too short for the title.z1Unexpected possible title overline or transition.é   é   é   é   é   é   é
   é   é   é   é   é   é   é   é   é   )z;Block quote ends without a blank line; unexpected unindent.z;Bullet list ends without a blank line; unexpected unindent.z?Definition list ends without a blank line; unexpected unindent.z?Enumerated list ends without a blank line; unexpected unindent.z?Explicit markup ends without a blank line; unexpected unindent.z:Field list ends without a blank line; unexpected unindent.z=Literal block ends without a blank line; unexpected unindent.z;Option list ends without a blank line; unexpected unindent.z.Inline strong start-string without end-string.z Blank line required after table.zTitle underline too short.z0Inline emphasis start-string without end-string.z/Inline literal start-string without end-string.zLInline interpreted text or phrase reference start-string without end-string.zVMultiple roles in interpreted text (both prefix and suffix present; only one allowed).zAMismatch: both interpreted text role suffix and reference suffix.z#Literal block expected; none found.z>Inline substitution_reference start-string without end-string.)zUnexpected indentation.zMalformed table.zUnknown directive type "*".z"Unknown interpreted text role "*".z'Undefined substitution referenced: "*".zUnknown target name: "*".zError in "*" directive:zUnexpected section title.)r   r   r   r   éc   c             C   s¬   yt |  | S  tk
r    Y nX | d¡dkr¨d|kr¨| dd¡d }| d| d d¡}|dkrp||krpdS |dkr„||kr„dS |d	kr˜||kr˜dS t |   ||¡S |S )
z&Return an error code between 0 and 99.ú"r   z "r   z "*"zUnknown directive type "*".r   z"Unknown interpreted text role "*".z'Undefined substitution referenced: "*".)Úcode_mappings_by_levelÚKeyErrorÚcountÚsplitÚreplaceÚget)ÚlevelÚmsgÚextra_directivesÚextra_rolesÚextra_substitutionsÚdefaultÚvalueÚtxt© r%   úX/home/ankuromar296_gmail_com/.local/lib/python3.7/site-packages/flake8_rst_docstrings.pyÚcode_mapping^   s     	r'   c               @   sB   e Zd ZdZdZeZddd„Zedd„ ƒZ	edd	„ ƒZ
d
d„ ZdS )ÚreStructuredTextCheckerz1Checker of Python docstrings as reStructuredText.zrst-docstringsú(none)c             C   s   || _ || _dS )zInitialise.N)ÚtreeÚfilename)Úselfr*   r+   r%   r%   r&   Ú__init__„   s    z reStructuredTextChecker.__init__c             C   sF   |j ddddddd |j ddddddd |j d	ddddd
d dS )z4Add RST directives, roles and substitutions options.z--rst-directivesÚLISTÚ Tz2Comma-separated list of additional RST directives.)Úmetavarr"   Zparse_from_configÚcomma_separated_listÚhelpz--rst-rolesz-Comma-separated list of additional RST roles.z--rst-substitutionsz5Comma-separated list of additional RST substitutions.N)Ú
add_option)ÚclsÚparserr%   r%   r&   Úadd_options‰   s*    z#reStructuredTextChecker.add_optionsc             C   s   |j | _|j| _|j| _dS )zAdding black-config option.N)Zrst_directivesr   Z	rst_rolesr    Zrst_substitutionsr!   )r4   Úoptionsr%   r%   r&   Úparse_options¥   s    z%reStructuredTextChecker.parse_optionsc             c   sR  | j dkr4dttd| j f }dd|t| ƒfV  ntjtjtjtj	f}xt 
| j ¡D ]ð}t||ƒsjqXtj|dd}|s~qX| ¡ d }t | ¡ ¡r¦| |dd¡}ytt |¡ƒ}W nP tk
r } z0dttd	|j|f f }dd|t| ƒfV  wXW dd}~X Y nX |r y |jd j |jd jd }W n: tk
rj   |jd jtj|d
d d¡ d }Y nX |jd jdkrˆ|dks td|jd j|f ƒ‚x¨|D ] }	|	jdkrºq¦|	j  dd¡d }t!|	j|| j"| j#| j$ƒ}
|
sîq¦d|
  k rdk sn t|
ƒ‚|
d|	j 7 }
dt|
|f }||	j% d|t| ƒfV  q¦W qXW dS )z/Use docutils to check docstrings are valid RST.Nz	%s%03i %szFailed to load file: %sr   T)Úcleanr/   r   z!Failed to lint docstring: %s - %sFÚ
z,Bad start line, node line number %i for: %s
éd   )&r*   Ú
rst_prefixÚrst_fail_loadÚerrÚtypeÚastÚModuleÚClassDefÚFunctionDefÚAsyncFunctionDefÚwalkÚ
isinstanceÚget_docstringÚ
splitlinesr   ÚmatchÚstripr   ÚlistÚrst_lintZlintÚ	ExceptionÚrst_fail_lintÚnameÚbodyZ
end_linenoÚlinenoÚAttributeErrorr   ÚAssertionErrorr   Úmessager   r'   r   r    r!   Úline)r,   r   ÚwantedÚnodeZ	docstringÚ	firstlineZ
rst_errorsr>   ÚstartZ	rst_errorÚcoder%   r%   r&   Úrun¬   sl    

*



"zreStructuredTextChecker.runN)r)   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rO   Ú__version__Úversionr-   Úclassmethodr6   r8   r[   r%   r%   r%   r&   r(   ~   s   
r(   )r   )r_   r@   ÚreZrestructuredtext_lintrL   Zsphinx.ext.autodocr   ÚImportErrorÚcompileÚVERBOSEr`   r<   r=   rN   Zcode_mapping_infoZcode_mapping_warningZcode_mapping_errorZcode_mapping_severer   r'   r(   r%   r%   r%   r&   Ú<module>   s^   
