
    -Ph7X                        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	#  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   c                       e Zd ZdS )
InputErrorN__name__
__module____qualname__     K/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/docutils/io.pyr   r   +             r   r   c                       e Zd ZdS )OutputErrorNr	   r   r   r   r   r   ,   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   /   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   ?   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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__U   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__i   s(    26...$+++262B2BD 	Dr   c                     t           )z,Return input as `str`. Define in subclasses.NotImplementedErrorr.   s    r   readz
Input.readm       !!r   c                    | j         r<| j                                         dk    rt          |t                    s
J d            t          |t                    r|S | j         r	| j         g}nb|                     |          }|r|g}nGdg}t          j        d          }|r-|                                dk    r|                    |           |D ]C}	 t          ||| j                  }|| _	        |c S # t          t          f$ r}|}Y d}~<d}~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 and the locale's preferred encoding.
        The client application should call ``locale.setlocale()`` at the
        beginning of processing::

            locale.setlocale(locale.LC_ALL, '')

        Raise UnicodeError if unsuccessful.

        Provisional: encoding detection will be removed in Docutils 1.0.
        unicodez;input encoding is "unicode" but `data` is no `str` instancezutf-8F)do_setlocaleNz=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getpreferredencodingappendr&   r*   UnicodeErrorr   joinr   )	r+   dataencoding_candidatesdata_encodingfallbackr;   decodedr   errors	            r   decodezInput.decodeq   s   " = 	NT]0022i??dC(( N N ,M N N NdC   	K= 	9 $(=/ ==dCCM 9'4o##
 (/i#!6EJJJ 9 0 0G ; ;'..x888& 	 	CdC);<<+.( +.    'yyBB.ABBBBB' 'U##' ' '( ( 	(s   C33DDDs   coding[:=]\s*([-\w.]+)zutf-32z	utf-8-sigzutf-16c                    | 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+   rH   start_bytesr   linematchs         r   rB   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,   r/   r3   rN   recompilerU   r   BOM_UTF32_BEBOM_UTF32_LEBOM_UTF8BOM_UTF16_BEBOM_UTF16_LErR   rB   r\   r   r   r   r!   r!   E   s        	 	 N?C'F F F F(D D D" " "4( 4( 4(l "*788K',h7,h7+6,h7,h7	-       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+   rl   rm   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   rl   rm   r.   s    r   r/   zOutput.__repr__   s*    >>>4#3#3#3T5J5JL 	Mr   c                     t           )z#Write `data`. Define in subclasses.r1   r+   rH   s     r   writezOutput.write   r4   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.
        r6   z<output encoding is "unicode" but `data` is no `str` instance)r   r?   r@   rA   encoder&   rq   s     r   rt   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`   rn   r,   r/   rr   rt   r   r   r   ri   ri      s~        	 	 N#:>.6B B B B"M M M" " "B B B B Br   ri   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backslashreplacereplacec                     |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stderrr@   rA   openrl   getattr_locale_encodingr   encoding_errorsdecoding_errors)r+   rl   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)rl   r@   	ExceptionrA   rr   UnicodeEncodeErrorrt   r   r   r   r{   r|   stdoutbufferr   rq   s     r   rr   zErrorOutput.write2  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)rl   r{   r   r|   closer   r.   s    r   r   zErrorOutput.closeL  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)rl   r\   r   r.   s    r   r\   zErrorOutput.isattyZ  s>    	#**,,, 	 	 	55	r]   )NNrw   rx   )r
   r   r   r_   r,   rr   r   r\   r   r   r   rv   rv   
  sn          37!3!*& & & &BB B B4      r   rv   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                      | _        |e|rQ	 t          ||| j        | 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 for reading.
            - `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').
        Nr   errorsFz#Encoding clash: encoding given is "z&" but source is opened with encoding "z".)r!   r,   	autocloserv   _stderrr}   r   r&   r'   OSErrorr   errnostrerrorr{   stdinr   rF   namer(   r   )r+   r'   r(   r   r&   r   moderM   s           r   r,   zFileInput.__init__g  sO    	tV[(MJJJ""}}> (O"&{D04.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$C7 7
DDc                    	 | j         stt          | j        d          r_| j        j                                        }|                     |          }d                    |                                dgz             }n| j                                        }| j        r| 	                                 n!# | j        r| 	                                 w w xY w|S )zA
        Read and decode a single file, return as `str`.
        r   
 )
r   hasattrr'   r   r3   rN   rG   rT   r   r   rq   s     r   r3   zFileInput.read  s    	= *WT[(%C%C *{)..00{{4((yy!2!2B4!788{''))~ 

 ~ 

s   BB2 2Cc                 P    |                                                      d          S )zC
        Return lines of a single file as list of strings.
        T)r3   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'   r{   r   r   r.   s    r   r   zFileInput.close  s3    ;ci''K ('r   )NNNr#   Tr   )r
   r   r   r_   r,   r3   r   r   r   r   r   r   r   b  sk          15.6&)& & & &P  &, , ,         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>rz   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)ri   r,   openedr   warningswarnDeprecationWarningr   rv   r   r{   r   rl   r   printr   rm   r   )r+   rl   rm   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&   r}   rm   rl   r   r   r   r   r   )r+   kwargsrM   s      r   r}   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   r}   r@   rA   r   rl   r   oslineseprx   rt   rr   r   bytesr   r   
ValueErrorrm   rF   r   r   r   r   )r+   rH   r   s      r   rr   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)rl   r{   r   r|   r   r   r.   s    r   r   zFileOutput.close$  sA    CJ
#;;;""$$$DKKK <;r   )NNNr#   TNN)
r
   r   r   r_   rn   r   r,   r}   rr   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   *  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   r3   zStringInput.read8  s    
 {{4;'''r   Nr
   r   r   r_   r)   r3   r   r   r   r   r   3  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).
        )rt   rl   rq   s     r   rr   zStringOutput.writeH  s!      ;;t,,r   Nr
   r   r   r_   rn   rr   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.r   r   r.   s    r   r3   zNullInput.reada  s    rr   Nr   r   r   r   r   r   [  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   rq   s     r   rr   zNullOutput.writel  s    r   Nr   r   r   r   r   r   f  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   r3   zDocTreeInput.read{  s
    {r   Nr   r   r   r   r   r   q  s5          *    r   r   )#r_   __docformat__r   rC   r   ra   r{   r   docutilsr   catch_warningssimplefilter	getlocalegetdefaultlocaler   r?   r   r   r   r   r   r   r   r   r!   ri   rv   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                      '         . . .D D D D DM D D DN;B ;B ;B ;B ;B] ;B ;B ;B|U U U U U U U UpH  H  H  H  H  H  H  H Vz  z  z  z  z  z  z  z z    z   
( 
( 
( 
( 
(% 
( 
( 
(         6      6                  5     sA   B ABB BB BB B $B5 5	C C