https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/sphinx/pycode/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/sphinx/pycode/__pycache__/parser.cpython-310.pyc
o

�$�aR�@s�dZddlZddlZddlZddlZddlmZddlmZddlm	Z	m
Z
mZmZm
Z
mZmZddlmZmZddlmZmZmZmZmZddlmZdd	lmZmZe�d
�Ze�d�Ze�d�Zd
e de fdd�Z!dej"deej#fdd�Z$d&dej"dej%dee fdd�Z&de de fdd�Z'Gdd�d�Z(Gdd�d�Z)Gdd�de)�Z*Gd d!�d!ej+�Z,Gd"d#�d#e)�Z-Gd$d%�d%�Z.dS)'z�
    sphinx.pycode.parser
    ~~~~~~~~~~~~~~~~~~~~

    Utilities parsing and analyzing Python code.

    :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
�N)�OrderedDict)�	Signature)�DEDENT�INDENT�NAME�NEWLINE�NUMBER�OP�STRING)�COMMENT�NL)�Any�Dict�List�Optional�Tuple)�ast)�parse�unparsez^\s*#: ?(.*)
?
?$z^\s*$z^\s*(#.*)?$�code�returncCs|�dd�S)N�� )�replace)r�r�6/usr/lib/python3/dist-packages/sphinx/pycode/parser.py�filter_whitespacesr�nodecCst|tj�r	|jS|jgS)z3Get list of targets from Assign and AnnAssign node.)�
isinstancer�Assign�targets�target)rrrr�get_assign_targets sr"�selfc	Cs|r|j}|jj}|dvrtd|��|dkr*|dus |j|kr$|jgStd|��|dvrKg}|jD]}z
|�t||��Wq3tyHYq3w|S|dkro|jjjdkri|ri|jj|kridt|j	|�d	gStd|��|d
krv|gS|dkr�t|j|�St
d|��)
z�Convert assignment-AST to variable names.

    This raises `TypeError` if the assignment does not create new variable::

        ary[0] = 'foo'
        dic["bar"] = 'baz'
        # => TypeError
    )�Index�Num�Slice�Str�	Subscriptz%r does not create new variable�NameNz*The assignment %r is not instance variable)rr�	Attributez%sr�str�StarredzUnexpected node name %r)�arg�	__class__�__name__�	TypeError�id�elts�extend�get_lvar_names�value�attr�NotImplementedError)rr#�self_id�	node_name�members�eltrrrr4(s6	
�r4�scCs2ddd�}||_t�|�}|r|�d��d�SdS)z1Remove common leading indentation from docstring.rNcSsdS�Nrrrrr�dummyTszdedent_docstring.<locals>.dummyz
��rN)�__doc__�inspect�getdoc�lstrip�rstrip)r<r>�	docstringrrr�dedent_docstringRs

rGc@steZdZdZdededeeefdeeefdeddfd	d
�Zdede	fdd
�Z
dede	fdd�Zdefdd�ZdS)�Tokenz)Better token wrapper for tokenize module.�kindr5�start�end�sourcerNcCs"||_||_||_||_||_dSr=)rIr5rJrKrL)r#rIr5rJrKrLrrr�__init__cs

zToken.__init__�othercCsbt|t�r
|j|kSt|t�r|j|kSt|ttf�r%|j|jgt|�kS|dur+dStd|��)NFzUnknown value: %r)r�intrIr+r5�list�tuple�
ValueError)r#rNrrr�__eq__ks



