o
    f'haµd  ã                   @   sT  d Z dZddlZddlZddlZddl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 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lmZ G dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZ G dd„ deƒZ!G dd„ deƒZ"G dd„ deƒZ#G dd„ deƒZ$G dd„ deƒZ%G dd„ deƒZ&dS ) zMiscellaneous directives.ÚreStructuredTexté    N)ÚioÚnodesÚstatemachineÚutils)Ú
SafeStringÚErrorString)Úlocale_encoding)Ú	DirectiveÚconvert_directive_function)Ú
directivesÚrolesÚstates)Ú	CodeBlockÚNumberLines)Úset_classes)Úmiscc                   @   sj   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j e ej¡d¡Zd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.
    é   r   T)ÚliteralÚcodeÚencodingÚparserú	tab-widthú
start-lineúend-lineústart-afterú
end-beforeúnumber-linesÚclassÚnameÚincludec                    sf  ˆj jjjsˆ dˆj ¡‚ˆjj ˆj	ˆjj
 d ¡}tj tj |¡¡}t ˆjd ¡}| d¡rD| d¡rDtj ˆj|dd… ¡}tj tj ||¡¡}t d|¡}t |¡}ˆj dˆj jjj¡}ˆj jjj}ˆj d	ˆj jjj¡}zˆj jjj  |¡ t!j"|||d
�}W n/ t#y¡ } zˆ $dˆjt%|ƒf ¡‚d}~w t&y¸ } zˆ $dˆjt'|ƒf ¡‚d}~ww ˆj dd¡}	ˆj dd¡}
z|	sÎ|
durÜ| (¡ }d ||	|
… ¡}n| )¡ }W n t*yù } zˆ $dˆjt'|ƒf ¡‚d}~ww ˆj dd¡}|�r | +|¡}|dk �rˆ $dˆj ¡‚||t,|ƒ d… }ˆj dd¡}|�rB| +|¡}|dk �r<ˆ $dˆj ¡‚|d|… }t-j.||dd�‰ t/ˆ ƒD ]\}}t,|ƒˆj jjj0k�rhˆ d||d f ¡‚�qNdˆjv �rø|dk�r{| 1|¡}n|}tj2||ˆj dg ¡d�}d|_3ˆ 4|¡ dˆjv �rîzt5ˆjd �p¡dƒ}	W n t6�y±   ˆ 7d¡‚w |	t,ˆ ƒ }
| d¡�rÄ|dd… }t8g |fg|	|
ƒ}|D ]\}}|�râ|tj9|||d�7 }�qÏ|t :|¡7 }�qÏ|gS |t :|¡7 }|gS dˆjv �r(|ˆjd < |dk �r| ;¡ ‰ t<ˆjˆj =d¡gˆjˆ ˆj	ˆj>ˆj?ˆj ˆjƒ	}| @¡ S d!ˆjv �rIˆjd! ƒ }t A|ˆj jj¡}| Bd ˆ ¡|¡ |jCS t d|¡}|	|
||f}ˆj jjD}|�sf|d"tEjFd# fg}‡fd$d%„|D ƒ}||fd&d%„ |D ƒv �r•ˆ d'ˆjd( |gd)d%„ |ddd… D ƒ ¡f ¡‚ˆj Gˆ |¡ | H||ˆj	f¡ ‡ fd*d%„|D ƒˆj j_Dg S )+z8Include a file as part of the content of this reST file.ú"%s" directive disabled.r   r   ú<ú>éÿÿÿÿNr   r   ©Úsource_pathr   Úerror_handlerzVProblems with "%s" directive path:
Cannot encode input file path "%s" (wrong locale?).ú&Problems with "%s" directive path:
%s.r   r   Ú úProblem with "%s" directive:
%sr   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Ú
)r.   r   r-   r   )NNNNé   c                    s   g | ]}|d  ˆ j kr|‘qS ©r0   )Úlineno)Ú.0Úentry©Úself© úF/usr/lib/python3/dist-packages/docutils/parsers/rst/directives/misc.pyÚ
<listcomp>¼   s    ÿzInclude.run.<locals>.<listcomp>c                 S   s   g | ]	\}}}||f‘qS r7   r7   ©r3   ÚpthÚoptÚer7   r7   r8   r9   ¾   s    ÿz(circular inclusion in "%s" directive: %sz < c                 S   s   g | ]\}}}|‘qS r7   r7   r:   r7   r7   r8   r9   Á   s    c                    s(   g | ]\}}}|||t ˆ ƒ d  f‘qS r1   )Úlenr:   )Úinclude_linesr7   r8   r9   Ç   s    ÿ)IÚstateÚdocumentÚsettingsÚfile_insertion_enabledÚwarningr    Ústate_machineÚinput_linesr-   r2   Úinput_offsetÚosÚpathÚdirnameÚabspathr   Ú	argumentsÚ
startswithÚendswithÚjoinÚstandard_include_pathÚnormpathr   Úrelative_pathr   ÚreprunicodeÚoptionsÚgetÚinput_encodingÚinput_encoding_error_handlerÚ	tab_widthÚrecord_dependenciesÚaddr   Ú	FileInputÚUnicodeEncodeErrorÚseverer   ÚIOErrorr   Ú	readlinesÚreadÚUnicodeErrorÚfindr>   r   Ústring2linesÚ	enumerateÚline_length_limitÚ
expandtabsÚliteral_blockÚlineÚadd_nameÚintÚ
ValueErrorÚerrorr   ÚinlineÚTextÚ
splitlinesr   ÚpopÚcontent_offsetÚ
block_textÚrunÚnew_documentÚparseÚchildrenÚinclude_logÚsysÚmaxsizeÚinsert_inputÚappend)r6   r-   Ú
source_dirrI   r   Ú	e_handlerrX   Úinclude_filerl   Ú	startlineÚendlineÚlinesÚrawtextÚ
after_textÚafter_indexÚbefore_textÚbefore_indexÚirh   Útextrg   Útokensr.   ÚvalueÚ	codeblockr   rA   Úclip_optionsrw   r7   )r?   r6   r8   rs   7   s  ÿ
ÿÿ
þý€ÿ€ÿ€ÿ€ÿ

