
    O&iS                         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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)path)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	            c/home/geonatureadmin/si_en_reseau/tutos/venv/lib/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[=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                      | |||          S )N )clsr;   r   r<   s       r8   
for_stringzModuleAnalyzer.for_stringK   s     s67G,,,    r3   c                    d|f| j         v r| j         d|f         S 	 t          j        |          5 }|                                }d d d            n# 1 swxY w Y    | |||          }|| j         d|f<   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openreadr$   r   r,   for_eggr   )r?   r3   r   fr;   objr1   s          r8   for_filezModuleAnalyzer.for_fileP   sN   H**9VX-..		Ox(( "A" " " " " " " " " " " " " " "#fgx00C*-CIfh&'' 	O 	O 	O H,,47KK'4R4RRci 011!"4x"?EE3N 21111	O
 
s;   A6 AA6 AA6 AA6 6
C ACC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"   rD   )r-   r.   r   r,   r/   r   rG   decoder@   r$   r   )	r?   r3   r   SEPr6   relpatheggcodeexcs	            r8   rH   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   r9   r@   rK   )r?   r   entryr3   r4   rJ   r1   s          r8   
for_modulezModuleAnalyzer.for_modulek   s    g#)++Ih/0E%-- L	"44W==Hf!nnVWh6L*MM%ll8W55 	 	 	+.CIh'(	 (+	(G#$
s   AB 
BBBr4   Nc                 >    || _         || _        || _        d| _        d S )NF)r   r<   rQ   	_analyzed)selfr4   r   r<   s       r8   __init__zModuleAnalyzer.__init__   s$     	rA   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: )rY   r   rQ   parser   r   commentsitems
splitlinesr   r   r   definitionsr   	defordersr   r$   r   r<   )rZ   parserscopecommentrR   s        r8   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.)rg   r   rZ   s    r8   find_attr_docszModuleAnalyzer.find_attr_docs   s    ~rA   c                 8    |                                   | j        S )z?Find class, function and method definitions and their location.)rg   r   ri   s    r8   	find_tagszModuleAnalyzer.find_tags   s    yrA   )r:   )r   N)__name__
__module____qualname__r   r   str__annotations__r	   r   intr   r   staticmethodr
   r9   classmethodr@   rK   rH   rW   r[   rg   rj   rl   r>   rA   r8   r   r      s        eCHos*++++E#s(OT#Y.////ICi())))38n
sE#sC-((
)))) )+E4c3h$%***-3 -5#1M+N - - - \-^ - - -c -C -(- - - [-  c 6F    [ Ks KS K5E K K K [K  )9    [&s S 3 4    V V V V2U38_d3i%? @    
4U3S=%9 9:      rA   r   )__doc__r-   rE   collectionsr   	importlibr   inspectr   osr   typingr   r   r	   r
   r   zipfiler   sphinx.errorsr   sphinx.pycode.parserr   r   r>   rA   r8   <module>r~      s   2 2 				  # # # # # # # # # # # #             3 3 3 3 3 3 3 3 3 3 3 3 3 3       % % % % % % ' ' ' ' ' 'Y Y Y Y Y Y Y Y Y YrA   