o ÿé!^6ã@sLddlZddlmZmZGdd„deƒZGdd„deƒZGdd „d eƒZdS) éNé)ÚEOFÚTIMEOUTc@sTeZdZddd„Zdd„Zdd„Zdd „Zdd d „Zdd d„Zdd„Z ddd„Z d S)ÚExpecteréÿÿÿÿcCs@||_||_|dkr |j}||_d|_t|dƒr|j|_dSdS)NrÚlongest_string)ÚspawnÚsearcherÚsearchwindowsizeÚlookbackÚhasattrr)Úselfrr r ©rú0/usr/lib/python3/dist-packages/pexpect/expect.pyÚ__init__s  ÿzExpecter.__init__cCs|j}|j}|t|ƒkrt|ƒ}| |||j¡}|dkr^| ¡|_|j ||jd…¡|j   ¡dt|ƒ|j  …|_ | ¡|_ |j  ||jd…¡||j |j…|_ |j|_||_|S|jsd|jrƒ|jpi|j}|j ¡|kr…| ¡|_|j || d…¡dSdSdS©Nr)rr ÚlenÚsearchr Ú buffer_typeÚ_bufferÚwriteÚendÚ_beforeÚgetvalueÚstartÚbeforeÚafterÚmatchÚ match_indexr Útell)r ÚwindowÚfreshlenrr ÚindexÚmaintainrrrÚ do_searchs0  ÿ    üzExpecter.do_searchcCsö|j}|j ¡}|j ¡}|}||kr[|js'| ¡|_|j ¡}|j |¡nN||jkrI| ¡|_|j t d||jƒ¡|j  ¡}|j |¡n,|j t d||jƒ¡|j  ¡}n|jrp|j t d||jƒ¡|j  ¡}n|j ¡}|  ||¡Sr) rrrrr rrrÚseekÚmaxÚreadr$)r rÚ before_lenÚbuf_lenr!r rrrÚ existing_data*s.      ÿ     zExpecter.existing_datacCs|j}t|ƒ}|j |¡|js:|jr0|j ¡}|j |¡|j t d||jƒ¡|j  ¡}nL|j |¡|j }nBt|ƒ|jksF|j ¡s`||j d…}|  ¡|_|j ||j d…¡n|j |¡|j ¡}|j t d||jƒ¡|j  ¡}|  ||¡Sr)rrrrr r rrr%r&r'Úbufferrr$)r Údatarr!Úold_lenr Únew_lenrrrÚnew_dataHs(          zExpecter.new_dataNcCs˜|j}|j ¡|_| ¡|_| ¡|_t|_|jj }|dkr&t|_ ||_ |Sd|_ d|_ t |ƒ}|d|j7}|durCt |ƒd|}t|ƒ}d|_ |‚©Nrz searcher: %sÚ )rrrrrrrrr Ú eof_indexrrÚstrÚ __cause__©r Úerrrr"ÚmsgÚexcrrrÚeofds&   z Expecter.eofcCs„|j}|j ¡|_t|_|jj}|dkrt|_||_ |Sd|_d|_ t |ƒ}|d|j7}|dur9t |ƒd|}t|ƒ}d|_ |‚r0) rrrrrrr Ú timeout_indexrrr3r4r5rrrÚtimeout|s" zExpecter.timeoutcCs(|j}|j ¡|_d|_d|_d|_dS©N)rrrrrrr)r rrrrÚerrored’s   zExpecter.erroredc Cs |j}|dur t ¡|}zD| ¡}|dur|WS |dur'|dkr'| ¡WS| |j|¡}|jjdur;t |jj¡| |¡}|durG|WS|durQ|t ¡}qt yh}z |  |¡WYd}~Sd}~wt y~}z | |¡WYd}~Sd}~w|  ¡‚)zBlocking expectNTr) rÚtimer*r;Úread_nonblockingÚmaxreadÚdelayafterreadÚsleepr/rr9rr=)r r;rÚend_timeÚidxÚincomingÚerrrÚ expect_loop™s8     ó€€zExpecter.expect_loop)rr<) Ú__name__Ú __module__Ú __qualname__rr$r*r/r9r;r=rGrrrrrs    rc@ó*eZdZdZdd„Zdd„Zd dd„ZdS) Ú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 cCsvd|_d|_g|_d|_t|ƒD](\}}|tur||_q|tur$||_q|j ||f¡t|ƒ|jkr8t|ƒ|_qdS)zThis creates an instance of searcher_string. This argument 'strings' may be a list; a sequence of strings; or the EOF or TIMEOUT types. rrN) r2r:Ú_stringsrÚ enumeraterrÚappendr)r ÚstringsÚnÚsrrrrÎs  €÷zsearcher_string.__init__cCs|dd„|jDƒ}| d¡|jdkr| |jd|jf¡|jdkr-| |jd|jf¡| ¡tt|Žƒd}d |¡S) úUThis returns a human-readable string that represents the state of the object.cSsg|] }|dd|f‘qS)rz %d: %rr)Ú.0ÚnsrrrÚ åsz+searcher_string.__str__..)rzsearcher_string:rú %d: EOFú %d: TIMEOUTrr1)rMrOr2r:ÚsortÚlistÚzipÚjoin)r ÚssrrrÚ__str__ás   ÿ zsearcher_string.__str__Nc Cs’d}|jD],\}}|dur|t|ƒ }n| }| ||¡}|dkr1|dus*||kr1|}||} } q|dur8dS| |_||_|jt|jƒ|_| S)aëThis 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)rMrÚfindrrr) r r+r!r Ú first_matchr"rRÚoffsetrQÚ best_indexÚ best_matchrrrrðs    €zsearcher_string.searchr<©rHrIrJÚ__doc__rr^rrrrrrL»s rLc@rK) Ú 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 cCsXd|_d|_g|_t|ƒD]\}}|tur||_q |tur!||_q |j ||f¡q dS)z´This 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.rN)r2r:Ú _searchesrNrrrO)r ÚpatternsrQrRrrrr0sùzsearcher_re.__init__cCsštƒ}|jD]\}}| |d||jff¡q| d¡|jdkr,| |jd|jf¡|jdkr<| |jd|jf¡| ¡tt|Žƒd}d |¡S)rSz %d: re.compile(%r))rz searcher_re:rrWrXrr1) rZrgrOÚpatternr2r:rYr[r\)r r]rQrRrrrr^As    ÿ zsearcher_re.__str__Nc Cs–d}|dur d}n tdt|ƒ|ƒ}|jD]!\}}| ||¡}|dur$q| ¡} |dus0| |kr6| }|} |} q|dur=dS||_| |_|j ¡|_| S)a‘This 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&rrgrrrr) r r+r!r r`Ú searchstartr"rRrrQÚ the_matchrbrrrrTs(  € zsearcher_re.searchr<rdrrrrrfs rf)r>Ú exceptionsrrÚobjectrrLrfrrrrÚs 7b