o
    N i  ã                   @  s`   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„Z
dddd„Zddd„ZdS )z#Utilities for docstring processing.é    )ÚannotationsN)ÚBodyÚfield_markerÚsú
str | NoneÚreturnú!tuple[str | None, dict[str, str]]c                 C  sÌ   d}i }g }| s| |fS t | ƒD ]N}| ¡ dkr d}| |¡ qt |¡}|rW|sW| ¡ dd…  dd¡d }| d¡rQ|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   Úin_other_elementÚmetadataÚlinesÚlineÚmatchedÚ
field_nameÚname© r   úJ/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/util/docstrings.pyÚseparate_metadata   s&   

r!   é   ÚstrÚtabsizeÚintú	list[str]c                 C  sÒ   |   |¡ ¡ }tj}|dd… D ]}t| ¡ ƒ}|r%t|ƒ| }t||ƒ}qt|ƒr2|d  ¡ |d< |tjk rKtdt|ƒƒD ]}|| |d… ||< q>|r\|d s\| d¡ |r\|d rQ|rg|d rg| 	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… }|r*|d dkr*|dd… }| |¡ q|r;|d	 r;| 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   

€
r:   )r   r   r   r   )r"   )r   r#   r$   r%   r   r&   )r   r#   r   r&   )Ú__doc__Ú
__future__r   Úrer*   Údocutils.parsers.rst.statesr   ÚcompileÚpatternsr   r!   r   r:   r   r   r   r    Ú<module>   s    
