
    -PhLh                        d Z dZddlmZ ddlZddlZddlmZ ddlm	Z	 ddl
mZmZmZmZ ddlmZmZ dd	lmZmZmZ dd
lmZmZ ddlmZ d'dZ G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z  G d de          Z! G d de          Z" G d d ej#                  Z$ G d! d"e          Z% G d# d$e          Z& G d% d&e          Z'dS )(zMiscellaneous directives.reStructuredText    )PathN)urlopen)URLError)ionodesstatemachineutils)	Directiveconvert_directive_function)
directivesrolesstates)	CodeBlockNumberLines)misc /c                     |                      d          rt          |          }| dd          } nt          |          j        }t          j        d || z            S )Nr      )
startswithr   parentr
   relative_path)pathsourceroot_prefixbases       d/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/docutils/parsers/rst/directives/misc.py
adapt_pathr      sY    
 s #K  ABBxF||"tT$Y///    c                       e Zd ZdZdZdZdZej        ej	        ej
        ej        eeeej        ej        ej	        ej        ej	        dZ eej                  j        dz  Zd ZdS )	Includea  
    Include content read from a separate source file.

    Content may be parsed by the parser, or included as a literal
    block.  The encoding of the included file can be specified.  Only
    a part of the given file argument may be included by specifying
    start and end line or text to match before and/or after the text
    to be used.

    https://docutils.sourceforge.io/docs/ref/rst/directives.html#including-an-external-document-fragment
    r   r   T)literalcodeencodingparser	tab-width
start-lineend-linestart-after
end-beforenumber-linesclassnameincludec                    | j         j        j        }|j        s|                     d| j        z            | j                            d|j                  }| j         j        j	        }t          j        | j        d                   }|                    d          r*|                    d          rd|dd         z   }| j        }n|j        }t#          |||          }| j                            d	|j                  }|j        }	 t)          j        |||
          }|j                            |           no# t0          $ r" |                     d| j         d| d          t4          $ r8}	|                     d| j         dt)          j        |	           d          d}	~	ww xY w| j                            dd          }
| j                            dd          }	 |
s|2|                                }d                    ||
|                   }n|                                }nE# t>          $ r8}	|                     d| j         dt)          j        |	          z             d}	~	ww xY w| j                            dd          }|rR|                     |          }|dk     r|                     d| j        z            ||tC          |          z   d         }| j                            dd          }|rB|                     |          }|dk     r|                     d| j        z            |d|         }tE          j#        ||d          }tI          |          D ]:\  }}tC          |          |j%        k    r|                     d||dz   fz            ;d| j        v rP|dk    r|&                    |          }n|}tO          j(        ||| j                            dg                     }d|_)        | *                    |           d | j        v r	 tW          | j        d          pd          }
n## tX          $ r | -                    d!          w xY w|
tC          |          z   }|                    d"          r
|dd         }t]          g |fg|
|          }|D ]9\  }}|r|tO          j/        |||#          z  }"|tO          j0        |          z  }:n|tO          j0        |          z  }|gS d$| j        v r|| j        d%<   |dk     r|1                                }te          | j        | j        3                    d$          g| j        || j4        | j5        | j6        | j         | j7        	  	        }|8                                S |
|||f}| j         j        j9        }|s*|:                    tw          j<        d|          d&f           ||f|v rRd' t{          |          D             }d(                    |g|R           }|                     d)| j        d|          d*| j        v rtw          j>        ||          }|||fgz   |_9         | j        d*                     } | ?                    d"                    |          |           |j@        A                    | f           |j@        B                                 |jC        S |dd+|z  gz  }| j7        D                    ||           |:                    ||f           g S ),zInclude a file as part of the content of this reST file.

        Depending on the options, the file (or a clipping) is
        converted to nodes and returned or inserted into the input stream.
        "%s" directive disabled.r'   r   <>r   r   r%   source_pathr%   error_handlerProblems with "z1" directive path:
