o
    i
e                  	   @  s
  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rIddlmZmZmZmZmZmZ ddl
mZ dd	lmZ z-e	  e	d
 e d p_e d  Zded< W d   n1 spw   Y  W n   dZY zee W n ee fy   dZY nw G dd de!Z"G dd de!Z#d4ddZ$d5ddZ%G dd deZ&G d d! d!eZ'G d"d# d#Z(G d$d% d%e&Z)G d&d' d'e'Z*G d(d) d)e*Z+G d*d+ d+e&Z,G d,d- d-e'Z-G d.d/ d/e&Z.G d0d1 d1e'Z/G d2d3 d3e&Z0dS )6z
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dS )
InputErrorN__name__
__module____qualname__ r   r   Q/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/docutils/io.pyr   4       r   c                   @  r   )OutputErrorNr   r   r   r   r   r   5   r   r   streamr
   encodingstrreturnbool | Nonec              
   C  s4   zt | jt |kW S  tttfy   Y dS 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lookupr   LookupErrorAttributeError	TypeError)r   r   r   r   r   check_encoding8   s
   
r%   errBaseExceptionc                 C  s   | j j d|  S )z5Return string representation of Exception `err`.
    z: )	__class__r   )r&   r   r   r   error_stringH   s   r)   c                   @  s   e Zd ZU dZdZded< dZded< 					d-d.ddZd/ddZd/ddZ	d0ddZ
e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&< 	 d1d(d)Zd2d+d,ZdS )3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_pathutf-8strictsource$str | TextIO | nodes.document | Nonesource_pathStrPath | Noner   str | Literal['unicode'] | Noneerror_handlerr   r   Nonec                 C  s6   || _ 	 || _	 || _	 || _	 |s| j| _d | _d S N)r   r6   r1   r3   r.   successful_encoding)selfr1   r3   r   r6   r   r   r   __init__^   s   zInput.__init__r   c                 C     d| j | j| jf S )Nz%s: source=%r, source_path=%r)r(   r1   r3   r:   r   r   r   __repr__w   s   
zInput.__repr__c                 C     t )z,Return input as `str`. Define in subclasses.NotImplementedErrorr=   r   r   r   read{      z
Input.readdatastr | bytesc           	      C  sx  | j r| j  dkrt|tsJ dt|tr|S | j r"| j g}nJt  tjdtd | |}W d   n1 s=w   Y  |rH|g}n$dg}t	j
dd dkrYt }ntjd	d
}|rl| dkrl|| | j s}|d dkr}tjdtdd |D ]'}zt||| j}|| _|W   S  ttfy } z|}W Y d}~qd}~ww td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` instancer   )categoryNr/      )      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                 s  s    | ]}t |V  qd S r8   )repr).0encr   r   r   	<genexpr>   s    zInput.decode.<locals>.<genexpr>.
())r   lower
isinstancer   warningscatch_warningsfilterwarningsDeprecationWarningdetermine_encoding_from_datasysversion_infolocalegetencodinggetpreferredencodingappendwarnr6   r9   UnicodeErrorr"   joinr)   )	r:   rD   encoding_candidatesdata_encodingfallbackrP   decodedr&   errorr   r   r   decode   sL   





zInput.decodes   coding[:=]\s*([-\w.]+)zClassVar[re.Pattern[bytes]]coding_slugzutf-32z	utf-8-sigzutf-16z'ClassVar[tuple[tuple[bytes, str], ...]]byte_order_marksbytesc                 C  sp   t jdtdd | jD ]\}}||r|  S q| dd D ]}| j|}|r5|d	d  S q!dS )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.rH   rL   Nr   ascii)
rV   ra   rY   rk   
startswith
splitlinesrj   searchgroupri   )r:   rD   start_bytesr   linematchr   r   r   rZ      s   
z"Input.determine_encoding_from_databoolc                 C  "   z| j  W S  ty   Y dS w )z>Return True, if the input source is connected to a TTY device.F)r1   isattyr#   r=   r   r   r   rw      
   zInput.isatty)NNr/   r0   )
r1   r2   r3   r4   r   r5   r6   r   r   r7   r   r   )rD   rE   r   r   )rD   rl   r   r   r   ru   )r   r   r   __doc__r,   __annotations__r.   r;   r>   rB   ri   recompilerj   r    BOM_UTF32_BEBOM_UTF32_LEBOM_UTF8BOM_UTF16_BEBOM_UTF16_LErk   rZ   rw   r   r   r   r   r*   N   s2   
 