zToken.__eq__�
conditionscst�fdd�|D��S)Nc3s�|]}�|kVqdSr=r)�.0�	candidate�r#rr�	<genexpr>xs�zToken.match.<locals>.<genexpr>)�any)r#rTrrWr�matchwszToken.matchcCsdtj|j|j��fS)Nz<Token kind=%r value=%r>)�tokenize�tok_namerIr5�striprWrrr�__repr__zs�zToken.__repr__)
r/�
__module__�__qualname__rArOr
rr+rM�boolrSrZr^rrrrrH`s"�
�rHc@sXeZdZdeeddfdd�Zdedefdd�Zdefd	d
�Z	de
deefdd
�ZdS)�TokenProcessor�buffersrNcs2t|��||_t��fdd��|_d|_d|_dS)Ncst��Sr=)�nextr��linesrr�<lambda>�sz)TokenProcessor.__init__.<locals>.<lambda>)�iterrcr[�generate_tokens�tokens�current�previous)r#rcrrerrM�s

zTokenProcessor.__init__�linenocC�|j|dS�zReturns specified line.��rc�r#rmrrr�get_line��zTokenProcessor.get_linecCs>z|j|_tt|j��|_W|jStyd|_Y|jSw)z_Fetch the next token from source code.

        Returns ``None`` if sequence finished.
        N)rkrlrHrdrj�
StopIterationrWrrr�fetch_token�s��zTokenProcessor.fetch_token�	conditioncCs�g}|��rJ|�|j�|j|kr	|S|jtdgkr%||�tdg�7}n!|jtdgkr6||�tdg�7}n|jtdgkrF||�tdg�7}|��s|S)zlFetch tokens until specified token appeared.

        .. note:: This also handles parenthesis well.
        �(�)�{�}�[�])rv�appendrkr	�fetch_until)r#rwrjrrrr�s
��zTokenProcessor.fetch_until)r/r_r`rr+rMrOrsrHrvr
rrrrrrbs

rbcsJeZdZdZdeeddf�fdd�Zdeefdd�Zdd	d
�Z	�Z
S)�AfterCommentParserz�Python source code parser to pick up comments after assignments.

    This parser takes code which starts with an assignment statement,
    and returns the comment for the variable if one exists.
    rfrNcst��|�d|_dSr=)�superrM�comment�r#rf�r.rrrM�s
