
    }c`                         d Z ddlZddlZddlmZ ddlmZ ddlm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 dd	lmZ dd
lmZ ddlmZ  G d d          ZdS )z,Utilities parsing and analyzing Python code.    N)OrderedDict)import_module)	SignatureStringIO)path)IOAnyDictListOptionalTuple)ZipFile)PycodeError)Parserc            
          e Zd ZU eeeef         ef         ed<   eeeef         ee         f         ed<   ee         ed<   eeee         f         ed<   eee	f         ed<   eeeee	e	f         f         ed<   i Z
eeeef         ef         ed<   eded	eee         ee         f         fd
            Zeddededed	d fd            Zededed	d fd            Zededed	d fd            Zeded	d fd            Zdededed	dfdZddZd	eeeef         ee         f         fdZd	eeeee	e	f         f         fdZdS )ModuleAnalyzerannotations	attr_docsfinals	overloadstagordertagscachemodnamereturnc                    	 t          |           }n&# t          $ r}t          d| z  |          |d}~ww xY wt          |dd          }t          |dd          }|r>t          |dd          r-	 |                    |           }|r||fS n# t
          $ r Y nw xY w|P|rNt          |dd          r=	 |                    |           }n&# t
          $ r}t          d| z  |          |d}~ww xY w|t          d| z            t          j        t          j	        |                    }|
                                                    d	          r;|dd
         }t          j        |          st          j        |dz             r|dz  }n|
                                                    d          st          d|z            dt          j        z   |v rRdt          j        t          j                  z   }t          j        ||d          \  }}t          j        |          r|dfS t          j        |          st          d|z            |dfS )zTry to find the source code for a module.

        Returns ('filename', 'source'). One of it can be None if
        no filename or source found
        zerror importing %rN
__loader____file__
get_sourceget_filenamezerror getting filename for %rzno source found for module %r)z.pyoz.pycw)z.pyz.pywzsource is not a .py file: %r.egg
(?<=\.egg)   zsource file is not present: %r)r   	Exceptionr   getattrr    ImportErrorr!   r   normpathabspathlowerendswithisfilesepreescapesplit)	r   moderrloaderfilenamesourcepateggpath_s	            6lib/python3.11/site-packages/sphinx/pycode/__init__.pyget_module_sourcez ModuleAnalyzer.get_module_source   s   	L((CC 	L 	L 	L2W<cBBK	LlD113
D11 	gflD99 	**733 ,#V++,     	[ 	[76>4+P+P 	[[!..w77 [ [ [!"AG"KSQQWZZ[ 	I=GHHH=h!7!788>>$$%566 
	&}H;x((  T[C-H-H  C!!**?;; 	&<xGHHHtxH, 	&")DH"5"55C#x33JGQ{7## &~%{8$$ 	K>IJJJ~s:    
505.B
 

BB0C 
C)C$$C)<string>stringsrcnamec                 6     | t          |          ||          S )Nr   )clsr>   r   r?   s       r;   
for_stringzModuleAnalyzer.for_stringL   s      s8F##Wg666    r6   c                    d|f| j         v r| j         d|f         S 	 t          j        |          5 } | |||          }|| j         d|f<   d d d            n# 1 swxY w Y   n_# t          $ rR}dt          j        z   |v r#|                     ||          x}| j         d|f<   nt          d|z  |          |Y d }~nd }~ww xY w|S )Nfiler$   error opening %r)r   tokenizeopenr'   r   r/   for_eggr   )rA   r6   r   fobjr4   s         r;   for_filezModuleAnalyzer.for_fileQ   sF   H* 	/9VX-..	Ox(( 2Ac!Wh//.1	&(*+2 2 2 2 2 2 2 2 2 2 2 2 2 2 2  	O 	O 	O H, O47KK'4R4RRci 011!"4x"?EE3N 21111	O
 
s;   A" A
A" AA" AA" "
B>,AB99B>c                    t          j        t          j                  }t          j        d|z   |          \  }}	 t          |          5 }|                    |                                          }|                     |||          cd d d            S # 1 swxY w Y   d S # t          $ r}t          d|z  |          |d }~ww xY w)Nr%   rF   )r0   r1   r   r/   r2   r   readdecoderB   r'   r   )	rA   r6   r   SEPr9   relpatheggcodeexcs	            r;   rI   zModuleAnalyzer.for_egg`   s   i!!8MC$7BB	K!! ?Sxx((//11~~dGX>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?  	K 	K 	K08;SAAsJ	Ks;   B" 
>BB" BB" BB" "
C,C  Cc                 ^   d|f| j         v r(| j         d|f         }t          |t                    r||S 	 |                     |          \  }}||                     |||pd          }n||                     ||          }n# t          $ r}|| j         d|f<    d }~ww xY w|| j         d|f<   |S )Nmoduler=   )r   
isinstancer   r<   rB   rL   )rA   r   entryr6   r7   rK   r4   s          r;   
for_modulezModuleAnalyzer.for_modulek   s    g#)+ 	Ih/0E%-- L	"44W==Hf 6nnVWh6L*MM 6ll8W55 	 	 	+.CIh'(	 (+	(G#$
s   AB 
BBBr7   Nc                 b    || _         || _        |                                | _        d| _        d S )NF)r   r?   rN   rS   	_analyzed)selfr7   r   r?   s       r;   __init__zModuleAnalyzer.__init__   s,     KKMM	rC   c                 
   | j         rdS 	 t          | j                  }|                                 t	                      | _        |j                                        D ]3\  }}|r!|                                dgz   | j        |<   (dg| j        |<   4|j	        | _	        |j
        | _
        |j        | _        |j        | _        |j        | _        d| _         dS # t           $ r }t#          d| j        d|          |d}~ww xY w)zAnalyze the source code.N Tzparsing z	 failed: )r[   r   rS   parser   r   commentsitems
splitlinesr   r   r   definitionsr   	defordersr   r'   r   r?   )r\   parserscopecommentrT   s        r;   analyzezModuleAnalyzer.analyze   s   > 	4	VDI&&FLLNNN(]]DN$*O$9$9$;$; 1 1  1,3,>,>,@,@B4,GDN5))-/DDN5))%1D -DK#-DN*DI",DM!DNNN 	V 	V 	V+ssKLLRUU	Vs   CC 
D"C==Dc                 8    |                                   | j        S )z?Find class and module-level attributes and their documentation.)ri   r   r\   s    r;   find_attr_docszModuleAnalyzer.find_attr_docs   s    ~rC   c                 8    |                                   | j        S )z?Find class, function and method definitions and their location.)ri   r   rk   s    r;   	find_tagszModuleAnalyzer.find_tags   s    yrC   )r=   )r   N)__name__
__module____qualname__r   r   str__annotations__r   r   intr   r
   staticmethodr   r<   classmethodrB   rL   rI   rY   r	   r]   ri   rl   rn    rC   r;   r   r      s        eCHos*++++E#s(OT#Y.////ICi())))38n
sE#sC-((
)))) )+E4c3h$%***-3 -5#1M+N - - - \-^ 7 7 7c 7C 7(7 7 7 [7  c 6F    [ Ks KS K5E K K K [K  )9    [&r C # $    V V V V2U38_d3i%? @    
4U3S=%9 9:      rC   r   )__doc__r0   rG   collectionsr   	importlibr   inspectr   ior   osr   typingr	   r
   r   r   r   r   zipfiler   sphinx.errorsr   sphinx.pycode.parserr   r   rw   rC   r;   <module>r      s   2 2 				  # # # # # # # # # # # #                   7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7       % % % % % % ' ' ' ' ' 'X X X X X X X X X XrC   