
    O&iG              
       
   d dl Z d dl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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 d dlmZ d dlmZmZ d dlm Z  d dl!m"Z" erd dl#m$Z$  ej%        e&          Z' G d de           Z(	 d$dee)         de	e*         de	e
e)e*f                  dee)         fdZ+de dede)dej,        fdZ- G d de           Z. G d d          Z/ G d d e           Z0d!d"dee)ef         fd#Z1dS )%    N)unified_diff)TYPE_CHECKINGAnyDictListOptionalTuple)nodes)ElementNode)
directives)
StringList)addnodes)Config)optional_int)__)loggingparselinenos)SphinxDirective)
OptionSpec)Sphinxc                   d    e Zd ZU dZdZdZdZdZej	        ej
        dZeed<   dee         fdZd	S )
	Highlightzt
    Directive to set the highlighting language for code blocks, as well
    as the threshold for line numbers.
    F   r   )forcelinenothresholdoption_specreturnc                     | j         d                                         }| j                            dt          j                  }d| j        v }|| j        j        d<   t          j	        |||          gS )Nr   r   r   highlight_language)langr   r   )
	argumentsstripoptionsgetsysmaxsizeenv	temp_datar   highlightlang)selflanguager   r   s       c/home/geonatureadmin/si_en_reseau/tutos/venv/lib/python3.11/site-packages/sphinx/directives/code.pyrunzHighlight.run(   s|    >!$**,,,**+<ckJJ4<'3;/0&H-27FH H H I 	I    N)__name__
__module____qualname____doc__has_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacer   flagpositive_intr   r   __annotations__r   r   r.    r/   r-   r   r      s          
 K %%2 K   
IT$Z I I I I I Ir/   r   linesdedentlocationr   c                    :t          j        d                    |                                         d          S t	          fd| D                       r)t
                              t          d          |           g }| D ]:}|d          }|                    d          r|sd}|	                    |           ;|S )N Tc              3   P   K   | ] }|d                                           V  !d S N)r#   ).0sr=   s     r-   	<genexpr>zdedent_lines.<locals>.<genexpr>9   s7      
