
    X
jD              	          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 dZdej        dej        fdZd	edej        e         fd
Z ej        dej                  Z ej        d          Z ej        d          Z ej        d          Z ej        d          Z ej        d          Z G d d          Z G d de          Z  G d de          Z! G d de           Z" G d de           Z# G d de           Z$ G d de$          Z% G d  d!e!          Z& G 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.d/           e"d0d/           e#d1d2           e#d3d2           e#d4d5           e#d6d5           e"d7d8           e"d9d8           e$d:d;           e$d<d;           e%d=d>           e%d?d>           e'd@dA           e'dBdA           edCdD           edEdD           edFdG           edHdG           edIdJ           edKdJ           edLdM           edNdM           e&dOdP          Z( G dQ dR          Z)dSej        e         de	fdTZ*ej+        dUfdVe	dWedXedefdY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                 ~    t          j        |           \  }}t          |d            t          j        |||          S )N)	fillvalue)	itertoolsteenextzip_longest)r   endleftrights       _/home/kuhnn/.hermes/hermes-agent/venv/lib/python3.11/site-packages/docstring_parser/numpydoc.py	_pairwiser      s=    -))KD% u<<<<    stringc                 X    |                                  } t          |           dk    r| S d S )Nr   )striplen)r   s    r   
_clean_strr       s(    \\^^F
6{{Q4r   z	^[^\s].*$flagsz(^(?P<name>.*?)(?:\s*:\s*(?P<type>.*?))?$z)(?P<type>.*?)(?:, optional|\(optional\))$zI(?P<type>.*?)(?:, default|\(default\))(?: | |=| = |= |: |)*(?P<value>.*)$z`(?<!\S)[Dd]efault(?:s to |(?:\s*(?:is|[=:])\s*|\s+))(?P<value>(?:['\"]).*?(?:['\"])|[\w\-\.]*\w)z(^(?:(?P<name>.*?)\s*:\s*)?(?P<type>.*?)$c                   h    e Zd ZdZdededdfdZedefd            Zdedej	        e
         f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                 "    || _         || _        d S N)r%   r&   )selfr%   r&   s      r   __init__zSection.__init__I   s    
r   c                 L    dt          | j                  z  }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)   dashess     r   title_patternzSection.title_patternM   s1     s4:&4TZ444444r   textc              #   V   K   t          | j        gt          |                    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/   s     r   parsezSection.parseW   s3       TXJJt4D4DEEEEEEEEr   )__name__
__module____qualname____doc__strr*   propertyr.   TIterabler   r2    r   r   r$   r$   ?   s         c       5s 5 5 5 X5F# F!*]"; F F F F F Fr   r$   c                   L    e Zd ZdZdededefdZdedej        e         f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                     d S r(   r;   r)   r&   r>   s      r   _parse_itemz_KVSection._parse_itemk   s    r   r/   c              #   J  K   t          t                              |                    D ]x\  }}|                                }||                                nd }|||         }|                     |                                t          j        |                    V  yd S )N)r&   r>   )	r   KV_REGEXfinditerr   startrA   groupinspectcleandoc)r)   r/   match
next_matchrE   r   r>   s          r   r2   z_KVSection.parsen   s      !*8+<+<T+B+B!C!C 	 	E:IIKKE(2(>*""$$$DCsOE""KKMM)9%)@)@ #      		 	r   N)
r3   r4   r5   r6   r7   r   rA   r9   r:   r2   r;   r   r   r=   r=   `   sp         s 3 =    # !*]";      r   r=   c                   .    e Zd ZdZedef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                     d| j          dS )Nz	^\.\.\s*(z)\s*::r%   r)   s    r   r.   z_SphinxSection.title_pattern   s    .DJ....r   N)r3   r4   r5   r6   r8   r7   r.   r;   r   r   rL   rL   x   sE          /s / / / X/ / /r   rL   c                   &    e Zd ZdZdededef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&   r>   r   c                 |   t                               |          }d x}x}x}}||                    d          }|                    d          }|~t                              |          }||                    d          }d}nd}t                              |          }	|	,d}|	                    d          }|	                    d          }t          |          dk    r3|1t                              |          }	|	|	                    d          }t          | j	        |gt          |          ||||          S )NnametypeTFr>   r   )argsr1   arg_name	type_nameis_optionaldefault)PARAM_KEY_REGEXrI   rF   PARAM_OPTIONAL_REGEXPARAM_DEFAULT_REGEXr   PARAM_DEFAULT_REGEX_IN_DESCsearchr	   r&   r    )
r)   r&   r>   rI   rV   rW   rX   rY   optional_matchdefault_matchs
             r   rA   zParamSection._parse_item   sL   %%c**7;;;9;{W{{6**HF++I$!5!;!;I!F!F!- . 4 4V < <I"&KK"'K 3 9 9) D D ,"&K - 3 3F ; ;I+11'::G u::>>go7>>uEEM('--g66(H%"5))#
 
 
 	
r   N)r3   r4   r5   r6   r7   r	   rA   r;   r   r   rQ   rQ      sG         "
s "
3 "
> "
 "
 "
 "
 "
 "
r   rQ   c                   &    e Zd ZdZdededefdZdS )RaisesSectionzParser for numpydoc raises sections.

    E.g. any section that looks like this:
        ValueError
            A description of what might raise ValueError
    r&   r>   r   c                 x    t          | j        |gt          |          t          |          dk    r|nd           S )Nr   )rU   r1   rW   )r
   r&   r    r   r@   s      r   rA   zRaisesSection._parse_item   sB    (C"5)) XX\\cct
 
 
 	
r   N)r3   r4   r5   r6   r7   r
   rA   r;   r   r   rb   rb      sG         
s 
3 
? 
 
 
 
 
 
r   rb   c                   *    e Zd ZdZdZdededef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&   r>   r   c                     t                               |          }|+|                    d          }|                    d          }nd }d }t          | j        gt          |          || j        |          S )NrS   rT   )rU   r1   rW   is_generatorreturn_name)RETURN_KEY_REGEXrI   rF   r   r&   r    rg   )r)   r&   r>   rI   rh   rW   s         r   rA   zReturnsSection._parse_item   s~     &&s++++f--KF++IIKI("5))*#
 
 
 	
r   N)r3   r4   r5   r6   rg   r7   r   rA   r;   r   r   re   re      sO          L
s 
3 
3C 
 
 
 
 
 
