o
    w!g                     @  s|  U d dl mZ d dlZd dlm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mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z  d dl!m"Z"m#Z# d dl$m%Z%m&Z& eryd dlm'Z' d d	lm(Z(m)Z) d d
l*m+Z+ d dl,m-Z- i de%j.de%j.de%j.de%j.de%j/de%j/de%j/de%j/de%j/de%j/de%j0de%j0de%j1de%j2de%j3de%j4de%j5e%j6e%j6e%j7e%j8e%j9e%j9dZ:e;e<e=e> f Z?e=e? Z@e;e@e<f ZAeBdejCZDdeEd < eBd!ZFdeEd"< eBd#ZGdeEd$< eBd%ZHdeEd&< dd/d0ZIdd2d3ZJd4d5dd9d:ZKdd<d=ZLd4d5dd?d@ZMddBdCZNddEdFZOddHdIZPddKdLZQddNdOZRddQdRZSd4dSddUdVZTd4dWdd]d^ZUd_d d`ddedfZVd4d4dgddkdlZWd4d4dgddndoZXd4d4dpddtduZYd4dvddydzZZdd}d~Z[e%j.eLe%j/eMe%j0eRe%j9eSe%j4eZe%j5eNe%j6eOe%j7ePe%j8eQe%j1eWe%j2eXe%j3eYiZ\e] Z^d_d4d4d4d_d4d4d4ddddZ_dS )    )annotationsN)suppress)TYPE_CHECKING)DocstringAttributeDocstringClassDocstringFunctionDocstringModuleDocstringParameterDocstringRaiseDocstringReceiveDocstringReturnDocstringSectionDocstringSectionAdmonitionDocstringSectionAttributesDocstringSectionClassesDocstringSectionExamplesDocstringSectionFunctionsDocstringSectionModulesDocstringSectionOtherParametersDocstringSectionParametersDocstringSectionRaisesDocstringSectionReceivesDocstringSectionReturnsDocstringSectionTextDocstringSectionWarnsDocstringSectionYieldsDocstringWarnDocstringYield)docstring_warningparse_docstring_annotation)DocstringSectionKindLogLevel)Pattern)AnyLiteral)Expr)	Docstringargs	argumentsparams
parameterszkeyword argszkeyword argumentsz
other argszother argumentszother paramszother parametersraises
exceptionsreturnsyieldsreceivesexamples
attributes)	functionsmethodsclassesmoduleswarnswarningsz4^(?P<type>[\w][\s\w-]*):(\s+(?P<title>[^\s].*))?\s*$r"   _RE_ADMONITIONz=^(?:(?P<name>\w+)?\s*(?:\((?P<type>.+)\))?:\s*)?(?P<desc>.*)$_RE_NAME_ANNOTATION_DESCRIPTIONz^\s*<BLANKLINE>\s*$_RE_DOCTEST_BLANKLINEz(\s*#\s*doctest:.+)$_RE_DOCTEST_FLAGS	docstringr&   offsetintoptionsr#   return_ItemsBlockc          
      K  s  | j }|t|krg |fS |}g }t|| r!|d7 }t|| st|| t||   }|dkr9g |d fS ||| |d  gf}|d7 }|t|k r|| }t|r^|d d nc||d d ru|d ||d d   nL||d d rt|t|  }	|d ||	d   t| |d|d  d| d|d  d	|	  n||d r|| |||d  gf}nn
