Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/docutils/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/docutils/__pycache__/io.cpython-35.pyc



��])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@seZdZdS)�
InputErrorN)�__name__�
__module__�__qualname__�rr�</opt/alt/python35/lib/python3.5/site-packages/docutils/io.pyrsrc@seZdZdS)�OutputErrorN)rr	r
rrrrr
sr
c
CsIy#tj|j�tj|�kSWntttfk
rDdSYnXdS)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@s�eZdZdZdZdZdddddd�Zdd�Zd	d
�Zdd�Z	e
jed
��Z
ejdfejdfejdffZdd�ZdS)�Inputz1
    Abstract base class for input wrappers.
    �inputN�strictcCsC||_||_||_||_|s6|j|_d|_dS)N)r�
error_handler�source�source_path�default_source_path�successful_encoding)�selfrrrrrrr�__init__2s					zInput.__init__cCsd|j|j|jfS)Nz%s: source=%r, source_path=%r)�	__class__rr)rrrr�__repr__FszInput.__repr__cCs
t�dS)N)�NotImplementedError)rrrr�readJsz
Input.readcCsT|jr9|jj�dkr9t|t�s9td��t|t�rL|S|jrd|jg}nC|j|�}|r�|g}n"ddg}tr�|jdt�xt|D]l}y2t|||j�}||_	|j
dd�SWq�ttfk
r}z|}WYdd}~Xq�Xq�Wtd	d
j
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>zs	z 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]\}}|j|�r
|Sq
WxL|j�dd�D]4}|jj|�}|rD|jd�jd�SqDWdS)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/�sz"Input.determine_encoding_from_data)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^eZdZdZdZdZdddddd�Zdd�Zd	d
�Zdd�Z	dS)
�Outputz2
    Abstract base class for output wrappers.
    �outputNrcCs@||_|pd|_||_||_|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__cCs
t�dS)z;`data` is a Unicode string, to be encoded by `self.encode`.N)r")rr4rrr�write�szOutput.writecCsj|jr=|jj�dkr=t|t�s9td��|St|t�sP|S|j|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)
rr	r
rDrErOrr!rPrQrrrrrK�srKc@sXeZdZdZdddddddd�Zdd	�Zd
d�Zdd
�ZdS)�	FileInputz5
    Input for single, simple file-like objects.
    NrT�rUc
Ks�tj|||||�||_t�|_x=|D]5}|dkrZtjjd�q5td|��q5W|dkr|rtj	dkr�d|j
d|ji}ni}yt|||�|_
Wqtk
r}	zt|	j|	j|��WYdd}	~	XqXqdtj|_
nItj	dkrdt|j
|j
�d	krdtd
|j
|j
j
f��|s�y|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�rr�errorsFzOEncoding clash: encoding given is "%s" but source is opened with encoding "%s".)rUr)rUr)rr�	autocloser�_stderr�sys�stderrrPr�version_inforr�openr�IOErrorr�errno�strerror�stdinrr2�namerr)
rrrrrrW�mode�kwargs�keyr8rrrr�s8	
	.
zFileInput.__init__cCs*zyn|jtjkratjdkra|jjj�}td�j|j��td�}n|jj�}Wn�t	t
fk
r}zk|jr�|jr�t
|jd�}|j�}|j�td�j|j��td�}n�WYdd}~XnXWd|jr|j�X|j|�S)zU
        Read and decode a single file and return the data (Unicode string).
        rUr�
�rbN)rUr)rrYr`r[�bufferr#rr3r>r2rrrr\�closerWr9)rr4r7Zb_sourcerrrr#s !(
(	zFileInput.readcCs|j�jd�S)zK
        Return lines of a single file as list of Unicode strings.
        T)r#r>)rrrr�	readlines"szFileInput.readlinescCs#|jtjk	r|jj�dS)N)rrYr`rh)rrrrrh(szFileInput.close)rr	r
rDrr#rirhrrrrrR�s7rRc	@saeZdZdZdZddddddddd�Zdd	�Zd
d�Zdd
�ZdS)�
FileOutputz6
    Output for single, simple file-like objects.
    �wNrTcCs�tj|||||�d|_||_|dk	r@||_t�|_|dkry|rjd|_q�tj|_	nM|r�t
|j	d�r�||j	jkr�td|j	j|fd|j�|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__cCs�tjdkr9d|jkr9d|jd|ji}ni}yt|j|j|�|_Wn@tk
r�}z t	|j
|j|j��WYdd}~XnXd|_dS)NrUrrrrVT)rUr)
rYr[rbrrr\rNrMr]r
r^r_rm)rrcr8rrrr\ds	zFileOutput.opencCs�|js|j�d|jkr1tjd
ksLt|j|j�dkr�|j|�}tjdkr�t	j
dkr�|jtd�tt	j
��}z"y|jj
|�Wntk
rq}z�tjdkr_t|t�r_y|jjj
|�Wnatk
r^t|j|j�dkrTtd|jp8d|jj|jf��n|�YnXWYdd}~XnJttfk
r�}z$td	|jt|�f��WYdd}~XnXWd|jr�|j�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.
        rrUrFrez;Encoding of %s (%s) differs 
  from specified encoding (%s)rMNz:Unable to encode output data. output-encoding is: %s.
(%s))rUr)rUr)rUr)rmr\rbrYr[rrMrrQ�os�linesepr1rrPrr,�bytesrgr�
ValueErrorrNr2rrrWrh)rr4�er7rrrrPrs8	
!
	0	zFileOutput.writecCs5|jtjtjfkr1|jj�d|_dS)NF)rMrYrnrZrhrm)rrrrrh�s
zFileOutput.close)	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�srvc@s(eZdZdZdZdd�ZdS)�StringInputz
    Direct string input.
    z<string>cCs|j|j�S)z$Decode and return the source string.)r9r)rrrrr#�szStringInput.readN)rr	r
rDrr#rrrrrx�srxc@s(eZdZdZdZdd�ZdS)�StringOutputz
    Direct string output.
    z<string>cCs|j|�|_|jS)z=Encode `data`, store it in `self.destination`, and return it.)rQrM)rr4rrrrP�szStringOutput.writeN)rr	r
rDrOrPrrrrry�sryc@s(eZdZdZdZdd�ZdS)�	NullInputz)
    Degenerate input: read nothing.
    z
null inputcCsdS)zReturn a null string.r&r)rrrrr#�szNullInput.readN)rr	r
rDrr#rrrrrz�srzc@s(eZdZdZdZdd�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{�sr{c@s(eZdZdZdZdd�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|�sr|)rDZ
__docformat__rYrqrFr�docutilsrZdocutils._compatrZdocutils.utils.error_reportingrrrr]rr
rrrKrRrjrvrxryrzr{r|rrrr�<module>s*p0es