
    Kid                       U d Z ddlm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 dZerddlmZmZmZmZmZmZ ddl
mZ dd	lmZ 	  e	j.                         5   e	j0                  d
        ej2                         d   xs  ej4                         d   j7                         Zded<   ddd       	  ej<                  e        G d de!      Z" G d de!      Z#d*dZ$d+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&      Z0y# 1 sw Y   xY w#  dZY xY w# ee f$ r dZY w xY w),z
I/O classes provide a uniform API for low-level input and output.  Subclasses
exist for a variety of input/output mechanisms.
    )annotationsreStructuredTextN)TransformSpecF)AnyBinaryIOClassVarFinalLiteralTextIO)nodes)StrPathignore   
str | None_locale_encodingc                      e Zd Zy)
InputErrorN__name__
__module____qualname__     W/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/docutils/io.pyr   r   4       r   r   c                      e Zd Zy)OutputErrorNr   r   r   r   r   r   5   r   r   r   c                    	 t        j                  | j                        t        j                  |      k(  S # t        t        t
        f$ r Y y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&   8   sA    }}V__-x1HHH3 s   47 AAc                8    | j                   j                   d|  S )z5Return string representation of Exception `err`.
    z: )	__class__r   )errs    r   error_stringr*   H   s      mm$$%Ru--r   c                  <   e Zd ZU dZdZded<   dZded<   	 	 	 	 d	 	 	 	 	 	 	 	 	 ddZdd	Zdd
Z	ddZ
 ej                  d      Zded<   	 ej                  dfej                   dfej"                  dfej$                  dfej&                  dffZded<   	 ddZddZy)Inputak  
    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" to
    the "Transformer".  (Since Docutils 0.19, input objects are no longer
    required to be `TransformSpec` instances.)
    inputr	   component_typeNClassVar[str | None]default_source_pathc                x    || _         	 || _        	 || _        	 || _        	 |s| j                  | _        d | _        y N)r!   error_handlersourcesource_pathr0   successful_encoding)selfr4   r5   r!   r3   s        r   __init__zInput.__init__^   sJ     !1**'&-#77D#' Er   c                R    | j                   d| j                  d| j                  S )Nz	: source=z, source_path=)r(   r4   r5   r7   s    r   __repr__zInput.__repr__w   s$    26..$++262B2BD 	Dr   c                    t         )z,Return input as `str`. Define in subclasses.NotImplementedErrorr:   s    r   readz
Input.read{       !!r   c                ~   t        |t              r|S | j                  r2| j                  j                         dk7  sJ d       | j                  g}nt	        j
                         5  t	        j                  dt               | j                  |      }ddd       r|g}njdg}t        j                  dd dk\  rt        j                         }nt        j                  d	
      }|r$|j                         dk7  r|j                  |       | j                  s$|d   dk7  rt	        j                  dt        d       |D ]$  }	 t        ||| j                         }|| _        |c S  t%        ddj)                  d |D               dt+               d      # 1 sw Y   xY w# t$        t&        f$ r}|}Y d}~{d}~ww xY w)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` instancer   )categoryNutf-8   )      F)do_setlocaler   ur   Input encoding auto-detection will be removed and the encoding values None and "" become invalid in Docutils 1.0.
