
    zi]                     8   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Zddlm	Z	 	  ej
                    5   ej        d            ej                    d         p ej                    d         Ze                                Zddd           n# 1 swxY w Y   n$# e$ rZdej        v rdZndZY dZ[ndZ[w dZY nxY w	  ej        e           n# eef$ r dZY nw xY w G d	 d
e          Z G d de          Zd Zd Z G d de	          Z G d de	          Z G 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%dS )%z
I/O classes provide a uniform API for low-level input and output.  Subclasses
exist for a variety of input/output mechanisms.
reStructuredText    N)TransformSpecignore   zunknown locale: UTF-8utf-8c                       e Zd ZdS )
InputErrorN__name__
__module____qualname__     V/var/www/tmov.alphamb/tmov_inventario/venv/lib/python3.11/site-packages/docutils/io.pyr	   r	   3             r   r	   c                       e Zd ZdS )OutputErrorNr
   r   r   r   r   r   4   r   r   r   c                     	 t          j        | j                  t          j        |          k    S # t          t          t
          f$ r Y dS w xY w)aN  Test, whether the encoding of `stream` matches `encoding`.

    Returns

    :None:  if `encoding` or `stream.encoding` are not a valid encoding
            argument (e.g. ``None``) or `stream.encoding is missing.
    :True:  if the encoding argument resolves to the same value as `encoding`,
    :False: if the encodings differ.
    N)codecslookupencodingLookupErrorAttributeError	TypeError)streamr   s     r   check_encodingr   7   sQ    }V_--x1H1HHH3   tts   .1 AAc                 $    | j         j         d|  S )z5Return string representation of Exception `err`.
    z: )	__class__r   )errs    r   error_stringr    G   s     m$-----r   c                       e Zd ZdZdZdZ	 	 ddZd Zd Zd Z	 e
j        d	          Z	 ej        d
fej        dfej        dffZ	 d Zd ZdS )Inputah  
    Abstract base class for input wrappers.

    Docutils input objects must provide a `read()` method that
    returns the source, typically as `str` instance.

    Inheriting `TransformSpec` allows input objects to add
    "transforms" and "unknown_reference_resolvers" to the "Transformer".
    (Optional for custom input objects since Docutils 0.19.)
    inputNstrictc                 p    || _         	 || _        	 || _        	 || _        	 |s| j        | _        d | _        d S N)r   error_handlersourcesource_pathdefault_source_pathsuccessful_encoding)selfr(   r)   r   r'   s        r   __init__zInput.__init__]   sM     1**'&- 	8#7D#' EEr   c                 4    | j         d| j        d| j        S )Nz	: source=z, source_path=)r   r(   r)   r,   s    r   __repr__zInput.__repr__q   s(    26...$+++262B2BD 	Dr   c                     t           )z,Return input as `str`. Define in subclasses.NotImplementedErrorr/   s    r   readz
Input.readu       !!r   c                    | j         r<| j                                         dk    rt          |t                    s
J d            t          |t                    r|S | j         r	| j         g}n_|                     |          }|r|g}nDdg}t
          r%t
          dk    r|                    t
                     |                    d           |D ]W}	 t          ||| j                  }|| _        |	                    dd          c S # t          t          f$ r}|}Y d}~Pd}~ww xY wt          dd	                    d
 |D                        dt          |           d          )a  
        Decode `data` if required.

        Return Unicode `str` instances unchanged (nothing to decode).

        If `self.encoding` is None, determine encoding from data
        or try UTF-8, locale encoding, and (as last ressort) 'latin-1'.
        The client application should call ``locale.setlocale`` at the
        beginning of processing::

            locale.setlocale(locale.LC_ALL, '')

        Raise UnicodeError if unsuccessful.

        Provisional:
          - Raise UnicodeError (instead of falling back to the locale
            encoding) if decoding the source with the default encoding (UTF-8)
            fails and Python is started in `UTF-8 mode`.

            Raise UnicodeError (instead of falling back to "latin1") if both,
            default and locale encoding, fail.

          - Only remove BOM (U+FEFF ZWNBSP at start of data),
            no other ZWNBSPs.
        unicodez;input encoding is "unicode" but `data` is no `str` instancer   zlatin-1u   ﻿ Nz=Unable to decode input data.  Tried the following encodings: z, c              3   4   K   | ]}t          |          V  d S r&   )repr).0encs     r   	<genexpr>zInput.decode.<locals>.<genexpr>   s(      BBscBBBBBBr   .
())r   lower
isinstancestrdetermine_encoding_from_data_locale_encodingappendr'   r+   replaceUnicodeErrorr   joinr    )r,   dataencoding_candidatesdata_encodingr<   decodedr   errors           r   decodezInput.decodey   s   4 = 	NT]0022i??dC(( N N ,M N N NdC   	K= 	6 $(=/ ==dCCM 6 (5o##
 (/i# $ A(8G(C(C'../?@@@#**9555& 
	 
	C	dC);<<+.( x44444 +.    'yyBB.ABBBBB' 'U##' ' '( ( 	(s   2DD!DD!s   coding[:=]\s*([-\w.]+)r   z	utf-16-bez	utf-16-lec                    | j         D ]\  }}|                    |          r|c S |                                dd         D ]H}| j                            |          }|r*|                    d                              d          c S IdS )z
        Try to determine the encoding of `data` by looking *in* `data`.
        Check for a byte order mark (BOM) or an encoding declaration.
        N   r   ascii)byte_order_marks
startswith
splitlinescoding_slugsearchgrouprN   )r,   rI   start_bytesr   linematchs         r   rC   z"Input.determine_encoding_from_data   s     &*%: 	  	 !K{++    OO%%bqb) 	6 	6D$++D11E 6{{1~~,,W555556tr   c                 X    	 | j                                         S # t          $ r Y dS w xY w)z>Return True, if the input source is connected to a TTY device.F)r(   isattyr   r/   s    r   r\   zInput.isatty   s=    	;%%''' 	 	 	55	    
))NNNr$   )r   r   r   __doc__component_typer*   r-   r0   r4   rN   recompilerU   r   BOM_UTF8BOM_UTF16_BEBOM_UTF16_LErR   rC   r\   r   r   r   r"   r"   M   s        	 	 N?C'F F F F(D D D" " "D( D( D(L "*788K''2,k:,k:=-       r   r"   c                   8    e Zd ZdZdZdZ	 	 d	dZd Zd Zd Z	dS )
Outputak  
    Abstract base class for output wrappers.

    Docutils output objects must provide a `write()` method that
    expects and handles one argument (the output).

    Inheriting `TransformSpec` allows output objects to add
    "transforms" and "unknown_reference_resolvers" to the "Transformer".
    (Optional for custom output objects since Docutils 0.19.)
    outputNr$   c                 j    || _         	 |pd| _        	 || _        	 || _        	 |s| j        | _        d S d S )Nr$   )r   r'   destinationdestination_pathdefault_destination_path)r,   rj   rk   r   r'   s        r   r-   zOutput.__init__   sX     7*6h*&. 02 	B$($AD!!!	B 	Br   c                 4    | j         d| j        d| j        S )Nz: destination=z, destination_path=)r   rj   rk   r/   s    r   r0   zOutput.__repr__  s*    >>>4#3#3#3T5J5JL 	Mr   c                     t           )z#Write `data`. Define in subclasses.r2   r,   rI   s     r   writezOutput.write  r5   r   c                     | j         r>| j                                         dk    r!t          |t                    s
J d            |S t          |t                    s|S |                    | j         | j                  S )a?  
        Encode and return `data`.

        If `data` is a `bytes` instance, it is returned unchanged.
        Otherwise it is encoded with `self.encoding`.

        Provisional: If `self.encoding` is set to the pseudo encoding name
        "unicode", `data` must be a `str` instance and is returned unchanged.
        r7   z<output encoding is "unicode" but `data` is no `str` instance)r   r@   rA   rB   encoder'   ro   s     r   rr   zOutput.encode
  s     = 	T]0022i??dC(( N N ,M N N NK$$$ 	BK;;t}d.@AAAr   r^   )
r   r   r   r_   r`   rl   r-   r0   rp   rr   r   r   r   rg   rg      s~        	 	 N#:>.6B B B B"M M M" " "B B B B Br   rg   c                   2    e Zd ZdZ	 	 	 d	dZd Zd Zd ZdS )
ErrorOutputz
    Wrapper class for file-like error streams with
    failsafe de- and encoding of `str`, `bytes`, `unicode` and
    `Exception` instances.
    NbackslashreplacerF   c                     |t           j        }n*|sd}n%t          |t                    rt	          |d          }|| _        	 |pt          |dd          pt          pd| _        	 || _	        	 || _
        dS )a  
        :Parameters:
            - `destination`: a file-like object,
                        a string (path to a file),
                        `None` (write to `sys.stderr`, default), or
                        evaluating to `False` (write() requests are ignored).
            - `encoding`: `destination` text encoding. Guessed if None.
            - `encoding_errors`: how to treat encoding errors.
        NFwr   rQ   )sysstderrrA   rB   openrj   getattrrD   r   encoding_errorsdecoding_errors)r,   rj   r   r|   r}   s        r   r-   zErrorOutput.__init__&  s     *KK 	1KKS)) 	1{C00K&+! 8W[*d%K%K 8,807 	,.%.%%r   c                    | j         sdS t          |t                    rt          |          }	 | j                             |           dS # t
          $ r< | j                             |                    | j        | j                             Y dS t          $ r t          |t                    r;| j                             |                    | j        | j                             Y dS | j         t          j        t          j        fv r"| j         j                            |           Y dS | j                             t          || j        | j                             Y dS w xY w)z
        Write `data` to self.destination. Ignore, if self.destination is False.

        `data` can be a `bytes`, `str`, or `Exception` instance.
        N)rj   rA   	ExceptionrB   rp   UnicodeEncodeErrorrr   r   r|   r   rx   ry   stdoutbufferr}   ro   s     r   rp   zErrorOutput.writeG  s     	FdI&& 	t99D	B""4(((((! 	F 	F 	F""4;;t}/3/C$E $E F F F F F F 		B 		B 		B$$$ B &&t{{4=373G(I (I J J J J J J!cj#*%=== '--d333333 &&s4+/+?(A (A B B B B B B		Bs%   A AE!AE!)>E!*3E! E!c                     | j         t          j        t          j        fv rdS 	 | j                                          dS # t
          $ r Y dS w xY w)z
        Close the error-output stream.

        Ignored if the destination is` sys.stderr` or `sys.stdout` or has no
        close() method.
        N)rj   rx   r   ry   closer   r/   s    r   r   zErrorOutput.closea  sb     
CJ777F	""$$$$$ 	 	 	DD	s   > 
AAc                 X    	 | j                                         S # t          $ r Y dS w xY w)z=Return True, if the destination is connected to a TTY device.F)rj   r\   r   r/   s    r   r\   zErrorOutput.isattyo  s>    	#**,,, 	 	 	55	r]   )NNru   rF   )r   r   r   r_   r-   rp   r   r\   r   r   r   rt   rt     sn          37!3!*& & & &BB B B4      r   rt   c                   2    e Zd ZdZ	 	 	 d
dZd Zd Zd	 ZdS )	FileInputz5
    Input for single, simple file-like objects.
    Nr$   Trc                    t                               | ||||           || _        t                      | _        |g|rS	 t          ||| j        pd| j                  | _        n# t          $ r }t          |j        |j        |          d}~ww xY wt          j        | _        nAt          | j        | j                  du r%t!          d| j        d| j        j        d          |s%	 | j        j        | _        dS # t&          $ r Y dS w xY wdS )a  
        :Parameters:
            - `source`: either a file-like object (which is read directly), or
              `None` (which implies `sys.stdin` if no `source_path` given).
            - `source_path`: a path to a file, which is opened and then read.
            - `encoding`: the expected text encoding of the input file.
            - `error_handler`: the encoding error handler to use.
            - `autoclose`: close automatically after read (except when
              `sys.stdin` is the source).
            - `mode`: how the file is to be opened (see standard function
              `open`). The default is read only ('r').
        Nz	utf-8-sigr   errorsFz#Encoding clash: encoding given is "z&" but source is opened with encoding "z".)r"   r-   	autoclosert   _stderrrz   r   r'   r(   OSErrorr	   errnostrerrorrx   stdinr   rG   namer)   r   )r,   r(   r)   r   r'   r   moderM   s           r   r-   zFileInput.__init__|  sT    	tV[(MJJJ""}}> (O"&{D040L.2.@#B #B #BDKK  O O O$U[%.+NNNO "iDK775@@, $t{/C/C/C E F F F  	#';#3   !   	 	s)   $A# #
B-BB&C9 9
DDc                 ^   	 | j         t          j        u r| j         j                                        }n| j                                         }nd# t
          t          f$ rP | j        sE| j        r>t          | j        d          }|                                }|
                                 n Y nw xY w| j        r| 
                                 n!# | j        r| 
                                 w w xY w|                     |          }d                    |                                dgz             S )zU
        Read and decode a single file and return the data (Unicode string).
        rb
