
    Y	go>              	          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 dYdej$                  dej$                  fdZd	edej*                  e   fd
Z ej.                  dej0                        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!d/d.       e"d0d1       e"d2d1       e"d3d4       e"d5d4       e!d6d7       e!d8d7       e#d9d:       e#d;d:       e$d<d=       e$d>d=       e&d?d@       e&dAd@       edBdC       edDdC       edEdF       edGdF       edHdI       edJdI       edKdL       edMdL       e%dNdO      Z' G dP dQ      Z(dRede	fdSZ)ejT                  dTfdUe	dVedWedefdXZ+y)Zz_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                 z    t        j                  |       \  }}t        |d        t        j                  |||      S )N)	fillvalue)	itertoolsteenextzip_longest)r   endleftrights       Z/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/docstring_parser/numpydoc.py	_pairwiser      s3    --)KD%  u<<    stringc                 D    | j                         } t        |       dkD  r| S y )Nr   )striplen)r   s    r   
_clean_strr       s     \\^F
6{Q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                   d    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y)
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                      || _         || _        y N)r%   r&   )selfr%   r&   s      r   __init__zSection.__init__=   s    
r   c                 X    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_patternA   s/     s4::&TZZLxt44r   textc              #   R   K   t        | j                  gt        |             yw)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.parseK   s       TXXJJt4DEEs   %')__name__
__module____qualname____doc__strr*   propertyr.   TIterabler   r2    r   r   r$   r$   3   s[    c    5s 5 5F# F!**]"; Fr   r$   c                   N    e Zd ZdZdededefdZdedej                  e   fdZ	y)	
_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                      y r(   r;   r)   r&   r>   s      r   _parse_itemz_KVSection._parse_item_   s    r   r/   c              #     K   t        t        j                  |            D ]d  \  }}|j                         }||j	                         nd }||| }| j                  |j                         t        j                  |             f y w)N)r&   r>   )	r   KV_REGEXfinditerr   startrA   groupinspectcleandoc)r)   r/   match
next_matchrE   r   r>   s          r   r2   z_KVSection.parseb   s     !*8+<+<T+B!C 	E:IIKE(2(>*""$DCsOE""KKM)9)9%)@ #  		s   BB	N)
r3   r4   r5   r6   r7   r   rA   r9   r:   r2   r;   r   r   r=   r=   T   s=    s 3 = # !**]"; r   r=   c                   &    e Zd ZdZedefd       Zy)_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_patternt   s    DJJ<v..r   N)r3   r4   r5   r6   r8   r7   r.   r;   r   r   rL   rL   l   s"     /s / /r   rL   c                   $    e Zd ZdZdededefdZy)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         j                  |      }d x}x}}|Q|j                  d      }|j                  d      }|-t        j                  |      }||j                  d      }d}nd}d }t	        |      dkD  r(t
        j                  |      }	|	|	j                  d      }t        | j                  |gt        |      ||||      S )NnametypeTFr   r>   )argsr1   arg_name	type_nameis_optionaldefault)