stacklevelz=Unable to decode input data.  Tried the following encodings: z, c              3  2   K   | ]  }t        |        y wr2   )repr).0encs     r   	<genexpr>zInput.decode.<locals>.<genexpr>   s     BscBs   .
())
isinstancestrr!   lowerwarningscatch_warningsfilterwarningsDeprecationWarningdetermine_encoding_from_datasysversion_infolocalegetencodinggetpreferredencodingappendwarnr3   r6   UnicodeErrorr"   joinr*   )	r7   dataencoding_candidatesdata_encodingfallbackrN   decodedr)   errors	            r   decodezInput.decode   s   " dC K== ==&&(I5 OMO5#'==/((* H'';MN $ A A$ GH '4o#
 (/i###BQ'72%113H%::NH 0G ;'..x8}}!4Q!77!BMM ./AaQ ' 	CdC););<+.(		 KyyB.ABBC DU#$A'( 	(=H H6 !+. s$   %-F F!F!F<0F77F<s   coding[:=]\s*([-\w.]+)zClassVar[re.Pattern[bytes]]coding_slugzutf-32z	utf-8-sigzutf-16z'ClassVar[tuple[tuple[bytes, str], ...]]byte_order_marksc                <   t        j                  dt        d       | j                  D ]  \  }}|j	                  |      s|c S  |j                         dd D ]A  }| j                  j                  |      }|s!|j                  d      j                  d      c S  y)z
        Try to determine the encoding of `data` by looking *in* `data`.
        Check for a byte order mark (BOM) or an encoding declaration.

        Deprecated. Will be removed in Docutils 1.0.
        uR   docutils.io.Input.determine_encoding_from_data() will be removed in Docutils 1.0.rE   rI   Nr   ascii)
rU   r`   rX   rk   
startswith
splitlinesrj   searchgroupri   )r7   rc   start_bytesr!   linematchs         r   rY   z"Input.determine_encoding_from_data   s     	 :(Q	8 &*%:%: 	 !K{+	  OO%bq) 	6D$$++D1E{{1~,,W55	6 r   c                V    	 | j                   j                         S # t        $ r Y yw xY w)z>Return True, if the input source is connected to a TTY device.F)r4   isattyr#   r:   s    r   rv   zInput.isatty   s,    	;;%%'' 		    	(()NNrD   strict)
r4   z$str | TextIO | nodes.document | Noner5   StrPath | Noner!   str | Literal['unicode'] | Noner3   r   returnNoner{   rS   )rc   str | bytesr{   rS   )rc   bytesr{   r   r{   bool)r   r   r   __doc__r.   __annotations__r0   r8   r;   r?   ri   recompilerj   r   BOM_UTF32_BEBOM_UTF32_LEBOM_UTF8BOM_UTF16_BEBOM_UTF16_LErk   rY   rv   r   r   r   r,   r,   N   s   	 $NE#04-4 8<&*4;$,F4F $F 2	F
 "F 
F2D";(z 0:rzz"0K,  ( 
		h'			h'	+&			h'			h'A= *r   r,   c                  j    e Zd ZU dZdZded<   dZded<   	 	 	 	 d	 	 	 	 	 	 	 	 	 ddZdd	Zdd
Z	ddZ
y)Outputan  
    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" to
    the "Transformer".  (Since Docutils 0.19, output objects are no longer
    required to be `TransformSpec` instances.)
    outputr	   r.   Nr/   default_destination_pathc                t    || _         	 |xs d| _        	 || _        	 || _        	 |s| j                  | _        y y )Nrx   )r!   r3   destinationdestination_pathr   )r7   r   r   r!   r3   s        r   r8   zOutput.__init__   sJ     %-7"/";8*8C.0@2$($A$AD!  r   c                R    | j                   d| j                  d| j                  S )Nz: destination=z, destination_path=)r(   r   r   r:   s    r   r;   zOutput.__repr__  s%    >>4#3#3T5J5JL 	Mr   c                    t         )z#Write `data`. Define in subclasses.r=   r7   rc   s     r   writezOutput.write  r@   r   c                    | j                   r6| j                   j                         dk(  rt        |t              sJ d       |S t        |t              s|S |j	                  | 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.
        rB   z<output encoding is "unicode" but `data` is no `str` instance)r!   rT   rR   rS   encoder3   r   s     r   r   zOutput.encode  sm     ==T]]002i?dC( N ,M N(K$$K;;t}}d.@.@AAr   )NNNrx   )
r   zTextIO | str | bytes | Noner   ry   r!   r   r3   r   r{   r|   r}   )rc   r~   r{   zstr | bytes | Nonerc   r~   r{   r~   )r   r   r   r   r.   r   r   r8   r;   r   r   r   r   r   r   r      sy    	 %NE$5929 48+/#$,B0B )B 	B
 "B 
B,M"Br   r   c                  L    e Zd ZdZ	 	 	 	 d	 	 	 	 	 	 	 	 	 ddZd	dZd
dZddZy)ErrorOutputz
    Wrapper class for file-like error streams with
    failsafe de- and encoding of `str`, `bytes`, and `Exception` instances.
    Nc                    |t         j                  }n!|sd}nt        |t              rt	        |d      }|| _        	 |xs t        |dd      xs
 t        xs d| _        	 || _	        	 || _
        y)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!   rm   )rZ   stderrrR   rS   openr   getattrr   r!   encoding_errorsdecoding_errors)r7   r   r!   r   r   s        r   r8   zErrorOutput.__init__5  s      **KKS){C0K?J+  {J5 	 	 	-$3%$3%r   c                   | j                   syt        |t              rt        |      }	 | j                   j	                  |       y# t
        $ rD |j                  | j                  | j                        }| j                   j	                  |       Y yt        $ r t        |t              rC|j                  | j                  | j                        }| j                   j	                  |       Y y| j                   t        j                  t        j                  fv r'| j                   j                  j	                  |       Y y|j                  | j                  | j                        }| j                   j	                  |       Y y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)r   rR   	ExceptionrS   r   UnicodeEncodeErrorr   r!   r   r$   rZ   r   stdoutbufferri   r   )r7   rc   binarystrings       r   r   zErrorOutput.write^  s     dI&t9D	/""4(! 	+ [[0D0DEF""6* 
	/$$T]]D4H4HI  &&v.!!cjj#**%==  ''--d3 T]]D4H4HI  &&v.
	/s'   A A
FAF-AF AFFc                    | j                   t        j                  t        j                  fv ry	 | j                   j	                          y# t
        $ r Y y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)r   rZ   r   r   closer#   r:   s    r   r   zErrorOutput.close~  sK     

CJJ77	""$ 		s   A
 
	AAc                V    	 | j                   j                         S # t        $ r Y yw xY w)z=Return True, if the destination is connected to a TTY device.F)r   rv   r#   r:   s    r   rv   zErrorOutput.isatty  s.    	##**,, 		rw   )NNbackslashreplacereplace)
r   z/TextIO | BinaryIO | str | Literal[False] | Noner!   r   r   rS   r   rS   r{   r|   )rc   zstr | bytes | Exceptionr{   r|   r{   r|   r   )r   r   r   r   r8   r   r   rv   r   r   r   r   r   /  s]     HL#1('&D'& '& 	'&
 '& 
'&R/@r   r   c                  d     e Zd ZdZ	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZddZd	dZd
dZ xZS )	FileInputz5
    Input for single, simple file-like objects.
    c                B   t         |   ||||       || _        t               | _        |B|r*	 t        ||| j                  | j                        | _        nht        j                  | _        nRt        | j                  | j                        du r0t!        d| j                  d| j                  j                  d      |s	 | j                  j"                  | _        yy# t        $ r&}t        |j                  |j                  |      d}~ww xY w# t&        $ r Y yw xY w)a  
        :Parameters:
            - `source`: either a file-like object (with `read()` and `close()`
              methods) or None (use source indicated by `source_path`).
            - `source_path`: a path to a file (which is opened for reading
              if `source` is None) or `None` (implies `sys.stdin`).
            - `encoding`: the text encoding of the input file.
            - `error_handler`: the encoding error handler to use.
            - `autoclose`: close automatically after read (except when
              the source is `sys.stdin`).
            - `mode`: how the file is to be opened. Default is read only ('r').
        Nr!   errorsFz#Encoding clash: encoding given is "z&" but source is opened with encoding "z".)superr8   	autocloser   _stderrr   r!   r3   r4   OSErrorr   errnostrerrorrZ   stdinr&   ra   namer5   r#   )	r7   r4   r5   r!   r3   r   moderh   r(   s	           r   r8   zFileInput.__init__  s   * 	hF""}>O"&{D04.2.@.@#BDK "iiDKK75@ $t{{/C/C E F F #';;#3#3    O$U[[%..+NNO " s)   (C  D  	D)!D

D	DDc                   	 | j                   sot        | j                  d      rY| j                  j                  j	                         }| j                  |      }dj                  |j                         dgz         }n)| j                  | j                  j	                               }| j                  r| j                          |S # | j                  r| j                          w w xY w)zA
        Read and decode a single file, return as `str`.
        r   
 )
r!   hasattrr4   r   r?   ri   rb   ro   r   r   r   s     r   r?   zFileInput.read  s    	==WT[[(%C{{))..0{{4(yy!2B4!78{{4;;#3#3#56~~

 ~~

 s   B$C C#c                @    | j                         j                  d      S )zC
        Return lines of a single file as list of strings.
        T)r?   ro   r:   s    r   	readlineszFileInput.readlines  s     yy{%%d++r   c                r    | j                   t        j                  ur| j                   j                          y y r2   )r4   rZ   r   r   r:   s    r   r   zFileInput.close  s'    ;;cii'KK (r   )NNrD   rx   Tr)r4   TextIO | Noner5   ry   r!   rz   r3   r   r   r   r   zLiteral['r', 'rb', 'br']r{   r|   r}   )r{   z	list[str]r   )	r   r   r   r   r8   r?   r   r   __classcell__r(   s   @r   r   r     su    
 !%&*4;$,),,, $, 2	,
 ", , ', 
,\&, r   r   c                       e Zd ZU dZdZded<   dZded<   	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZdd	Zdd
Z	ddZ
 xZS )
FileOutputz,Output for single, simple file-like objects.z<file>r	   r   r   z:Literal['w', 'a', 'x', 'wb', 'ab', 'xb', 'bw', 'ba', 'bx']r   c                   t         |   ||||       d| _        || _        |t	        j
                  dt        d       ||| _        t               | _	        | |rd| _        nyt        j                  | _        nc|rat        | j                  d      rK|| j                  j                  k7  r2t        d| j                  j                  d	|d
| j                         |s	 | j                  j                  | _        yy# t"        $ r Y yw xY w)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.rE   rI   Fr   zWarning: Destination mode "z" differs from specified mode "")file)r   r8   openedr   rU   r`   rX   r   r   r   rZ   r   r   r   printr   r   r#   )	r7   r   r   r!   r3   r   handle_io_errorsr   r(   s	           r   r8   zFileOutput.__init__  s    2 	)8]	D"'MM *+=!M DI"}##&:: wt//8$**///!%!1!1!6!6>||%  (,(8(8(=(=%   " s    C= =	D	D	c                ,   d| j                   vr| j                  | j                  d}ni }	 t        | j                  | j                   fi || _        d| _
        y # t        $ r0}t        |j                  |j                  | j                        d }~ww xY w)Nbr   T)r   r!   r3   r   r   r   r   r   r   r   r   )r7   kwargsrh   s      r   r   zFileOutput.open&  s    dii"&-- $ 2 24F F	5#D$9$9499OOD   	5ekk5>>"335 5	5s   &A 	B#+BBc                   | j                   s| j                          t        |t              rft	        | j
                  | j                        du rDt        j                  dk7  r |j                  dt        j                        }| j                  |      }	 | j
                  j                  |       | j*                  r| j-                          |S # t        $ r}t        |t              r	 | j
                  j                  j                  |       nn# t        $ rb t	        | j
                  | j                        du r=t!        d| j"                   d| j
                  j                   d| j                   d      |w xY wY d}~d}~wt$        t&        f$ r*}t%        d| j                   d	t)        |       d      d}~ww xY w# | j*                  r| j-                          w w xY w)
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 (rQ   Nz2Unable to encode output data. output-encoding is: rP   )r   r   rR   rS   r&   r   r!   oslinesepr   r   r   r$   r   r   r#   
ValueErrorr   ra   r"   r*   r   r   )r7   rc   r)   s      r   r   zFileOutput.write4  s    {{IIKtS!t//?5HzzT!||D"**5;;t$D	""4(& ~~

)  	"$&
"$$++11$7% "%d&6&6&*mm58=>(*4+@+@*A B  $ 0 0 9 9: ;::>--KL L
 "	" k* 	<D==/l3&7%8;< <	<
 ~~

 sO   C 	F<F '%DF A+E88F ;F?  F<%F77F<<F? ?Gc                    | j                   t        j                  t        j                  fvr"| j                   j	                          d| _        y y )NF)r   rZ   r   r   r   r   r:   s    r   r   zFileOutput.closeb  s;    CJJ

#;;""$DK <r   )NNNrx   TNN)r   r   r   ry   r!   r   r3   r   r   r   r   r|   r{   r|   r   r   )r   r   r   r   r   r   r   r8   r   r   r   r   r   s   @r   r   r     s    6&.e.GJD
DJ) /348(,-5#'*.3+3#13 &3 !+	3
 !3 $(3 3j,\ r   r   c                  (     e Zd ZdZdZd fdZ xZS )BinaryFileOutputu   
    A version of docutils.io.FileOutput which writes to a binary file.

    Deprecated. Use `FileOutput` (works with `bytes` since Docutils 0.20).
    Will be removed in Docutils 0.24.
    wbc                \    t        j                  dt        d       t        |   |i | y )NzU"BinaryFileOutput" is obsoleted by "FileOutput" and will be removed in Docutils 0.24.rE   rI   )rU   r`   rX   r   r8   )r7   argsr   r(   s      r   r8   zBinaryFileOutput.__init__r  s-     ?(Q	8 	$)&)r   )r   r   r   r   r{   r|   )r   r   r   r   r   r8   r   r   s   @r   r   r   h  s     D* *r   r   c                  2    e Zd ZU dZded<   dZded<   d	dZy)
StringInputz'Input from a `str` or `bytes` instance.r~   r4   <string>r	   r0   c                8    | j                  | j                        S )z`Return the source as `str` instance.

        Decode, if required (see `Input.decode`).
        )ri   r4   r:   s    r   r?   zStringInput.read  s    
 {{4;;''r   Nr}   r   r   r   r   r   r0   r?   r   r   r   r   r   y  s    1!++(r   r   c                  2    e Zd ZU dZded<   dZded<   d	dZy)
StringOutputz=Output to a `bytes` or `str` instance.

    Provisional.
    r~   r   r   r	   r   c                F    | j                  |      | _        | 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).
        )r   r   r   s     r   r   zStringOutput.write  s!      ;;t,r   Nr   r   r   r   r   r   r   r   r   r   r   r   r     s    
 &0e0 r   r   c                  2    e Zd ZU dZded<   dZded<   d	dZy)
	NullInputzDegenerate input: read nothing.r|   r4   z
