
    }cG              
          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	 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)d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          Z/d!d"dee(ef         fd#Z0dS )%    N)unified_diff)TYPE_CHECKINGAnyDictList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       6lib/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>7   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_linesrR   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
ValueErrorrU   	rawsourcechildrenrZ   rP   RuntimeError)rS   rT   rU   container_nodeparsedmsgcaption_nodes          r,   container_wrapperrj   D   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-linesrU   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 )NrF   ro   c              3   $   K   | ]
}|k    V  d S rA   r:   )rB   inliness     r,   rD   z CodeBlock.run.<locals>.<genexpr>x   s'      55qqF{555555r.   *line number spec is out of range(1-%d): %rrE   c                 &    g | ]}|k     |d z   S r   r:   )rB   xru   s     r,   
<listcomp>z!CodeBlock.run.<locals>.<listcomp>}   s&    BBBaq6zBAEBBBr.   rP   r<   Tr?   rm   rn   rX   rp   r   r   r+   r   highlight_argshl_lineslinenostartrU   )r\   documentrH   contentstate_machineget_source_and_linelinenor#   r$   lenr   rJ   rK   rL   r   rb   reporterrI   rR   r	   rW   r!   r'   r(   configr   set_source_inforj   add_name)r*   r   coder=   linespecr}   errr;   literal
extra_argsrU   excru   s               @r,   r-   zCodeBlock.runn   sz   :&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 	&!%GI	dl..w;;;"dl2> 	Y"&."3GJ
 #'("4"8"89M9=9W#Y #YGJ133
