
    ohef                        d Z dZddlmZ ddlZddlZddlZddlmZ ddl	m
Z
 ddl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  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jF                        Z$ G d de      Z% G d  d!e      Z& G d" d#e      Z'y)$zMiscellaneous directives.reStructuredText    )PathN)urlopen)URLError)ionodesstatemachineutils)	Directiveconvert_directive_function)
directivesrolesstates)	CodeBlockNumberLines)miscc                   >   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$                  ej(                              dz  Zd Zy)	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   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| j	                  d| j
                  z        | j                   j                  j                  }t        j                  | j                  d         }|j                  d      r#|j                  d      r| j                  }|dd }nt        |      j                  }t        j                   d||z        }| j"                  j%                  d| j                   j                  j                  j&                        }| j                   j                  j                  j(                  }| j"                  j%                  d	| j                   j                  j                  j*                        }	 t-        j.                  |||
      }| j                   j                  j                  j0                  j3                  |       | j"                  j%                  dd      }	| j"                  j%                  dd      }
	 |	s|
%|j=                         }dj?                  ||	|
       }n|jA                         }| j"                  j%                  dd      }|rE|jE                  |      }|dk  r| j7                  d| j
                  z        ||tG        |      z   d }| j"                  j%                  dd      }|r9|jE                  |      }|dk  r| j7                  d| j
                  z        |d| }tI        jJ                  ||d      }tM        |      D ]T  \  }}tG        |      | j                   j                  j                  jN                  kD  s=| j	                  d||dz   fz         d| j"                  v r |dk\  r|jQ                  |      }n|}tS        jT                  ||| j"                  j%                  dg             }d|_+        | jY                  |       d| j"                  v r	 t[        | j"                  d   xs d      }	|	tG        |      z   }
|j                  d!      r|dd }ta        g |fg|	|
      }|D ];  \  }}|r|tS        jb                  |||"      z  }$|tS        jd                  |      z  }= |gS |tS        jd                  |      z  }|gS d#| j"                  v r|| j"                  d$<   |dk  r|jg                         }ti        | j
                  | j"                  jk                  d#      g| j"                  || jl                  | jn                  | jp                  | j                   | jr                  	      }|ju                         S |	|
||f}| j                   j                  jv                  }|s'|jy                  t        j                   d|      d%f       ||f|v rHd& t{        |      D        }d'j?                  |g|      }| j	                  d(| j
                  d|      d)| j"                  v rt        j|                  || j                   j                  j                        }|||fgz   |_;         | j"                  d)          }|j                  d!j?                  |      |       |j                  j                  |f       |j                  j                          |j                  S |dd*|z  gz  }| jr                  j                  ||       |jy                  ||f       g S # t4        $ r# | j7                  d| j
                   d| d      t8        $ r:}| j7                  d| j
                   dt-        j:                  |       d      d}~ww xY w# tB        $ r:}| j7                  d| j
                   dt-        j:                  |      z         d}~ww xY w# t\        $ r | j_                  d       w xY w)+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   Nr   r   source_pathr   error_handlerProblems with "z1" directive path:
Cannot encode input file path "z" (wrong locale?)." directive path:
.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    )sourceclassesr   z+:number-lines: with non-integer start value
)r3   r   r2   )NNNNc              3   &   K   | ]	  \  }}|  y w)N ).0pthopts      F/usr/lib/python3/dist-packages/docutils/parsers/rst/directives/misc.py	<genexpr>zInclude.run.<locals>.<genexpr>   s     HJS#CHs   z
> zcircular inclusion in "r   z.. end of inclusion from "%s")Estatedocumentsettingsfile_insertion_enabledwarningr!   current_sourcer   path	arguments
startswithendswithstandard_include_pathr   parentr
   relative_pathoptionsgetinput_encodinginput_encoding_error_handler	tab_widthr   	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appendreversednew_documentparsetransformerpopulate_from_componentsapply_transformschildreninsert_input) selfrA   rB   _baser   	e_handlerrM   include_filerd   	startlineendlinelinesrawtext