null inputr	   r0   c                     y)zReturn an empty string.r   r   r:   s    r   r?   zNullInput.read  s    r   Nr}   r   r   r   r   r   r     s    )L!--r   r   c                  2    e Zd ZU dZded<   dZded<   d	dZy)

NullOutputz!Degenerate output: write nothing.r|   r   znull outputr	   r   c                     y)zDo nothing, return None.Nr   r   s     r   r   zNullOutput.write  s    r   N)rc   r~   r{   r|   r   r   r   r   r   r     s    +&3e3'r   r   c                  2    e Zd ZU dZded<   dZded<   d	dZy)
DocTreeInputzm
    Adapter for document tree input.

    The document tree must be passed in the ``source`` parameter.
    nodes.documentr4   zdoctree inputr	   r0   c                    | j                   S )zReturn the document tree.)r4   r:   s    r   r?   zDocTreeInput.read  s    {{r   N)r{   r   r   r   r   r   r   r     s     !00r   r   )r%   r   r!   rS   r{   zbool | None)r)   BaseExceptionr{   rS   )1r   
__future__r   __docformat__r   r\   r   r   rZ   rU   docutilsr   TYPE_CHECKINGtypingr   r   r   r	   r
   r   r   docutils.nodesr   rV   simplefilter	getlocalegetdefaultlocalerT   r   r   r    r"   r$   r   r   r   r&   r*   r,   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s  

 #"   	 	 
  "FF&		 	 	 	" 2h'(8(8(8(:1(= )H+B6+B+B+DQ+G*/%' 	* 	22FMM"#
     '   .[M [|@B] @BFb bJN  N b@  @ F*z *"(% ( 6  :
 
	' 	'5 q2 2
 	Y s7   E* AE,E* 5E3 E'#E* *E03	E?>E?