|d7 }|t|k sN|r|| ||d fS )
N   r        z,Confusing indentation for continuation line z in docstring, should be z * 2 = z spaces, not )lineslen_is_empty_linelstripappend
startswithr   )
r<   r=   r?   rF   
new_offsetitemsindentcurrent_itemlinecont_indent rR   [/mnt/skqttb/ctump_chatbot/chatbot/lib/python3.10/site-packages/_griffe/docstrings/google.py_read_block_itemsS   sT   
!
rT   tuple[str, int]c                K  s  | j }|t|krd|d fS |}g }t|| r#|d7 }t|| st|| t||   }|dkr;d|d fS |||   |d7 }|t|k r|| |d s]t|| r||| |d   |d7 }|t|k r|| |d s]t|| s]d|d|d fS )NrC   rB   r   rE   
)rF   rG   rH   rI   rJ   rK   joinrstrip)r<   r=   r?   rF   rL   blockrN   rR   rR   rS   _read_block   s$   **rZ   T)warn_unknown_paramsr[   bool$tuple[list[DocstringParameter], int]c             
   K  s  g }t | fd|i|\}}|D ]\}}z|d dd\}	}
W n ty5   t| |d|d  d Y qw d|
 g|dd  d}
d|	v rc|	dd\}}|d	}|d
}t	|| }n|	}z	| j
j| j}W n ttfy{   d }Y nw z	| j
j| j}W n ttfy   d }Y nw |d u rt| |d| d |rtt7 | j
j}||vrd| d}d| d| fD ]}||v r|d| d7 } nqt| || W d    n1 sw   Y  |t||||
d q||fS )Nr=   r   :rB   -Failed to get 'name: description' pair from ''rV   rE   ()
, optionalz%No type or annotation for parameter 'zParameter 'z+' does not appear in the function signature*z**z. Did you mean 'z'?)namevalue
annotationdescription)rT   split
ValueErrorr   rW   rI   rX   stripremovesuffixr   parentr*   rf   AttributeErrorKeyErrordefaultr   rJ   r	   )r<   r=   r[   r?   r*   rY   rL   line_numberparam_linesname_with_typerg   rd   rf   ro   r)   messagestarred_namerR   rR   rS   _read_parameters   sV   "



ru   -tuple[DocstringSectionParameters | None, int]c                K  s$   t | fd|i|\}}t||fS Nr=   )ru   r   )r<   r=   r?   r*   rL   rR   rR   rS   _read_parameters_section   s   rx   2tuple[DocstringSectionOtherParameters | None, int]c                K  s&   t | f|dd|\}}t||fS )NF)r=   r[   )ru   r   )r<   r=   r[   r?   r*   rL   rR   rR   rS   _read_other_parameters_section   s   rz   -tuple[DocstringSectionAttributes | None, int]c             
   K  s(  g }t | fd|i|\}}d }|D ]{\}}z|d dd\}	}
W n ty7   t| |d|d  d Y qw d|
 g|dd  d}
d|	v re|	dd\}}|d	}|d
}t	|| }n|	}t
ttt | j| j}W d    n1 s~w   Y  |t|||
d qt||fS )Nr=   r   r^   rB   r_   r`   rV   rE   ra   rb   rd   rf   rg   )rT   rh   ri   r   rW   rI   rX   rj   rk   r   r   rm   rn   	TypeErrorrl   rf   rJ   r   r   )r<   r=   r?   r1   rY   rL   rf   rp   
attr_linesrr   rg   rd   rR   rR   rS   _read_attributes_section  s,   "

r   ,tuple[DocstringSectionFunctions | None, int]c             
   K     g }t | fd|i|\}}d }|D ]T\}}z|d dd\}	}
W n ty7   t| |d|d  d Y qw d|
 g|dd  d}
d|	v rX|	ddd }|	}n|	}d }|t|||
d	 qt	||fS 
Nr=   r   r^   rB   z2Failed to get 'signature: description' pair from 'r`   rV   (r|   )
rT   rh   ri   r   rW   rI   rX   rJ   r   r   )r<   r=   r?   r2   rY   rL   	signaturerp   
func_linesname_with_signaturerg   rd   rR   rR   rS   _read_functions_section'  ,   "r   *tuple[DocstringSectionClasses | None, int]c             
   K  r   r   )
