
    -Ph                         d Z ddlZddlZddlmZ  ej        ded           ej        dk    re	Z
 G d d	          Z G d
 de          Z G d d          ZdS )u9  
Deprecated module to handle Exceptions across Python versions.

.. warning::
   This module is deprecated with the end of support for Python 2.7
   and will be removed in Docutils 0.21 or later.

   Replacements:
     | SafeString  -> str
     | ErrorString -> docutils.io.error_string()
     | ErrorOutput -> docutils.io.ErrorOutput

Error reporting should be safe from encoding/decoding errors.
However, implicit conversions of strings and exceptions like

>>> u'%s world: %s' % ('Hällo', Exception(u'Hällo'))

fail in some Python versions:

* In Python <= 2.6, ``unicode(<exception instance>)`` uses
  `__str__` and fails with non-ASCII chars in`unicode` arguments.
  (work around http://bugs.python.org/issue2517):

* In Python 2, unicode(<exception instance>) fails, with non-ASCII
  chars in arguments. (Use case: in some locales, the errstr
  argument of IOError contains non-ASCII chars.)

* In Python 2, str(<exception instance>) fails, with non-ASCII chars
  in `unicode` arguments.

The `SafeString`, `ErrorString` and `ErrorOutput` classes handle
common exceptions.
    N)_locale_encodingzThe `docutils.utils.error_reporting` module is deprecated and will be removed in Docutils 0.21 or later.
Details with help("docutils.utils.error_reporting").   )
stacklevel   r   c                   *    e Zd ZdZ	 	 ddZd Zd ZdS )	
SafeStringzG
    A wrapper providing robust conversion to `str` and `unicode`.
    Nbackslashreplacereplacec                 r    || _         |pt          |dd           pt          pd| _        || _        || _        d S )Nencodingascii)datagetattrlocale_encodingr   encoding_errorsdecoding_errors)selfr   r   r   r   s        ^/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/docutils/utils/error_reporting.py__init__zSafeString.__init__C   sL    	! 7WT:t%D%D 7+7/6 	..    c                     	 t           j                  S # t          $ r t           j        t                    r/ fd j        j        D             }d                    |          cY S t           j        t                    r@t          j	        dk    r	 j        cY S  j        
                     j         j                  cY S  w xY w)Nc           	      `    g | ]*}t          t          |j        j                            +S  )strr	   r   r   .0argr   s     r   
<listcomp>z&SafeString.__str__.<locals>.<listcomp>P   sK     3 3 3 JsDM'+';= = > > 3 3 3r   , r   )r   r   UnicodeEncodeError
isinstance	Exceptionargsjoinunicodesysversion_infoencoder   r   )r   r$   s   ` r   __str__zSafeString.__str__K   s    	ty>>!! 	 	 	$)Y// '3 3 3 3#'9>3 3 3 yy&&&$)W-- B#f,,9$$$9++DM,0,@B B B B B	s    AC*1C%CCc                     	 t           j                  }t           j        t                    r|                    dd          }|S # t
          $ r}t           j        t                    rad j        j        dt           j        j         j	         j
                  dt           j        j         j	         j
                  dcY d}~S t           j        t                    r2 fd j        j        D             }d                    |          cY d}~S t          |t                    r%t           j         j	         j
                  cY d}~S  d}~ww xY w)	af  
        Return unicode representation of `self.data`.

        Try ``unicode(self.data)``, catch `UnicodeError` and

        * if `self.data` is an Exception instance, work around
          http://bugs.python.org/issue2517 with an emulation of
          Exception.__unicode__,

        * else decode with `self.encoding` and `self.decoding_errors`.
        z: u'z: 'z[Errno z] 'Nc           	      b    g | ]+}t          t          |j        j                             ,S ))r   )r&   r	   r   r   r   s     r   r   z*SafeString.__unicode__.<locals>.<listcomp>v   sX     3 3 3    