PARAM_KEY_REGEXrI   rF   PARAM_OPTIONAL_REGEXr   PARAM_DEFAULT_REGEXsearchr	   r&   r    )
r)   r&   r>   rI   rU   rV   rW   optional_matchrX   default_matchs
             r   rA   zParamSection._parse_item   s    %%c*-1119{{{6*HF+I$!5!;!;I!F!- . 4 4V <I"&K"'Ku:>/66u=M('--g6((H%"5)#
 	
r   N)r3   r4   r5   r6   r7   r	   rA   r;   r   r   rP   rP   y   s!    
s 
3 
> 
r   rP   c                   $    e Zd ZdZdededefdZy)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                 r    t        | j                  |gt        |      t        |      dkD  r|      S d       S )Nr   )rT   r1   rV   )r
   r&   r    r   r@   s      r   rA   zRaisesSection._parse_item   s>    ((C"5) X\c
 	
 04
 	
r   N)r3   r4   r5   r6   r7   r
   rA   r;   r   r   r`   r`      s!    
s 
3 
? 
r   r`   c                   (    e Zd ZdZdZdededefdZy)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         j                  |      }|#|j                  d      }|j                  d      }nd }d }t        | j                  gt        |      || j                  |      S )NrR   rS   )rT   r1   rV   is_generatorreturn_name)RETURN_KEY_REGEXrI   rF   r   r&   r    re   )r)   r&   r>   rI   rf   rV   s         r   rA   zReturnsSection._parse_item   sk     &&s+++f-KF+IKI(("5)**#
 	
r   N)r3   r4   r5   r6   re   r7   r   rA   r;   r   r   rc   rc      s)     L
s 
3 
3C 
r   rc   c                       e Zd ZdZdZy)YieldsSectionz0Parser for numpydoc generator "yields" sections.TN)r3   r4   r5   r6   re   r;   r   r   ri   ri      s
    :Lr   ri   c                   :    e Zd ZdZdedej                  e   fdZy)DeprecationSectionz3Parser for numpydoc "deprecation warning" sections.r/   r   c              #      K   |j                  dd      d d gz   ^}}}|t        t        j                  |            }t	        | j
                  g|t        |             y w)N
r   )sepmaxsplit)rT   r1   version)splitr    rG   rH   r   r&   )r)   r/   rp   desc_s        r   r2   zDeprecationSection.parse   sb      JJ4!J<d|Kg..t45D!((z'7J
 	
s   A!A#N)	r3   r4   r5   r6   r7   r9   r:   r   r2   r;   r   r   rk   rk      s"    =
# 
!**-@"A 
r   rk   c                   :    e Zd ZdZdedej                  e   fdZy)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        |      j                         j                         }|rg }g }|r8|d   j                  d      sn#|j	                  |j                  d             |r8|r8|d   j                  d      rn#|j	                  |j                  d             |r8t        | j                  g|rdj                  |      nddj                  |             |ryyw)zParse ``DocstringExample`` objects from the body of this section.

        :param text: section body text. Should be cleaned with
                     ``inspect.cleandoc`` before parsing.
        r   z>>>rm   N)snippetr1   )	r   r   
splitlines
startswithappendpopr   r&   join)r)   r/   linessnippet_linesdescription_liness        r   r2   zExamplesSection.parse   s      t""$//1M "Qx**51$$UYYq\2  8&&u-!((16  #
4A		-0t II&78  s   A'C&*9C&$?C&$C&N)	r3   r4   r5   r6   r7   r9   r:   r   r2   r;   r   r   ru   ru      s#    
# !**]"; r   ru   
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                   x    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d	efd
Zy)NumpydocParserz%Parser for numpydoc-style docstrings.Nsectionsc                     |xs t         }|D ci c]  }|j                  | c}| _        | j                          yc c}w )z[Setup sections.

        :param sections: Recognized sections or None to defaults.
        N)DEFAULT_SECTIONSr%   r   _setup)r)   r   ss      r   r*   zNumpydocParser.__init__0  s7    
 //-56!6 7s   <c                     t        j                  dj                  d | j                  j	                         D              t         j
                        | _        y )N|c              3   4   K   | ]  }|j                     y wr(   )r.   ).0r   s     r   	<genexpr>z(NumpydocParser._setup.<locals>.<genexpr>;  s     F!aooFs   r!   )recompiler|   r   valuesM	titles_rerN   s    r   r   zNumpydocParser._setup9  s8    IIFt}}/C/C/EFF$$
r   sectionc                 V    || j                   |j                  <   | j                          y)zLAdd or replace a section.

        :param section: The new section.
        N)r   r%   r   )r)   r   s     r   add_sectionzNumpydocParser.add_section?  s     (/gmm$r   r/   r   c                 L   t        t        j                        }|s|S t        j                  |      }| j
                  j                  |      }|r'|d|j                          }||j                         d }n|}d}|j                  dd      }|d   xs d|_	        t        |      dkD  rN|d   xs d}|j                  d      |_        |j                  d      |_        |j                         xs d|_        t#        | j
                  j%                  |            D ]  \  }}t'        d |j)                         D              }	| j*                  |	   }
|j-                         }||j                         nd}|j.                  j1                  |
j3                  |||               |S )	zaParse the numpy-style docstring into its components.

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

c              3   &   K   | ]	  }||  y wr(   r;   )r   gs     r   r   z'NumpydocParser.parse.<locals>.<genexpr>i  s     DqamDs   )r   r   NUMPYDOCrG   rH   r   r\   rE   rq   short_descriptionr   ry   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.parseH  s   
 n556J % %%d+o.Jekkmo.JJJ   q) %a 0Du:>#Ahn"O0?0J0J1C- 0?/G/G/OC,#2#8#8#:#BdC  )$..*A*A**M N 	BE9DELLNDDEmmE*G IIKE'0'<)//#$CHHOOGMM*U3*?@A	B 
r   r(   )r3   r4   r5   r6   r9   OptionalDictr7   r$   r*   r   r   r   r2   r;   r   r   r   r   -  sK    /AFF3<,@!A 
7 *# *) *r   r   r/   c                 4    t               j                  |       S )zYParse the numpy-style docstring into its components.

    :returns: parsed docstring
    )r   r2   )r/   s    r   r2   r2   u  s    
 !!$''r   z    	docstringrendering_styleindentc                 L	  
 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                         | j                  r
j                  d       | j                  rd}| j                  j                  r|d| j                  j                   z  }| j                  j                  r%| j                  j                  j                         }ng }d	 }
j                  |j                  |g|z                | j                   r
j                  | j                          | j"                  r
j                  d        |d
| j$                  xs g D cg c]  }|j&                  d   dk(  s| c}        |d| j$                  xs g D cg c]  }|j&                  d   dk(  r| c}        |d| j(                  xs g D cg c]  }|j*                  s| c}        |d| j(                  xs g D cg c]  }|j*                  s| c}       | j,                  rU| j(                  sI| j,                  }
j                  |rdnd       
j                  dt/        
d         z          |        |d| j$                  xs g D cg c]  }|j&                  d   dk(  r| c}        |d| j$                  xs g D cg c]  }|j&                  d   dk(  r| c}        |d| j0                  xs g D cg c]  }|j&                  d   dk(  s| c}        |d| j0                  xs g D cg c]  }|j&                  d   dk(  s| c}       | j2                  D ]  }	t5        |	t6        t        t        t        f      r$
j                  d       
j                  |	j&                  d   j9                  dd      j;                                
j                  dt/        |	j&                  d         z         |	j                  s
j                  |	j                          d	j                  
      S c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w )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                  r|dz  }| j                  rBd j                  |g| j                  j                         z         }j                  |       y j                  |       y )Nz : r   z
, optionalrm   )
isinstancer	   rU   r   rf   rV   rW   r1   r|   rx   rz   )r   headbodyr   r   s      r   process_onezcompose.<locals>.process_one  s     c>*<<D-.??DD==Tc#--))D]]==DDc>*sL D??x=%%tfs/I/I/K&KLDLLLLr   rR   rT   c                     |rRj                  d       j                  |        j                  dt        d         z         |D ]
  } |        y y )Nr   r,   )rz   r   )rR   rT   argr   r   s      r   process_sectzcompose.<locals>.process_sect  sS    LLLLLLs59~-. !C !	 r   r   z.. deprecated:: rm   r   r   r   r   r   r   r   r,   r   r   r   r   r   r   r   r   r   rs   )r9   Unionr	   r   r
   r7   ListAnyr   rz   r   r   rp   r1   rx   r|   r   r   paramsrT   many_returnsre   r   r   r   r   r   r   replacer%   )r   r   r   r   firstrestrn   itemr   r   r   r   s     `       @@r   composer   }  s*   WW^%5FG4!3 !affQUUm ! E""Y001..R!  ((q..66788E  ,,((44??ADD6(mSXXugn-.!!Y//0--R#**0bL$DIIaLG4KL
  "((.B	
yy|{* 	
  "..4"	
$$ 	
 #006BL$$:K:KL
 !7!7X)4S3uRy>)*C "((.B	
yy|z) 	
  "((.B	
yy|}, 	
 #**0bM$DIIaLH4LM
 #**0bL$DIIaLG4KL
  +# 	
 RTYYq\))#r288:;S3tyy|,,-LL))*#+& 99U_ 	M
	
	
 	M	
	
 	N
 	MsH    Q>
8Q>
R
R
 R
R
R

R
R
R
9R!
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   rY   rZ   r[   rg   r$   r=   rL   rP   r`   rc   ri   rk   ru   r   r   r2   COMPACTr   r;   r   r   <module>r      s  
   	  
 
 
=

 = =s qzz#  2::l"$$/"**HI!rzz"NO  !bjjG  2::IJ F FB 0
/W 
/&
: &
R
J 
 
Z 
<N 
 
#g #L w' 7#  g&  !	 
 #]3  /  "M2  }-  Z(  J'  (H%  '8$  '7#  &'"  {+   k*! " 9i(# $ 8Y'% & (H%' ( '8$) * J
++ , Iz*- . J
#/ 0 Iz"1 2 J
#3 4 Iz"5 6 GW7 8 FG9 : L,'; < K&= > |]3?  FE EP( (	 ( '5&<&<	WW $W 	W
 	Wr   