-
-!1WfW:
-
-
-
-
-
-r/   z!non-whitespace stripped by dedentr>   
)
textwrapr=   join
splitlinesanyloggerwarningr   endswithappend)r<   r=   r>   	new_lineslinenew_lines    `    r-   dedent_linesrS   3   s     ~rwwu~~..99$???

-
-
-
-u
-
-
--- Sr=>>RRRI # #=== 	x 	H""""r/   	directiveliteral_nodecaptionc                 T   t          j        dddg          }t          j                    }| j                            t          |gd          | j        |           t          |d         t           j                  r9t          d|d         
                                z            }t          |          t          |d         t           j                  rMt          j        |d         j        dg|d         j        R  }|j        |_        |j        |_        ||z  }||z  }|S t"          )Nr@   Tzliteral-block-wrapper)literal_blockclassessourcer   zInvalid caption: %s)r
   	containerr   statenested_parser   content_offset
isinstancesystem_messager   astext
ValueErrorrV   	rawsourcechildrenr[   rQ   RuntimeError)rT   rU   rV   container_nodeparsedmsgcaption_nodes          r-   container_wrapperrk   F   s,   _Rt.E-FH H HN]__FO  WIb!A!A!A!*!96C C C&)U122 &)9)9););;<<oo	F1Iu}	-	- 	}VAY%8" :&,Qi&8: : :*1(-,&,&r/   c            	           e Zd ZU dZdZdZdZdZej	        ej	        e
eej        ej        ej        ej        dZeed<   dee         fd	Zd
S )	CodeBlockz^
    Directive for a code block with special highlighting or line numbering
    settings.
    Tr   r   F)r   linenosr=   lineno-startemphasize-linesrV   classnamer   r   c                    | j         j        }d                    | j                  }| j                            | j                  }| j                            d          }|r	 t          | j                  t          |          }t          fd|D                       r9t                              t          d          | j        d         fz  |           fd|D             }n;# t          $ r,}|j                            || j                  gcY d }~S d }~ww xY wd }d| j        v rf| j                            | j                  }|                    d	          }t%          || j        d         |          }d
                    |          }t'          j        ||          }d| j        v s	d| j        v rd	|d<   |dxx         | j                            dg           z  cc<   d| j        v |d<   | j        r| j        d         |d<   n-| j        j                            d| j        j                  |d<   i x}	|d<   |||	d<   d| j        v r| j        d         |	d<   |                     |           | j                            d          }
|
rL	 t7          | ||
          }n9# t          $ r,}|j                            || j                  gcY d }~S d }~ww xY w|                     |           |gS )NrG   rp   c              3   $   K   | ]
}|k    V  d S rB   r;   )rC   inliness     r-   rE   z CodeBlock.run.<locals>.<genexpr>z   s'      55qqF{555555r/   *line number spec is out of range(1-%d): %rrF   c                 &    g | ]}|k     |d z   S r   r;   )rC   xrv   s     r-   
<listcomp>z!CodeBlock.run.<locals>.<listcomp>   s"    BBBaq6zzAEzzzr/   rQ   r=   Tr@   rn   ro   rY   rq   r   r   r,   r    highlight_argshl_lineslinenostartrV   )r]   documentrI   contentstate_machineget_source_and_linelinenor$   r%   lenr   rK   rL   rM   r   rc   reporterrJ   rS   r
   rX   r"   r(   r)   configr    set_source_infork   add_name)r+   r   coder>   linespecr~   errr<   literal
extra_argsrV   excrv   s               @r-   r.   zCodeBlock.runp   so   :&yy&&%99$+FF<##$566 	
JT\**'&995555H55555 6NN2&R#S#S$*DL9J,K#L$M,4 # 6 6 6 CBBB8BBB J J J )11#DK1HHIIIIIIIJ Ht|##)==dkJJHOOD))E X(>RRRE775>>D .tT::$$$,(F(F!%GI	dl..w;;;"dl2> 	Y"&."3GJ
 #'("4"8"89M9=9W#Y #YGJ133
W-.%-Jz"T\))(,^(DJ}%W%%%,""9-- 	JJ+D'7CC J J J )11#DK1HHIIIIIIIJ
 	gys=   $BC+ +
D!5!DD!D!J& &
K0!KKKN)r0   r1   r2   r3   r4   r5   r6   r7   r   r8   r   intunchanged_requiredclass_option	unchangedr   r   r:   r   r   r.   r;   r/   r-   rm   rm   [   s          
 K %?%80($	 	K 	 	 	;T$Z ; ; ; ; ; ;r/   rm   c                      e Zd Zg dZdedeeef         deddfdZddZ		 dded	e
eeef                  dee         fd
Zdd	e
eeef                  deeef         fdZdd	e
eeef                  dee         fdZ	 ddee         d	e
eeef                  dee         fdZ	 ddee         d	e
eeef                  dee         fdZ	 ddee         d	e
eeef                  dee         fdZ	 ddee         d	e
eeef                  dee         fdZ	 ddee         d	e
eeef                  dee         fdZ	 ddee         d	e
eeef                  dee         fdZ	 ddee         d	e
eeef                  dee         fdZdS )LiteralIncludeReader))lineno-matchro   )r   rO   )r   prepend)start-afterstart-at)
end-beforeend-at)diffpyobject)r   ro   )r   r   )r   r<   )r   r   )r   r   )r   r   )r   r   filenamer$   r   r   Nc                     || _         || _        |                    d|j                  | _        | j                            dd          | _        |                                  d S )Nencodingro   r   )r   r$   r%   source_encodingr   lineno_startparse_options)r+   r   r$   r   s       r-   __init__zLiteralIncludeReader.__init__   sZ     J0FGG L,,^Q??r/   c                     | j         D ]8\  }}|| j        v r*|| j        v r!t          t          d          ||fz            9d S )Nz%Cannot use both "%s" and "%s" options)INVALID_OPTIONS_PAIRr$   rc   r   )r+   option1option2s      r-   r   z"LiteralIncludeReader.parse_options   sg     $ 9 	5 	5GW$,&&7dl+B+B $K!L!L")7!3"4 5 5 5	5 	5r/   r>   c                    	 t          || j        d          5 }|                                }d| j        v r |                    | j        d                   }|                    d          cd d d            S # 1 swxY w Y   d S # t          $ r%}t          t          d          |z            |d }~wt          $ r,}t          t          d          | j        |fz            |d }~ww xY w)Nstrict)r   errors	tab-widthTz.Include file %r not found or reading it failedz`Encoding %r used for reading included file %r seems to be wrong, try giving an :encoding: option)	openr   readr$   
expandtabsrJ   OSErrorr   UnicodeError)r+   r   r>   ftextr   s         r-   	read_filezLiteralIncludeReader.read_file   s]   	ChxHHH -Avvxx$,..??4<+DEEDt,,- - - - - - - - - - - - - - - - - -  	- 	- 	-"MNN"# $ $),- 	C 	C 	Cr #N  O  O $x8 9 : :?BC	CsG   B AA8+B 8A<<B ?A< B 
C( B//C(<'C##C(c                 :   d| j         v r|                                 }nZ| j        | j        | j        | j        | j        | j        | j        g}| 	                    | j
        |          }|D ]} |||          }d                    |          t          |          fS )Nr   rF   r@   )r$   	show_diffpyobject_filterstart_filter
