
    dd]                        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   xs  ej                         d   Zej                         Zddd       	  ej&                  e        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%y# 1 sw Y   xY w# e$ rZdej$                  v rdZndZY dZ[dZ[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.
reStructuredText    N)TransformSpecignore   zunknown locale: UTF-8utf-8c                       e Zd Zy)
InputErrorN__name__
__module____qualname__     -/usr/lib/python3/dist-packages/docutils/io.pyr	   r	   3       r   r	   c                       e Zd Zy)OutputErrorNr
   r   r   r   r   r   4   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   7   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    G   s      mm$$%Ru--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y)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.)
    inputNc                 x    || _         	 || _        	 || _        	 || _        	 |s| j                  | _        d | _        y N)r   error_handlersourcesource_pathdefault_source_pathsuccessful_encoding)selfr'   r(   r   r&   s        r   __init__zInput.__init__]   sH     1**'&-#77D#' Er   c                 R    | 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                   r4| j                   j                         dk(  rt        |t              sJ d       t        |t              r|S | j                   r| j                   g}nO| j	                  |      }|r|g}n8dg}t
        rt
        dk7  r|j                  t
               |j                  d       |D ]4  }	 t        ||| j                        }|| _        |j                  dd      c S  t        dd	j                  d
 |D               dt               d      # 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, 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   2   K   | ]  }t        |        y wr%   )repr).0encs     r   	<genexpr>zInput.decode.<locals>.<genexpr>   s     BscBs   .
())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   sR   4 ==T]]002i?dC( N ,M N(dC K== $(==/ ==dCM (5o#
 (/i# $(8G(C'../?@#**95& 
	C	dC););<+.( x44
	 KyyB.ABBC DU#$A'( 	( !+. s   /D&&E5D<<Es   coding[:=]\s*([-\w.]+)r   z	utf-16-bez	utf-16-lec                    | 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.
        N   r   ascii)byte_order_marks
startswith
splitlinescoding_slugsearchgrouprM   )r+   rH   start_bytesr   linematchs         r   rB   z"Input.determine_encoding_from_data   s     &*%:%: 	 !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)r'   isattyr   r.   s    r   r[   zInput.isatty   s,    	;;%%'' 		    	((NNNstrict)r   r   r   __doc__component_typer)   r,   r/   r3   rM   recompilerT   r   BOM_UTF8BOM_UTF16_BEBOM_UTF16_LErQ   rB   r[   r   r   r   r"   r"   M   s    	 N?C'F(D"D(L "**78K''2,,k:,,k:=- r   r"   c                   6    e Zd ZdZdZdZ	 	 ddZd Zd Zd Z	y)	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.)
    outputNc                 t    || _         	 |xs d| _        	 || _        	 || _        	 |s| j                  | _        y y )Nr^   )r   r&   destinationdestination_pathdefault_destination_path)r+   rj   rk   r   r&   s        r   r,   zOutput.__init__   sH     7*6h*&. 02$($A$AD!  r   c                 R    | j                   d| j                  d| j                  S )Nz: destination=z, destination_path=)r   rj   rk   r.   s    r   r/   zOutput.__repr__  s%    >>4#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                   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.
        r6   z<output encoding is "unicode" but `data` is no `str` instance)r   r?   r@   rA   encoder&   ro   s     r   rr   zOutput.encode
  sm     ==T]]002i?dC( N ,M N(K$$K;;t}}d.@.@AAr   r]   )