?
r*   c                   @  s\   e Zd ZU dZdZded< dZded< 				ddddZd ddZd!ddZ	d"ddZ
dS )#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_pathr0   destinationTextIO | str | bytes | Nonedestination_pathr4   r   r   r6   r   r7   c                 C  s8   || _ 	 |pd| _	 || _	 || _	 |s| j| _d S d S )Nr0   )r   r6   r   r   r   )r:   r   r   r   r6   r   r   r   r;      s   
zOutput.__init__r   c                 C  r<   )Nz'%s: destination=%r, destination_path=%r)r(   r   r   r=   r   r   r   r>     s   zOutput.__repr__rD   rE   str | bytes | Nonec                 C  r?   )z#Write `data`. Define in subclasses.r@   r:   rD   r   r   r   write  rC   zOutput.writec                 C  sH   | 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.
        rF   z<output encoding is "unicode" but `data` is no `str` instance)r   rT   rU   r   encoder6   r   r   r   r   r     s   

zOutput.encode)NNNr0   )
r   r   r   r4   r   r   r6   r   r   r7   ry   )rD   rE   r   r   rD   rE   r   rE   )r   r   r   r{   r,   r|   r   r;   r>   r   r   r   r   r   r   r      s   
 

r   c                   @  sB   e Zd ZdZ				ddddZdddZdddZdddZdS )ErrorOutputz
    Wrapper class for file-like error streams with
    failsafe de- and encoding of `str`, `bytes`, and `Exception` instances.
    Nbackslashreplacereplacer   /TextIO | BinaryIO | str | Literal[False] | Noner   r   encoding_errorsr   decoding_errorsr   r7   c                 C  sd   |du r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   rm   )r[   stderrrU   r   openr   getattrr   r   r   r   )r:   r   r   r   r   r   r   r   r;   7  s(   


zErrorOutput.__init__rD   str | bytes | Exceptionc                 C  s   | j sdS t|trt|}z	| j | W dS  ty/   || j| j}| j | Y dS  t	yo   t|trK|| j| j}| j | Y dS | j t
jt
jfv r^| j j| Y dS || j| j}| j | Y dS w )z
        Write `data` to self.destination. Ignore, if self.destination is False.

        `data` can be a `bytes`, `str`, or `Exception` instance.
        N)r   rU   	Exceptionr   r   UnicodeEncodeErrorr   r   r   r$   r[   r   stdoutbufferri   r   )r:   rD   binarystringr   r   r   r   `  s$   

zErrorOutput.writec                 C  s<   | j tjtjfv rdS z| j   W dS  ty   Y dS w )z
        Close the error-output stream.

        Ignored if the destination is` sys.stderr` or `sys.stdout` or has no
        close() method.
        N)r   r[   r   r   closer#   r=   r   r   r   r     s   zErrorOutput.closeru   c                 C  rv   )z=Return True, if the destination is connected to a TTY device.F)r   rw   r#   r=   r   r   r   rw     rx   zErrorOutput.isatty)NNr   r   )
r   r   r   r   r   r   r   r   r   r7   )rD   r   r   r7   r   r7   rz   )r   r   r   r{   r;   r   r   rw   r   r   r   r   r   1  s    
)
 r   c                      sN   e Zd ZdZ						dd  fddZd!ddZd"ddZd#ddZ  ZS )$	FileInputz5
    Input for single, simple file-like objects.
    Nr/   r0   Trr1   TextIO | Noner3   r4   r   r5   r6   r   	autocloseru   modeLiteral['r', 'rb', 'br']r   r7   c              
     s   t  |||| || _t | _|du r=|r8zt||| j| jd| _W n- t	y7 } zt
|j|j|d}~ww tj| _nt| j| jdu rQtd| j| jjf |sfz| jj| _W dS  tye   Y dS 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   errorsFzOEncoding clash: encoding given is "%s" but source is opened with encoding "%s".)superr;   r   r   _stderrr   r   r6   r1   OSErrorr   errnostrerrorr[   stdinr%   rb   namer3   r#   )r:   r1   r3   r   r6   r   r   rh   r(   r   r   r;     s4   
zFileInput.__init__r   c                 C  sp   z.| j s t| jdr | jj }| |}d| dg }n| j }W | jr-| 	  |S | jr7| 	  w w )zA
        Read and decode a single file, return as `str`.
        r   
 )
r   hasattrr1   r   rB   ri   rc   ro   r   r   r   r   r   r   rB     s   


zFileInput.read	list[str]c                 C  s   |   dS )zC
        Return lines of a single file as list of strings.
        T)rB   ro   r=   r   r   r   	readlines  s   zFileInput.readlinesc                 C  s   | j tjur| j   d S d S r8   )r1   r[   r   r   r=   r   r   r   r     s   zFileInput.close)NNr/   r0   Tr   )r1   r   r3   r4   r   r5   r6   r   r   ru   r   r   r   r7   ry   )r   r   r   )	r   r   r   r{   r;   rB   r   r   __classcell__r   r   r   r   r     s    
.
r   c                      sl   e Zd ZU dZdZded< dZded< 	 						
		d!d" fddZd#ddZd$ddZ	d#dd Z
  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   Nr0   Tr   r   r   r4   r   r   r6   r   ru   handle_io_errorsr7   r   c                   s   t  |||| d| _|| _|durtjdtdd |dur"|| _t | _	|du r5|r0d| _n t
j| _n|rPt| jdrP|| jjkrPtd| jj|f | j	d	 |sez| jj| _W dS  tyd   Y dS 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.rH   rL   Fr   z?Warning: Destination mode "%s" differs from specified mode "%s")file)r   r;   openedr   rV   ra   rY   r   r   r   r[   r   r   r   printr   r   r#   )r:   r   r   r   r6   r   r   r   r   r   r   r;     sB   


zFileOutput.__init__c              
   C  sp   d| j vr| j| jd}ni }zt| j| j fi || _W n ty2 } z	t|j|j	| jd }~ww d| _
d S )Nbr   T)r   r   r6   r   r   r   r   r   r   r   r   )r:   kwargsrh   r   r   r   r   (  s   


zFileOutput.openrD   rE   c                 C  sF  | j s|   t|tr&t| j| jdu r&tjdkr!|	dtj}| 
|}zsz| j| W n` tyt } z9t|trjz	| jj| W n$ tyi   t| j| jdu rgtd| j d| jj d| j d|w W Y d}~n d}~w ttfy } ztd| j d	t| dd}~ww W | jr|   |S | jr|   w 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 (rS   Nz2Unable to encode output data. output-encoding is: rR   )r   r   rU   r   r%   r   r   oslinesepr   r   r   r$   rl   r   r#   
ValueErrorr   rb   r"   r)   r   r   )r:   rD   r&   r   r   r   r   6  s\   




	
zFileOutput.writec                 C  s*   | j tjtjfvr| j   d| _d S d S )NF)r   r[   r   r   r   r   r=   r   r   r   r   d  s   

zFileOutput.close)NNNr0   TNN)r   r   r   r4   r   r   r6   r   r   ru   r   r7   r   r7   r   r   )r   r   r   r{   r   r|   r   r;   r   r   r   r   r   r   r   r   r     s    
 
5
.r   c                      s&   e Zd ZdZdZd
 fdd	Z  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.
    wbargsr   r   r   r7   c                   s&   t jdtdd t j|i | d S )NzU"BinaryFileOutput" is obsoleted by "FileOutput" and will be removed in Docutils 0.24.rH   rL   )rV   ra   rY   r   r;   )r:   r   r   r   r   r   r;   t  s   zBinaryFileOutput.__init__)r   r   r   r   r   r7   )r   r   r   r{   r   r;   r   r   r   r   r   r   j  s    r   c                   @  0   e Zd ZU dZded< dZded< dd	d
ZdS )StringInputz'Input from a `str` or `bytes` instance.rE   r1   <string>r   r.   r   r   c                 C  s   |  | jS )z`Return the source as `str` instance.

        Decode, if required (see `Input.decode`).
        )ri   r1   r=   r   r   r   rB     s   zStringInput.readNry   r   r   r   r{   r|   r.   rB   r   r   r   r   r   {  s
   
 r   c                   @  r   )StringOutputz=Output to a `bytes` or `str` instance.

    Provisional.
    rE   r   r   r   r   rD   r   c                 C  s   |  || _| 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   r   r   r   r     s   zStringOutput.writeNr   r   r   r   r{   r|   r   r   r   r   r   r   r     s
   
 r   c                   @  r   )	NullInputzDegenerate input: read nothing.r7   r1   z
null inputr   r.   r   r   c                 C     dS )zReturn an empty string.r   r   r=   r   r   r   rB     rC   zNullInput.readNry   r   r   r   r   r   r     
   
 r   c                   @  s0   e Zd ZU dZded< dZded< dd
dZdS )
NullOutputz!Degenerate output: write nothing.r7   r   znull outputr   r   rD   rE   r   c                 C  r   )zDo nothing, return None.Nr   r   r   r   r   r     s    zNullOutput.writeN)rD   rE   r   r7   r   r   r   r   r   r     r   r   c                   @  s0   e Zd ZU dZded< dZded< ddd	Zd
S )DocTreeInputzm
    Adapter for document tree input.

    The document tree must be passed in the ``source`` parameter.
    nodes.documentr1   zdoctree inputr   r.   r   c                 C  s   | j S )zReturn the document tree.)r1   r=   r   r   r   rB     s   zDocTreeInput.readN)r   r   r   r   r   r   r   r     s
   
 r   )r   r
   r   r   r   r   )r&   r'   r   r   )1r{   
__future__r   __docformat__r    r]   r   r}   r[   rV   docutilsr   TYPE_CHECKINGtypingr   r   r   r   r	   r
   r   docutils.nodesr   rW   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   r   <module>   s`    




 !CeQ 