eaiovnaovbqoebvqoeavibavo 3 .]q)@sLddlZddlmZmZGdddeZGdddeZGdd d eZdS) N)EOFTIMEOUTc@sDeZdZdddZddZdddZdd d Zd d Zdd dZdS)ExpecterrcCs$||_||_|dkr|j}||_dS)Nr)spawnsearchersearchwindowsize)selfrrr r /usr/lib/python3.6/expect.py__init__s zExpecter.__init__cCs|j}|j}|j|}t|}|j|||j}|dkrz||jd|_|d|j|_||j|j|_ |j |_ ||_ |S||_dS)Nr) rrbufferlensearchr endstartbeforeaftermatch match_index)r datarrincomingfreshlenindexr r r new_data s zExpecter.new_dataNcCs|j}|j|_|j|_t|_|jj}|dkr>t|_||_ |Sd|_d|_ t |}|d|j7}|dk rxt |d|}t|dS)Nrz searcher: %s ) rrr string_typerrr eof_indexrrstr)r errrrmsgr r r eofs  z Expecter.eofcCsz|j}|j|_t|_|jj}|dkr4t|_||_|Sd|_d|_t |}|d|j7}|dk rnt |d|}t|dS)Nrz searcher: %sr) rrrrrr timeout_indexrrr)r r rrr!r r r timeout3szExpecter.timeoutcCs$|j}|j|_d|_d|_d|_dS)N)rrrrrr)r rr r r erroredFs zExpecter.erroredcCs|j}|dk rtj|}y|j}|j|_xn|j|}|dk rD|S|dk r\|dkr\|jS|j|j|}|jjdk rtj |jj|dk r.|tj}q.WWn^t k r}z |j |Sd}~Xn:t k r}z |j|Sd}~Xn|j YnXdS)zBlocking expectNr)rtimerrrr$Zread_nonblockingZmaxreadZdelayafterreadZsleeprr"rr%)r r$rZend_timeridxer r r expect_loopMs0    zExpecter.expect_loopr)r)N)Nr)r) __name__ __module__ __qualname__r rr"r$r%r)r r r r rs    rc@s*eZdZdZddZddZd 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 cCs\d|_d|_g|_xDt|D]8\}}|tkr4||_q|tkrD||_q|jj||fqWdS)zThis creates an instance of searcher_string. This argument 'strings' may be a list; a sequence of strings; or the EOF or TIMEOUT types. rNrr)rr#_strings enumeraterrappend)r Zstringsnsr r r r szsearcher_string.__init__cCs|dd|jD}|jd |jdkr:|j|jd|jf|jdkrZ|j|jd|jf|jtt|d}dj|S) zUThis returns a human-readable string that represents the state of the object.cSsg|]}|dd|fqS)rz %d: "%s"r ).0nsr r r sz+searcher_string.__str__..rsearcher_string:rz %d: EOFz %d: TIMEOUTrr)rr6)r.r0rr#sortlistzipjoin)r ssr r r __str__s   zsearcher_string.__str__Nc Csd}xb|jD]X\}}|dkr,|t| }n| }|j||}|dkr |dksV||kr |}||} } q W|dkrtdS| |_||_|jt|j|_| S)aThis searches 'buffer' for the first occurrence of one of the search strings. 'freshlen' must indicate the number of bytes at the end of 'buffer' which have not been searched before. It helps to avoid searching the same, possibly big, buffer over and over again. See class spawn for the 'searchwindowsize' argument. If there is a match this returns the index of that string, and sets 'start', 'end' and 'match'. Otherwise, this returns -1. Nrrr)r.rfindrrr) r rrr first_matchrr2offsetr1 best_indexZ best_matchr r r rs  zsearcher_string.search)N)r*r+r,__doc__r r<rr r r r r-nsr-c@s*eZdZdZddZddZd ddZdS) searcher_reaVThis is regular expression string search helper for the spawn.expect_any() method. This helper class is for powerful pattern matching. For speed, see the helper class, searcher_string. 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 re.match object returned by a successful re.search cCsjd|_d|_g|_xRtttt||D]8\}}|tkrB||_q*|tkrR||_q*|jj ||fq*WdS)zThis creates an instance that searches for 'patterns' Where 'patterns' may be a list or other sequence of compiled regular expressions, or the EOF or TIMEOUT types.rNrr) rr# _searchesr9r8rangerrrr0)r Zpatternsr1r2r r r r s zsearcher_re.__init__c Cst}x\|jD]R\}}y|j|d||jffWqtk r^|j|d||jffYqXqW|jd |jdkr|j|jd|jf|jdkr|j|jd|jf|jtt|d}dj |S) zUThis returns a human-readable string that represents the state of the object.z %d: re.compile("%s")z %d: re.compile(%r)r searcher_re:rz %d: EOFz %d: TIMEOUTrr)rrE) r8rCr0patternUnicodeEncodeErrorrr#r7r9r:)r r;r1r2r r r r<s"     zsearcher_re.__str__Nc Csd}|dkrd}ntdt||}xL|jD]B\}}|j||}|dkrJq,|j} |dksb| |kr,| }|} |} q,W|dkr~dS||_| |_|jj|_| S)aThis searches 'buffer' for the first occurrence of one of the regular expressions. 'freshlen' must indicate the number of bytes at the end of 'buffer' which have not been searched before. See class spawn for the 'searchwindowsize' argument. If there is a match this returns the index of that string, and sets 'start', 'end' and 'match'. Otherwise, returns -1.Nrrr)maxrrCrrrr) r rrr r>Z searchstartrr2rr1Z the_matchr@r r r r s&   zsearcher_re.search)N)r*r+r,rAr r<rr r r r rBsrB)r& exceptionsrrobjectrr-rBr r r r si_