e6^ddlZddlmZmZGddeZGddeZGdd eZy) N)EOFTIMEOUTcDeZdZd dZdZdZdZd dZd dZdZ d d Z y) Expecterc||_||_|dk(r |j}||_d|_t |dr|j |_yy)Nlongest_string)spawnsearchersearchwindowsizelookbackhasattrr )selfr r r s 0/usr/lib/python3/dist-packages/pexpect/expect.py__init__zExpecter.__init__sR    r !$55  0 8- .$33DM /c|j}|j}|t|kDr t|}|j|||j}|dk\r|j |_|j j||jd|jjdt||jz |_ |j |_ |jj||jd||j|j|_ |j|_||_|S|js |j rm|jxs |j }|j j#|kDr5|j |_|j j|| dyyyNr)r r lensearchr buffer_type_bufferwriteend_beforegetvaluestartbeforeaftermatch match_indexrtell)rwindowfreshlenr r indexmaintains r do_searchzExpecter.do_searchsk == c&k !6{H$2G2GH A:!--/EM MM  x||} 5 6 ==113CK(..013EL!--/EM MM  x||} 5 6  =EK"..EK %E L  " "dmm,,= H}}!!#h. % 1 1 3  ##FH9:$67/'4rc|j}|jj}|jj}|}||kDr1|jsL|j |_|jj }|jj|nL||jkr}|j |_|jjtd||jz |jj}|jj|n|jjtd||jz |jj}ns|jrM|jjtd||jz |jj}n|jj }|j||Sr) r rr#rr rrrseekmaxreadr()rr before_lenbuf_lenr%r$s r existing_datazExpecter.existing_data*s} ]]'') --$$&  (( % 1 1 3 //1 ##F+4000 % 1 1 3  "":(=(==>@++- ##F+ ""3q'D4I4I*I#JK++-$$ ""3q'D4I4I*I#JK++-//1~~fh//rc|j}t|}|jj||js|j r|j j}|j j||j jtd||j z |j j}n+|j j||j}nt||jk\s|j jsO||j d}|j|_|j j||j dn|j j||j j}|j jtd||jz |j j}|j||Sr)r rrrr rrr#r*r+r,bufferrr()rdatar r%old_lenr$new_lens rnew_datazExpecter.new_dataHs t9 D!$$}}--,,. ##D) ""3q'DMM*A#BC++- ##D)4yD1119K9K9Mt44456 % 1 1 3  ##FD,A,A+A+B$CD ##D)--,,. ""3q'D4I4I*I#JK++-~~fh//rNc|j}|jj|_|j |_|j |_t |_|jj}|dk\rt |_ ||_ |Sd|_ d|_ t|}|d|jzz }|t|dz|z}t |}d|_ |Nrz searcher: %s )r rrrrrrr r eof_indexr!r"str __cause__rerrr r&msgexcs reofz Expecter.eofds }}--/ ))+ ))+   '' A:EK %E LEK $E e*C #dmm3 3C#ho+c(C CMIrcp|j}|jj|_t|_|j j}|dk\rt|_||_ |Sd|_d|_ t|}|d|j zz }|t|dz|z}t |}d|_ |r7) r rrrrr r timeout_indexr!r"r:r;r<s rtimeoutzExpecter.timeout|s }}--/   ++ A:!EK %E LEK $E e*C #dmm3 3C#ho+#,C CMIrc|j}|jj|_d|_d|_d|_yN)r rrrr r!r")rr s rerroredzExpecter.erroreds5 }}--/    rcn|j}|tj|z} |j}||S ||dkr|jS|j |j |}|jj )tj|jj |j|}||S|tjz }#t$r}|j|cYd}~Sd}~wt$r}|j|cYd}~Sd}~w|jxYw)zBlocking expectNr) r timer/rCread_nonblockingmaxreaddelayafterreadsleepr5rr@rrF)rrCr end_timeidxincominges r expect_loopzExpecter.expect_loops    yy{W,H $$&C 'gk<<>) 11%--I::,,8JJtzz889mmH-?J&&4G 88A;  #<<? "  LLN sACCA/CC D4&C<6D4< D4DD4D4)r rE) __name__ __module__ __qualname__rr(r/r5r@rCrFrQrrrrs* 4800<080,!rrc$eZdZdZdZdZddZy)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.d|_d|_g|_d|_t |D]k\}}|t ur||_|t ur||_&|jj||ft||jkDs\t||_my)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 rN) r9rB_stringsr enumeraterrappendr)rstringsnss rrzsearcher_string.__init__s g& -DAqCx!"G|%&" MM !Q (1v+++&)!f# -rc|jDcgc] }|dd|zf}}|jd|jdk\r*|j|jd|jzf|jdk\r*|j|jd|jzf|j t t |d}dj|Scc}w)UThis returns a human-readable string that represents the state of the object.rz %d: %r)r zsearcher_string: %d: EOF %d: TIMEOUTrr8)rYr[r9rBsortlistzipjoin)rnssss r__str__zsearcher_string.__str__s48== ARr!ulR'( A A *+ >>Q  IIt~~}t~~'EF G    " IIt))!D$6$668 9  #r(^A yy}BsCNcd}|jD]@\}}||t|z }n| }|j||}|dk\s3|||ks;|}||} } B|y |_||_|jt|jz|_ 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. Nrr )rYrfindr!rr) rr1r%r first_matchr&r^offsetr] best_index best_matchs rrzsearcher_string.searchs  2HE1'$c!f,-+* Av&AAv;.!k/ ).J  2     ::DJJ/rrErRrSrT__doc__rrirrUrrrWrWs$-& *rrWc$eZdZdZdZdZddZy) 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 cd|_d|_g|_t|D]B\}}|tur||_|t ur||_&|jj ||fDy)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.r N)r9rB _searchesrZrrr[)rpatternsr]r^s rrzsearcher_re.__init__0sk h' *DAqCx!"G|%&" NN ! !1a& ) *rct}|jD]'\}}|j|d||jfzf)|jd|jdk\r*|j|jd|jzf|j dk\r*|j|j d|j zf|j tt|d}dj|S)r`z %d: re.compile(%r))r z searcher_re:rrarbrr8) rdrur[patternr9rBrcrerf)rrhr]r^s rrizsearcher_re.__str__As VNN FDAq IIq2a^CD E F &' >>Q  IIt~~}t~~'EF G    " IIt))+<"",#$ %  #r(^A yy}rNc2d}|d}ntdt||z }|jD]8\}}|j||}||j } || |ks3| }|} |} :|y||_ |_|j j |_ 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.Nrr )r+rrurrr!r) rr1r%r rl searchstartr&r^r!r] the_matchrns rrzsearcher_re.searchTs   #KaV/?!?@K #HE1HHV[1E} A"a+o ! "  #     ::>>#rrErprUrrrsrss$*"&rrs)rH exceptionsrrobjectrrWrsrUrrr~s7 $svsl_f_DV&Vr