Cannot encode input file path "z" (wrong locale?)." directive path:
.Nr(   r)   r   Problem with "" directive:
r*   zDProblem with "start-after" option of "%s" directive:
Text not found.r+   zCProblem with "end-before" option of "%s" directive:
Text not found.T)convert_whitespacez,"%s": line %d exceeds the line-length-limit.r#   r-   )r   classesr,   z+:number-lines: with non-integer start value
)r>   r$   r   )NNNNc              3       K   | ]	\  }}|V  
d S )N ).0pthopts      r   	<genexpr>zInclude.run.<locals>.<genexpr>   s&      HHJS#CHHHHHHr    z
> zcircular inclusion in "r&   z.. end of inclusion from "%s")Estatedocumentsettingsfile_insertion_enabledwarningr.   optionsget	tab_widthcurrent_sourcer   r   	argumentsr   endswithstandard_include_pathr   r   input_encodinginput_encoding_error_handlerr   	FileInputrecord_dependenciesaddUnicodeEncodeErrorsevereOSErrorerror_string	readlinesjoinreadUnicodeErrorfindlenr	   string2lines	enumerateline_length_limit
expandtabsr   literal_blocklineadd_nameint
ValueErrorerrorr   inlineText
splitlinesr   poplinenocontent_offset
block_textstate_machineruninclude_logappendr
   r   reversednew_documentparsetransformerpopulate_from_componentsapply_transformschildreninsert_input)!selfrH   rM   rN   r   r   r%   r7   include_filerj   	startlineendlinelinesrawtext
after_textafter_indexbefore_textbefore_indexinclude_linesirf   textre   tokensr>   value	codeblockclip_optionsrt   master_pathsinclusion_chainrG   r&   s!                                    r   rs   zInclude.runE   s<    :&/. 	G,,9DIEFFFL$$[(2DEE	,;t~a011??3 	/DMM#$6$6 	/ad#D4KK".K$<<<##J0GHH =	3<D196CE E EL (,,T2222 " 	2 	2 	2++ 1	 1 1@D1 1 1 2 2 2  	C 	C 	C++ B	 B B(*(>(>B B B C C C	C L$$\488	,"":t44	8 .W0$..00''%	'(9":;;&++-- 	8 	8 	8++HtyHHH " 6 67 8 8 8	8
 \%%mT::
 	>!,,z22KQkk #@BF)#L M M MkC
OO;<<=Gl&&|T:: 	-"<<44Lakk #@BF)#L M M Mm|m,G$1'9EIK K K // 	H 	HGAt4yy8555ll $9<@!A#;$G H H H 6 $$A~~)))44!/ '(,(8(8"(E(EG G GM "#MMM-(((--4 #DL$@$EA F FII! 4 4 4** &3 4 4 44 $c-&8&88==&& %9D$r4j\9gFF&, ; ;NGU ;%eU>E*G *G *G G &E):)::; D!1!11!?"T\!!%)DL"1}} ' 2 2 4 4!$)#'<#3#3F#;#;"<"&,"/"&+"&"5"&/"&*"&"46 6I ==??" "7KDj)5 	; 3D. I I 8 : ; ; ;,;..HH(;2G2GHHHL$kk4*?,*?*?@@O,,,"&)))__ > ? ? ? t|##)$99H#.42F1G#GH +T\(+--FLL=118<<< 996)DDD 11333$$
 	"=DEE''t<<<D,/000	s=   D7 74F#+3FF#A
