
    N&iB                        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	m
Z
 ddlmZmZmZ ej        dk    reZ G d d	e          Z G d
 de          Z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 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.
    )print_functionreStructuredTextN)TransformSpec)locale_encodingErrorStringErrorOutput   r   c                       e Zd ZdS )
InputErrorN__name__
__module____qualname__     X/home/geonatureadmin/si_en_reseau/tutos/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                       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S )Inputz1
    Abstract base class for input wrappers.
    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__6   sM     1**'&- 	8#7D#' EEr   c                 4    | j         d| j        d| j        S )Nz	: source=z, source_path=)	__class__r'   r(   r+   s    r   __repr__zInput.__repr__J   s(    26...$+++262B2BD 	Dr   c                     t           r%   NotImplementedErrorr/   s    r   readz
Input.readN   s    !!r   c                    | j         r<| j                                         dk    rt          |t                    s
J d            t          |t                    r|S | j         r	| j         g}nA|                     |          }|r|g}n&ddg}t
          r|                    dt
                     |D ]W}	 t          ||| j                  }|| _        |	                    dd          c S # t          t          f$ r}|}Y d}~Pd}~ww xY wt          d	d
                    d |D                       dt          |          d          )a   
        Decode a string, `data`, heuristically.
        Raise UnicodeError if unsuccessful.

        The client application should call ``locale.setlocale`` at the
        beginning of processing::

            locale.setlocale(locale.LC_ALL, '')
        unicodez=input encoding is "unicode" but input is not a unicode objectutf-8zlatin-1   u   ﻿ Nz=Unable to decode input data.  Tried the following encodings: z, c                 ,    g | ]}t          |          S r   )repr).0encs     r   
<listcomp>z Input.decode.<locals>.<listcomp>~   s    %E%E%ECd3ii%E%E%Er   .
())r   lower
isinstancer6   determine_encoding_from_datar   insertr&   r*   replaceUnicodeErrorr   joinr   )r+   data	encodingsdata_encodingr=   decodederrerrors           r   decodezInput.decodeQ   s    = 	5T]0022i??dG,, 5 545 5 5 dG$$ 	K= 	9 II ==dCCM 
9 +O		
 %i0	" 9$$Q888 	 	C!$T-?@@+.(y#66666 +.    l99%E%E9%E%E%EFFFF$U++++-. . 	.s   12C&&D7C>>Ds   coding[:=]\s*([-\w.]+)r7   z	utf-16-bez	utf-16-lec                    | 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   r8   ascii)byte_order_marks
startswith
splitlinescoding_slugsearchgrouprN   )r+   rH   start_bytesr   linematchs         r   rC   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   NNNr#   )r   r   r   __doc__component_typer)   r,   r0   r4   rN   recompilerU   r   BOM_UTF8BOM_UTF16_BEBOM_UTF16_LErR   rC   r   r   r   r!   r!   ,   s          N?C'F F F F(D D D" " ".. .. ..` "*788K''2,k:,k:=-    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 )
Outputz2
    Abstract base class for output wrappers.
    outputNr#   c                 j    || _         	 |pd| _        	 || _        	 || _        	 |s| j        | _        d S d S )Nr#   )r   r&   destinationdestination_pathdefault_destination_path)r+   rg   rh   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.   rg   rh   r/   s    r   r0   zOutput.__repr__   s*    >>>4#3#3#3T5J5JL 	Mr   c                     t           )z;`data` is a Unicode string, to be encoded by `self.encode`.r2   r+   rH   s     r   writezOutput.write   s    !!r   c                     | j         r>| j                                         dk    r!t          |t                    s
J d            |S t          |t                    s|S |                    | j         | j                  S )Nr6   zFthe encoding given is "unicode" but the output is not a Unicode string)r   rA   rB   r6   encoder&   rl   s     r   ro   zOutput.encode   s    = 	T]0022i??dG,, $ $#$ $ $ K$(( 	BK;;t}d.@AAAr   r[   )
r   r   r   r\   r]   ri   r,   r0   rm   ro   r   r   r   rd   rd      s~          N#:>.6B B B B"M M M" " "
B 
B 
B 
B 
Br   rd   c                   R    e Zd ZdZdddddej        dk    rdndfdZd	 Zd
 Zd Z	dS )	FileInputz5
    Input for single, simple file-like objects.
    Nr#   Tr	   rrUc                 Z   t                               | ||||           || _        t                      | _        |x|rdt
          j        dk    r| j        | j        d}ni }	 t          ||fi || _
        n# t          $ r }t          |j        |j        |          d}~ww xY wt
          j        | _
        nQt
          j        dk    rAt!          | 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 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 'rU' provides universal newline support
              for text files with Python 2.x.
        Nr	   r   errorsFz#Encoding clash: encoding given is "z&" but source is opened with encoding "z".)r!   r,   	autocloser   _stderrsysversion_infor   r&   openr'   IOErrorr   errnostrerrorstdinr   rF   namer(   r   )	r+   r'   r(   r   r&   rw   modekwargsrM   s	            r   r,   zFileInput.__init__   sz   " 	tV[(MJJJ""}}> (#v--*.-(,(:< <FF  FO"&{D"C"CF"C"CDKK O O O$U[%.+NNNO "i&((T[$-88EAA, $t{/C/C/C E F F F  	#';#3   !   	 	s*    A4 4
B>BBD 
D('D(c                    	 | j         t          j        u rYt          j        dk    rI| j         j                                        }d                    |                                          dz   }n| j                                         }n# t          t          f$ r}| j
        so| j        rht          | j        d          }|                                }|                                 d                    |                                          dz   }n Y d}~nd}~ww xY w| j        r|                                  n!# | j        r|                                  w w xY w|                     |          S )zU
        Read and decode a single file and return the data (Unicode string).
        r	      