ÿ

ÿÿ
ÿÿ
ÿ

ÿ
ÿÿ

ø	

ÿ
ÿÿ
ÿzInclude.runN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úrequired_argumentsÚoptional_argumentsÚfinal_argument_whitespacer   ÚflagÚ	unchangedr   Úparser_namerj   Úunchanged_requiredÚclass_optionÚoption_specrH   rI   rO   ÚdocutilsÚ_datadirr   Ú__file__rP   rs   r7   r7   r7   r8   r      s,    
ôÿr   c                   @   s:   e Zd ZdZdZdZdZejej	ej
dœZdZd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   c              
   C   sê  | j jjjr| j jjjsd| jv sd| jv r|  d| j ¡‚dd | j	d  
¡  ¡ ¡i}| j d| j jjj¡}| j jjj}| jrZd| jv sJd| jv rR|  d| j ¡‚d	 | j¡}�nd| jv rÝd| jv rl|  d
| j ¡‚tj tj | j jj¡¡}tj tj || jd ¡¡}t d |¡}ztj|||d�}| j jjj |¡ W n ty¸ } z|  d| jt|ƒf ¡‚d }~ww z|  ¡ }W n t!y× } z|  d| jt|ƒf ¡‚d }~ww ||d< n€d| jv �rY| jd }	t"j#dkrúddl$m%}
 ddl&m'} nddl(m%}
m'} z|
|	ƒ  ¡ }W n  |tt)f�y* } z|  d| j| jd t|ƒf ¡‚d }~ww tj*||	||d�}z|  ¡ }W n t!�yS } z|  d| jt|ƒf ¡‚d }~ww |	|d< n|  +¡  t,j-d|fi |¤Ž}| j. /| j0¡\|_1|_2|gS )Nrž   rŸ   r"   Ú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.r&   r)   r+   r-   ©é   r   )Úurlopen)ÚURLError)r¤   r¥   z*Problems with "%s" directive URL "%s":
%s.)r-   r'   r   r(   r*   )3r@   rA   rB   Úraw_enabledrC   rT   rD   r    rO   rL   ÚlowerÚsplitrU   rV   rW   Úcontentrl   rH   rI   rJ   rK   Úcurrent_sourcerQ   r   rR   r   r[   rY   rZ   r^   r]   r   r`   ra   rx   Úversion_infoÚurllib.requestr¤   Úurllib.errorr¥   Úurllib2ÚOSErrorÚStringInputÚassert_has_contentr   ÚrawrE   Úget_source_and_liner2   r-   rh   )r6   Ú
attributesr   r}   rˆ   r|   rI   Úraw_filerl   r-   r¤   r¥   Úraw_textÚraw_noder7   r7   r8   rs   ß   s®   
ÿ

ÿÿÿ

ÿÿÿÿþÿ€ÿÿ€ÿ