r8   )r(   rx   r   r   r4   rG   r   r   r)   rz   r   r   rN   rH   rT   )r,   rI   b_sources      r   r4   zFileInput.read  s%   	{ci''{)..00{''))k* 	 	 	= T%5  0$77}}     ! 	 ~ 

 ~ 

{{4  yy**B4/000s+   AA C AB/,C .B//C C,c                 P    |                                                      d          S )zK
        Return lines of a single file as list of Unicode strings.
        T)r4   rT   r/   s    r   	readlineszFileInput.readlines  s      yy{{%%d+++r   c                 b    | j         t          j        ur| j                                          d S d S r&   )r(   rx   r   r   r/   s    r   r   zFileInput.close  s3    ;ci''K ('r   )NNNr$   Tr   )r   r   r   r_   r-   r4   r   r   r   r   r   r   r   w  sk          15.6&)& & & &P1 1 12, , ,         r   r   c                   <    e Zd ZdZdZdZ	 	 	 	 ddZd Zd	 Zd
 Z	dS )
FileOutputz,Output for single, simple file-like objects.z<file>rw   Nr$   Tc                    t                               | ||||           d| _        || _        |t	          j        dt          d           ||| _        t                      | _	        ||rd| _        n`t          j        | _        nN|rLt          | j        d          r7|| j        j        k    r't          d| j        j        d	|d
| j	                   |s%	 | j        j        | _        dS # t"          $ r Y dS w xY wdS )aA  
        :Parameters:
            - `destination`: either a file-like object (which is written
              directly) or `None` (which implies `sys.stdout` if no
              `destination_path` given).
            - `destination_path`: a path to a file, which is opened and then
              written.
            - `encoding`: the text encoding of the output file.
            - `error_handler`: the encoding error handler to use.
            - `autoclose`: close automatically after write (except when
              `sys.stdout` or `sys.stderr` is the destination).
            - `handle_io_errors`: ignored, deprecated, will be removed.
            - `mode`: how the file is to be opened (see standard function
              `open`). The default is 'w', providing universal newline
              support for text files.
        TNz_io.FileOutput: init argument "handle_io_errors" is ignored and will be removed in Docutils 2.0.rP   )
stacklevelFr   zWarning: Destination mode "z" differs from specified mode "")file)rg   r-   openedr   warningswarnDeprecationWarningr   rt   r   rx   r   rj   hasattrprintr   rk   r   )r,   rj   rk   r   r'   r   handle_io_errorsr   s           r   r-   zFileOutput.__init__  sT   & 	k+; -	1 	1 	1"'M *+=!M M M M DI"}} .##&:  	%t/88	%$*///E!%!1!6!6!6>|% % % %   	(,(8(=%%%!   	 	s   C) )
C76C7c                     d| j         vr| j        | j        d}ni }	 t          | j        | j         fi || _        n2# t          $ r%}t          |j        |j	        | j                  d }~ww xY wd| _
        d S )Nbr   T)r   r   r'   rz   rk   rj   r   r   r   r   r   )r,   kwargsrM   s      r   rz   zFileOutput.open  s    di"&- $ 24 4FF F	5#D$949OOOOD 	5 	5 	5ek5>"35 5 5	5 s   ; 
A* A%%A*c                    | j         s|                                  t          |t                    rat	          | j        | j                  du rEt          j        dk    r |	                    dt          j                  }| 
                    |          }	 | j                            |           n# t          $ r}t          |t                    rz	 | j        j                            |           nY# t          $ rL t	          | j        | j                  du r-t!          d| j         d| j        j         d| j         d          |w xY wY d}~nDd}~wt$          t&          f$ r-}t%          d| j         d	t)          |           d          d}~ww xY w| j        r|                                  n!# | j        r|                                  w w xY w|S )
aB  Write `data` to a single file, also return it.

        `data` can be a `str` or `bytes` instance.
        If writing `bytes` fails, an attempt is made to write to
        the low-level interface ``self.destination.buffer``.

        If `data` is a `str` instance and `self.encoding` and
        `self.destination.encoding` are  set to different values, `data`
        is encoded to a `bytes` instance using `self.encoding`.

        Provisional: future versions may raise an error if `self.encoding`
        and `self.destination.encoding` are set to different values.
        Fr   zEncoding of z (z&) differs 
  from specified encoding (r?   Nz2Unable to encode output data. output-encoding is: r>   )r   rz   rA   rB   r   rj   r   oslineseprF   rr   rp   r   bytesr   r   
ValueErrorrk   rG   r   r    r   r   )r,   rI   r   s      r   rp   zFileOutput.write  s/    { 	IIKKKtS!! 	%t/??5HHzT!!||D"*55;;t$$D	""4(((( 	" 	" 	"$&& "
"$+11$7777% " " "%d&6&*m5 58=> >(K4+@ K K $ 0 9K K:>-K K KL L L
 "	" k* 	< 	< 	<;=; ;&23&7&7; ; ;< < <	<
 ~ 

 ~ 

sU   B. -F, .
F8EC.-E.AEEF, F (FFF, ,G
c                     | j         t          j        t          j        fvr"| j                                          d| _        d S d S )NF)rj   rx   r   ry   r   r   r/   s    r   r   zFileOutput.close?  sA    CJ
#;;;""$$$DKKK <;r   )NNNr$   TNN)
r   r   r   r_   rl   r   r-   rz   rp   r   r   r   r   r   r     sv        66'D)
 ;?BF-1- - - -^  , , ,\         r   r   c                       e Zd ZdZdZdS )BinaryFileOutputzL
    A version of docutils.io.FileOutput which writes to a binary file.
    wbN)r   r   r   r_   r   r   r   r   r   r   E  s         
 DDDr   r   c                       e Zd ZdZdZd ZdS )StringInputz'Input from a `str` or `bytes` instance.<string>c                 6    |                      | j                  S )z`Return the source as `str` instance.

        Decode, if required (see `Input.decode`).
        )rN   r(   r/   s    r   r4   zStringInput.readS  s    
 {{4;'''r   Nr   r   r   r_   r*   r4   r   r   r   r   r   N  s/        11$( ( ( ( (r   r   c                       e Zd ZdZdZd ZdS )StringOutputz=Output to a `bytes` or `str` instance.

    Provisional.
    r   c                 D    |                      |          | _        | j        S )av  Store `data` in `self.destination`, and return it.

        If `self.encoding` is set to the pseudo encoding name "unicode",
        `data` must be a `str` instance and is stored/returned unchanged
        (cf. `Output.encode`).

        Otherwise, `data` can be a `bytes` or `str` instance and is
        stored/returned as a `bytes` instance
        (`str` data is encoded with `self.encode()`).

        Attention: the `output_encoding`_ setting may affect the content
        of the output (e.g. an encoding declaration in HTML or XML or the
        representation of characters as LaTeX macro vs. literal character).
        )rr   rj   ro   s     r   rp   zStringOutput.writec  s!      ;;t,,r   Nr   r   r   r_   rl   rp   r   r   r   r   r   [  s5         
  *         r   r   c                       e Zd ZdZdZd ZdS )	NullInputzDegenerate input: read nothing.z
null inputc                     dS )zReturn an empty string.r8   r   r/   s    r   r4   zNullInput.read|  s    rr   Nr   r   r   r   r   r   v  s/        ))&    r   r   c                       e Zd ZdZdZd ZdS )
NullOutputz!Degenerate output: write nothing.znull outputc                     dS )zDo nothing, return None.Nr   ro   s     r   rp   zNullOutput.write  s    r   Nr   r   r   r   r   r     s/        ++,    r   r   c                       e Zd ZdZdZd ZdS )DocTreeInputzm
    Adapter for document tree input.

    The document tree must be passed in the ``source`` parameter.
    zdoctree inputc                     | j         S )zReturn the document tree.)r(   r/   s    r   r4   zDocTreeInput.read  s
    {r   Nr   r   r   r   r   r     s5          *    r   r   )&r_   __docformat__r   localer   ra   rx   r   docutilsr   catch_warningssimplefilter	getlocalegetdefaultlocalerD   r@   r   rM   argsr   r   r   r   r	   r   r   r    r"   rg   rt   r   r   r   r   r   r   r   r   r   r   r   <module>r      s  
 
 #   				 				 



  " " " " " "	 	 	"	" 4 4h''',F,..q1 <6v688; 	+1133	4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
        %*,,"FM"####Y                      '         . . .Q Q Q Q QM Q Q Qh;B ;B ;B ;B ;B] ;B ;B ;B|U U U U U U U UpN  N  N  N  N  N  N  N bz  z  z  z  z  z  z  z z    z   
( 
( 
( 
( 
(% 
( 
( 
(         6      6                  5     sM   B ABB BB BB B;B22B;?C 	CC