Your IP : 216.73.216.196


Current Path : /opt/alt/python37/lib/python3.7/site-packages/docutils/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/docutils/__pycache__/io.cpython-37.pyc

B

7��])D�@s dZdZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZmZm
Z
Gdd�de�ZGd	d
�d
e�Zdd�ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd �d e�ZdS)!z
I/O classes provide a uniform API for low-level input and output.  Subclasses
exist for a variety of input/output mechanisms.
ZreStructuredText�N)�
TransformSpec)�b)�locale_encoding�ErrorString�ErrorOutputc@seZdZdS)�
InputErrorN)�__name__�
__module__�__qualname__�rr�</opt/alt/python37/lib/python3.7/site-packages/docutils/io.pyrsrc@seZdZdS)�OutputErrorN)rr	r
rrrrr
sr
c
Cs6yt�|j�t�|�kStttfk
r0dSXdS)aNTest, 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)�streamrrrr�check_encodings
rc@sleZdZdZdZdZddd�Zdd�Zd	d
�Zdd�Z	e
�ed
��Z
ejdfejdfejdffZdd�ZdS)�Inputz1
    Abstract base class for input wrappers.
    �inputN�strictcCs.||_||_||_||_|s$|j|_d|_dS)N)r�
error_handler�source�source_path�default_source_path�successful_encoding)�selfrrrrrrr�__init__2szInput.__init__cCsd|j|j|jfS)Nz%s: source=%r, source_path=%r)�	__class__rr)rrrr�__repr__Fs
zInput.__repr__cCst�dS)N)�NotImplementedError)rrrr�readJsz
Input.readcCs�|jr&|j��dkr&t|t�s&td��t|t�r4|S|jrD|jg}n.|�|�}|rZ|g}nddg}trr|�dt�xX|D]P}y t|||j�}||_	|�
dd�Sttfk
r�}z|}Wdd}~XYqxXqxWtd	d
�
dd�|D��t|�f��dS)
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 objectzutf-8zlatin-1�u�NzEUnable to decode input data.  Tried the following encodings: %s.
(%s)z, cSsg|]}t|��qSr)�repr)�.0�encrrr�
<listcomp>zsz Input.decode.<locals>.<listcomp>)r�lower�
isinstance�str�AssertionError�determine_encoding_from_datar�insertrr�replace�UnicodeErrorr�joinr)r�data�	encodings�
data_encodingr)Zdecoded�err�errorrrr�decodeMs0




zInput.decodezcoding[:=]\s*([-\w.]+)zutf-8z	utf-16-bez	utf-16-lecCs`x |jD]\}}|�|�r|SqWx8|��dd�D]$}|j�|�}|r4|�d��d�Sq4WdS)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�groupr9)rr4Zstart_bytesr�line�matchrrrr/�s
z"Input.determine_encoding_from_data)NNNr)rr	r
�__doc__�component_typerrr!r#r9�re�compilerr?r�BOM_UTF8�BOM_UTF16_BE�BOM_UTF16_LEr<r/rrrrr(s
0rc@s:eZdZdZdZdZd
dd�Zdd�Zd	d
�Zdd�Z	dS)�Outputz2
    Abstract base class for output wrappers.
    �outputNrcCs,||_|pd|_||_||_|s(|j|_dS)Nr)rr�destination�destination_path�default_destination_path)rrMrNrrrrrr�s
zOutput.__init__cCsd|j|j|jfS)Nz'%s: destination=%r, destination_path=%r)r rMrN)rrrrr!�szOutput.__repr__cCst�dS)z;`data` is a Unicode string, to be encoded by `self.encode`.N)r")rr4rrr�write�szOutput.writecCsL|jr*|j��dkr*t|t�s&td��|St|t�s8|S|�|j|j�SdS)Nr$zFthe encoding given is "unicode" but the output is not a Unicode string)rr+r,r-r.�encoder)rr4rrrrQ�s
z
Output.encode)NNNr)
rr	r
rDrErOrr!rPrQrrrrrK�s
rKc@s2eZdZdZddd�Zdd	�Zd
d�Zdd
�ZdS)�	FileInputz5
    Input for single, simple file-like objects.
    NrT�rUc

Ks4t�|||||�||_t�|_x.|D]&}|dkr@tj�d�q&td|��q&W|dkr�|r�tj	dkrv|j
|jd�}ni}yt||f|�|_
Wq�tk
r�}	zt|	j|	j|��Wdd}	~	XYq�Xntj|_
n6tj	dk�rt|j
|j
�dk�rtd|j
|j
j
f��|�s0y|j
j|_Wntk
�r.YnXdS)	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.
        �handle_io_errorsz�deprecation warning: io.FileInput() argument `handle_io_errors` is ignored since "Docutils 0.10 (2012-12-16)" and will soon be removed.z2__init__() got an unexpected keyword argument '%s'N)�r)r�errorsFzOEncoding clash: encoding given is "%s" but source is opened with encoding "%s".)rr�	autocloser�_stderr�sys�stderrrPr�version_inforr�openr�IOErrorr�errno�strerror�stdinrr2�namerr)
rrrrrrW�mode�kwargs�keyr8rrrr�s8

$
zFileInput.__init__c
Cs�z�yL|jtjkrBtjdkrB|jj��}td��|���td�}n
|j��}Wnlt	t
fk
r�}zJ|js�|jr�t
|jd�}|��}|��td��|���td�}n�Wdd}~XYnXWd|jr�|��X|�|�S)zU
        Read and decode a single file and return the data (Unicode string).
        )rUr�
�rbN)rrYr`r[�bufferr#rr3r>r2rrrr\�closerWr9)rr4r7Zb_sourcerrrr#s 
zFileInput.readcCs|���d�S)zK
        Return lines of a single file as list of Unicode strings.
        T)r#r>)rrrr�	readlines"szFileInput.readlinescCs|jtjk	r|j��dS)N)rrYr`rh)rrrrrh(szFileInput.close)NNNrTrS)rr	r
