
    Y	gX              	       ~   d Z ddl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 ej                  diZej                  dd dk  r5ej                  ej                   dej"                  d	ej$                  d
i       dej&                  dej(                  fdZdej&                  dej,                  e   fdZdej&                  defdZdej&                  dej,                  ej6                  eej,                  e   ej,                  e   f      fdZ G d dej:                        Zdej>                  e ef   de
ddfdZ!y)zbAttribute docstrings parsing.

.. seealso:: https://peps.python.org/pep-0257/#what-is-a-docstring
    N)
ModuleType   )	DocstringDocstringParamvalue   )      nsnodereturnc                 <    t        | t        | j                           S )z<Return the constant's value if the given node is a constant.)getattrast_constant_attr	__class__r   s    Y/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/docstring_parser/attrdoc.pyast_get_constant_valuer      s    4*4>>:;;    c                 R   t        t        d      rt        j                  |       S t        | t        j                  t        j
                  t        j                  t        j                  f      rt        t        |             S t        | t        j                        r| j                  S y)z0Convert the AST node to source code as a string.unparseN)hasattrastr   
isinstanceStrNumNameConstantConstantstrr   Nameidr   s    r   ast_unparser#       sk    sI{{4  $#''3+;+;S\\JK)$/00$!wwr   c                     t        | t        j                        xrY t        | j                  t        j                  t        j
                  f      xr# t        t        | j                        t              S )z2Return True if the given node is a literal string.)r   r   Exprr   r   r   r   r    r   s    r   ast_is_literal_strr&   ,   sR     	4" 	@tzzCLL#''#:;	@-djj93?r   c                    t        | t        j                  t        j                  f      rt        | t        j                        r| j                  d   n| j
                  }t        |t        j                        rcd}t        | t        j                        rt        | j                        }d}| j                  rt        | j                        }|j                  ||fS y)z@Return name, type and default if the given node is an attribute.r   N)r   r   Assign	AnnAssigntargetstargetr!   r#   
annotationr   r"   )r   r+   type_strdefaults       r   ast_get_attributer/   5   s     $S]]34)$

;DLLO 	 fchh'H$.&t7Gzz%djj199h//r   c            
           e Zd ZdZdZdZd Zdej                  dej                  e
ej                  e
ej                  e
   ej                  e
   f   f   fdZy)AttributeDocstringsz6An ast.NodeVisitor that collects attribute docstrings.Nc                 4   | j                   r@t        |      r5| j                   \  }}}t        |j                        ||f| j                  |<   t        |      | _         t        |t        j                  t        j                  f      r| j                  |       y y N)	prev_attrr&   r   r   	attr_docsr/   r   r   ClassDefModulegeneric_visit)selfr   	attr_name	attr_typeattr_defaults        r   visitzAttributeDocstrings.visitN   s{    >>0615.Iy,&tzz2)DNN9%
 +40dS\\3::67t$ 8r   	componentr   c                    i | _         d| _        	 t        j                  t	        j
                  |            }t        j                  |      }t	        j                  |      r| j                  |       | j                   S t        |t        j                        rEt        |j                  d   t        j                        r| j                  |j                  d          | j                   S # t        $ r Y | j                   S w xY w)zGet attribute docstrings from the given component.

        :param component: component to process (class or module)
        :returns: for each attribute docstring, a tuple with (description,
            type, default)
        Nr   )r5   r4   textwrapdedentinspect	getsourcer   parseismoduler=   r   r7   bodyr6   OSError)r9   r>   sourcetrees       r   get_attr_docsz!AttributeDocstrings.get_attr_docsZ   s     	)__W%6%6y%ABF 99V$D	*

4 
 ~~	 D#**-*		!cll3 

499Q<(~~  	 ~~	s   (C* *	D D)__name__
__module____qualname____doc__r5   r4   r=   TAnyDictr    TupleOptionalrJ    r   r   r1   r1   H   s[    @II
%	
QWWS!**S/1::c?BCC	Dr   r1   obj	docstringc           	         t        d |j                  D              }t               j                  |       j	                         D ]>  \  }\  }}}||vst        d|g||||du|      }|j                  j                  |       @ y)zAdd attribute docstrings found in the object's source code.

    :param obj: object from which to parse attribute docstrings
    :param docstring: Docstring object where found attributes are added
    :returns: list with names of added attributes
    c              3   4   K   | ]  }|j                     y wr3   )arg_name).0ps     r   	<genexpr>z+add_attribute_docstrings.<locals>.<genexpr>}   s     66s   	attributeN)argsdescriptionrY   	type_nameis_optionalr.   )setparamsr1   rJ   itemsr   metaappend)rU   rV   rc   rY   r_   r`   r.   params           r   add_attribute_docstringsrh   t   s     6Y%5%566F++C0668)33;	7 6!"!8,'!##4/E NN!!%()r   )"rN   r   rB   sysr@   typingrO   typesr   commonr   r   r   r   version_infoupdater   r   r   ASTrP   r   rS   r    r#   boolr&   rR   r/   NodeVisitorr1   Uniontyperh   rT   r   r   <module>rt      sD  
   
    -\\7+ BQ6!gGGSGGS	
< <QUU <
	cgg 	!**S/ 	SWW  
''ZZQZZ_ajjo=>?&)#// )X)	
z!	")/8)	)r   