o
    Nii                     @  sz   d Z 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
 ddlmZ ddlmZ e	r4dd	lmZ G d
d dZdS )z,Utilities parsing and analyzing Python code.    )annotationsN)import_module)path)TYPE_CHECKINGAny)PycodeError)Parser)	Signaturec                   @  s   e Zd ZU ded< ded< ded< ded< d	ed
< ded< i Zded< ed,ddZe	d-d.ddZed/ddZ	ed0dd Z
d1d#d$Zd2d%d&Zd3d'd(Zd4d)d*Zd+S )5ModuleAnalyzerzdict[tuple[str, str], str]r    dict[tuple[str, str], list[str]]	attr_docsz	list[str]finalszdict[str, list[Signature]]	overloadszdict[str, int]tagorderdict[str, tuple[str, int, int]]tagszdict[tuple[str, str], Any]cachemodnamestrreturntuple[str | None, str | None]c              
   C  sv  zt | }W n ty } ztd|  ||d}~ww t|dd}t|dd}|rGt|ddrGz|| }|r<||fW S W n	 tyF   Y nw |du ro|rot|ddroz|| }W n tyn } ztd|  ||d}~ww |du rytd|  tt	|}|
 d	r|dd
 }t|st|d r|d7 }n|
 dstd| t|std| |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: %rzsource file is not present: %r)r   	Exceptionr   getattrr   ImportErrorr   r   normpathabspathlowerendswithisfile)r   moderrloaderfilenamesource r*   J/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/pycode/__init__.pyget_module_source   sR   


z ModuleAnalyzer.get_module_source<string>clstype[ModuleAnalyzer]stringsrcnamec                 C  s   | |||S )Nr*   )r.   r0   r   r1   r*   r*   r+   
for_stringI   s   zModuleAnalyzer.for_stringr(   c              
   C  s   d|f| j v r| j d|f S z)t|}| }W d    n1 s#w   Y  | |||}|| j d|f< W |S  tyK } ztd| ||d }~ww )Nfilezerror opening %r)r   tokenizeopenreadr   r   )r.   r(   r   fr0   objr&   r*   r*   r+   for_fileR   s   
zModuleAnalyzer.for_filec              
   C  s   d|f| j v r| j d|f }t|tr||S z!| |\}}|d ur-| |||p*d}n
|d ur7| ||}W n tyL } z|| j d|f<  d }~ww || j d|f< |S )Nmoduler-   )r   
isinstancer   r,   r2   r9   )r.   r   entryr(   r)   r8   r&   r*   r*   r+   
for_modulea   s&   
zModuleAnalyzer.for_moduler)   Nonec                 C  s   || _ || _|| _d| _d S )NF)r   r1   code	_analyzed)selfr)   r   r1   r*   r*   r+   __init__u   s   
zModuleAnalyzer.__init__c              
   C  s   | j rdS zDt| j}|  i | _|j D ]\}}|r)g | d| j|< qdg| j|< q|j| _|j	| _	|j
| _
|j| _|j| _d| _ W dS  tyc } zd| jd|}t||d}~ww )zAnalyze the source code.N Tzparsing z	 failed: )r@   r   r?   parser   commentsitems
splitlinesr   r   r   definitionsr   	defordersr   r   r1   r   )rA   parserscopecommentexcmsgr*   r*   r+   analyze~   s*   

zModuleAnalyzer.analyzec                 C     |    | jS )z?Find class and module-level attributes and their documentation.)rO   r   rA   r*   r*   r+   find_attr_docs      zModuleAnalyzer.find_attr_docsc                 C  rP   )z?Find class, function and method definitions and their location.)rO   r   rQ   r*   r*   r+   	find_tags   rS   zModuleAnalyzer.find_tagsN)r   r   r   r   )r-   )
r.   r/   r0   r   r   r   r1   r   r   r
   )r.   r/   r(   r   r   r   r   r
   )r.   r/   r   r   r   r
   )r)   r   r   r   r1   r   r   r>   )r   r>   )r   r   )r   r   )__name__
__module____qualname____annotations__r   staticmethodr,   classmethodr2   r9   r=   rB   rO   rR   rT   r*   r*   r*   r+   r
      s*   
 ,

	
r
   )__doc__
__future__r   r4   	importlibr   osr   typingr   r   sphinx.errorsr   sphinx.pycode.parserr   inspectr	   r
   r*   r*   r*   r+   <module>   s    