H( (
I*23I%%I*P7 7 QN)__name__
__module____qualname____doc__required_argumentsoptional_argumentsfinal_argument_whitespacer   flag	unchangedr%   parser_namerh   unchanged_requiredclass_optionoption_specr   r   __file__r   rQ   rs   rA   r    r   r"   r"   $   s        
 
  $(o%/)2'3 #!$"","?!+!>#-#7&3%/1 1K !D1189DV V V V Vr    r"   c                   ^    e Zd ZdZdZdZdZej        ej	        ej
        ej        dZdZd ZdS )Rawz
    Pass through content unchanged

    Content is included in output based on type argument

    Content may be included inline (content section of directive) or
    imported from a file or url.
    r   r   T)fileurlr%   r-   c                    | j         j        j        }|j        r|j        s/d| j        v s	d| j        v r|                     d| j        z            dd                    | j	        d         
                                                                          i}| j                            d|j                  }|j        }| j        rKd| j        v s	d| j        v r|                     d| j        z            d	                    | j                  }n[d| j        v r0d| j        v r|                     d
| j        z            t#          | j        d         | j         j        j        |j                  }	 t)          j        |||          }|j                            |           nE# t0          $ r8}|                     d| j         dt)          j        |           d          d }~ww xY w	 |                                }nE# t8          $ r8}|                     d| j         dt)          j        |          z             d }~ww xY w||d<   n!d| j        v r| j        d         }		 t;          |	                                          }
nZ# t<          t0          f$ rF}|                     d| j         d| j        d          dt)          j        |           d          d }~ww xY wt)          j        |
|	||          }	 |                                }nE# t8          $ r8}|                     d| j         dt)          j        |          z             d }~ww xY w|	|d<   n|                                   tC          j"        d|fd| j                            dg           i|}| j#        $                    | j%                  \  |_&        |_'        |gS )Nr   r   r1   format r   r%   zF"%s" directive may not both specify an external file and have content.r?   zXThe "file" and "url" options may not be simultaneously specified for the "%s" directive.r5   r8   r9   r:   r;   r<   r   z" directive URL "z":
)r   r6   r%   r7   r   r>   r-   )(rF   rG   rH   raw_enabledrI   rK   rJ   r.   r\   rO   lowersplitrL   rR   rS   contentrj   r   rN   r   r   rT   rU   rV   rY   rX   rZ   r]   r^   r   r   StringInputassert_has_contentr   rawrr   get_source_and_linero   r   rf   )r~   rH   
attributesr%   r7   r   r   raw_filerj   r   raw_textraw_nodes               r   rs   zRaw.run   s   :&/$ 	G3	Gt|++u/D/D,,9DIEFFF):)@)@)B)B)H)H)J)J K KL
<##J0GHH =< 2	&%%$,)>)>jj(*.)45 5 5 99T\**DDt|##$$jj8:>)DE E E dl62"j1@&24 4D
7<D196CE E E ,006666  G G Gkk #FDI #F #F,.OE,B,B#F #F #F G G GG<}} < < <kk"L49"L"L"L$&OE$:$:#; < < << $(Jx  dl""\%(F@"6??//11g& @ @ @kk #?DI #? #?&*l5&9#? #?%'_U%;%;#? #? #? @ @ @@ ~X6/74AC C CH<}} < < <kk"L49"L"L"L$&OE$:$:#; < < << $*Jx   ##%%%9R + +t|/?/?/L/L +)+ + ,@@MM		zsa   /F! !
G#+3GG#'G< <
H>3H99H> !J KAKK5L
 

M3MMN)r   r   r   r   r   r   r   r   r   urir%   r   r   has_contentrs   rA   r    r   r   r      so           $%?$.)2&35 5K K@ @ @ @ @r    r   c                       e Zd ZdZd ZdS )ReplaceTc                 x   t          | j        t          j                  s|                     d| j        z            |                                  d                    | j                  }t          j
        |          }| j                            | j        | j        |           d }g }|D ]}|st          |t          j                  r|}!t          |t          j                  rg |d<   |                    |           V| j                            d| j         d| j                  gc S |r
||j        z   S |S )NVInvalid context: the "%s" directive can only be used within a substitution definition.r?   backrefs
Error in "z1" directive: may contain a single paragraph only.rf   )
isinstancerF   r   SubstitutionDefrj   r.   r   r\   r   r   Elementnested_parserp   	paragraphsystem_messageru   reporterro   r|   )r~   r   elementnodemessageselems         r   rs   zReplace.run9  s   $*f&<== 	:**-/3y9: : : 	!!!yy&&-%%
d.A '	) 	) 	)  
	G 
	GD 	GJtU_== 	GD%"677 G#%Z %%%% M''3TY 3 3 39= ( F FG G G G  	,dm++r    Nr   r   r   r   rs   rA   r    r   r   r   5  s(        K    r    r   c                   n    e Zd ZdZdZdZdZej        ej        ej        dZ	 e