ÿ€ÿþÿ€ÿ
ÿzRaw.runN)r�   rŽ   r�   r�   r‘   r’   r“   r   rI   Úurir   r™   Úhas_contentrs   r7   r7   r7   r8   r�   Ì   s    	þr�   c                   @   ó   e Zd ZdZdd„ ZdS )ÚReplaceTc                 C   sÈ   t | jtjƒs|  d| j ¡‚|  ¡  d | j¡}t	 
|¡}| j | j| j|¡ d }g }|D ],}|s;t |t	jƒr;|}q.t |t	jƒrKg |d< | |¡ q.| jjjd| j | jd�g  S |rb||j S |S )NúVInvalid context: the "%s" directive can only be used within a substitution definition.r/   Úbackrefsz=Error in "%s" directive: may contain a single paragraph only.©rh   )Ú
isinstancer@   r   ÚSubstitutionDefrl   r    r±   rO   r©   r   ÚElementÚnested_parserq   Ú	paragraphÚsystem_messager{   rE   Úreporterr2   rv   )r6   rˆ   ÚelementÚnodeÚmessagesÚelemr7   r7   r8   rs   .  s<   ÿÿ
ÿÿþÿ
zReplace.runN©r�   rŽ   r�   r¹   rs   r7   r7   r7   r8   r»   *  ó    r»   c                   @   s@   e Zd ZdZdZdZdZejejejdœZ	e
 d¡Zd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                 C   sê   t | jtjƒs|  d| j ¡‚| jj}d| jv r"d|j	d< d|j	d< d| jv r,d|j	d< d| jv r6d|j	d< | j
 | jd ¡d  ¡ }t ¡ }|D ](}zt |¡}W n tyi } z|  d|t|ƒf ¡‚d }~ww |t |¡7 }qI|jS )Nr¼   rÍ   r   rÎ   rÏ   r   zInvalid character code: %s
%s)r¿   r@   r   rÀ   rl   r    rE   rÇ   rT   r´   Úcomment_patternr¨   rL   r   rÁ   r   Úunicode_coderk   r   rn   rv   )r6   Úsubstitution_definitionÚcodesrÆ   r   Údecodedrl   r7   r7   r8   rs   ]  s6   ÿÿ







ÿ€ÿzUnicode.runN)r�   rŽ   r�   r�   r‘   r’   r“   r   r”   r™   ÚreÚcompilerÐ   rs   r7   r7   r7   r8   rÌ   J  s    þ
rÌ   c                   @   s(   e Zd ZdZdZdZdZdZd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              	   C   sÂ   z
t  | jd ¡}W n ty   |  d| j| jd f ¡‚w g }| jrFt ¡ }| j	 
| j| j|¡ |D ]	}|d  |¡ q4| |j¡ |S t tj|| jdœ| j¡}| jj |¡ | |¡ |S )Nr   z7Invalid class attribute value for "%s" directive: "%s".r.   )r   Ú	directive)r   r˜   rL   rk   rl   r    r©   r   rÁ   r@   rÂ   rq   Úextendrv   Úpendingr   ÚClassAttributerr   rE   rA   Únote_pendingr{   )r6   Úclass_valueÚ	node_listÚ	containerrÇ   rÚ   r7   r7   r8   rs   ƒ  s6   ÿÿÿÿú
ý
z	Class.runN)	r�   rŽ   r�   r�   r‘   r’   r“   r¹   rs   r7   r7   r7   r8   r×   v  s    r×   c                   @   s0   e Zd ZdZe dejjfd  ¡Z	dd„ Z
dS )ÚRoleTz(%s)\s*(\(\s*(%s)\s*\)\s*)?$r0   c              
   C   s  | j | jks	| js|  d| j ¡‚| jd }| j |¡}|s(|  d| j|f ¡‚| d¡}| d¡}g }|rbt 	|| j