r   re   c                       e Zd ZdZdZdS )YieldsSectionz0Parser for numpydoc generator "yields" sections.TN)r3   r4   r5   r6   rg   r;   r   r   rk   rk      s        ::LLLr   rk   c                   8    e Zd ZdZdedej        e         fdZdS )DeprecationSectionz3Parser for numpydoc "deprecation warning" sections.r/   r   c              #      K   |                     dd          d d gz   ^}}}|!t          t          j        |                    }t	          | j        g|t          |                    V  d S )N
r   )sepmaxsplit)rU   r1   version)splitr    rG   rH   r   r&   )r)   r/   rr   desc_s        r   r2   zDeprecationSection.parse   s       JJ4!J<<d|Kg.t4455D!(z'7J7J
 
 
 	
 	
 	
 	
 	
r   N)	r3   r4   r5   r6   r7   r9   r:   r   r2   r;   r   r   rm   rm      sD        ==
# 
!*-@"A 
 
 
 
 
 
r   rm   c                   8    e Zd ZdZdedej        e         fdZdS )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              #   ,  K   t          |                                                                          }|rg }g }|rF|d                             d          sn*|                    |                    d                     |F|rF|d                             d          rn*|                    |                    d                     |Ft          | j        g|rd                    |          ndd                    |                    V  |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>>>ro   N)snippetr1   )	r   r   
splitlines
startswithappendpopr   r&   join)r)   r/   linessnippet_linesdescription_liness        r   r2   zExamplesSection.parse  sK      t""$$//11 	M " 3Qx**511 $$UYYq\\222  3  78&&u-- !((1666  7 #
4AK		-000t II&788       	 	 	 	 	r   N)	r3   r4   r5   r6   r7   r9   r:   r   r2   r;   r   r   rw   rw      sG        
 
# !*]";      r   rw   
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                       e Zd ZdZddej        ej        eef                  fdZ	d Z
defdZdej        e         d	efd
ZdS )NumpydocParserz%Parser for numpydoc-style docstrings.Nsectionsc                 b    |pt           }d |D             | _        |                                  dS )z[Setup sections.

        :param sections: Recognized sections or None to defaults.
        c                     i | ]
}|j         |S r;   rN   .0ss     r   
<dictcomp>z+NumpydocParser.__init__.<locals>.<dictcomp>I  s    666!666r   N)DEFAULT_SECTIONSr   _setup)r)   r   s     r   r*   zNumpydocParser.__init__C  s5    
 //66X666r   c                     t          j        d                    d | j                                        D                       t           j                  | _        d S )N|c              3   $   K   | ]}|j         V  d S r(   )r.   r   s     r   	<genexpr>z(NumpydocParser._setup.<locals>.<genexpr>N  s$      FF!aoFFFFFFr   r!   )recompiler~   r   valuesM	titles_rerO   s    r   r   zNumpydocParser._setupL  sO    IIFFt}/C/C/E/EFFFFF$
 
 