end_filterlines_filterdedent_filterprepend_filterappend_filterr   r   rI   r   )r+   r>   r<   filtersfuncs        r-   r   zLiteralIncludeReader.read   s    T\!!NN$$EE+(()*)+G NN4=8NDDE 7 7UX666wwu~~s5zz))r/   c                     |                      | j                  }| j        d         }|                      |          }t          |||| j                  }t	          |          S )Nr   )r   r   r$   r   list)r+   r>   rP   old_filename	old_linesr   s         r-   r   zLiteralIncludeReader.show_diff   sS    NN4=11	|F+NN<00	Iy,NNDzzr/   r<   c                 n   | j                             d          }|rddlm} |                    | j        d          }|                                }||vr&t          t          d          || j        fz            ||         d         }||         d         }||dz
  |         }d| j         v r|| _	        |S )	Nr   r   )ModuleAnalyzerr@   z,Object named %r not found in include file %rr      r   )
r$   r%   sphinx.pycoder   for_filer   	find_tagsrc   r   r   )	r+   r<   r>   r   r   analyzertagsstartends	            r-   r   z$LiteralIncludeReader.pyobject_filter   s     <##J// 	.444444%..t}bAAH%%''Dt## $R!S!S"*DM!:"; < < < Xq)8nQ'eaim,!T\11(-D%r/   c                 v   | j                             d          }|rt          |t                              }t	          fd|D                       r;t
                              t          d          t                    |fz  |           d| j         v rc|d         t          fdt          |          D                       r| xj
        |d         z  c_
        nt          t          d                    fd	|D             g k    r&t          t          d
          || j        fz            S )Nr<   c              3   >   K   | ]}|t                    k    V  d S rB   r   rC   ru   r<   s     r-   rE   z4LiteralIncludeReader.lines_filter.<locals>.<genexpr>  s-      55q1E