rT   rh   ri   r   rW   rI   rX   rJ   r   r   )r<   r=   r?   r4   rY   rL   r   rp   class_linesr   rg   rd   rR   rR   rS   _read_classes_sectionJ  r   r   *tuple[DocstringSectionModules | None, int]c          
   
   K     g }t | fd|i|\}}|D ]@\}}z|d dd\}}	W n ty5   t| |d|d  d Y qw d|	 g|dd  d}	|t||	d qt	||fS )	Nr=   r   r^   rB   r_   r`   rV   )rd   rg   )
rT   rh   ri   r   rW   rI   rX   rJ   r   r   )
r<   r=   r?   r5   rY   rL   rp   module_linesrd   rg   rR   rR   rS   _read_modules_sectionm  s    "r   )tuple[DocstringSectionRaises | None, int]c          
   
   K  s   g }t | fd|i|\}}|D ]E\}}z|d dd\}}	W n ty5   t| |d|d  d Y qw d|	 g|dd  d}	t|| }|t	||	d qt
||fS )	Nr=   r   r^   rB   z2Failed to get 'exception: description' pair from 'r`   rV   rf   rg   )rT   rh   ri   r   rW   rI   rX   r   rJ   r
   r   )
r<   r=   r?   r,   rY   rL   rp   exception_linesrf   rg   rR   rR   rS   _read_raises_section  s    "
r   (tuple[DocstringSectionWarns | None, int]c          
   
   K  r   )	Nr=   r   r^   rB   z0Failed to get 'warning: description' pair from 'r`   rV   r   )
rT   rh   ri   r   rW   rI   rX   rJ   r   r   )
r<   r=   r?   r6   rY   rL   rp   warning_linesrf   rg   rR   rR   rS   _read_warns_section  s   "r   )multipler   c                K  sB   |rt | fd|i|S t| fd|i|\}}|| fg|fS rw   )rT   rZ   
splitlines)r<   r=   r   r?   	one_blockrL   rR   rR   rS   _read_block_items_maybe  s   r   namedrp   rF   	list[str]r   tuple[str | None, Any, str]c                C  s   |r!t |d }|st| |d|d  d t| \}}}n!d }d|d v r<|d dd\}}|dd}nd }|d }d| g|dd  d}|||fS )	Nr   z4Failed to get name, annotation or description from 'r`   r^   rB   r   )rV   )	r9   matchr   ri   groupsrh   rI   rX   rW   )r<   rp   rF   r   r   rd   rf   rg   rR   rR   rS    _get_name_annotation_description  s$   "
r   F)r   index	gen_indexLiteral[0, 1, 2]r   str | Expr | Nonec                C  s   d }t t< | jj}|jr|jj| }n
|jr|dkr|j}|r2|jr:|jj| }W d    |S W d    |S W d    |S 1 sEw   Y  |S )Nr   )	r   	Exceptionrl   rf   is_generatorsliceelementsis_iteratoris_tuple)r<   r   r   r   rf   rR   rR   rS   _annotation_from_parent  s&   




