3 .�]q) � @ sL d dl Z ddlmZmZ G dd� de�ZG dd� de�ZG dd � d e�ZdS ) � N� )�EOF�TIMEOUTc @ sD e Zd Zddd�Zdd� Zddd�Zdd d �Zdd� Zdd d�ZdS )�Expecterr c C s$ || _ || _|dkr|j}|| _d S )Nr ���)�spawn�searcher�searchwindowsize)�selfr r r � r �/usr/lib/python3.6/expect.py�__init__ s zExpecter.__init__c C s� | j }| j}|j| }t|�}|j||| j�}|dkrz||jd � |_|d |j� |_||j|j� |_ |j |_ ||_|S ||_d S )Nr )r r �buffer�len�searchr �end�start�before�after�match�match_index)r �datar r �incoming�freshlen�indexr r r �new_data s zExpecter.new_dataNc C s� | j }|j|_|j� |_t|_| jj}|dkr>t|_||_ |S d |_d |_ t |�}|d| j 7 }|d k rxt |�d | }t|��d S )Nr z searcher: %s� )r r r �string_typer r r � eof_indexr r �str)r �errr r �msgr r r �eof s zExpecter.eofc C sz | j }|j|_t|_| jj}|dkr4t|_||_|S d |_d |_t |�}|d| j 7 }|d k rnt |�d | }t|��d S )Nr z searcher: %sr ) r r r r r r � timeout_indexr r r )r r r r r! r r r �timeout3 s zExpecter.timeoutc C s$ | j }|j|_d |_d |_d |_d S )N)r r r r r r )r r r r r �erroredF s zExpecter.erroredc C s | j }|dk rtj� | }y�|j}|j� |_xn| j|�}|dk rD|S |dk r\|dk r\| j� S |j|j|�}| j jdk r�tj | j j� |dk r.|tj� }q.W W n^ t k r� } z | j|�S d}~X n: tk r� } z | j|�S d}~X n | j � � Y nX dS )zBlocking expectNr )r �timer r r r$ Zread_nonblockingZmaxreadZdelayafterreadZsleepr r"