o
    ]ip>                  	   @   s  d Z ddlZddlZddlZddlZddlmZ ddlm	Z	m
Z
mZmZmZmZmZmZmZ d]dejdejfdd	Zd
edeje fddZejdejdZedZedZedZedZG dd 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$G d!d" d"e Z%G d#d$ d$eZ&g e!d%d&e!d'd&e!d(d&e!d)d&e!d*d+e!d,d+e!d-d+e!d.d+e!d/d0e!d1d0e"d2d3e"d4d3e"d5d6e"d7d6e!d8d9e!d:d9e#d;d<e#d=d<e$d>d?e$d@d?e&dAdBe&dCdBedDdEedFdEedGdHedIdHedJdKedLdKedMdNedOdNe%dPdQZ'G dRdS dSZ(dTede	fdUdVZ)ej*dWfdXe	dYedZedefd[d\Z+dS )^z_Numpydoc-style docstring parsing.

:see: https://numpydoc.readthedocs.io/en/latest/format.html
    N)dedent   )		DocstringDocstringDeprecatedDocstringExampleDocstringMetaDocstringParamDocstringRaisesDocstringReturnsDocstringStyleRenderingStyleiterablereturnc                 C   s(   t | \}}t|d  t j|||dS )N)	fillvalue)	itertoolsteenextzip_longest)r   endleftright r   ^/var/www/html/stock_analysis/be/venv/lib/python3.10/site-packages/docstring_parser/numpydoc.py	_pairwise   s   
r   stringc                 C   s   |   } t| dkr| S d S )Nr   )striplen)r   r   r   r   
_clean_str   s   r   z	^[^\s].*$flagsz(^(?P<name>.*?)(?:\s*:\s*(?P<type>.*?))?$z)(?P<type>.*?)(?:, optional|\(optional\))$z@(?<!\S)[Dd]efault(?: is | = |: |s to |)\s*(?P<value>[\w\-\.]*\w)z(^(?:(?P<name>.*?)\s*:\s*)?(?P<type>.*?)$c                   @   sP   e Zd ZdZdededdfddZedefdd	Zd
edej	e
 fddZdS )Sectiona  Numpydoc section parser.

    :param title: section title. For most sections, this is a heading like
                  "Parameters" which appears on its own line, underlined by
                  en-dashes ('-') on the following line.
    :param key: meta key string. In the parsed ``DocstringMeta`` instance this
                will be the first element of the ``args`` attribute list.
    titlekeyr   Nc                 C   s   || _ || _d S N)r!   r"   )selfr!   r"   r   r   r   __init__=   s   
zSection.__init__c                 C   s"   dt | j }d| j d| dS )zRegular expression pattern matching this section's header.

        This pattern will match this instance's ``title`` attribute in
        an anonymous group.
        -z^(z)\s*?\nz\s*$)r   r!   )r$   dashesr   r   r   title_patternA   s   zSection.title_patterntextc                 c   s    t | jgt|dV  dS )zParse ``DocstringMeta`` objects from the body of this section.

        :param text: section body text. Should be cleaned with
                     ``inspect.cleandoc`` before parsing.
        )descriptionN)r   r"   r   )r$   r)   r   r   r   parseK   s   zSection.parse)__name__