after_textafter_indexbefore_textbefore_indexinclude_linesir`   textr_   tokensr3   value	codeblockclip_optionsrn   master_pathsinclusion_chainr=   r   s                                    r:   rm   zInclude.run9   ss    zz""++BB,,9DIIEFF,,;;t~~a01??3DMM#$6..E":D(//E""4t4<<##

++44CCEJJ''00MM	LL$$,,55??A		G<<D196?AL JJ((<<@@F LL$$\48	,,"":t4	8W0$..0''%	'":;&++- \\%%mT:
!,,z2KQkk #@BF))#L M MkC
O;<=Gll&&|T:"<<4Lakk #@BF))#L M Mm|,G$11'9EIK / 	HGAt4y4::..77IIIll $9<@!A#;$G H H	H
 $A~)))4!// '(,(8(8"(EGM "#MMM-(-4 #DLL$@$EA FI $c-&88==&9D$r4j\9gF&, ;NGU%eU>E*G G &E)::; "?" D!11!?"T\\!%)DLL"1} ' 2 2 4!$))#'<<#3#3F#;"<"&,,"/"&++"&"5"5"&//"&**"&"4"46I ==?" "7KDjj))55 3 3D. I 8 : ;,;.H(;2GHL$kk4*?,*?@O,,"&))_ > ? ? t||#))$

0C0C0L0LMH#.42F1G#GH +T\\(+-FLL=18<  996)D  113$$$
 	"=DEE''t<D,/0	} " 	2++		{ ;@@Dv F11 2 2  	C++		{ ;((*(>'?qB C C	C  	8++tyykH " 67 8 8	8V " 4** &3 4 44s<    \ *9^	 _ 3^5^^		_5___*N)__name__
__module____qualname____doc__required_argumentsoptional_argumentsfinal_argument_whitespacer   flag	unchangedr   parser_namerb   unchanged_requiredclass_optionoption_specr   docutils_datadirr   __file__rF   rm   r6       r:   r   r      s    
  $(oo%//)22'33 #!$"","?"?!+!>!>#-#7#7&33%//1K !!2!2!26??!CDyPW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y)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                 N	   | j                   j                  j                  j                  rF| j                   j                  j                  j                  s:d| j
                  v sd| j
                  v r| j                  d| j                  z        ddj                  | j                  d   j                         j                               i}| j
                  j                  d| j                   j                  j                  j                        }| j                   j                  j                  j                  }| j                  rWd| j
                  v sd| j
                  v r| j!                  d| j                  z        d	j                  | j                        }nud| j
                  v rd| j
                  v r| j!                  d
| j                  z        | j
                  d   }t#        | j                   j                  j$                        j&                  }t)        j*                  d ||z        }	 t-        j.                  |||      }| j                   j                  j                  j0                  j3                  |       	 |j;                         }||d<   nwd| j
                  v rY| j
                  d   }		 t?        |	      j;                         }
t-        jB                  |
|	||      }	 |j;                         }|	|d<   n| jE                          tG        jH                  dfd| j
                  j                  dg       i|}| jJ                  jM                  | jN                        \  |_(        |_)        |gS # t4        $ r:}| j7                  d| j                   dt-        j8                  |       d      d }~ww xY w# t<        $ r:}| j7                  d| j                   dt-        j8                  |      z         d }~ww xY w# t@        t4        f$ rJ}| j7                  d| j                   d| j
                  d    dt-        j8                  |       d      d }~ww xY w# t<        $ r:}| j7                  d| j                   dt-        j8                  |      z         d }~ww xY w)Nr   r   r$   format r   r   zF"%s" directive may not both specify an external file and have content.r4   zXThe "file" and "url" options may not be simultaneously specified for the "%s" directive.r(   r+   r,   r-   r/   r0   r2   z" directive URL "z":
)r2   r)   r   r*   r.   r3   r    )*r<   r=   r>   raw_enabledr?   rI   r@   r!   rV   rC   lowersplitrJ   rK   rL   contentrd   r   rA   rG   r
   rH   r   rN   rO   rP   rS   rR   rT   rW   rX   r   r   StringInputassert_has_contentr   rawrl   get_source_and_lineri   r2   r`   )rx   
attributesr   rz   r   rB   ry   raw_filerd   r2   raw_textraw_nodes               r:   rm   zRaw.run   s   

##,,88JJ''00GGt||+-,,9DIIEFF):)@)@)B)H)H)J KL
<<##