rDrr#rirhrrrrrR�s
7rRc@s6eZdZdZdZddd�Zdd	�Zd
d�Zdd
�ZdS)�
FileOutputz6
    Output for single, simple file-like objects.
    �wNrTcCs�t�|||||�d|_||_|dk	r,||_t�|_|dkrR|rHd|_q�tj|_	n6|r�t
|j	d�r�||j	jkr�td|j	j|f|jd�|s�y|j	j|_
Wntk
r�YnXdS)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.
        TNFrbz?Warning: Destination mode "%s" differs from specified mode "%s")�file)rKr�openedrWrbrrXrY�stdoutrM�hasattr�printrarNr)rrMrNrrrWrTrbrrrr9s(

zFileOutput.__init__c
Cs�tjdkr$d|jkr$|j|jd�}ni}yt|j|jf|�|_Wn4tk
rt}zt	|j
|j|j��Wdd}~XYnXd|_dS)N)rUrr)rrVT)
rYr[rbrrr\rNrMr]r
r^r_rm)rrcr8rrrr\ds
zFileOutput.opencCsn|js|��d|jkr"tjdks4t|j|j�dkrh|�|�}tjdkrht	j
dkrh|�td�tt	j
��}z�y|j�
|�Wn�tk
�r}z|tjdk�rt|t��ry|jj�
|�WnLtk
�rt|j|j�dkr�td|jp�d|jj|jf��n|�YnXWdd}~XYn>ttfk
�rR}ztd|jt|�f��Wdd}~XYnXWd|j�rh|��X|S)	z�Encode `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)rUrFrez;Encoding of %s (%s) differs 
  from specified encoding (%s)rMNz:Unable to encode output data. output-encoding is: %s.
(%s))rmr\rbrYr[rrMrrQ�os�linesepr1rrPrr,�bytesrgr�
ValueErrorrNr2rrrWrh)rr4�er7rrrrPrs8
(
zFileOutput.writecCs&|jtjtjfkr"|j��d|_dS)NF)rMrYrnrZrhrm)rrrrrh�s
zFileOutput.close)NNNrTNN)	rr	r
rDrbrr\rPrhrrrrrj-s
)(rjc@seZdZdZdZdS)�BinaryFileOutputzL
    A version of docutils.io.FileOutput which writes to a binary file.
    �wbN)rr	r
rDrbrrrrrv�srvc@seZdZdZdZdd�ZdS)�StringInputz
    Direct string input.
    z<string>cCs|�|j�S)z$Decode and return the source string.)r9r)rrrrr#�szStringInput.readN)rr	r
rDrr#rrrrrx�srxc@seZdZdZdZdd�ZdS)�StringOutputz
    Direct string output.
    z<string>cCs|�|�|_|jS)z=Encode `data`, store it in `self.destination`, and return it.)rQrM)rr4rrrrP�szStringOutput.writeN)rr	r
rDrOrPrrrrry�sryc@seZdZdZdZdd�ZdS)�	NullInputz)
    Degenerate input: read nothing.
    z
null inputcCsdS)zReturn a null string.r&r)rrrrr#�szNullInput.readN)rr	r
rDrr#rrrrrz�srzc@seZdZdZdZdd�ZdS)�
NullOutputz+
    Degenerate output: write nothing.
    znull outputcCsdS)z6Do nothing ([don't even] send data to the bit bucket).Nr)rr4rrrrP�szNullOutput.writeN)rr	r
rDrOrPrrrrr{�sr{c@seZdZdZdZdd�ZdS)�DocTreeInputzm
    Adapter for document tree input.

    The document tree must be passed in the ``source`` parameter.
    z
doctree inputcCs|jS)zReturn the document tree.)r)rrrrr#�szDocTreeInput.readN)rr	r
rDrr#rrrrr|�sr|)rDZ
__docformat__rYrqrFr�docutilsrZdocutils._compatrZdocutils.utils.error_reportingrrrr]rr
rrrKrRrjrvrxryrzr{r|rrrr�<module>s*p0es