3
.]q) @ sL d dl Z ddlmZmZ G dd deZG dd deZG dd d eZdS )
N )EOFTIMEOUTc @ sD e Zd ZdddZdd ZdddZdd d
Zdd Zdd
dZdS )Expecterr c C s$ || _ || _|dkr|j}|| _d S )Nr )spawnsearchersearchwindowsize)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 bufferlensearchr endstartbeforeaftermatchmatch_index)r
datar r incomingfreshlenindexr 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 rtj | 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" r r% )r
r$ r Zend_timer idxer r r expect_loopM s0
zExpecter.expect_loopr )r )N)Nr )r ) __name__
__module____qualname__r
r r" r$ r% r) r r r r r s
r c @ s* e Zd ZdZdd Zdd Zd ddZdS )
searcher_stringa- This is a plain string search helper for the spawn.expect_any() method.
This helper class is for speed. For more powerful regex patterns
see the helper class, searcher_re.
Attributes:
eof_index - index of EOF, or -1
timeout_index - index of TIMEOUT, or -1
After a successful match by the search() method the following attributes
are available:
start - index into the buffer, first byte of match
end - index into the buffer, first byte after match
match - the matching string itself
c C s\ d| _ d| _g | _xDt|D ]8\}}|tkr4|| _ q|tkrD|| _q| jj||f qW dS )zThis creates an instance of searcher_string. This argument 'strings'
may be a list; a sequence of strings; or the EOF or TIMEOUT types. r Nr r )r r# _strings enumerater r append)r
Zstringsnsr r r r
s zsearcher_string.__init__c C s| dd | j D }|jd
| jdkr:|j| jd| j f | jdkrZ|j| jd| j f |j tt| d }dj|S )zUThis returns a human-readable string that represents the state of
the object.c S s g | ]}|d d| fqS )r z %d: "%s"r ).0nsr r r