__module____qualname____doc__strr%   propertyr(   TIterabler   r+   r   r   r   r   r    3   s    		r    c                   @   s>   e Zd ZdZdededefddZdedeje fdd	Z	d
S )
_KVSectionzBase parser for numpydoc sections with key-value syntax.

    E.g. sections that look like this:
        key
            value
        key2 : type
            values can also span...
            ... multiple lines
    r"   valuer   c                 C   s   d S r#   r   r$   r"   r5   r   r   r   _parse_item_   s   z_KVSection._parse_itemr)   c                 c   s`    t t|D ]%\}}| }|d ur| nd }||| }| j| t|dV  qd S )N)r"   r5   )	r   KV_REGEXfinditerr   startr7   groupinspectcleandoc)r$   r)   match
next_matchr:   r   r5   r   r   r   r+   b   s   
z_KVSection.parseN)
r,   r-   r.   r/   r0   r   r7   r2   r3   r+   r   r   r   r   r4   T   s    
r4   c                   @   s"   e Zd ZdZedefddZdS )_SphinxSectionzBase parser for numpydoc sections with sphinx-style syntax.

    E.g. sections that look like this:
        .. title:: something
            possibly over multiple lines
    r   c                 C   s   d| j  dS )Nz	^\.\.\s*(z)\s*::r!   r$   r   r   r   r(   t   s   z_SphinxSection.title_patternN)r,   r-   r.   r/   r1   r0   r(   r   r   r   r   r@   l   s    r@   c                   @   &   e Zd ZdZdededefddZdS )ParamSectionzParser for numpydoc parameter sections.

    E.g. any section that looks like this:
        arg_name
            arg_description
        arg_2 : type, optional
            descriptions can also span...
            ... multiple lines
    r"   r5   r   c           
      C   s   t |}d  } }}|d ur0|d}|d}|d ur0t|}|d ur.|d}d}nd}d }t|dkrFt|}	|	d urF|	d}t| j|gt	|||||dS )NnametypeTFr   r5   )argsr*   arg_name	type_nameis_optionaldefault)
PARAM_KEY_REGEXr>   r;   PARAM_OPTIONAL_REGEXr   PARAM_DEFAULT_REGEXsearchr   r"   r   )
r$   r"   r5   r>   rH   rI   rJ   optional_matchrK   default_matchr   r   r   r7      s0   






zParamSection._parse_itemN)r,   r-   r.   r/   r0   r   r7   r   r   r   r   rD   y   s    
rD   c                   @   rC   )RaisesSectionzParser for numpydoc raises sections.

    E.g. any section that looks like this:
        ValueError
            A description of what might raise ValueError
    r"   r5   r   c                 C   s,   t | j|gt|t|dkr|dS d dS )Nr   )rG   r*   rI   )r	   r"   r   r   r6   r   r   r   r7      s   zRaisesSection._parse_itemN)r,   r-   r.   r/   r0   r	   r7   r   r   r   r   rR      s    rR   c                   @   s*   e Zd ZdZdZdededefddZdS )	ReturnsSectionzParser for numpydoc returns sections.

    E.g. any section that looks like this:
        return_name : type
            A description of this returned value
        another_type
            Return names are optional, types are required
    Fr"   r5   r   c                 C   sL   t |}|d ur|d}|d}nd }d }t| jgt||| j|dS )NrE   rF   )rG   r*   rI   is_generatorreturn_name)RETURN_KEY_REGEXr>   r;   r
   r"   r   rT   )r$   r"   r5   r>   rU   rI   r   r   r   r7      s   

zReturnsSection._parse_itemN)r,   r-   r.   r/   rT   r0   r
   r7   r   r   r   r   rS      s    	rS   c                   @   s   e Zd ZdZdZdS )YieldsSectionz0Parser for numpydoc generator "yields" sections.TN)r,   r-   r.   r/   rT   r   r   r   r   rW      s    rW   c                   @   (   e Zd ZdZdedeje fddZdS )DeprecationSectionz3Parser for numpydoc "deprecation warning" sections.r)   r   c                 c   sP    |j dddd d g ^}}}|d urtt|}t| jg|t|dV  d S )N
r   )sepmaxsplit)rG   r*   version)splitr   r<   r=   r   r"   )r$   r)   r]   desc_r   r   r   r+      s   zDeprecationSection.parseN)	r,   r-   r.   r/   r0   r2   r3   r   r+   r   r   r   r   rY      s    rY   c                   @   rX   )ExamplesSectiona  Parser for numpydoc examples sections.

    E.g. any section that looks like this:
        >>> import numpy.matlib
        >>> np.matlib.empty((2, 2))    # filled with random data
        matrix([[  6.76425276e-320,   9.79033856e-307], # random
                [  7.39337286e-309,   3.22135945e-309]])
        >>> np.matlib.empty((2, 2), dtype=int)
        matrix([[ 6600475,        0], # random
                [ 6586976, 22740995]])
    r)   r   c                 c   s    t |  }|rOg }g }|r#|d dsn
||d |s|r7|d dr-n
||d |s%t| jg|rBd|ndd|dV  |sdS dS )zParse ``DocstringExample`` objects from the body of this section.

        :param text: section body text. Should be cleaned with
                     ``inspect.cleandoc`` before parsing.
        r   z>>>rZ   N)snippetr*   )	r   r   
splitlines
startswithappendpopr   r"   join)r$   r)   linessnippet_linesdescription_linesr   r   r   r+      s*   zExamplesSection.parseN)	r,   r-   r.   r/   r0   r2   r3   r   r+   r   r   r   r   ra      s    ra   
ParametersparamParams	ArgumentsArgsOther Parametersother_paramzOther ParamszOther Argumentsz
Other ArgsReceivesreceivesReceiveRaisesraisesRaiseWarnswarnsWarn
Attributes	attribute	AttributeReturnsreturnsReturnYieldsyieldsYieldExamplesexamplesExampleWarningswarningsWarningzSee Alsosee_alsoRelatedNotesnotesNote
References
references	Reference
deprecateddeprecationc                   @   sX   e Zd ZdZddejejeef  fddZ	dd Z
defd	d
ZdedefddZdS )NumpydocParserz%Parser for numpydoc-style docstrings.Nsectionsc                 C   s$   |pt }dd |D | _|   dS )z[Setup sections.

        :param sections: Recognized sections or None to defaults.
        c                 S   s   i | ]}|j |qS r   rA   .0sr   r   r   
<dictcomp>6  s    z+NumpydocParser.__init__.<locals>.<dictcomp>N)DEFAULT_SECTIONSr   _setup)r$   r   r   r   r   r%   0  s   zNumpydocParser.__init__c                 C   s,   t jddd | j D t jd| _d S )N|c                 s   s    | ]}|j V  qd S r#   )r(   r   r   r   r   	<genexpr>;  s    z(NumpydocParser._setup.<locals>.<genexpr>r   )recompilerg   r   valuesM	titles_rerB   r   r   r   r   9  s   zNumpydocParser._setupsectionc                 C   s   || j |j< |   dS )zLAdd or replace a section.

        :param section: The new section.
        N)r   r!   r   )r$   r   r   r   r   add_section?  s   zNumpydocParser.add_sectionr)   r   c                 C   s$  t tjd}|s
|S t|}| j|}|r(|d|  }|| d }n|}d}|dd}|d p7d|_	t
|dkrX|d pDd}|d|_|d|_| pVd|_t| j|D ]/\}}tdd	 | D }	| j|	 }
| }|dur| nd}|j|
|||  q`|S )
zaParse the numpy-style docstring into its components.

        :returns: parsed docstring
        )styleN rZ   r   r   z