W-. 	.%-Jz"T\) 	E(,^(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)r/   r0   r1   r2   r3   r4   r5   r6   r   r7   r   intunchanged_requiredclass_option	unchangedr   r   r9   r   r   r-   r:   r.   r,   rl   rl   Y   s          
 K %?%80($	 	K 	 	 	;T$Z ; ; ; ; ; ;r.   rl   c                   z   e Zd Zg dZdedededdfdZddZdded	e	ee
f         dee         fd
Zdd	e	ee
f         de	ee
f         fdZdd	e	ee
f         dee         fdZddee         d	e	ee
f         dee         fdZddee         d	e	ee
f         dee         fdZddee         d	e	ee
f         dee         fdZddee         d	e	ee
f         dee         fdZddee         d	e	ee
f         dee         fdZddee         d	e	ee
f         dee         fdZddee         d	e	ee
f         dee         fdZdS )LiteralIncludeReader))lineno-matchrn   )r   rN   )r   prepend)start-afterstart-at)
end-beforeend-at)diffpyobject)r   rn   )r   r   )r   r;   )r   r   )r   r   )r   r   )r   r   filenamer#   r   r   Nc                     || _         || _        |                    d|j                  | _        | j                            dd          | _        |                                  d S )Nencodingrn   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#   rb   r   )r*   option1option2s      r,   r   z"LiteralIncludeReader.parse_options   sk     $ 9 	5 	5GW$,& 57dl+B 5 $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#   
expandtabsrI   OSErrorr   UnicodeError)r*   r   r=   ftextr   s         r,   	read_filezLiteralIncludeReader.read_file   s`   	ChxHHH -Avvxx$,. F??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   rE   r?   )r#   	show_diffpyobject_filterstart_filter
end_filterlines_filterdedent_filterprepend_filterappend_filterr   r   rH   r   )r*   r=   r;   filtersfuncs        r,   r   zLiteralIncludeReader.read   s    T\! 	7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$   r   list)r*   r=   rO   old_filename	old_linesr   s         r,   r   zLiteralIncludeReader.show_diff   s\    NN4=11	|''//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_tagsrb   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 .(-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 rA   r   rB   rt   r;   s     r,   rD   z4LiteralIncludeReader.lines_filter.<locals>.<genexpr>	  s-      55q1E

?555555r.   rv   rE   r   r   c              3   0   K   | ]\  }}|z   |k    V  d S rA   r:   )rB   rt   nfirsts      r,   rD   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   )rB   r   r;   s     r,   rz   z5LiteralIncludeReader.lines_filter.<locals>.<listcomp>  s,    BBB!1s5zz>BU1XBBBr.   z2Line spec %r: no lines pulled from include file %r)r#   r$   r   r   rJ   rK   rL   r   all	enumerater   rb   r   )r*   r;   r=   r   linelistr   s    `   @r,   r   z!LiteralIncludeReader.lines_filter  s{   <##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   rb   )r*   r;   r=   r   	inclusiver   rP   s          r,   r   z!LiteralIncludeReader.start_filter  sN   % 	L$$Z00EIIdl* 	L$$]33EIIE 	K )% 0 0 . .D= 
.  	.)T\9 < --!;--$VaZ[[1111)T\9 8 --7--$VWW~---
. D  K !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   rb   )r*   r;   r=   r   r   r   rP   s          r,   r   zLiteralIncludeReader.end_filter<  s   t|# 	,""8,,CIIT\) 	,""<00CIIC 	K )% 0 0 2 2$; 2  2$[fqj[1111!Q; 2 #(&>1112 D  K !?#!EFFF !Cc!IJJJr.   c                 p    | j                             d          }|r|                    d|dz              |S )Nr   r   rF   )r#   r$   insert)r*   r;   r=   r   s       r,   r   z#LiteralIncludeReader.prepend_filterW  s<    ,""9-- 	,LLGdN+++r.   c                 n    | j                             d          }|r|                    |dz              |S )NrN   rF   )r#   r$   rN   )r*   r;   r=   rN   s       r,   r   z"LiteralIncludeReader.append_filter^  s:    !!(++ 	(LL$'''r.   c                 l    d| j         v r*t          || j                             d          |          S |S )Nr<   rE   )r#   rR   r$   )r*   r;   r=   s      r,   r   z"LiteralIncludeReader.dedent_filtere  s;    t|# 	t|'7'7'A'AHUUUULr.   )r   NrA   )r/   r0   r1   r   strr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r:   r.   r,   r   r      s           t V     5 5 5 5C C# CsCx CDQTI C C C C * *U38_ *c3h * * * *" %S/ T#Y     T#Y %S/ UYZ]U^    $ $s) uS#X RVWZR[    0 $s) uS#X RVWZR[    > S	 U38_ PTUXPY    6 DI sCx TXY\T]     49 c3h SWX[S\     49 c3h SWX[S\      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<   rm   rn   r   r   r+   r   r   r   r;   r   r   r   r   r   rN   ro   )rU   rp   rq   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   rE   rY   r   udiffr+   rm   rn   r   TrX   rp   r|   ro   c              3   $   K   | ]
}|k    V  d S rA   r:   r   s     r,   rD   z%LiteralInclude.run.<locals>.<genexpr>  s'      44aqEz444444r.   rv   c                 &    g | ]}|k     |d z   S rx   r:   )rB   ry   r;   s     r,   rz   z&LiteralInclude.run.<locals>.<listcomp>  s&    )O)O)OAQY)O!a%)O)O)Or.   r}   r~   rU   )r\   r   settingsfile_insertion_enabledr   rL   r   r#   r'   
relfn2pathr   r   r!   note_dependencyr   r   r   r	   rW   r   r$   r   rJ   rK   r   r   rj   r   	Exception)r*   r   _pathr=   rel_filenamer   readerr   retnoder   r}   rU   r   r;   s                 @r,   r-   zLiteralInclude.run  sa   :& 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 *"dl2*%)	"I$,"2"27B"?"??577J!12 DL0 P'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( D,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)r/   r0   r1   r2   r3   r4   r5   r6   r   r   r7   r   r   r   r   r   r   r   r9   r   r   r-   r:   r.   r,   r   r   l  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   rl   r   )r   s    r,   setupr     si    !+y999!,	:::!,	:::!"2NCCC "#  r.   rA   )1r%   rG   difflibr   typingr   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   	getLoggerr/   rK   r   r   r   rR   r[   rj   rl   r   r   r   r:   r.   r,   <module>r
     s   



              8 8 8 8 8 8 8 8 8 8 8 8 8 8       ( ( ( ( ( ( ( ( + + + + + + , , , , , ,                   * * * * * *       - - - - - - - - 0 0 0 0 0 0 ) ) ) ) ) ) *))))))		8	$	$I I I I I I I I4 S	 3 %S/ UYZ]U^    "  s W\Wf    *P P P P P P P Pf} } } } } } } }@TF TF TF TF TF_ TF TF TFn
x 
DcN 
 
 
 
 
 
r.   