r   r   r   r_   r`   rl   r,   r/   rp   rr   r   r   r   rg   rg      s1    	 N#:>.6B"M"Br   rg   c                   0    e Zd ZdZ	 	 	 ddZd Zd Zd Zy)ErrorOutputz
    Wrapper class for file-like error streams with
    failsafe de- and encoding of `str`, `bytes`, `unicode` 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   rP   )sysstderrr@   rA   openrj   getattrrC   r   encoding_errorsdecoding_errors)r+   rj   r   r{   r|   s        r   r,   zErrorOutput.__init__&  s     **KKS){C0K&+! 8W[*d%K 8,807 	,.%.%r   c                    | j                   syt        |t              rt        |      }	 | j                   j	                  |       y# t
        $ rB | j                   j	                  |j                  | j                  | j                               Y yt        $ r t        |t              rA| j                   j	                  |j                  | j                  | j                               Y y| j                   t        j                  t        j                  fv r'| j                   j                  j	                  |       Y y| j                   j	                  t        || 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)rj   r@   	ExceptionrA   rp   UnicodeEncodeErrorrr   r   r{   r   rw   rx   stdoutbufferr|   ro   s     r   rp   zErrorOutput.writeG  s$    dI&t9D	B""4(! 	F""4;;t}}/3/C/C$E F 		B$$  &&t{{4==373G3G(I J!!cjj#**%==  ''--d3  &&s4+/+?+?(A B		Bs&   A AE9AE9)AE9<:E98E9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)rj   rw   r   rx   closer   r.   s    r   r   zErrorOutput.closea  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)rj   r[   r   r.   s    r   r[   zErrorOutput.isattyo  s.    	##**,, 		r\   )NNbackslashreplacerE   )r   r   r   r_   r,   rp   r   r[   r   r   r   rt   rt     s(     37!3!*&BB4r   rt   c                   0    e Zd ZdZ	 	 	 ddZd Zd Zd Zy)	FileInputz5
    Input for single, simple file-like objects.
    Nc                 V   t         j                  | ||||       || _        t               | _        |F|r.	 t        ||| j                  xs d| 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 (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   _stderrry   r   r&   r'   OSErrorr	   errnostrerrorrw   stdinr   rF   namer(   r   )r+   r'   r(   r   r&   r   moderL   s           r   r,   zFileInput.__init__|  s    	tV[(MJ""}>O"&{D040L.2.@.@#BDK "iiDKK75@ $t{{/C/C E F F #';;#3#3    O$U[[%..+NNO " s)   ,C* D *	D3!DD	D('D(c                 j   	 | j                   t        j                  u r%| j                   j                  j	                         }n| j                   j	                         }| j                  r| j                          	 | j                  |      }dj                  |j                         dgz         S # t
        t        f$ rS | j                  sC| j                  r7t        | j                  d      }|j	                         }|j                          n Y w xY w# | j                  r| j                          w w xY w)zU
        Read and decode a single file and return the data (Unicode string).
        rb
r7   )r'   rw   r   r   r3   rF   r   r   r(   ry   r   r   rM   rG   rS   )r+   rH   b_sources      r   r3   zFileInput.read  s    	{{cii'{{))..0{{'') ~~

{{4 yy*B4/00 k* 	==T%5%5 0 0$7}}  !	 ~~

 s%   AB. .ADD DD D2c                 @    | j                         j                  d      S )zK
        Return lines of a single file as list of Unicode strings.
        T)r3   rS   r.   s    r   	readlineszFileInput.readlines  s     yy{%%d++r   c                 r    | j                   t        j                  ur| j                   j                          y y r%   )r'   rw   r   r   r.   s    r   r   zFileInput.close  s'    ;;cii'KK (r   )NNNr^   Tr)r   r   r   r_   r,   r3   r   r   r   r   r   r   r   w  s'     15.6&)&P12, r   r   c                   :    e Zd ZdZdZdZ	 	 	 	 d	dZd Zd Zd Z	y)

FileOutputz,Output for single, simple file-like objects.z<file>rv   Nc                 $   t         j                  | ||||       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.rO   )
stacklevelFr   zWarning: Destination mode "z" differs from specified mode "")file)rg   r,   openedr   warningswarnDeprecationWarningr   rt   r   rw   r   rj   hasattrprintr   rk   r   )r+   rj   rk   r   r&   r   handle_io_errorsr   s           r   r,   zFileOutput.__init__  s    & 	k+; -	1"'MM *+=!M DI"}##&:: wt//8$**///!%!1!1!6!6>||%  (,(8(8(=(=%   " s   &D 	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   r&   ry   rk   rj   r   r   r   r   r   )r+   kwargsrL   s      r   ry   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 (r>   Nz2Unable to encode output data. output-encoding is: r=   )r   ry   r@   rA   r   rj   r   oslineseprE   rr   rp   r   bytesr   r   
ValueErrorrk   rF   r   r    r   r   )r+   rH   r   s      r   rp   zFileOutput.write  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)rj   rw   r   rx   r   r   r.   s    r   r   zFileOutput.close?  s;    CJJ

#;;""$DK <r   )NNNr^   TNN)
r   r   r   r_   rl   r   r,   ry   rp   r   r   r   r   r   r     s4    6'D)
 ;?BF-1-^,\ r   r   c                       e Zd ZdZdZy)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    
 Dr   r   c                       e Zd ZdZdZd Zy)StringInputz'Input from a `str` or `bytes` instance.<string>c                 8    | j                  | j                        S )z`Return the source as `str` instance.

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

    Provisional.
    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).
        )rr   rj   ro   s     r   rp   zStringOutput.writec  s!      ;;t,r   Nr   r   r   r_   rl   rp   r   r   r   r   r   [  s    
  * r   r   c                       e Zd ZdZdZd Zy)	NullInputzDegenerate input: read nothing.z
null inputc                      y)zReturn an empty string.r7   r   r.   s    r   r3   zNullInput.read|  s    r   Nr   r   r   r   r   r   v  s    )&r   r   c                       e Zd ZdZdZd Zy)
NullOutputz!Degenerate output: write nothing.znull outputc                      y)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y)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     s     *r   r   )&r_   __docformat__r   localer   ra   rw   r   docutilsr   catch_warningssimplefilter	getlocalegetdefaultlocalerC   r?   r   rL   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h',F,,.q1 <6v668; 	+113	4FMM"#
     '   .QM Qh;B] ;B|U UpN  N bz  z zz 
(% 
( 6  6  5 ]4 4
    %**," 	Y sA   D> AD2D> E' 2D;7D> >E$EE$'	E32E3