++44CCEJJ''00MM	<<%$,,)>jj(*.))45 5 99T\\*Dt||#$jj8:>))DE E <<'D,,;;<CCE&&tU4Z8D
K<<D196?A 

##,,@@DDTJ<}} $(Jx dll"\\%(F@"6?//1
 ~~X6/74=?H<}} $*Jx  ##%99R +t||/?/?/L +)+ ,,@@M		zK  GkkODII; ?,,.OOE,B+C1#F G GG   <kkN499+^"L$&OOE$:#; < << g& @kkODII; ?&&*ll5&9%:$%'__U%;$<A#? @ @@   <kkN499+^"L$&OOE$:#; < <<sa   2M9 N? 8P +Q! 9	N<5N77N<?	P5O==PQAQQ!	R$*5RR$N)r   r   r   r   r   r   r   r   rB   urir   r   r   has_contentrm   r6   r   r:   r   r      sO      $%??$..)22&335K KAr   r   c                       e Zd ZdZd Zy)ReplaceTc                    t        | j                  t        j                        s| j	                  d| j
                  z        | j                          dj                  | j                        }t        j                  |      }| j                  j                  | j                  | j                  |       d }g }|D ]  }|st        |t        j                        r|}"t        |t        j                        rg |d<   |j                  |       S| j                   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.r4   backrefs