r   sectionc                 L    || j         |j        <   |                                  dS )zLAdd or replace a section.

        :param section: The new section.
        N)r   r%   r   )r)   r   s     r   add_sectionzNumpydocParser.add_sectionR  s#     (/gm$r   r/   r   c                    t          t          j                  }|s|S t          j        |          }| j                            |          }|r9|d|                                         }||                                d         }n|}d}|                    dd          }|d         pd|_	        t          |          dk    rY|d         pd}|                    d          |_        |                    d          |_        |                                pd|_        t#          | j                            |                    D ]\  }}t'          d |                                D                       }	| j        |	         }
|                                }||                                nd}|j                            |
                    |||                              |S )	zaParse the numpy-style docstring into its components.

        :returns: parsed docstring
        )styleN ro   r   r   z

c              3      K   | ]}||V  	d S r(   r;   )r   gs     r   r   z'NumpydocParser.parse.<locals>.<genexpr>|  s"      DDqammmmmDDr   )r   r   NUMPYDOCrG   rH   r   r^   rE   rs   short_descriptionr   r{   blank_after_short_descriptionendswithblank_after_long_descriptionr   long_descriptionr   rD   r   groupsr   r   metaextendr2   )r)   r/   retrI   
desc_chunk
meta_chunkpartslong_desc_chunk	nextmatchr%   factoryrE   r   s                r   r2   zNumpydocParser.parse[  s   
 n5666 	J %% %%d++ 	oo.Jekkmmoo.JJJJ   q)) %a 0Du::>>#Ahn"O0?0J0J1 1C- 0?/G/G/O/OC,#2#8#8#:#:#BdC  )$.*A*A**M*M N N 	B 	BE9DDELLNNDDDDDEmE*G IIKKE'0'<)//###$CHOOGMM*U3Y*?@@AAAA