?555555r/   rw   rF   r   r   c              3   0   K   | ]\  }}|z   |k    V  d S rB   r;   )rC   ru   nfirsts      r-   rE   z4LiteralIncludeReader.lines_filter.<locals>.<genexpr>  s/      FF$!QuqyA~FFFFFFr/   z8Cannot use "lineno-match" with a disjoint set of "lines"c                 F    g | ]}|t                    k     |         S r;   r   )rC   r   r<   s     r-   r{   z5LiteralIncludeReader.lines_filter.<locals>.<listcomp>  s(    BBB!1s5zz>>U1X>>>r/   z2Line spec %r: no lines pulled from include file %r)r$   r%   r   r   rK   rL   rM   r   all	enumerater   rc   r   )r+   r<   r>   r   linelistr   s    `   @r-   r   z!LiteralIncludeReader.lines_filter  sx    <##G,, 	<#Hc%jj99H5555H55555 Jr"NOO #E

H5 6@H  J J J -- FFFF)H2E2EFFFFF ;%%!4%%%$R )9 &: &: ; ; ; CBBBxBBBE{{ $X!Y!Y"*DM!:"; < < < r/   c                    d| j         v r| j                             d          }d}n(d| j         v r| j                             d          }d}nd }|rt          |          D ][\  }}||v rR|r+d| j         v r| xj        |dz   z  c_        ||dz   d          c S d| j         v r| xj        |z  c_        ||d          c S \|du rt	          d|z            t	          d|z            |S )	Nr   Fr   Tr   r   z!start-after pattern not found: %szstart-at pattern not found: %s)r$   r%   r   r   rc   )r+   r<   r>   r   	inclusiver   rQ   s          r-   r   z!LiteralIncludeReader.start_filter%  sB    %%L$$Z00EIIdl**L$$]33EIIE 	K )% 0 0 . .D==  	.)T\99 --!;--$VaZ[[1111)T\99 --7--$VWW~--- ! D   !Du!LMMM !AE!IJJJr/   c                 p   d| j         v r| j                             d          }d}n(d| j         v r| j                             d          }d}nd }|ret          |          D ]-\  }}||v r$|r|d |dz            c S |dk    r!|d |         c S .|du rt          d|z            t          d|z            |S )	Nr   Tr   Fr   r   zend-at pattern not found: %sz end-before pattern not found: %s)r$   r%   r   rc   )r+   r<   r>   r   r   r   rQ   s          r-   r   zLiteralIncludeReader.end_filterF  s    t|##,""8,,CIIT\)),""<00CIIC 	K )% 0 0 2 2$;;  2$[fqj[1111!Q;; #(&>111  D   !?#!EFFF !Cc!IJJJr/   c                 p    | j                             d          }|r|                    d|dz              |S )Nr   r   rG   )r$   r%   insert)r+   r<   r>   r   s       r-   r   z#LiteralIncludeReader.prepend_filterc  s>     ,""9-- 	,LLGdN+++r/   c                 n    | j                             d          }|r|                    |dz              |S )NrO   rG   )r$   r%   rO   )r+   r<   r>   rO   s       r-   r   z"LiteralIncludeReader.append_filterl  s<     !!(++ 	(LL$'''r/   c                 l    d| j         v r*t          || j                             d          |          S |S )Nr=   rF   )r$   rS   r%   )r+   r<   r>   s      r-   r   z"LiteralIncludeReader.dedent_filteru  s;     t|##t|'7'7'A'AHUUUULr/   )r   NrB   )r0   r1   r2   r   strr   r   r   r   r   r   r	   r   r   r   r   r   r   r   r   r   r   r   r   r;   r/   r-   r   r      sT           tCH~ v RV    5 5 5 5 DHC CC'/c3h'@C	cC C C C$* *XeCHo6 *%S/ * * * *" (5c?"; tCy     GK #Y*25c?*C	c   * GK #Y*25c?*C	c   6 GK #Y*25c?*C	c   D GK #Y*25c?*C	c   < GK #Y*25c?*C	c    GK #Y*25c?*C	c    GK #Y*25c?*C	c     r/   r   c                   r   e Zd ZU dZdZdZdZdZi dede	j
        ded	e	j
        d
e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	j        de	j        e	j        e	j        e	j        e	j        dZeed<   dee         fdZdS )LiteralIncludez
    Like ``.. include:: :literal:``, but only warns if the include file is
    not found, and does not raise errors.  Also has several options for
    selecting what to include.
    Fr   r   Tr=   rn   ro   r   r   r,   r   r   r   r<   r   r   r   r   r   rO   rp   )rV   rq   rr   r   r   r   c                    | j         j        }|j        j        s"|j                            d| j                  gS d| j        v r2| j        	                    | j        d                   \  }}|| j        d<   	 | j
                            | j                  }| j        	                    | j        d                   \  }}| j                            |           t          || j        | j                  }|                    |          \  }t#          j        |||          }	d| j        v |	d<   |                     |	           | j                            d          rd|	d	<   nd	| j        v r| j        d	         |	d	<   d
| j        v sd| j        v s	d| j        v rd|	d
<   |	dxx         | j                            dg           z  cc<   i x}
|	d<   d| j        v rt+          | j        d                   }t-          fd|D                       r9t.                              t1          d          | j        d         fz  |           fd|D             |
d<   |j        |
d<   d| j        v r+| j        d         p| j        d         }t5          | |	|          }	|                     |	           |	gS # t8          $ r,}|j                            || j                  gcY d }~S d }~ww xY w)NzFile insertion disabledr|   r   r   rF   rZ   r   udiffr,   rn   ro   r   TrY   rq   r}   rp   c              3   $   K   | ]
}|k    V  d S rB   r;   r   s     r-   rE   z%LiteralInclude.run.<locals>.<genexpr>  s'      44aqEz444444r/   rw   c                 &    g | ]}|k     |d z   S ry   r;   )rC   rz   r<   s     r-   r{   z&LiteralInclude.run.<locals>.<listcomp>  s"    )O)O)OAQYY!a%YYYr/   r~   r   rV   )r]   r   settingsfile_insertion_enabledr   rM   r   r$   r(   
relfn2pathr   r   r"   note_dependencyr   r   r   r
   rX   r   r%   r   rK   rL   r   r   rk   r   	Exception)r+   r   _pathr>   rel_filenamer   readerr   retnoder   r~   rV   r   r<   s                 @r-   r.   zLiteralInclude.run  sQ   :& 7 	A%--.G37; . @ @ A A T\!!h))$,v*>??GAt#'DL '	F)==dkJJH%)X%8%89J%K%K"L(H$$\222)(DL$+NNF ++x+88KD%$24hOOOG&$,6GG  )))|'' ?&-
##t|++&*l:&>
#T\))^t|-K-K"dl22%)	"I$,"2"27B"?"??577J!12 DL00'5F(GOO4444844444 6NN2&R#S#S$)4<8I+J#K$L,4 # 6 6 6 *P)O)O)O)O)O)O
:&(.(;J}%DL((,y1FT^A5F+D'7CC MM'"""9 	F 	F 	F%--c-DDEEEEEEE	Fs   8H4J- -
K#7!KK#K#N)r0   r1   r2   r3   r4   r5   r6   r7   r   r   r8   r   r   r   r   r   r   r   r:   r   r   r.   r;   r/   r-   r   r   ~  s          K $,:? 	 	
	
 	S 	J1 	 	J' 	J1 	. 	z4 	j3 	J1 	*/ 	:0  	*/!" 	:8#$ '($-+  K   01FT$Z 1F 1F 1F 1F 1F 1Fr/   r   appr   c                     t          j        dt                     t          j        dt                     t          j        dt                     t          j        dt                     ddddS )N	highlightz
code-block
sourcecodeliteralincludebuiltinT)versionparallel_read_safeparallel_write_safe)r   register_directiver   rm   r   )r   s    r-   setupr     si    !+y999!,	:::!,	:::!"2NCCC "#  r/   rB   )2r&   rH   difflibr   typingr   r   r   r   r   r	   docutilsr
   docutils.nodesr   r   docutils.parsers.rstr   docutils.statemachiner   sphinxr   sphinx.configr   sphinx.directivesr   sphinx.localer   sphinx.utilr   r   sphinx.util.docutilsr   sphinx.util.typingr   sphinx.applicationr   	getLoggerr0   rL   r   r   r   rS   r\   rk   rm   r   r   r   r;   r/   r-   <module>r     s   



              B B B B B B B B B B B B B B B B       ( ( ( ( ( ( ( ( + + + + + + , , , , , ,                   * * * * * *       - - - - - - - - 0 0 0 0 0 0 ) ) ) ) ) ) *))))))		8	$	$I I I I I I I I6 TX 9&sm7?c3h7P	#Y   &  s W\Wf    *P P P P P P P PfM M M M M M M M`TF TF TF TF TF_ TF TF TFn
x 
DcN 
 
 
 
 
 
r/   