r   )returns_multiple_itemsreturns_named_valuer   r   *tuple[DocstringSectionReturns | None, int]c             	   K     g }t | f||d|\}}t|D ]T\}\}	}
zt| |	|
|d\}}}W n	 ty/   Y qw |r8t|| }n#t| dt|dk|d}|d u r[|rNt|n|d }t| |	d|  |	t
|pad||d qt||fS )	Nr=   r   r   rD   rB   r   r   r   z)No type or annotation for returned value rC   r|   )r   	enumerater   ri   r   r   rG   reprr   rJ   r   r   )r<   r=   r   r   r?   r-   rY   rL   r   rp   return_linesrd   rf   rg   returned_valuerR   rR   rS   _read_returns_section  8   
r   )tuple[DocstringSectionYields | None, int]c             	   K  r   )	Nr   r   r   rB   r   z(No type or annotation for yielded value rC   r|   )r   r   r   ri   r   r   rG   r   r   rJ   r   r   )r<   r=   r   r   r?   r.   rY   rL   r   rp   yield_linesrd   rf   rg   yielded_valuerR   rR   rS   _read_yields_section$  r   r   )receives_multiple_itemsreceives_named_valuer   r   +tuple[DocstringSectionReceives | None, int]c             	   K  s   g }t | f||d|\}}t|D ]T\}\}	}
zt| |	|
|d\}}}W n	 ty/   Y qw |r8t|| }nt| dt|dk|d}|d u r[|rNt|n|d }t| |	d|  |	t
|pad||d qt||fS )Nr   r   rB   r   z)No type or annotation for received value rC   r|   )r   r   r   ri   r   r   rG   r   r   rJ   r   r   )r<   r=   r   r   r?   r/   rY   rL   r   rp   receive_linesrd   rf   rg   received_valuerR   rR   rS   _read_receives_sectionP  r   r   )trim_doctest_flagsr   +tuple[DocstringSectionExamples | None, int]c                K  sp  t | fd|i|\}}g }d}d}g }	g }
|dD ]x}t|r;|r5|
r2|tjd|
f g }
d}q|	| q|rQ|rKtd|}t	d|}|
| q|
dr_| }|	| q|rg|	| q|
dr|	r~|tjd|	df g }	d}|rtd|}|
| q|	| q|	r|tjd|	df n|
r|tjd|
f t||fS )Nr=   FrV   rC   ```z>>>T)rZ   rh   rH   rJ   r    r0   rW   r;   subr:   rK   textrX   r   )r<   r=   r   r?   r   rL   sub_sectionsin_code_examplein_code_blockcurrent_textcurrent_examplerP   rR   rR   rS   _read_examples_section|  sL   

r   rP   strc                 C  s
   |    S )N)rj   )rP   rR   rR   rS   rH     s   
rH   ignore_init_summaryr   r   r    returns_type_in_property_summaryr   r   r[   r   r   list[DocstringSection]c          &   	   K  s~  g }
g }d}| j }||||||||d|	}	|	d o3| jduo3| jjdko3| jjo3| jjduo3| jjj}|r8dnd}|t|k r||  }|r\|dd	rSd}|	||  nu|dd	rod
}|	||  nbt
||  }r| }|d }|d }| tv }|dk}| pt||d  }|t|d k }|t|d k }|ot||d  }|ot||d  }|o| o||d  d}|o| o||d  d}|s|s|	||  |d7 }q:g }|rdnd}|s|r|s|	d|  |r|r|	d| d |r3d|} t| |d| d|  tj |	||  |d7 }q:|ro|rMt|rK|
	td|d g }tt|   }!|!| fd|d i|	\}"}|"rn||"_|
	|" nbt| |d d\}#}|#r|rt|r|
	td|d g }|du r|}| dd}|
	t||#|d n$tt |	||  W d   n	1 sw   Y  n|	||  |d7 }|t|k sA|r|
	td|d |r=|
r=| jr=| jjr=d| jjv r=|
d j  d}d|d v r=|d  dd\}$}%|%g|dd }d||
d _|
	t!t"ddt#|$| dg |
S )a  Parse a Google-style docstring.

    This function iterates on lines of a docstring to build sections.
    It then returns this list of sections.

    Parameters:
        docstring: The docstring to parse.
        ignore_init_summary: Whether to ignore the summary in `__init__` methods' docstrings.
        trim_doctest_flags: Whether to remove doctest flags from Python example blocks.
        returns_multiple_items: Whether to parse multiple items in `Yields` and `Returns` sections.
            When true, each item's continuation lines must be indented.
            When false (single item), no further indentation is required.
        returns_named_value: Whether to parse `Yields` and `Returns` section items as name and description, rather than type and description.
            When true, type must be wrapped in parentheses: `(int): Description.`. Names are optional: `name (int): Description.`.
            When false, parentheses are optional but the items cannot be named: `int: Description`.
        receives_multiple_items: Whether to parse multiple items in `Receives` sections.
            When true, each item's continuation lines must be indented.
            When false (single item), no further indentation is required.
        receives_named_value: Whether to parse `Receives` section items as name and description, rather than type and description.
            When true, type must be wrapped in parentheses: `(int): Description.`. Names are optional: `name (int): Description.`.
            When false, parentheses are optional but the items cannot be named: `int: Description`.
        returns_type_in_property_summary: Whether to parse the return type of properties
            at the beginning of their summary: `str: Summary of the property`.
        warn_unknown_params: Warn about documented parameters not appearing in the signature.
        **options: Additional parsing options.

    Returns:
        A list of docstring sections.
    Fr   r   N__init__rD   r   rE   r   TtitletyperB   section
admonitionzMissing blank line above zExtraneous blank line below z titlez; z	Possible z skipped, reasons: rV   r=   )r=   -)kindr   r   propertyr^   rC   )rg   rf   )$rF   rl   rd   is_functionis_classrG   lowerrI   rK   rJ   r8   r   	groupdict_section_kindrH   rW   r   r!   debuganyr   rX   _section_readerr   rZ   replacer   r   
IndexErroris_attributelabelsre   rh   r   r   r   )&r<   r   r   r   r   r   r   r   r[   r?   sectionscurrent_sectionr   rF   ignore_summaryr=   
line_lowerr   r   r   admonition_type
is_sectionhas_previous_lineblank_line_abovehas_next_linehas_next_linesblank_line_belowblank_lines_belowindented_line_belowindented_lines_belowreasonsr   reasons_stringreaderr   contentsrf   rP   rR   rR   rS   parse_google  s   *	

	





Pr   )r<   r&   r=   r>   r?   r#   r@   rA   )r<   r&   r=   r>   r?   r#   r@   rU   )
r<   r&   r=   r>   r[   r\   r?   r#   r@   r]   )r<   r&   r=   r>   r?   r#   r@   rv   )
r<   r&   r=   r>   r[   r\   r?   r#   r@   ry   )r<   r&   r=   r>   r?   r#   r@   r{   )r<   r&   r=   r>   r?   r#   r@   r   )r<   r&   r=   r>   r?   r#   r@   r   )r<   r&   r=   r>   r?   r#   r@   r   )r<   r&   r=   r>   r?   r#   r@   r   )r<   r&   r=   r>   r?   r#   r@   r   )
r<   r&   r=   r>   r   r\   r?   r#   r@   rA   )
r<   r&   rp   r>   rF   r   r   r\   r@   r   )
r<   r&   r   r   r   r\   r   r>   r@   r   )r<   r&   r=   r>   r   r\   r   r\   r?   r#   r@   r   )r<   r&   r=   r>   r   r\   r   r\   r?   r#   r@   r   )r<   r&   r=   r>   r   r\   r   r\   r?   r#   r@   r   )
r<   r&   r=   r>   r   r\   r?   r#   r@   r   )rP   r   r@   r\   )r<   r&   r   r\   r   r\   r   r\   r   r\   r   r\   r   r\   r   r\   r[   r\   r?   r#   r@   r   )`
__future__r   re
contextlibr   typingr   _griffe.docstrings.modelsr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _griffe.docstrings.utilsr   r   _griffe.enumerationsr    r!   r"   r#   r$   _griffe.expressionsr%   _griffe.modelsr&   r*   other_parametersr+   r-   r.   r/   r0   r1   r2   r4   r5   r6   r   tupler>   listr   
_BlockItem_BlockItemsrA   compile
IGNORECASEr8   __annotations__r9   r:   r;   rT   rZ   ru   rx   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   rH   r   object	_sentinelr   rR   rR   rR   rS   <module>   s   l	


?#
=

$
#
#

!000
;