Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../proc/self/root/usr/share/ruby
File: expect.rb
# frozen_string_literal: true
[0] Fix | Delete
$expect_verbose = false
[1] Fix | Delete
[2] Fix | Delete
# Expect library adds the IO instance method #expect, which does similar act to
[3] Fix | Delete
# tcl's expect extension.
[4] Fix | Delete
#
[5] Fix | Delete
# In order to use this method, you must require expect:
[6] Fix | Delete
#
[7] Fix | Delete
# require 'expect'
[8] Fix | Delete
#
[9] Fix | Delete
# Please see #expect for usage.
[10] Fix | Delete
class IO
[11] Fix | Delete
# call-seq:
[12] Fix | Delete
# IO#expect(pattern,timeout=9999999) -> Array
[13] Fix | Delete
# IO#expect(pattern,timeout=9999999) { |result| ... } -> nil
[14] Fix | Delete
#
[15] Fix | Delete
# Reads from the IO until the given +pattern+ matches or the +timeout+ is over.
[16] Fix | Delete
#
[17] Fix | Delete
# It returns an array with the read buffer, followed by the matches.
[18] Fix | Delete
# If a block is given, the result is yielded to the block and returns nil.
[19] Fix | Delete
#
[20] Fix | Delete
# When called without a block, it waits until the input that matches the
[21] Fix | Delete
# given +pattern+ is obtained from the IO or the time specified as the
[22] Fix | Delete
# timeout passes. An array is returned when the pattern is obtained from the
[23] Fix | Delete
# IO. The first element of the array is the entire string obtained from the
[24] Fix | Delete
# IO until the pattern matches, followed by elements indicating which the
[25] Fix | Delete
# pattern which matched to the anchor in the regular expression.
[26] Fix | Delete
#
[27] Fix | Delete
# The optional timeout parameter defines, in seconds, the total time to wait
[28] Fix | Delete
# for the pattern. If the timeout expires or eof is found, nil is returned
[29] Fix | Delete
# or yielded. However, the buffer in a timeout session is kept for the next
[30] Fix | Delete
# expect call. The default timeout is 9999999 seconds.
[31] Fix | Delete
def expect(pat,timeout=9999999)
[32] Fix | Delete
buf = ''.dup
[33] Fix | Delete
case pat
[34] Fix | Delete
when String
[35] Fix | Delete
e_pat = Regexp.new(Regexp.quote(pat))
[36] Fix | Delete
when Regexp
[37] Fix | Delete
e_pat = pat
[38] Fix | Delete
else
[39] Fix | Delete
raise TypeError, "unsupported pattern class: #{pat.class}"
[40] Fix | Delete
end
[41] Fix | Delete
@unusedBuf ||= ''
[42] Fix | Delete
while true
[43] Fix | Delete
if not @unusedBuf.empty?
[44] Fix | Delete
c = @unusedBuf.slice!(0)
[45] Fix | Delete
elsif !IO.select([self],nil,nil,timeout) or eof? then
[46] Fix | Delete
result = nil
[47] Fix | Delete
@unusedBuf = buf
[48] Fix | Delete
break
[49] Fix | Delete
else
[50] Fix | Delete
c = getc
[51] Fix | Delete
end
[52] Fix | Delete
buf << c
[53] Fix | Delete
if $expect_verbose
[54] Fix | Delete
STDOUT.print c
[55] Fix | Delete
STDOUT.flush
[56] Fix | Delete
end
[57] Fix | Delete
if mat=e_pat.match(buf) then
[58] Fix | Delete
result = [buf,*mat.captures]
[59] Fix | Delete
break
[60] Fix | Delete
end
[61] Fix | Delete
end
[62] Fix | Delete
if block_given? then
[63] Fix | Delete
yield result
[64] Fix | Delete
else
[65] Fix | Delete
return result
[66] Fix | Delete
end
[67] Fix | Delete
nil
[68] Fix | Delete
end
[69] Fix | Delete
end
[70] Fix | Delete
[71] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function