
    zif                        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  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)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                  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   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         j        j        }t          j        | j	        d                   }|
                    d          r'|                    d          r| j        }|dd         }nt          |          j        }t          j        d||z            }| j                            d| j         j        j        j                  }| j         j        j        j        }| j                            d	| j         j        j        j                  }	 t-          j        |||
          }| j         j        j        j                            |           no# t4          $ r" |                     d| j         d| d          t8          $ r8}|                     d| j         dt-          j        |           d          d}~ww xY w| j                            dd          }	| j                            dd          }
	 |	s|
2|                                }d                    ||	|
                   }n|                                 }nE# tB          $ r8}|                     d| j         dt-          j        |          z             d}~ww xY w| j                            dd          }|rR|"                    |          }|dk     r|                     d| j        z            ||tG          |          z   d         }| j                            dd          }|rB|"                    |          }|dk     r|                     d| j        z            |d|         }tI          j%        ||d          }tM          |          D ]I\  }}tG          |          | j         j        j        j'        k    r|                     d||dz   fz            Jd| j        v rP|dk    r|(                    |          }n|}tS          j*        ||| j                            dg                     }d|_+        | ,                    |           d| j        v r	 t[          | j        d         pd          }	n## t\          $ r | /                    d           w xY w|	tG          |          z   }
|                    d!          r
|dd         }ta          g |fg|	|
          }|D ]9\  }}|r|tS          j1        |||"          z  }"|tS          j2        |          z  }:n|tS          j2        |          z  }|gS d#| j        v r|| j        d$<   |dk     r|3                                }ti          | j        | j        5                    d#          g| j        || j6        | j7        | j8        | j         | j9        	  	        }|:                                S |	|