c                 s   s    | ]	}|d ur|V  qd S r#   r   )r   gr   r   r   r   i  s    z'NumpydocParser.parse.<locals>.<genexpr>)r   r   NUMPYDOCr<   r=   r   rO   r:   r^   short_descriptionr   rd   blank_after_short_descriptionendswithblank_after_long_descriptionr   long_descriptionr   r9   r   groupsr   r   metaextendr+   )r$   r)   retr>   
desc_chunk
meta_chunkpartslong_desc_chunk	nextmatchr!   factoryr:   r   r   r   r   r+   H  s4   

zNumpydocParser.parser#   )r,   r-   r.   r/   r2   OptionalDictr0   r    r%   r   r   r   r+   r   r   r   r   r   -  s     		r   r)   c                 C   s   t  | S )zYParse the numpy-style docstring into its components.

    :returns: parsed docstring
    )r   r+   )r)   r   r   r   r+   u  s   r+   z    	docstringrendering_styleindentc           	         sv  dt jtttf f fdddtdt jt j ffdd}g | jr+	| j | j
r3	d | jrbd	}| jjrE|d
| jj 7 }| jjrP| jj }ng }d  }	||g|  | jrk	| j | jrs	d |ddd | jp|g D  |ddd | jpg D  |ddd | jpg D  |ddd | jpg D  | jr| js| j}	|rdnd 	dtd   | |ddd | jpg D  |ddd | jpg D  |ddd | jpg D  |ddd | jpg D  | jD ]6}t|ttttfrq	d 	|jd d d  	dt|jd   |jr5	|j qdS )!a  Render a parsed docstring into docstring text.

    :param docstring: parsed docstring representation
    :param rendering_style: the style to render docstrings
    :param indent: the characters used as indentation in the docstring string
    :returns: docstring text
    onec                    s   t | tr	| j}nt | tr| j}nd }| jr"|r"|d| j 7 }n| jr)| j}n|s-d}t | tr9| jr9|d7 }| jrQd  |g| j	  }
| d S 
| d S )Nz : r   z
, optionalrZ   )
isinstancer   rH   r
   rU   rI   rJ   r*   rg   rc   re   )r   headbody)r   r   r   r   process_one  s"   


zcompose.<locals>.process_onerE   rG   c                    sH   |r   d   |    dt d   |D ]}| qd S d S )Nr   r&   )re   r   )rE   rG   arg)r   r   r   r   process_sect  s   


zcompose.<locals>.process_sectr   z.. deprecated:: rZ   rk   c                 S      g | ]}|j d  dkr|qS )r   rl   rG   r   itemr   r   r   
<listcomp>      zcompose.<locals>.<listcomp>r{   c                 S   r   )r   r|   r   r   r   r   r   r         r~   c                 S   s   g | ]}|j s|qS r   rT   r   r   r   r   r     s    r   c                 S   s   g | ]}|j r|qS r   r   r   r   r   r   r     s    r&   r   rr   c                 S   r   )r   rs   r   r   r   r   r   r     r   rp   c                 S   r   )r   rq   r   r   r   r   r   r     r   ru   c                 S   r   )r   rv   r   r   r   r   r   r     r   rx   c                 S   r   )r   ry   r   r   r   r   r   r     r   r   r`   )r2   Unionr   r
   r	   r0   ListAnyr   re   r   r   r]   r*   rc   rg   r   r   paramsmany_returnsr   r   rv   r   r   r   rG   replacer!   )	r   r   r   r   firstrestr[   r   r   r   )r   r   r   r   compose}  s    


				
	

r   r#   ),r/   r<   r   r   typingr2   textwrapr   commonr   r   r   r   r   r	   r
   r   r   r3   r   r0   r   r   r   r   r8   rL   rM   rN   rV   r    r4   r@   rD   rR   rS   rW   rY   ra   r   r   r+   COMPACTr   r   r   r   r   <module>   s    ,


!)&	
#H