j        d          Zd ZdS )	Unicodea{  
    Convert Unicode character codes (numbers) to characters.  Codes may be
    decimal numbers, hexadecimal numbers (prefixed by ``0x``, ``x``, ``\x``,
    ``U+``, ``u``, or ``\u``; e.g. ``U+262E``), or XML-style numeric character
    entities (e.g. ``&#x262E;``).  Text following ".." is a comment and is
    ignored.  Spaces are ignored, and any other text remains as-is.
    r   r   T)trimltrimrtrimz( |\n|^)\.\. c           
         t          | j        t          j                  s|                     d| j        z            | j        j        }d| j        v rd|j	        d<   d|j	        d<   d| j        v r
d|j	        d<   d| j        v r
d|j	        d<   | j
                            | j        d                   d                                         }t          j                    }|D ]n}	 t          j        |          }n?# t"          $ r2}|                     d|dt%          j        |                    d }~ww xY w|t          j        |          z  }o|j        S )	Nr   r   r   r   r   r   zInvalid character code: r?   )r   rF   r   r   rj   r.   rr   r   rK   r   comment_patternr   rO   r   r   r   unicode_coderi   r   rZ   rl   r|   )r~   substitution_definitioncodesr   r$   decodedrj   s          r   rs   zUnicode.runi  s   $*f&<== 	:**-/3y9: : : #'"4"9T\!!:;#.w7:;#.w7dl"":;#.w7dl"":;#.w7$**4>!+<==a@FFHH-// 	+ 	+DC$1$77 C C Cjjj$(DD"/%*@*@*@"B C C CC uz'***GGs   !C66
D2 -D--D2N)r   r   r   r   r   r   r   r   r   r   recompiler   rs   rA   r    r   r   r   V  sp           $%?&O&O- -K !bj!122O         r    r   c                   (    e Zd ZdZdZdZdZdZd ZdS )Classz
    Set a "class" attribute on the directive content or the next element.
    When applied to the next element, a "pending" element is inserted, and a
    transform does the work later.
    r   r   Tc                 x   	 t          j        | j        d                   }n:# t          $ r- |                     d| j        d| j        d         d          w xY wg }| j        rtt          j                    }| j	        
                    | j        | j        |           |D ]}|d                             |           |                    |j                   nat          j        t          j        || j        d| j                  }| j        j                            |           |                    |           |S )Nr   z#Invalid class attribute value for "z" directive: "".r>   )r-   	directive)r   r   rO   ri   rj   r.   r   r   r   rF   r   rp   extendr|   pendingr   ClassAttributerq   rr   rG   note_pendingru   )r~   class_value	node_list	containerr   r   s         r   rs   z	Class.run  sU   	2$1$.2CDDKK 	2 	2 	2***999dnQ///12 2 2	2 	< 	&IJ##DL$2E$-/ / /! 4 4Y&&{3333Y/0000m#%DI>>! !G '44W===W%%%s	   " 7AN)	r   r   r   r   r   r   r   r   rs   rA   r    r   r   r     sF           $K    r    r   c                   Z    e Zd ZdZ ej        dej        j        fdz  z            Z	d Z
dS )RoleTz(%s)\s*(\(\s*(%s)\s*\)\s*)?$   c                    | j         | j        k    s| j        s|                     d| j        z            | j        d         }| j                            |          }|s!|                     d| j        d|d          |                    d          }|                    d          }g }|rt          j	        || j
        j        | j        | j        j                  \  }}|M| j        j                            d	|z  t          j        | j        | j                  | j        
          }||gz   S nt          j        }t%          |d          rJ d| j        d|d            	 t'          |          }| j                            | j        dd         | j         |i           \  }	}
}}nm# t*          j        $ r[}| j                            d| j        d|dt          j        | j        | j                  | j        
          }||gz   cY d}~S d}~ww xY wd|
