U
    \ªShr  ã                   @  st   d Z ddlmZ ddlZddlZddlmZ e ejd ¡Z	dddœd	d
„Z
dddddœdd„Zdddœdd„ZdS )z#Utilities for docstring processing.é    )ÚannotationsN)ÚBodyZfield_markerÚstrztuple[str, dict[str, str]])ÚsÚreturnc                 C  sÌ   d}i }g }| s| |fS t | ƒD ]œ}| ¡ dkr@d}| |¡ q t |¡}|r®|s®| ¡ dd…  dd¡d }| d¡r¢|dd…  ¡ }|| ¡ d…  ¡ ||< q¼| |¡ q d	}| |¡ q d
 	|¡|fS )z,Separate docstring into metadata and others.FÚ é   Nú:r   zmeta é   TÚ
)
Úprepare_docstringÚstripÚappendÚfield_list_item_reÚmatchÚgroupÚsplitÚ
startswithÚendÚjoin)r   Zin_other_elementÚmetadataÚlinesÚlineZmatchedÚ
field_nameÚname© r   úI/root/rtd-docs/venv/lib/python3.8/site-packages/sphinx/util/docstrings.pyÚseparate_metadata   s&    

r   é   Úintz	list[str])r   Útabsizer   c                 C  sÈ   |   |¡ ¡ }tj}|dd… D ]*}t| ¡ ƒ}|r t|ƒ| }t||ƒ}q t|ƒrd|d  ¡ |d< |tjk r–tdt|ƒƒD ]}|| |d… ||< q||r®|d s®| d¡ q–|rÄ|d rÄ| 	d¡ |S )aw  Convert a docstring into lines of parseable reST.  Remove common leading
    indentation, where the indentation of the first line is ignored.

    Return the docstring as a list of lines usable for inserting into a docutils
    ViewList (used as argument of nested_parse().)  An empty line is added to
    act as a separator between this docstring and following content.
    r   Nr   éÿÿÿÿr   )
Ú
expandtabsÚ
splitlinesÚsysÚmaxsizeÚlenÚlstripÚminÚrangeÚpopr   )r   r    r   Úmarginr   ÚcontentÚindentÚir   r   r   r   *   s"    

r   c                 C  sz   g }dd„ |   ¡  ¡ D ƒ}|D ]@}| d¡r|dd… }|rT|d dkrT|dd… }| |¡ q|rv|d	 rv| d
¡ |S )z˜Extract documentation comment lines (starting with #:) and return them
    as a list of lines.  Returns an empty list if there is no documentation.
    c                 S  s   g | ]}|  ¡ ‘qS r   )r   )Ú.0r   r   r   r   Ú
<listcomp>N   s     z&prepare_commentdoc.<locals>.<listcomp>z#:é   Nr   ú r   r!   r   )r"   r#   r   r   )r   Úresultr   r   r   r   r   Úprepare_commentdocI   s    

r4   )r   )Ú__doc__Ú
__future__r   Úrer$   Zdocutils.parsers.rst.statesr   ÚcompileÚpatternsr   r   r   r4   r   r   r   r   Ú<module>   s   