Error in "z1" directive: may contain a single paragraph only.r`   )
isinstancer<   r   SubstitutionDefrd   r!   r   rV   r   r   Elementnested_parserj   	paragraphsystem_messagero   reporterri   rv   )rx   r   elementnodemessageselems         r:   rm   zReplace.run/  s<   $**f&<&<=**-/3yy9: : 	!yy&--%

d.A.A '	)  
	GDJtU__=D%"6"67#%Z % MM''$TYYK 03 39= ( FG G
	G dmm++r   Nr   r   r   r   rm   r6   r   r:   r   r   +  s    Kr   r   c                       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y)	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| j	                  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                  | j                  d         d   j                         }t        j                         }|D ]0  }	 t        j                   |      }|t        j(                  |      z  }2 |j*                  S # t"        $ r/}| j	                  d|dt%        j&                  |            d }~ww xY w)	Nr   r   r   r   r   r   zInvalid character code: r4   )r   r<   r   r   rd   r!   rl   r   rI   r   comment_patternr   rC   r   r   r   unicode_coderc   r   rT   rf   rv   )rx   substitution_definitioncodesr   r   decodedrd   s          r:   rm   zUnicode.run_  so   $**f&<&<=**-/3yy9: : #'"4"4"9"9T\\!:;#..w7:;#..w7dll":;#..w7dll":;#..w7$$**4>>!+<=a@FFH--/ 	+DC$11$7 uzz'**G	+ 	  Cjj$("//%*@"B C CCs   E	F*F  FN)r   r   r   r   r   r   r   r   r   r   recompiler   rm   r6   r   r:   r   r   L  sO      $%??&OO&OO-K !bjj!12O r   r   c                   &    e Zd ZdZdZdZdZdZd Zy)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                    	 t        j                  | j                  d         }g }| j                  r}t        j                         }| j                  j                  | j                  | j                  |       |D ]  }|d   j                  |        |j                  |j                         |S t        j                  t        j                   || j
                  d| j"                        }| j$                  j&                  j)                  |       |j+                  |       |S # t        $ r0 | j	                  d| j
                  d| j                  d   d      w xY w)Nr   z#Invalid class attribute value for "z" directive: "".r3   )r    	directive)r   r   rC   rc   rd   r!   r   r   r   r<   r   rj   extendrv   pendingr   ClassAttributerk   rl   r=   note_pendingro   )rx   class_value	node_list	containerr   r   s         r:   rm   z	Class.run  s.   	2$11$..2CDK
 	<<IJJ##DLL$2E2E$-/! 4Y&&{34Y//0  mm##%DII>!G ''44W=W%'  	2**99dnnQ/12 2	2s   "D# #9EN)	r   r   r   r   r   r   r   r   rm   r6   r   r:   r   r   x  s%      $Kr   r   c                   p    e Zd ZdZ ej
                  dej                  j                  fdz  z        Z	d Z
y)RoleTz(%s)\s*(\(\s*(%s)\s*\)\s*)?$   c                 l   | j                   | j                  kD  s| j                  s| j                  d| j                  z        | j                  d   }| j
                  j                  |      }|s"| j                  d| j                  d|d      |j                  d      }|j                  d      }g }|rt        j                  || j                  j                  | j                  | j                  j                        \  }}|s| j                  j                  j                  d	|z  t        j                  | j                   | j                         | j                  
      }||gz   S t        j"                  }t%        |d      rJ d| j                  d|d       	 t'        |      }| j                  j)                  | j                  dd | j                   |i       \  }	}
}}d|
vr	 t/        j0                  |      |
d<   t        j4                  |||
|      }t        j6                  ||       |S # t*        j,                  $ rq}| j                  j                  d| j                  d|dt        j                  | j                   | j                         | j                  
      }||gz   cY d}~S d}~ww xY w# t2        $ rq}| j                  j                  d| j                  d|dt        j                  | j                   | j                         | j                  
      }||gz   cY d}~S d}~ww xY w)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   rC   z&Supplemental directive arguments for "z)" directive not supported (specified by "z" role).)option_presetsr   r0   r-   r    zInvalid argument for ")rj   ri   r   rd   r!   argument_patternmatchgroupr   rolerl   languager<   r   r   r_   rk   generic_custom_rolehasattrr   parse_directive_blockr   MarkupErrorr   r   rc   
CustomRoleregister_local_role)rx   argsr   new_role_namebase_role_namer   	base_rolerd   converted_rolerC   rI   r   rj   detailr   s                  r:   rm   zRole.run  s   ,DLL** %'+yy1 2 2||A%%++D1**(,		49 : :AQ"'** 2 2 ; ;T[[

###%Ix  

++119NJ''I 2 &  5'))11I9k2 	L59YY	K	L2	&7	BN11LL$d&9&9"2 2 7Y. '!*#-#:#:=#I  y'7K!!-6% !! 	&MM''3799fE##DOOT__E[[ ( "E ug%%	&  *++yy&*''I	 , &
  5'))*s?   AH2 *J9 2J6A&J1+J61J69	L3A&L.(L3.L3N)r   r   r   r   r   r   r   Inliner
simplenamer   rm   r6   r   r:   r   r     s<    K!rzz"A&,nn&?&?%AA%E#G H4r   r   c                       e Zd ZdZdZdZd Zy)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                        \  }}|c| j                  j                  j                  d|z  t        j                  | j                  | j                        | j                        }||gz   S |t        j                  d<   |S )Nr.   r   r   r   )rC   r   _rolesr   rl   r   ri   r<   r   rd   r   r_   rk   )rx   	role_namer   r   rd   s        r:   rm   zDefaultRole.run  s    ~~U\\!LL$INN1%	It/A/A/J/J$(KK1D1DFh<JJ''--5	A##DOOT__E[[ . "E ug%%Rr   N)r   r   r   r   r   r   rm   r6   r   r:   r   r     s    0 %r   r   c                       e Zd ZdZdZdZd Zy)Titler   r   Tc                 R    | j                   d   | j                  j                  d<   g S )Nr   title)rC   rl   r=   )rx   s    r:   rm   z	Title.run  s&    /3~~a/@##G,	r   N)r   r   r   r   r   r   rm   r6   r   r:   r   r     s     $r   r   c                       e Zd Zd Zd Zy)MetaBodyc                 ^    | j                  |      \  }}| xj                  |z  c_        g |g fS )zMeta element.)	parsemetarG   )rx   r   context
next_stater   blank_finishs         r:   field_markerzMetaBody.field_marker  s0    !^^E2lt:r!!r   c           	      0   | j                  |      }t        j                  t        j                  |            }| j
                  j                  |j                               \  }}}}t        j                         }t        j                  t        j                  dj                  |                  |d<   |sM| j
                  j                  }| j                  j                  d|z  t        j                  ||            }	|	|fS |j                         }
	 t        j                  |
d         d   \  }}|||j!                         <   |
dd  D ]1  }	 t        j                  |      d   \  }}|||j!                         <   3 ||fS # t        j"                  $ r |
d   |d<   Y Zw xY w# t        j"                  $ r]}| j
                  j                  }| j                  j%                  d|d|d	t        j                  ||            }	|	|fcY d }~c S d }~ww xY w)
Nr   r   zNo content for meta tag "%s".r   r!   r   z"Error parsing meta tag attribute "z": r-   )parse_field_markerr   unescaper
   escape2nullrl   get_first_known_indentedendmetarV   r`   r   infor_   r   extract_name_valuer   NameValueErrorrd   )rx   r   r!   indentedindentline_offsetr	  r   r`   msgr   attnamevaltokenr   s                  r:   r  zMetaBody.parsemeta	  s   &&u-~~e//5688E	6;zz|..):):,/HHX,>*@ AY%%**D--$$1D8%%dD13C $$	% 33F1I>qALGS$'D! ABZ 		)E)$77>qA(+W]]_%		) \!! ## 	%!!9DL	% '' )))..mm))().)<)<T4)HJ L(()s1   1F .F%F"!F"%H8AHHHN)r   r   r   r
  r  r6   r   r:   r  r    s    ""r   r  c                        e Zd ZdZdefiZd Zy)MetaTstate_classesc                    | j                          t        j                         }| j                  j	                  | j
                  | j                  |dd| j                        \  }}|| j                  z
  t        | j
                        k7  rU| j                  j                  dt        j                  | j                  | j                        | j                        }||z  }| j                  j                  j                  t        j                   t        j"                  f      xs d}|j$                  | j                  j                  || g S )Nr  T)initial_stater	  state_machine_kwargszInvalid meta directive.r   r   )r   r   r   r<   nested_list_parser   rj   SMkwargsrZ   r   rd   r_   rk   ri   r=   first_child_not_matching_classTitularr  rv   )rx   r   new_line_offsetr	  rd   indexs         r:   rm   zMeta.run0  s   !}}(,

(D(DLL$--t$4!% )E )0% d111c$,,6GGMM'')##DOOT__E[[ ( "E EMD

##BB).

(CE JHI 	+/==

E%(	r   N)r   r   r   r   r  r#  rm   r6   r   r:   r  r  *  s    K(-Hr   r  c                       e Zd ZdZd Zy)DateTc                    t        | j                  t        j                        s| j	                  d| j
                  z        dj                  | j                        xs d}t        j                  j                  d      }|r3t        j                  |t        j                  t        |                  }nt        j                  |      }t        j                   |      gS )Nr   r4   z%Y-%m-%dSOURCE_DATE_EPOCH)r   r<   r   r   rd   r!   rV   r   osenvironrJ   timestrftimegmtimerb   r   rf   )rx   
format_strsource_date_epochr   s       r:   rm   zDate.runI  s    $**f&<&<=**-/3yy9: : YYt||,:

 JJNN+>?==!%S1B-C!DFD ==,D

4 !!r   Nr   r6   r   r:   r)  r)  E  s    K"r   r)  c                   >    e Zd ZdZdZdZdej                  iZdZ	d Z
y)TestDirectivez3This directive is useful only for testing purposes.r   Toptionc           	         | j                   rdj                  | j                         }| j                  j                  d| j                  d| j
                  d| j                  dt        j                  ||      | j                        }|gS | j                  j                  d| j                  d| j
                  d| j                  d| j                        }|gS )Nr4   zDirective processed. Type="z", arguments=z
, options=z
, content:r   z, content: None)
r   rV   r   r  r!   rC   rI   r   r_   ri   )rx   r   r  s      r:   rm   zTestDirective.runl  s    <<99T\\*D==%%"iiG##D$/dkk & CD v	 ==%%#'99dnndllL[[ & "D vr   N)r   r   r   r   r   r   r   r   r   r   rm   r6   r   r:   r4  r4  c  s+    = $Z::;KKr   r4  )(r   __docformat__pathlibr   r,  r   r.  urllib.requestr   urllib.errorr   r   r   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   SpecializedBodyr  r  r)  r4  r6   r   r:   <module>r?     s   
  "  	 	  " !  3 3 F : : G $xi xvU) Upi B) i ) X#I #L;9 ;|) 4I &"v%% &"R9 6"9 "<I r   