vr	 t/          j        |          |
d<   nh# t2          $ r[}| j                            d| j        d|dt          j        | j        | j                  | j        
          }||gz   cY d}~S d}~ww xY wt          j        |||
|          }t          j        ||           |S )z?Dynamically create and register a custom interpreted text role.z4"%s" directive requires arguments on the first line.r   "z-" directive arguments not valid role names: "r   r      N#Unknown interpreted text role "%s".r   rO   z&Supplemental directive arguments for "z)" directive not supported (specified by "z" role).)option_presetsr   r<   r:   r-   zInvalid argument for ")rp   ro   r   rj   r.   argument_patternmatchgroupr   rolerr   languagerF   r   r   re   rq   generic_custom_rolehasattrr   parse_directive_blockr   MarkupErrorr   r   ri   
CustomRoleregister_local_role)r~   argsr   new_role_namebase_role_namer   	base_rolerj   converted_rolerO   rK   r   rp   detailr   s                  r   rs   zRole.run  sY   ,,DL,** %'+y1 2 2 2|A%++D11 	:***(,			4449 : : :AQ 	2"'* 2 ;T[
##% #%Ix  
+119NJ'II 2 & &  5')) ! 1I9k22 	L 	L 	L59YYY			K	L 	L 	L	&7	BBN11L$d&9"2 2 7 7Y.. ! 	& 	& 	&M'''37999fffE#DOT_EE[ ( " "E ug%%%%%%%	& '!!*#-#:=#I#I   * * *+++yyy&&&*'II	 , & &
  5')))))))* y'7KK!-666s?   #AF( (H7AHHHH2 2
J<AJJJN)r   r   r   r   r   r   r   Inliner
simplenamer   rs   rA   r    r   r   r     sW        K!rz"A&,n&?%AA%E#G H H4 4 4 4 4r    r   c                        e Zd ZdZdZdZd ZdS )DefaultRolez&Set the default interpreted text role.r   Fc                    | j         sdt          j        v rt          j        d= g S | j         d         }t          j        || j        j        | j        | j        j                  \  }}|M| j        j        	                    d|z  t          j        | j        | j                  | j                  }||gz   S |t          j        d<   |S )Nr   r   r   r   )rO   r   _rolesr   rr   r   ro   rF   r   rj   r   re   rq   )r~   	role_namer   r   rj   s        r   rs   zDefaultRole.run  s    ~ 	U\!!L$IN1%	It/A/J$(K1DF Fh<J'--5	A#DOT_EE[ . " "E ug%%Rr    N)r   r   r   r   r   r   rs   rA   r    r   r   r     s5        00 %    r    r   c                        e Zd ZdZdZdZd ZdS )Titler   r   Tc                 :    | j         d         | j        j        d<   g S )Nr   title)rO   rr   rG   )r~   s    r   rs   z	Title.run  s    /3~a/@#G,	r    N)r   r   r   r   r   r   rs   rA   r    r   r  r     s5         $    r    r  c                       e Zd Zd Zd ZdS )MetaBodyc                 \    |                      |          \  }}| xj        |z  c_        g |g fS )zMeta element.)	parsemetar   )r~   r   context
next_stater   blank_finishs         r   field_markerzMetaBody.field_marker  s5    !^^E22lt:r!!r    c           	      0   |                      |          }t          j        t          j        |                    }| j                            |                                          \  }}}}t          j                    }t          j        t          j        d	                    |                              |d<   |sA| j        j
        }| j                            d|z  t          j        ||                    }	|	|fS |                                }
	 t          j        |
d                   d         \  }}|||                                <   n # t          j        $ r |
d         |d<   Y nw xY w|
dd          D ]}	 t          j        |          d         \  }}|||                                <   8# t          j        $ rQ}| j        j
        }| j                            d|d|d	t          j        ||                    }	|	|fcY d }~c S d }~ww xY w||fS )