$'484H!J !J !J K K 3 3 3r   r    )r&   r   r"   EnvironmentErrorr   UnicodeErrorerrnor	   strerrorr   r   filenamer#   r$   r%   UnicodeDecodeError)r   uerrorr$   s   `   r   __unicode__zSafeString.__unicode__\   s   		""A$)%566 -IIfe,,H 	 	 	$)%566 6 6IOOOty14=#35 5 5 5ty14=#35 5 5 5	6 6 6 6 6 6 6 $)Y// (3 3 3 3 $(9>3 3 3 zz$''''''''%!344 Oty$-9MNNNNNNNN!	s>   AA	 	EA5E	EAEE4EEEE)Nr
   r   )__name__
__module____qualname____doc__r   r*   r6   r   r   r   r	   r	   >   sY          =O!*/ / / /  "! ! ! ! !r   r	   c                   ,     e Zd ZdZ fdZ fdZ xZS )ErrorStringz3
    Safely report exception type and message.
    c                 z    | j         j        j        dt          t          |                                           S Nz: )r   	__class__r7   superr<   r*   r   r?   s    r   r*   zErrorString.__str__   s:    9.777 d33;;===? 	?r   c                 z    | j         j        j        dt          t          |                                           S r>   )r   r?   r7   r@   r<   r6   rA   s    r   r6   zErrorString.__unicode__   s<     I/888!+t44@@BBBD 	Dr   )r7   r8   r9   r:   r*   r6   __classcell__)r?   s   @r   r<   r<      sd         ? ? ? ? ?D D D D D D D D Dr   r<   c                   ,    e Zd ZdZ	 	 	 d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.
    Nr
   r   c                 ~   |t           j        }nt|sd}not          |t                    rt	          |d          }nIt          |t
                    r4t	          |                    t          j                              d          }|| _        	 |pt          |dd          pt          pd| _        	 || _        	 || _        dS )a  
        :Parameters:
            - `stream`: 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`: `stream` text encoding. Guessed if None.
            - `encoding_errors`: how to treat encoding errors.
        NFwr   r   )r'   stderrr"   r   openr&   r)   getfilesystemencodingstreamr   r   r   r   r   )r   rK   r   r   r   s        r   r   zErrorOutput.__init__   s     >ZFF 	KFF$$ 	K&#&&FF(( 	K&--(A(C(CDDcJJF+! 7WVZ%F%F 7+7/6 	,.%.%%r   c                 
   | j         du rdS t          |t                    r.t          t	          || j        | j        | j                            }	 | 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.stream. Ignore, if self.stream is False.

        `data` can be a `string`, `unicode`, or `Exception` instance.
        FN)rK   r"   r#   r&   r	   r   r   r   writer!   r)   	TypeErrorr'   rH   stdoutbuffer)r   r   s     r   rM   zErrorOutput.write   s    ;%FdI&& 	=:dDM&*&:&*&:< < = =D	AKd#####! 	P 	P 	PKdkk$-9MNNOOOOOO 		A 		A 		A$(( !!$++dm.2.B#D #D E E E{sz3:666"((......!!'$*.*>#@ #@ A A A A A A		As&   A, ,AF1AF
>F3FF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 stream is` sys.stderr` or `sys.stdout` or has no
        close() method.
        N)rK   r'   rO   rH   closeAttributeError)r   s    r   rR   zErrorOutput.close   s`     ;3:sz222F	K 	 	 	DD	s   > 
AA)NNr
   r   )r7   r8   r9   r:   r   rM   rR   r   r   r   rE   rE      s_          .2!3!*!& !& !& !&FA A A6    r   rE   )r:   r'   warningsdocutils.ior   r   warnDeprecationWarningr(   r   r&   r	   r<   rE   r   r   r   <module>rX      s
     D 


  ; ; ; ; ; ;  E !Q0 0 0 0 vG? ? ? ? ? ? ? ?D
D 
D 
D 
D 
D* 
D 
D 
DQ Q Q Q Q Q Q Q Q Qr   