rbN)r'   ry   r   rz   bufferr4   rG   rT   rF   r   r   r(   r{   closerw   rN   )r+   rH   rL   b_sources       r   r4   zFileInput.read   sX   	{ci''C,<,F,F{)..00zz$//"3"344u<{''))k* 		 		 		= T%5  0$77}}   zz$//"3"344u< 		 ~ 

 ~ 

{{4   s1   BB D9 DA7DD9 DD9 9Ec                 P    |                                                      d          S )zK
        Return lines of a single file as list of Unicode strings.
        T)r4   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'   ry   r   r   r/   s    r   r   zFileInput.close!  s3    ;ci''K ('r   )
r   r   r   r\   ry   rz   r,   r4   r   r   r   r   r   rq   rq      s          #h -77ccT- - - -^! ! !6, , ,         r   rq   c                   8    e Zd ZdZdZ	 	 	 	 d
dZd Zd Zd	 ZdS )
FileOutputz6
    Output for single, simple file-like objects.
    wNr#   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.
        TNziio.FileOutput: initialization argument "handle_io_errors" is ignored and will be removed in Docutils 1.2.rP   )
stacklevelFr   zWarning: Destination mode "z" differs from specified mode "")file)rd   r,   openedrw   warningswarnDeprecationWarningr   r   rx   ry   stdoutrg   hasattrprintr   rh   r   )r+   rg   rh   r   r&   rw   handle_io_errorsr   s           r   r,   zFileOutput.__init__2  sU   & 	k+; -	1 	1 	1"'M  !3C C C C DI"}} .##&:  	)t/88	)$*///%)%5%:%:%:DDDB<) ) ) )   	(,(8(=%%%!   	 	s   C) )
C76C7c                    t           j        dk    r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 )Nr	   bru   T)ry   rz   r   r   r&   r{   rh   rg   r|   r   r}   r~   r   )r+   r   rM   s      r   r{   zFileOutput.opena  s    v%%#TY*>*>"&- $ 24 4FF F	5#D$949OOOOD 	5 	5 	5ek5>"35 5 5	5 s   A 
A: A55A:c                    | j         s|                                  d| j        vrt          j        dk     st          | j        | j                  du rc|                     |          }t          j        dk    r>t          j
        dk    r.|                    dt          t          j
        d                    }	 | j                            |           n# t          $ r}t          j        dk    rt          |t                    r|	 | j        j                            |           n[# t"          $ rN t          | j        | j                  du r/t%          d| j        pd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 )zEncode `data`, write it to a single file, and return it.

        With Python 3 or binary output mode, `data` is returned unchanged,
        except when specified encoding and output encoding differ.
        r   r	   F
r   rQ   zEncoding of rg   z (z&) differs 
  from specified encoding (r@   Nz2Unable to encode output data. output-encoding is: r?   )r   r{   r   ry   rz   r   rg   r   ro   oslineseprE   bytesrm   r   rB   r   r   
ValueErrorrh   rF   r   r   rw   r   )r+   rH   rL   s      r   rm   zFileOutput.writeo  s@    { 	IIKKKty  S%5%>%>d.>>%GG;;t$$D6))bjD.@.@||E5W+E+EFF	""4(((( 	" 	" 	"6))ju.E.E)
"$+11$7777% " " "%d&6&*m5 58=> >(j!2CmCC ,555t}}}*F G G G
 "	" k* 	A 	A 	A,#}}}k#.>.>.>.>@A A A	A
 ~ 

 ~ 

sU   5C G  
G%F  D F  AE88F ;G   G(F<<GG   G>c                     | j         t          j        t          j        fvr"| j                                          d| _        d S d S )NF)rg   ry   r   stderrr   r   r/   s    r   r   zFileOutput.close  sA    CJ
#;;;""$$$DKKK <;r   )NNNr#   TNN)	r   r   r   r\   r   r,   r{   rm   r   r   r   r   r   r   &  sv          D)
 ;?BF-1- - - -^  % % %N         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
    Direct string input.
    <string>c                 6    |                      | j                  S )z$Decode and return the source string.)rN   r'   r/   s    r   r4   zStringInput.read  s    {{4;'''r   Nr   r   r   r\   r)   r4   r   r   r   r   r     s5          %( ( ( ( (r   r   c                       e Zd ZdZdZd ZdS )StringOutputz
    Direct string output.
    r   c                 D    |                      |          | _        | j        S )z=Encode `data`, store it in `self.destination`, and return it.)ro   rg   rl   s     r   rm   zStringOutput.write  s    ;;t,,r   Nr   r   r   r\   ri   rm   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 a null string.r9   r   r/   s    r   r4   zNullInput.read  s    sr   Nr   r   r   r   r   r     s5          '    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 )z6Do nothing ([don't even] send data to the bit bucket).Nr   rl   s     r   rm   zNullOutput.write  s    r   Nr   r   r   r   r   r     s5           -    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   r4   zDocTreeInput.read  s
    {r   Nr   r   r   r   r   r     s5          *    r   r   ) r\   
__future__r   __docformat__r   r   r^   ry   r   docutilsr   docutils.utils.error_reportingr   r   r   rz   strr6   r|   r   r   r   r!   rd   rq   r   r   r   r   r   r   r   r   r   r   <module>r      s  
  & % % % % %"  				 				 



  " " " " " " T T T T T T T T T TvG                  '         m m m m mM m m m`-B -B -B -B -B] -B -B -B`W  W  W  W  W  W  W  W ts  s  s  s  s  s  s  s l    z   
( 
( 
( 
( 
(% 
( 
( 
(         6      
 
 
 
 
 
 
 

 
 
 
 
 
 
 
    5     r   