File: //lib/python3.6/site-packages/docutils/__pycache__/io.cpython-36.opt-1.pyc
3
s2�e)D � @ s d Z dZddlZddlZddlZddlZddlmZ ddlm Z ddl
mZmZm
Z
G dd� de�ZG d d
� d
e�Zdd� ZG d
d� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd � 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 e Zd ZdS )�
InputErrorN)�__name__�
__module__�__qualname__� r r �/usr/lib/python3.6/io.pyr s r c @ s e Zd ZdS )�OutputErrorN)r r r
r r r r r
s r
c
C s6 yt j| j�t j|�kS tttfk
r0 dS X dS )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 r r r �check_encoding s
r c @ sl e Zd ZdZdZdZddd�Zdd� Zd d
� Zdd� Z e
jed
��Z
ejdfejdfejdffZdd� ZdS )�Inputz1
Abstract base class for input wrappers.
�inputN�strictc C s. || _ || _|| _|| _|s$| j| _d | _d S )N)r �
error_handler�source�source_path�default_source_path�successful_encoding)�selfr r r r r r r �__init__2 s zInput.__init__c C s d| j | j| jf S )Nz%s: source=%r, source_path=%r)� __class__r r )r r r r �__repr__F s
zInput.__repr__c C s t �d S )N)�NotImplementedError)r r r r �readJ s z
Input.readc C s� | j r| j j� dkrt|t�r"|S | j r2| j g}n.| j|�}|rH|g}nddg}tr`|jdt� xX|D ]P}y t||| j�}|| _|j dd�S t
tfk
r� } z
|}W Y dd}~X qfX qfW t
dd jd
d� |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, '')
�unicodezutf-8zlatin-1� u � NzEUnable to decode input data. Tried the following encodings: %s.
(%s)z, c S s g | ]}t |��qS r )�repr)�.0�encr r r �
<listcomp>z s z Input.decode.<locals>.<listcomp>)r �lower�
isinstance�str�determine_encoding_from_datar �insertr r �replace�UnicodeErrorr �joinr )r �dataZ encodings�
data_encodingr) Zdecoded�err�errorr r r �decodeM s,
zInput.decodezcoding[:=]\s*([-\w.]+)zutf-8z utf-16-bez utf-16-lec C s` x | j D ]\}}|j|�r|S qW x8|j� dd� D ]$}| jj|�}|r4|jd�jd�S q4W dS )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�groupr7 )r r3 Zstart_bytesr �line�matchr r r r. � s
z"Input.determine_encoding_from_data)NNNr )r r r
�__doc__�component_typer r r! r# r7 �re�compiler r= r �BOM_UTF8�BOM_UTF16_BE�BOM_UTF16_LEr: r. r r r r r ( s
0r c @ s: e Zd ZdZdZdZd
dd�Zdd� Zd d
� Zdd� Z dS )�Outputz2
Abstract base class for output wrappers.
�outputNr c C s, || _ |pd| _|| _|| _|s(| j| _d S )Nr )r r �destination�destination_path�default_destination_path)r rK rL r r r r r r � s
zOutput.__init__c C s d| j | j| jf S )Nz'%s: destination=%r, destination_path=%r)r rK rL )r r r r r! � s zOutput.__repr__c C s t �dS )z;`data` is a Unicode string, to be encoded by `self.encode`.N)r"