r   r(   )r3   r4   r5   r6   r9   OptionalDictr7   r$   r*   r   r   r   r2   r;   r   r   r   r   @  s        // AF3<,@!A    
 
 
7    *!*S/ *i * * * * * *r   r   r/   c                 D    t                                          |           S )zYParse the numpy-style docstring into its components.

    :returns: parsed docstring
    )r   r2   )r/   s    r   r2   r2     s    
 !!$'''r   z    	docstringrendering_styleindentc           	        
 dt           j        t          t          t          f         f
fddt
          dt           j        t           j                 f
fd}g 
| j        r
	                    | j                   | j
        r
	                    d           | j        r~d}| j        j        r|d| j        j         z  }| j        j        r| j        j                                        }ng }d	 }
	                    |                    |g|z                        | j        r
	                    | j                   | j        r
	                    d            |d
d | j        pg D                         |dd | j        pg D                         |dd | j        pg D                         |dd | j        pg D                        | j        r]| j        sV| j        }
	                    |rdnd           
	                    dt+          
d                   z              |            |dd | j        pg D                         |dd | j        pg D                         |dd | j        pg D                         |dd | j        pg D                        t+          | j                  dk    r
	                    d           
	                    d           
	                    d           | j        D ]D}|j        r
	                    |j                   |j        r
	                    |j                   E| j        D ]}	t5          |	t6          t          t          t          t8          f          r1
	                    d           
	                    |	j        d                             dd                                                     
	                    dt+          |	j        d                   z             |	j        r
	                    |	j                   d	                    
          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                 &   t          | t                    r| j        }nt          | t                    r| j        }nd }| j        r|r|d| j         z  }n| j        r| j        }n|sd}t          | t                    r.| j        dvr|d| j         z  }n| j        s| j        dk    r|dz  }| j        rJd 	                    |g| j        
                                z             }                    |           d S                     |           d S )Nz : r   )NNonez
, default=r   z
, optionalro   )
isinstancer	   rV   r   rh   rW   rY   rX   r1   r~   rz   r|   )r   headbodyr   r   s      r   process_onezcompose.<locals>.process_one  sI    c>** 	<DD-.. 	?DDD= 	T 	)#-)))DD] 	=DD 	D
 c>** 	%{.002S[222 %CK6$9$9$? 	 ==%%tfs/I/I/K/K&KLLDLLLLr   rS   rU   c                     |re                     d                                |                                 dt          d                   z             |D ]} |           d S d S )Nr   r,   )r|   r   )rS   rU   argr   r   s      r   process_sectzcompose.<locals>.process_sect  s     	!LLLLLLs59~~-... ! !C    	! 	!! !r   r   z.. deprecated:: ro   r   c                 4    g | ]}|j         d          dk    |S )r   r   rU   r   items     r   
<listcomp>zcompose.<locals>.<listcomp>  (    LLL$DIaLG4K4K4K4K4Kr   r   c                 4    g | ]}|j         d          dk    |S )r   r   r   r   s     r   r   zcompose.<locals>.<listcomp>  s3     	
 	
 	
y|{** ***r   r   c                      g | ]}|j         	|S r;   rg   r   s     r   r   zcompose.<locals>.<listcomp>  s1     	
 	
 	
$	
	
 	
 	
r   r   c                      g | ]}|j         	|S r;   r   r   s     r   r   zcompose.<locals>.<listcomp>  s     LLL$$:KLLLLr   r,   r   r   c                 4    g | ]}|j         d          dk    |S )r   r   r   r   s     r   r   zcompose.<locals>.<listcomp>   s3     	
 	
 	
y|z)) )))r   r   c                 4    g | ]}|j         d          dk    |S )r   r   r   r   s     r   r   zcompose.<locals>.<listcomp>	  s3     	
 	
 	
y|},, ,,,r   r   c                 4    g | ]}|j         d          dk    |S )r   r   r   r   s     r   r   zcompose.<locals>.<listcomp>  s(    MMM$DIaLH4L4L4L4L4Lr   r   c                 4    g | ]}|j         d          dk    |S )r   r   r   r   s     r   r   zcompose.<locals>.<listcomp>  r   r   r   r   z--------ru   ) r9   Unionr	   r   r
   r7   ListAnyr   r|   r   r   rr   r1   rz   r~   r   r   paramsmany_returnsr   r   r   r   ry   r   r   r   r   rU   replacer%   )r   r   r   r   firstrestrp   r   exampler   r   r   s     `       @@r   composer    s+   W^%5FG      @!3 !afQUm ! ! ! ! ! ! ! E" 2Y0111. R 	/! ( 	98.6888E , 	(4??AADDD6mmSXXugn--...! 1Y/000- RLLL)*0bLLL  
 L	
 	
!(.B	
 	
 	
   L	
 	
!.4"	
 	
 	
   LLL)06BLLL  
  !7 3XX)444S3uRy>>)***CL	
 	
!(.B	
 	
 	
   L	
 	
!(.B	
 	
 	
   LMM)*0bMMM  
 LLL)*0bLLL  
 9""RZ   Z    ) 	2 	2G .W_---" 2W0111 + +#  	
 	
 
	 RTYq\))#r2288::;;;S3ty|,,,--- 	+LL)***99Ur   r(   )-r6   rG   r   r   typingr9   textwrapr   commonr   r   r   r   r	   r
   r   r   r   r:   r   r7   r   r    r   r   rC   rZ   r[   r\   r]   ri   r$   r=   rL   rQ   rb   re   rk   rm   rw   r   r   r2   COMPACTr  r;   r   r   <module>r     s   
      				          
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
= =
 = = = = =s qz#     2:l"$///"*HII!rz"NOO  !bjP   )bjg   2:IJJ F F F F F F F FB       0
/ 
/ 
/ 
/ 
/W 
/ 
/ 
/-
 -
 -
 -
 -
: -
 -
 -
`
 
 
 
 
J 
 
 
 
 
 
 
 
Z 
 
 
<    N   
 
 
 
 
 
 
 
# # # # #g # # #L Lw'' L7##  Lg&&  L!!	 
 L#]33  L//  L"M22  L}--  LZ((  LJ''  M(H%%  M'8$$  M'7##  M&'""  L{++   Lk**! " N9i((# $ N8Y''% & M(H%%' ( M'8$$) * OJ
+++ , OIz**- . GJ
##/ 0 GIz""1 2 GJ
##3 4 GIz""5 6 GGW7 8 GFG9 : GL,''; < GK&&= > |]33?  FE E E E E E E EP(
3 (I ( ( ( ( '5&<	h hh $h 	h
 	h h h h h hr   