zAfterCommentParser.__init__cCs�g}|��rg|�|j�|jtdgkr||�tdg�7}nF|jtdgkr.||�tdg�7}n5|jtdgkr?||�tdg�7}n$|jtkrL||�t�7}n|jtdgkrV	|S|jjttt	t
fvrc	|S|��s|S)z%Fetch right-hand value of assignment.rxryrzr{r|r}�;)rvr~rkr	rrrrIrrr
)r#rjrrr�fetch_rvalue�s&
��zAfterCommentParser.fetch_rvaluecCsh|���tdgtt�s|jsJ�|���tdgtt�r|jtdgkr&|��|jtkr2|jj|_dSdS)z3Parse the code and obtain comment after assignment.�=N)	rvrZr	rrrkr�r5r�rWrrrr�s
�
�zAfterCommentParser.parser@)r/r_r`rArr+rMrHr�r�
__classcell__rrr�rr��s
r�cs�eZdZdZdeededdf�fdd�Zdedeeefd	d
�Zdeddfdd�Z	deddfd
d�Z
dejddfdd�Z
dededdfdd�Zdedejddfdd�Zdeejdefdd�Zdeejdefdd�Zdeejfdd�Zdedefd d!�Zd"ejddf�fd#d$�Zd"ejddfd%d&�Zd"ejddfd'd(�Zd"ejddfd)d*�Zd"ej ddfd+d,�Z!d"ej"ddfd-d.�Z#d"ej$ddfd/d0�Z%d"ej&ddfd1d2�Z'd"ejddfd3d4�Z(d"ej)ddfd5d6�Z*�Z+S)7�VariableCommentPickerz7Python source code parser to pick up variable comments.rc�encodingrNcsnt��|_||_||_g|_g|_d|_t�|_	i|_
d|_i|_g|_
i|_d|_d|_d|_t���dSr=)�	itertools�count�counterrcr��context�current_classes�current_functionr�comments�annotationsrl�	deforders�finals�	overloads�typing�typing_final�typing_overloadr�rM)r#rcr�r�rrrM�s 
zVariableCommentPicker.__init__�namecCs>|jr|jr|jddkr|jdd�|gSdS|j|gS)z;Get qualified name for given object as a list of string(s).���rMN)r�r�r�)r#r�rrr�get_qualname_for�s
z&VariableCommentPicker.get_qualname_forcCs,|�|�}|rt|j�|jd�|�<dSdS�N�.)r�rdr�r��join�r#r��qualnamerrr�	add_entry�s
�zVariableCommentPicker.add_entrycCs(|�|�}|r|j�d�|��dSdSr�)r�r�r~r�r�rrr�add_final_entry�s
�z%VariableCommentPicker.add_final_entry�funccCsFddlm}|�|j�}|r!|j�d�|�g�}|�||��dSdS)Nr)�signature_from_astr�)�sphinx.util.inspectr�r�r�r��
setdefaultr�r~)r#r�r�r�r�rrr�add_overload_entrys�z(VariableCommentPicker.add_overload_entryr�cCs6|�|�}|rd�|dd��}||j||f<dSdS�Nr�r�)r�r�r�)r#r�r�r��basenamerrr�add_variable_comments

�z*VariableCommentPicker.add_variable_comment�
annotationcCs:|�|�}|rd�|dd��}t|�|j||f<dSdSr�)r�r�rr�)r#r�r�r�r�rrr�add_variable_annotations

�z-VariableCommentPicker.add_variable_annotation�
decoratorsc	C�dg}|jr
|�d|j�|jr|�|j�|D]}zt|�|vr%WdSWqty/YqwdS)Nz%s.finalTF)r�r~r�rr7)r#r��final�	decoratorrrr�is_final���zVariableCommentPicker.is_finalc	Cr�)Nz%s.overloadTF)r�r~r�rr7)r#r��overloadr�rrr�is_overload'r�z!VariableCommentPicker.is_overloadcCs"|jr|jjjr|jjjdSdS)z8Returns the name of the first argument if in a function.rN)r��argsrWrrr�get_self7szVariableCommentPicker.get_selfrmcCrnrorqrrrrrrs>rtzVariableCommentPicker.get_linercst��|�||_dS)z(Updates self.previous to the given node.N)r��visitrl�r#rr�rrr�Bs
zVariableCommentPicker.visitcCsn|jD]1}|�|jp|j�|jdkr|jp|j|_q|jdkr(|jp%|j|_q|jdkr4|jp2|j|_qdS)�8Handles Import node and record the order of definitions.r�ztyping.finalztyping.overloadN)�namesr��asnamer�r�r�r��r#rr�rrr�visit_ImportGs



��z"VariableCommentPicker.visit_ImportcCsh|jD].}|�|jp|j�|jdkr |jdkr |jp|j|_q|jdkr1|jdkr1|jp/|j|_qdS)r�r�r�r�N)r�r�r�r��moduler�r�r�rrr�visit_ImportFromSs
��z&VariableCommentPicker.visit_ImportFromcs�zt|�}t�fdd�|D�g�}��|j�}Wn
ty"YdSwt|d�r8|jr8|D]	}��||j�q-nt|d�rL|jrL|D]	}��||j�qBt	||j
d�g�j|jd��}|��|j
r�t�|j
�r�|D]}��|t�d|j
����|�qmdSt�|d|j
��r�g}t|jd�D]}��|jd|�}	t�|	�r�|�t�d|	��q�|r�td�t|���}
|D]
}��||
���|�q�dS|D]}��|�q�dS)	z3Handles Assign node and pick up a variable comment.csg|]
}t|���d��qS)rW)r4r�)rU�trWrr�
<listcomp>asz6VariableCommentPicker.visit_Assign.<locals>.<listcomp>Nr��type_commentz\1rp�
)r"�sumrsrmr0�hasattrr�r�r�r��
col_offsetrcrr��
comment_rerZr��subr��	indent_re�ranger~rGr��reversed)r#rr �varnames�current_line�varname�parser�
comment_lines�i�before_liner�rrWr�visit_Assign]sN���
�z"VariableCommentPicker.visit_AssigncC�|�|�dS)z6Handles AnnAssign node and pick up a variable comment.N)r�r�rrr�visit_AnnAssign�rtz%VariableCommentPicker.visit_AnnAssigncCs�t|jtjtjf�rUt|jtj�rWz9t|j�}t|d|�	��}|D]%}t|jj
t�r0|jj
}n
|jj
�|j
p8d�}|�|t|��|�|�q"WdStyTYdSwdSdS)z2Handles Expr node and pick up a comment if string.r�utf-8N)rrlrr�	AnnAssignr5r'r"r4r�r<r+�decoder�r�rGr�r0)r#rr r�r�rFrrr�
visit_Expr�s"�

���z VariableCommentPicker.visit_ExprcCs0|jD]}|�|�q|jD]}|�|�qdS)z�Handles Try node and processes body and else-clause.

        .. note:: pycode parser ignores objects definition in except-clause.
        N)�bodyr��orelse)r#r�subnoderrr�	visit_Try�s


�zVariableCommentPicker.visit_TrycCst|j�|j�|�|j�|�|j�r|�|j�|j�|j�||_|j	D]}|�
|�q&|j��|j��dS)z&Handles ClassDef node and set context.N)r�r~r�r�r��decorator_listr�r�rlr�r��pop�r#r�childrrr�visit_ClassDef�s

z$VariableCommentPicker.visit_ClassDefcCs�|jdurA|�|j�|�|j�r|�|j�|�|j�r"|�|�|j�	|j�||_|j
D]}|�|�q/|j��d|_dSdS)z)Handles FunctionDef node and set context.N)
r�r�r�r�r�r�r�r�r�r~r�r�r�r�rrr�visit_FunctionDef�s




�z'VariableCommentPicker.visit_FunctionDefcCr�)z.Handles AsyncFunctionDef node and set context.N)r�r�rrr�visit_AsyncFunctionDef�rtz,VariableCommentPicker.visit_AsyncFunctionDef),r/r_r`rArr+rMrr�r�r�r�FunctionDefr�r��ASTr��exprrar�r�r-r�rOrsr��Importr��
ImportFromr�rr�r�r��Exprr��Tryr��ClassDefr�r��AsyncFunctionDefr�r�rrr�rr��s.
0