Nr   r   zNo content for meta tag "%s".r   r.   r   z"Error parsing meta tag attribute "z": r:   )parse_field_markerr   unescaper
   escape2nullrr   get_first_known_indentedendmetar\   rf   r   infore   r   extract_name_valuer   NameValueErrorrj   )r~   r   r.   indentedindentline_offsetr
  r   rf   msgr   attnamevaltokenr   s                  r   r  zMetaBody.parsemeta  s@   &&u--~e/556688EE	6;z||.):,/HHX,>,>*@ *@ A AY 	%%*D-$$1D8%dD113 3C $$	% 3F1I>>qALGS$'D!!# 	% 	% 	%!!9DLLL	%ABBZ 		) 		)E)$7>>qA(+W]]__%%' ) ) )).m)))().)<T4)H)HJ J L((((((((() \!!s1   :E E,+E,<4F11H AHHHN)r   r   r   r  r  rA   r    r   r  r    s2        " " "" " " " "r    r  c                   "    e Zd ZdZdefiZd ZdS )MetaTstate_classesc                    |                                   t          j                    }| j                            | j        | j        |dd| j                  \  }}|| j        z
  t          | j                  k    rD| j	        
                    dt          j        | j        | j                  | j                  }||z  }| j        j                            t          j        t          j        f          pd}|j        | j        j        ||<   g S )Nr  T)initial_stater
  state_machine_kwargszInvalid meta directive.r   r   )r   r   r   rF   nested_list_parser   rp   SMkwargsr`   r   rj   re   rq   ro   rG   first_child_not_matching_classTitularr  r|   )r~   r   new_line_offsetr
  rj   indexs         r   rs   zMeta.run:  s   !!!}(,
(D(DL$-t$4!% )E )0 )0% d11c$,6G6GGGM'')#DOT_EE[ ( " "E EMD
#BB).
(CE E JHI 	+/=
E%K(	r    N)r   r   r   r   r  r$  rs   rA   r    r   r  r  4  s4        K(-H    r    r  c                       e Zd ZdZd ZdS )DateTc                    t          | j        t          j                  s|                     d| j        z            d                    | j                  pd}t          j	        |          }t          j        |          gS )Nr   r?   z%Y-%m-%d)r   rF   r   r   rj   r.   r\   r   timestrftimer   rl   )r~   
format_strr   s      r   rs   zDate.runS  s|    $*f&<== 	:**-/3y9: : : YYt|,,:

" }Z((
4  !!r    Nr   rA   r    r   r*  r*  O  s(        K" " " " "r    r*  c                   6    e Zd ZdZdZdZdej        iZdZ	d Z
dS )TestDirectivez3This directive is useful only for testing purposes.r   Toptionc           	      \   | j         rid                    | j                   }| j                            d| j        d| j        d| j        dt          j        ||          | j	                  }n:| j                            d| j        d| j        d| j        d| j	                  }|gS )Nr?   zDirective processed. Type="z", arguments=z
, options=z
, content:r   z, content: None)
r   r\   r   r  r.   rO   rK   r   re   ro   )r~   r   r  s      r   rs   zTestDirective.runv  s    < 
	"99T\**D=%%%"iiiG#D$//dk & C CDD
 =%%%#'999dnnndlllL[ & " "D vr    N)r   r   r   r   r   r   r   r   r   r   rs   rA   r    r   r0  r0  m  sG        == $Z:;KK    r    r0  )r   r   )(r   __docformat__pathlibr   r   r,  urllib.requestr   urllib.errorr   docutilsr   r   r	   r
   docutils.parsers.rstr   r   r   r   r   $docutils.parsers.rst.directives.bodyr   r   docutils.transformsr   r   r"   r   r   r   r   r   r   r  SpecializedBodyr  r  r*  r0  rA   r    r   <module>r<     s  
   "       				  " " " " " " ! ! ! ! ! ! 3 3 3 3 3 3 3 3 3 3 3 3 F F F F F F F F : : : : : : : : : : G G G G G G G G $ $ $ $ $ $0 0 0 0w w w w wi w w wtT T T T T) T T Tn    i   B)  )  )  )  ) i )  )  ) X# # # # #I # # #L; ; ; ; ;9 ; ; ;|    )   4    I   &" &" &" &" &"v% &" &" &"R    9   6" " " " "9 " " "<    I     r    