j| j| jj¡\}}|du ra| jjjd| t | j| j¡| jd�}||g S ntj}t|d	ƒrsJ d
| j|f ƒ‚zt|ƒ}| jj| jdd… | j |i d�\}	}
}}W n. tjy» } z!| j
jjd| j|f t | j| j¡| jd�}||g W  Y d}~S d}~ww d|
vrùz	t |¡|
d< W n/ tyø } z#| j
jjd| jt|ƒf t | j| j¡| jd�}||g W  Y d}~S d}~ww t |||
|¡}t ||¡ |S )z?Dynamically create and register a custom interpreted text role.z4"%s" directive requires arguments on the first line.r   z4"%s" directive arguments not valid role names: "%s".r   r£   Nú#Unknown interpreted text role "%s".r¾   rL   z[Supplemental directive arguments for "%s" directive not supported (specified by "%r" role).)Úoption_presetszError in "%s" directive:
%s.r   z(Invalid argument for "%s" directive:
%s.)rq   r2   r©   rl   r    Úargument_patternÚmatchÚgroupr   ÚrolerE   Úlanguager@   rÅ   r   rg   rr   Úgeneric_custom_roleÚhasattrr   Úparse_directive_blockr   ÚMarkupErrorr   r˜   rk   r   Ú
CustomRoleÚregister_local_role)r6   Úargsrä   Únew_role_nameÚbase_role_namerÈ   Ú	base_rolerl   Úconverted_rolerL   rT   r©   rq   Údetailræ   r7   r7   r8   rs   £  s†   ÿ
ÿ

þý
ûÿÿþÿý€ûÿÿý€ûzRole.runN)r�   rŽ   r�   r¹   rÕ   rÖ   r   ÚInlinerÚ
simplenamerã   rs   r7   r7   r7   r8   rà   œ  s    ÿrà   c                   @   ó    e Zd ZdZdZdZdd„ ZdS )ÚDefaultRolez&Set the default interpreted text role.r   Fc                 C   sŠ   | j sdtjv rtjd= g S | j d }t || jj| j| jj¡\}}|d u r>| jjj	d| t
 | j| j¡| jd�}||g S |tjd< |S )Nr*   r   rá   r¾   )rL   r   Ú_rolesræ   rE   rç   r2   r@   rÅ   rl   r   rg   rr   )r6   Ú	role_nameræ   rÈ   rl   r7   r7   r8   rs   à  s"   


ÿý

zDefaultRole.runN)r�   rŽ   r�   r�   r’   r“   rs   r7   r7   r7   r8   r÷   Ù  s
    r÷   c                   @   rö   )ÚTitler   r   Tc                 C   s   | j d | jjd< g S )Nr   Útitle)rL   rE   rA   r5   r7   r7   r8   rs   ù  s   z	Title.runN)r�   rŽ   r�   r‘   r’   r“   rs   r7   r7   r7   r8   rú   ó  s
    rú   c                   @   rº   )ÚDateTc                 C   sÌ   t | jtjƒs|  d| j ¡‚d | j¡pd}tj	dk r4z	| 
tp"d¡}W n ty3   |  dt ¡‚w t |¡}tj	dk r`z	| tpDd¡}W n ty_   | tpSdd¡}|  d|tf ¡‚w t |¡gS )	Nr¼   r/   z%Y-%m-%dr¢   zutf-8z;Cannot encode date format string with locale encoding "%s".Úreplacez-Error decoding "%s"with locale encoding "%s".)r¿   r@   r   rÀ   rl   r    rO   r©   rx   r«   Úencoder	   r\   rD   ÚtimeÚstrftimeÚdecodeÚUnicodeDecodeErrorr   rn   )r6   Ú
format_strrˆ   r7   r7   r8   rs     s4   ÿÿ
ÿÿ

ÿþzDate.runNrÊ   r7   r7   r7   r8   rü   þ  rË   rü   c                   @   s.   e Zd ZdZdZdZdejiZdZ	dd„ Z
dS )ÚTestDirectivez3This directive is useful only for testing purposes.r   TÚoptionc                 C   sp   | j r#d | j ¡}| jjjd| j| j| jf t 	||¡| j
d�}|gS | jjjd| j| j| jf | j
d�}|gS )Nr/   zBDirective processed. Type="%s", arguments=%r, options=%r, content:r¾   zGDirective processed. Type="%s", arguments=%r, options=%r, content: None)r©   rO   rE   rÅ   Úinfor    rL   rT   r   rg   r2   )r6   rˆ   r  r7   r7   r8   rs   3  s    ÿý	üÿýzTestDirective.runN)r�   rŽ   r�   r�   r’   r“   r   r—   r™   r¹   rs   r7   r7   r7   r8   r  *  s    
r  )'r�   Ú__docformat__rx   Úos.pathrH   rÕ   rÿ   rš   r   r   r   r   Údocutils.utils.error_reportingr   r   r	   Údocutils.parsers.rstr
   r   r   r   r   Ú$docutils.parsers.rst.directives.bodyr   r   Údocutils.parsers.rst.rolesr   Údocutils.transformsr   r   r�   r»   rÌ   r×   rà   r÷   rú   rü   r  r7   r7   r7   r8   Ú<module>   s4    6^ ,&=,