a ÿé!^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ƒr8|j|_dS)NrÚlongest_string)ÚspawnÚsearcherÚsearchwindowsizeÚlookbackÚhasattrr)Úselfrr r ©rú2/usr/lib/python3.9/site-packages/pexpect/expect.pyÚ__init__s zExpecter.__init__cCs |j}|j}|t|ƒkr t|ƒ}| |||j¡}|dkr¼| ¡|_|j ||jd…¡|j   ¡dt|ƒ|j  …|_ | ¡|_ |j  ||jd…¡||j |j…|_ |j|_||_|S|jsÊ|jr|jpÔ|j}|j ¡|kr| ¡|_|j || d…¡dS©Nr)rr ÚlenÚsearchr Ú buffer_typeÚ_bufferÚwriteÚendÚ_beforeÚgetvalueÚstartÚbeforeÚafterÚmatchÚ match_indexr Útell)r ÚwindowÚfreshlenrr ÚindexZmaintainrrrÚ do_searchs,  ÿ   zExpecter.do_searchcCsö|j}|j ¡}|j ¡}|}||kr¶|jsN| ¡|_|j ¡}|j |¡qê||jkr’| ¡|_|j t d||jƒ¡|j  ¡}|j |¡qê|j t d||jƒ¡|j  ¡}n4|jrà|j t d||jƒ¡|j  ¡}n |j ¡}|  ||¡Sr) rrrrr rrrÚseekÚmaxÚreadr#)r rZ before_lenZbuf_lenr!r rrrÚ existing_data*s.      ÿ    zExpecter.existing_datacCs|j}t|ƒ}|j |¡|jst|jr`|j ¡}|j |¡|j t d||jƒ¡|j  ¡}qø|j |¡|j }n„t|ƒ|jksŒ|j ¡sÀ||j d…}|  ¡|_|j ||j d…¡n8|j |¡|j ¡}|j t d||jƒ¡|j  ¡}|  ||¡Sr)rrrrr r rrr$r%r&Úbufferrr#)r Údatarr!Zold_lenr Znew_lenrrrÚnew_dataHs(         zExpecter.new_dataNcCsœ|j}|j ¡|_| ¡|_| ¡|_t|_|jj }|dkrLt|_ ||_ |Sd|_ d|_ t |ƒ}|d|j7}|dur†t |ƒd|}t|ƒ}d|_ |‚dS©Nrz searcher: %sÚ )rrrrrrrrr Ú eof_indexrrÚstrÚ __cause__©r Úerrrr"ÚmsgÚexcrrrÚeofds&   z Expecter.eofcCsˆ|j}|j ¡|_t|_|jj}|dkr8t|_||_ |Sd|_d|_ t |ƒ}|d|j7}|durrt |ƒd|}t|ƒ}d|_ |‚dSr+) rrrrrrr Ú timeout_indexrrr.r/r0rrrÚtimeout|s" zExpecter.timeoutcCs(|j}|j ¡|_d|_d|_d|_dS)N)rrrrrrr)r rrrrÚerrored’s  zExpecter.erroredc Cs|j}|durt ¡|}zŠ| ¡}|dur2|WS|durL|dkrL| ¡WS| |j|¡}|jjdurtt |jj¡| |¡}|durŒ|WS|dur2|t ¡}q2Wnpt yÒ}z|  |¡WYd}~Sd}~0t y}z| |¡WYd}~Sd}~0|  ¡‚Yn0dS)zBlocking expectNr) rÚtimer'r6Zread_nonblockingZmaxreadZdelayafterreadÚsleepr*rr4rr7)r r6rZend_timeÚidxZincomingÚerrrÚ expect_loop™s0    zExpecter.expect_loop)r)N)N)r) Ú__name__Ú __module__Ú __qualname__rr#r'r*r4r6r7r<rrrrrs   rc@s*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]P\}}|tur8||_q |turH||_q |j ||f¡t|ƒ|jkr t|ƒ|_q 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. rrN) r-r5Ú_stringsrÚ enumeraterrÚappendr)r ÚstringsÚnÚsrrrrÎszsearcher_string.__init__cCs|dd„|jDƒ}| d¡|jdkr:| |jd|jf¡|jdkrZ| |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Ú åóz+searcher_string.__str__..)rzsearcher_string:rú %d: EOFú %d: TIMEOUTrr,)rArCr-r5ÚsortÚlistÚzipÚjoin)r ÚssrrrÚ__str__ás   ÿzsearcher_string.__str__Nc Cs’d}|jD]X\}}|dur*|t|ƒ }n| }| ||¡}|dkr |dusT||kr |}||} } q |durpdS| |_||_|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)rArÚfindrrr) r r(r!r Ú first_matchr"rFÚoffsetrEÚ best_indexZ best_matchrrrrðs   zsearcher_string.search)N©r=r>r?Ú__doc__rrSrrrrrr@»sr@c@s*eZdZdZdd„Zdd„Zd dd„ZdS) Ú 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]8\}}|tur2||_q|turB||_q|j ||f¡qdS)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)r-r5Ú _searchesrBrrrC)r ÚpatternsrErFrrrr0szsearcher_re.__init__cCsštƒ}|jD] \}}| |d||jff¡q | d¡|jdkrX| |jd|jf¡|jdkrx| |jd|jf¡| ¡tt|Žƒd}d |¡S)rGz %d: re.compile(%r))rz searcher_re:rrLrMrr,) rOr[rCÚpatternr-r5rNrPrQ)r rRrErFrrrrSAs    ÿzsearcher_re.__str__Nc Cs–d}|durd}ntdt|ƒ|ƒ}|jD]B\}}| ||¡}|durHq*| ¡} |dus`| |kr*| }|} |} q*|durzdS||_| |_|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%rr[rrrr) r r(r!r rUZ searchstartr"rFrrEZ the_matchrWrrrrTs&   zsearcher_re.search)NrXrrrrrZsrZ)r8Ú exceptionsrrÚobjectrr@rZrrrrÚs 7b