File: //proc/722141/root/lib/python3.6/site-packages/docutils/__pycache__/io.cpython-36.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� dkr&t|t�s&td��t|t�r4|S | j rD| j g}n.| j|�}|rZ|g}nddg}trr|jdt� xX|D ]P}y t||| j�}|| _ |j
dd�S ttfk
r� } z
|}W Y dd}~X qxX qxW td 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, c S s g | ]}t |��qS r )�repr)�.0�encr r r �
<listcomp>z s z Input.decode.<locals>.<listcomp>)r �lower�
isinstance�str�AssertionError�determine_encoding_from_datar �insertr r �replace�UnicodeErrorr �joinr )r �dataZ encodings�
data_encodingr) Zdecoded�err�errorr r r �decodeM s0
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�groupr8 )r r4 Zstart_bytesr �line�matchr r r r/ � s
z"Input.determine_encoding_from_data)NNNr )r r r
�__doc__�component_typer r r! r# r8 �re�compiler r>