r�csteZdZdZdeeddf�fdd�Zdedeeeefddfd	d
�Z	ddd�Z
d
eddfdd�Zddd�Z�Z
S)�DefinitionFinderzXPython source code parser to detect location of functions,
    classes and methods.
    rfrNcs(t��|�d|_g|_g|_i|_dSr=)r�rMr�r��indents�definitionsr�r�rrrM�s

zDefinitionFinder.__init__r��entrycCs6|jr|jdddkr|ddkrdS||j|<dS)zAdd a location of definition.r�r�defN)r�r�)r#r�r�rrr�add_definition�s$zDefinitionFinder.add_definitioncCs�	|��}|durdS|tkrnJ|tdgkr-|jdus$|j�tttt�r-|j	dur,||_	n-|�t
dg�r:|�d�n |�t
dg�rG|�d�n|tkrR|j�
d�n|tkrZ|��q)z1Parse the code to obtain location of definitions.TN�@�classr�)rNNN)rvrr	rlrZrrrrr�r�parse_definitionr�r~�finalize_block)r#�tokenrrrr�s*�
��zDefinitionFinder.parse�typcCs�|��}|j�|j�d�|j�}|jr|jjd}d|_n|jd}|�tdg�|���	t
t�rB|�t�|j
�|||f�dS|�||||jdf�|j��dS)zParse AST of definition.r�rN�:)rvr�r~r5r�r�rJrr	rZrrrr�r�rKr�)r#r�r��funcname�	start_posrrrr��s

z!DefinitionFinder.parse_definitioncCs||j��}|ddkr<|\}}}|jjdd}t�|�|��r,|d8}t�|�|��s |�||||f�|j��dSdS)zFinalize definition block.rrNrpN)	r�r�rkrK�emptyline_rerZrsr�r�)r#�
definitionr�r�r��end_posrrrr�s

��zDefinitionFinder.finalize_blockr@)r/r_r`rArr+rMrrOr�rr�r�r�rrr�rr��s 
r�c@sFeZdZdZddededdfdd�Zdd	d
�Zddd�Zdd
d�ZdS)�ParserzyPython source code parser to pick up variable comments.

    This is a better wrapper for ``VariableCommentPicker``.
    r�rr�rNcCs8t|�|_||_i|_i|_i|_i|_g|_i|_dSr=)	rrr�r�r�r�r�r�r�)r#rr�rrrrMs

zParser.__init__cCs|��|��dS)zParse the source code.N)�parse_commentsr�rWrrrr)szParser.parsecCsTt|j�}t|j�d�|j�}|�|�|j|_|j|_|j|_|j	|_	|j
|_
dS)z$Parse the code and pick up comments.TN)rrr��
splitlinesr�r�r�r�r�r�r�)r#�tree�pickerrrrr.s

zParser.parse_commentscCs$t|j�d��}|��|j|_dS)z0Parse the location of definitions from the code.TN)r�rrrr�)r#r�rrrr�9szParser.parse_definition)r�r@)	r/r_r`rAr+rMrrr�rrrrrs


rr=)/rArBr��rer[�collectionsrrr�rrrrrr	r
rrr�r
rrrr�sphinx.pycode.astrrr�compiler�r�r�r+rr�r�r"r-r4rGrHrbr��NodeVisitorr�r�rrrrr�<module>s4	$


 *--vK

https://t.me/RX1948 - 2025