
    e6                     ^    S SK r SSKJrJr   " S S\5      r " S S\5      r " S S	\5      rg)
    N   )EOFTIMEOUTc                   T    \ rS rSrSS jrS rS rS rSS jrSS jr	S	 r
SS
 jrSrg)Expecter   c                     Xl         X l        US:X  a  UR                  nX0l        S U l        [	        US5      (       a  UR
                  U l        g g )Nlongest_string)spawnsearchersearchwindowsizelookbackhasattrr   )selfr   r   r   s       0/usr/lib/python3/dist-packages/pexpect/expect.py__init__Expecter.__init__   sO    
  r!$55 08-..$33DM /    c                    U R                   nU R                  nU[        U5      :  a  [        U5      nUR                  XU R                  5      nUS:  a  UR                  5       Ul        UR                  R                  XR                  S  5        UR                  R                  5       S[        U5      UR                  -
  *  Ul        UR                  5       Ul	        UR                  R                  XR                  S  5        XR                  UR                   Ul        UR                  Ul        XSl        U$ U R                  (       d  U R                   (       ar  U R                  =(       d    U R                   nUR                  R#                  5       U:  a4  UR                  5       Ul        UR                  R                  X* S  5        g g g Nr   )r   r   lensearchr   buffer_type_bufferwriteend_beforegetvaluestartbeforeaftermatchmatch_indexr   tell)r   windowfreshlenr   r   indexmaintains          r   	do_searchExpecter.do_search   s_   

==c&k!6{H$2G2GHA:!--/EMMM||} 56 ==113CK(..013EL!--/EMMM||} 56 =EK"..EK %L""dmm,,=H}}!!#h. % 1 1 3##F9:$67 / '4r   c                 
   U R                   nUR                  R                  5       nUR                  R                  5       nUnX#:  Ga4  U R                  (       dL  UR                  5       Ul        UR                  R                  5       nUR                  R                  U5        GONX0R                  :  a|  UR                  5       Ul        UR                  R                  [        SX R                  -
  5      5        UR                  R                  5       nUR                  R                  U5        OUR                  R                  [        SX0R                  -
  5      5        UR                  R                  5       nOwU R                  (       aL  UR                  R                  [        SX0R                  -
  5      5        UR                  R                  5       nOUR                  R                  5       nU R                  XT5      $ r   )r   r   r%   r   r   r   r   r   seekmaxreadr*   )r   r   
before_lenbuf_lenr'   r&   s         r   existing_dataExpecter.existing_data*   sq    

]]'')
--$$&(( % 1 1 3//1##F+000 % 1 1 3"":(=(==>@++-##F+""3q'4I4I*I#JK++-$$""3q'4I4I*I#JK++-//1~~f//r   c                 ,   U R                   n[        U5      nUR                  R                  U5        U R                  (       d  U R
                  (       a  UR                  R                  5       nUR                  R                  U5        UR                  R                  [        SX@R
                  -
  5      5        UR                  R                  5       nGO.UR                  R                  U5        UR                  nGO[        U5      U R                  :  d  UR                  R                  5       (       dM  XR                  * S  nUR                  5       Ul        UR                  R                  XPR                  * S  5        OUR                  R                  U5        UR                  R                  5       nUR                  R                  [        SX`R                  -
  5      5        UR                  R                  5       nU R                  XS5      $ r   )r   r   r   r   r   r   r   r%   r-   r.   r/   bufferr   r*   )r   datar   r'   old_lenr&   new_lens          r   new_dataExpecter.new_dataH   sy   

t9D!$$}}--,,.##D)""3q'MM*A#BC++- ##D)4yD1119K9K9M9M44456 % 1 1 3##F,A,A+A+B$CD##D)--,,.""3q'4I4I*I#JK++-~~f//r   Nc                    U R                   nUR                  R                  5       Ul        UR	                  5       Ul        UR	                  5       Ul        [        Ul        U R                  R                  nUS:  a  [        Ul
        X2l        U$ S Ul
        S Ul        [        U5      nUSU R                  -  -  nUb  [        U5      S-   U-   n[        U5      nS Ul        UeNr   z
searcher: %s
)r   r   r   r!   r   r   r   r"   r   	eof_indexr#   r$   str	__cause__r   errr   r(   msgexcs         r   eofExpecter.eofd   s    

}}--/))+))+''A:EK %LEK $Ee*C#dmm33C#ho+c(C CMIr   c                 r   U R                   nUR                  R                  5       Ul        [        Ul        U R                  R                  nUS:  a  [        Ul        X2l	        U$ S Ul        S Ul	        [        U5      nUSU R                  -  -  nUb  [        U5      S-   U-   n[	        U5      nS Ul        Uer<   )r   r   r   r!   r   r"   r   timeout_indexr#   r$   r?   r@   rA   s         r   timeoutExpecter.timeout|   s    

}}--/++A:!EK %LEK $Ee*C#dmm33C#ho+#,C CMIr   c                     U R                   nUR                  R                  5       Ul        S Ul        S Ul        S Ul        g N)r   r   r   r!   r"   r#   r$   )r   r   s     r   erroredExpecter.errored   s5    

}}--/ r   c                    U R                   nUb  [        R                  " 5       U-   n U R                  5       nUb  U$  Ub  US:  a  U R                  5       $ UR	                  UR
                  U5      nU R                   R                  b*  [        R                  " U R                   R                  5        U R                  U5      nUb  U$ Ub  W[        R                  " 5       -
  nM  ! [         a  nU R                  U5      s SnA$ SnAf[         a  nU R                  U5      s SnA$ SnAf  U R                  5         e = f)zBlocking expectNr   )r   timer2   rI   read_nonblockingmaxreaddelayafterreadsleepr9   r   rE   r   rM   )r   rI   r   end_timeidxincominges          r   expect_loopExpecter.expect_loop   s   

yy{W,H	$$&C
'gk<<>) 11%--I::,,8JJtzz889mmH-?J&&4G   	88A; 	#<<?"	LLNsA   C( C( A2C( C( (
E2DEED+%E+E)r   r   r   r   )r
   rL   )__name__
__module____qualname____firstlineno__r   r*   r2   r9   rE   rI   rM   rY   __static_attributes__ r   r   r   r      s*    
4800<080,!r   r   c                   .    \ rS rSrSrS rS rSS jrSrg)	searcher_string   a  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                 6   SU l         SU l        / U l        SU l        [	        U5       Hn  u  p#U[
        L a  X l         M  U[        L a  X l        M'  U R                  R                  X#45        [        U5      U R                  :  d  M^  [        U5      U l        Mp     g)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
   r   N)	r>   rH   _stringsr   	enumerater   r   appendr   )r   stringsnss       r   r   searcher_string.__init__   s     g&DACx!"G|%&"MM  !(1v+++&)!f# 'r   c                    U R                    Vs/ s H  oS   SU-  4PM     nnUR                  S5        U R                  S:  a*  UR                  U R                  SU R                  -  45        U R                  S:  a*  UR                  U R                  SU R                  -  45        UR	                  5         [        [        U6 5      S   nSR                  U5      $ s  snf )MThis returns a human-readable string that represents the state of
the object.r   z
    %d: %r)r
   zsearcher_string:    %d: EOF    %d: TIMEOUTr   r=   )re   rg   r>   rH   sortlistzipjoin)r   nssss      r   __str__searcher_string.__str__   s     48==A=R!ulR'(=A
		*+>>QIIt~~}t~~'EFG"IIt))!D$6$668 9
	#r(^Ayy} Bs   CNc                    SnU R                    HB  u  pVUc  U[        U5      -   * nOU* nUR                  Xg5      nUS:  d  M4  Ub  X:  d  M>  UnXVpMD     Uc  gW
U l        X@l        U R                  [        U R                  5      -   U l        W	$ )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. Nr   r
   )re   r   findr#   r    r   )r   r5   r'   r   first_matchr(   rj   offsetri   
best_index
best_matchs              r   r   searcher_string.search   s      HE' $c!f,- +*A&AAv;.!/).J & 
 
::DJJ/r   )re   r   r>   r   r#   r    rH   rL   	r[   r\   r]   r^   __doc__r   rv   r   r_   r`   r   r   rb   rb      s    $-&*r   rb   c                   .    \ rS rSrSrS rS rSS jrSrg)	searcher_rei  a*  This 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

c                     SU l         SU l        / U l        [        U5       HC  u  p#U[        L a  X l         M  U[
        L a  X l        M'  U R                  R                  X#45        ME     g)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)r>   rH   	_searchesrf   r   r   rg   )r   patternsri   rj   s       r   r   searcher_re.__init__0  s^    
 h'DACx!"G|%&"NN!!1&) (r   c                    [        5       nU R                   H&  u  p#UR                  USX#R                  4-  45        M(     UR                  S5        U R                  S:  a*  UR                  U R                  SU R                  -  45        U R
                  S:  a*  UR                  U R
                  SU R
                  -  45        UR                  5         [        [        U6 5      S   nSR                  U5      $ )rm   z    %d: re.compile(%r))r
   zsearcher_re:r   rn   ro   r   r=   )	rq   r   rg   patternr>   rH   rp   rr   rs   )r   ru   ri   rj   s       r   rv   searcher_re.__str__A  s     VNNDAIIq2a^CDE #
		&'>>QIIt~~}t~~'EFG"IIt))+<"",# $ %
	#r(^Ayy}r   Nc                 <   SnUc  SnO[        S[        U5      U-
  5      nU R                   H;  u  pgUR                  X5      nUc  M  UR	                  5       n	Ub  X:  d  M5  U	nUn
UnM=     Uc  gX@l        W
U l        U R
                  R                  5       U l        W$ )ai  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.Nr   r
   )r.   r   r   r   r    r#   r   )r   r5   r'   r   rz   searchstartr(   rj   r#   ri   	the_matchr|   s               r   r   searcher_re.searchT  s      #KaV/?!?@KHEHHV1E}A"ao!	"
 '  

::>>#r   )r   r   r>   r#   r    rH   rL   r   r`   r   r   r   r     s    $*"&r   r   )rP   
exceptionsr   r   objectr   rb   r   r`   r   r   <module>r      s7     $sv sl_f _DV& Vr   