||f}| j         j        j;        }|s*|<                    t          j        d|          d%f           ||f|v rRd& t{          |          D             }d'                    |g|R           }|                     d(| j        d|          d)| j        v rt          j>        || j         j        j                  }|||fgz   |_;         | j        d)                     }|?                    d!                    |          |           |j@        A                    |f           |j@        B                                 |jC        S |dd*|z  gz  }| j9        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   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   | ]	\  }}|V  
d S )N ).0pthopts      o/var/www/tmov.alphamb/tmov_inventario/venv/lib/python3.11/site-packages/docutils/parsers/rst/directives/misc.py	<genexpr>zInclude.run.<locals>.<genexpr>   s&      HHJS#CHHHHHH    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) selfrB   rC   _baser   	e_handlerrN   include_filere   	startlineendlinelinesrawtext
after_textafter_indexbefore_textbefore_indexinclude_linesira   textr`   tokensr3   value	codeblockclip_optionsro   master_pathsinclusion_chainr>   r   s                                    r:   rn   zInclude.run7   s    z"+B 	G,,9DIEFFF,;t~a011??3 	0DMM#$6$6 	0.E":DD((/E"4t44<##
+4CE EJ'0M	L$$,5?A A		G<D196?A A AL J(<@@FFFF " 	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4yy4:.7IIIll $9<@!A#;$G H H H J $$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|##)$
0C0LMMH#.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=   F 4G.63G))G.(A
I3 3
J5=3J00J54R  R1N)__name__
__module____qualname____doc__required_argumentsoptional_argumentsfinal_argument_whitespacer   flag	unchangedr   parser_namerc   unchanged_requiredclass_optionoption_specr   r   __file__rH   rG   rn   r6   r<   r:   r   r      s        
 
  $(o%/)2'3 #!$"","?!+!>#-#7&3%/1 1K !D1189DW W W W 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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                 0   | j         j        j        j        r(| j         j        j        j        s/d| j        v s	d| j        v r|                     d| j        z            dd                    | j	        d         
                                                                          i}| j                            d| j         j        j        j                  }| j         j        j        j        }| j        rKd| j        v s	d| j        v r|                     d| j        z            d	                    | j                  }nd| j        v rWd| j        v r|                     d
| j        z            | j        d         }t#          | j         j        j                  j        }t)          j        d ||z            }	 t-          j        |||          }| j         j        j        j                            |           nE# t4          $ r8}|                     d| j         dt-          j        |           d          d }~ww xY w	 |                                }nE# t<          $ r8}|                     d| j         dt-          j        |          z             d }~ww xY w||d<   n!d| j        v r| j        d         }		 t?          |	                                          }
nZ# t@          t4          f$ rF}|                     d| j         d| j        d          dt-          j        |           d          d }~ww xY wt-          j!        |
|	||          }	 |                                }nE# t<          $ r8}|                     d| j         dt-          j        |          z             d }~ww xY w|	|d<   n| "                                 tG          j$        d|fd| j                            dg           i|}| j%        &                    | j'                  \  |_(        |_)        |gS )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@   rJ   rA   r!   rW   rD   lowersplitrK   rL   rM   contentre   r   rB   rH   r
   rI   r   rO   rP   rQ   rT   rS   rU   rX   rY   r   r   StringInputassert_has_contentr   rawrm   get_source_and_linerj   r2   ra   )ry   
attributesr   r{   r   rC   rz   raw_filere   r2   raw_textraw_nodes               r:   rn   zRaw.run   s   
#,8 	GJ'0G	Gt|++--,,9DIEFFF):)@)@)B)B)H)H)J)J K KL
<##
+4CE EJ'0M	< 2	&%%$,)>)>jj(*.)45 5 5 99T\**DDt|##$$jj8:>)DE E E <'D,;<<CE&tU4Z88D
K<D196?A A A 
#,@DDTJJJJ  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/74=? ? ?H<}} < < <kk"L49"L"L"L$&OE$:$:#; < < << $*Jx   ##%%%9R + +t|/?/?/L/L +)+ + ,@@MM		zsa   2G3 3
H5=3H00H59I 
J3JJ2!K L+%AL&&L+M 
N&3NNN)r   r   r   r   r   r   r   r   rC   urir   r   r   has_contentrn   r6   r<   r:   r   r      so           $%?$.)2&35 5K KA A A A A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.r4   backrefs
Error in "z1" directive: may contain a single paragraph only.ra   )
isinstancer=   r   SubstitutionDefre   r!   r   rW   r   r   Elementnested_parserk   	paragraphsystem_messagerp   reporterrj   rw   )ry   r   elementnodemessageselems         r:   rn   zReplace.run-  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   rn   r6   r<   r:   r   r   )  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: r4   )r   r=   r   r   re   r!   rm   r   rJ   r   comment_patternr   rD   r   r   r   unicode_coderd   r   rU   rg   rw   )ry   substitution_definitioncodesr   r   decodedre   s          r:   rn   zUnicode.run]  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   rn   r6   r<   r:   r   r   J  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: "".r3   )r    	directive)r   r   rD   rd   re   r!   r   r   r   r=   r   rk   extendrw   pendingr   ClassAttributerl   rm   r>   note_pendingrp   )ry   class_value	node_list	containerr   r   s         r:   rn   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   rn   r6   r<   r:   r   r   v  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   rD   z&Supplemental directive arguments for "z)" directive not supported (specified by "z" role).)option_presetsr   r0   r-   r    zInvalid argument for ")rk   rj   r   re   r!   argument_patternmatchgroupr   rolerm   languager=   r   r   r`   rl   generic_custom_rolehasattrr   parse_directive_blockr   MarkupErrorr   r   rd   
CustomRoleregister_local_role)ry   argsr   new_role_namebase_role_namer   	base_rolere   converted_rolerD   rJ   r   rk   detailr   s                  r:   rn   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   rn   r6   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   )rD   r   _rolesr   rm   r   rj   r=   r   re   r   r`   rl   )ry   	role_namer   r   re   s        r:   rn   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   rn   r6   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)rD   rm   r>   )ry   s    r:   rn   z	Title.run  s    /3~a/@#G,	r<   N)r   r   r   r   r   r   rn   r6   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.)	parsemetarH   )ry   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
   escape2nullrm   get_first_known_indentedendmetarW   ra   r   infor`   r   extract_name_valuer   NameValueErrorre   )ry   r   r!   indentedindentline_offsetr  r   ra   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  r6   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   r=   nested_list_parser   rk   SMkwargsr[   r   re   r`   rl   rj   r>   first_child_not_matching_classTitularr  rw   )ry   r   new_line_offsetr  re   indexs         r:   rn   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!  rn   r6   r<   r:   r  r  (  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   r4   z%Y-%m-%d)r   r=   r   r   re   r!   rW   r   timestrftimer   rg   )ry   
format_strr   s      r:   rn   zDate.runG  s|    $*f&<== 	:**-/3y9: : : YYt|,,:

" }Z((
4  !!r<   Nr   r6   r<   r:   r'  r'  C  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 )Nr4   zDirective processed. Type="z", arguments=z
, options=z
, content:r   z, content: None)
r   rW   r   r  r!   rD   rJ   r   r`   rj   )ry   r   r  s      r:   rn   zTestDirective.runj  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   rn   r6   r<   r:   r-  r-  a  sG        == $Z:;KK    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   SpecializedBodyr  r  r'  r-  r6   r<   r:   <module>r9     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 $ $ $ $ $ $x x x x xi x x xvU U U U U) U U Up    i   B)  )  )  )  ) i )  )  ) X# # # # #I # # #L; ; ; ; ;9 ; ; ;|    )   4    I   &" &" &" &" &"v% &" &" &"R    9   6" " " " "9 " " "<    I     r<   