ruby_expect 1.0 → 1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ruby_expect/expect.rb +38 -61
  3. metadata +20 -40
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2368eec4ae38e8bb2ed58807f8099580f1422ae9
4
+ data.tar.gz: 451408b972605853384ff5a4b43f98fab07ab7c7
5
+ SHA512:
6
+ metadata.gz: 39be417b404a55360e0a3a6e3c07cb6f98877087ca2c3d70984b2a3937d3fbe883070f3a60a8d027f96a01d3d022c905f3863bc8aedca029252dfdcb22ce4299
7
+ data.tar.gz: a3894950b06028cadef8dad7ba2d557d0baf3a953a398f720a30417c87182a6f43b975e913211a24fac08a66cd484ae3581a31750f4b15e823314056daee9ff3
@@ -90,8 +90,6 @@ module RubyExpect
90
90
  raise "Input file handle is not readable!" unless (@read_fh.stat.readable?)
91
91
  raise "Output file handle is not writable!" unless (@write_fh.stat.writable?)
92
92
 
93
- @buffer_sem = Mutex.new
94
- @buffer_cv = ConditionVariable.new
95
93
  @child_pid = options[:child_pid]
96
94
  @debug = options[:debug] || false
97
95
  @buffer = ''
@@ -99,8 +97,6 @@ module RubyExpect
99
97
  @match = ''
100
98
  @timeout = 0
101
99
 
102
- read_loop # start the read thread
103
-
104
100
  unless (block.nil?)
105
101
  procedure(&block)
106
102
  end
@@ -238,18 +234,16 @@ module RubyExpect
238
234
  matched_index = nil
239
235
  while (@end_time == 0 || Time.now < @end_time)
240
236
  return nil if (@read_fh.closed?)
237
+ break unless (read_proc)
241
238
  @last_match = nil
242
- @buffer_sem.synchronize do
243
- patterns.each_index do |i|
244
- if (match = patterns[i].match(@buffer))
245
- @last_match = match
246
- @before = @buffer.slice!(0...match.begin(0))
247
- @match = @buffer.slice!(0...match.to_s.length)
248
- matched_index = i
249
- break
250
- end
239
+ patterns.each_index do |i|
240
+ if (match = patterns[i].match(@buffer))
241
+ @last_match = match
242
+ @before = @buffer.slice!(0...match.begin(0))
243
+ @match = @buffer.slice!(0...match.to_s.length)
244
+ matched_index = i
245
+ break
251
246
  end
252
- @buffer_cv.wait(@buffer_sem) if (@last_match.nil?)
253
247
  end
254
248
  unless (@last_match.nil?)
255
249
  unless (block.nil?)
@@ -262,10 +256,8 @@ module RubyExpect
262
256
  end
263
257
 
264
258
  def soft_close
265
- while (! @read_fh.closed?)
266
- @buffer_sem.synchronize do
267
- @buffer_cv.wait(@buffer_sem)
268
- end
259
+ while (! @read_fh.eof?)
260
+ read_proc
269
261
  end
270
262
  @read_fh.close unless (@read_fh.closed?)
271
263
  @write_fh.close unless (@write_fh.closed?)
@@ -275,6 +267,34 @@ module RubyExpect
275
267
  end
276
268
 
277
269
  private
270
+ def read_proc
271
+ begin
272
+ ready = IO.select([@read_fh], nil, nil, 1)
273
+ unless (ready.nil? || ready.size == 0)
274
+ if (@read_fh.eof?)
275
+ @read_fh.close
276
+ return false
277
+ else
278
+ input = @read_fh.readpartial(4096)
279
+ @buffer << input
280
+ if (@debug)
281
+ STDERR.print input
282
+ STDERR.flush
283
+ end
284
+ end
285
+ end
286
+ rescue EOFError => e
287
+ rescue Exception => e
288
+ unless (e.to_s == 'stream closed')
289
+ STDERR.puts "Exception in read_loop:"
290
+ STDERR.puts "#{e}"
291
+ STDERR.puts "\t#{e.backtrace.join("\n\t")}"
292
+ end
293
+ return false
294
+ end
295
+ return true
296
+ end
297
+
278
298
  #####
279
299
  # This method will convert any strings in the argument list to regular
280
300
  # expressions that search for the literal string
@@ -294,49 +314,6 @@ module RubyExpect
294
314
  end
295
315
  escaped_patterns
296
316
  end
297
-
298
- #####
299
- # The read loop is an internal method that constantly waits for input to
300
- # arrive on the IO object. When input arrives it is appended to an
301
- # internal buffer for use by the expect method
302
- #
303
- def read_loop
304
- Thread.abort_on_exception = true
305
- Thread.new do
306
- while (true)
307
- begin
308
- ready = IO.select([@read_fh], nil, nil, 1)
309
- if (ready.nil? || ready.size == 0)
310
- @buffer_cv.signal()
311
- else
312
- if (@read_fh.eof?)
313
- @read_fh.close
314
- @buffer_cv.signal()
315
- break
316
- else
317
- input = @read_fh.readpartial(4096)
318
- @buffer_sem.synchronize do
319
- @buffer << input
320
- @buffer_cv.signal()
321
- end
322
- if (@debug)
323
- STDERR.print input
324
- STDERR.flush
325
- end
326
- end
327
- end
328
- rescue EOFError => e
329
- rescue Exception => e
330
- unless (e.to_s == 'stream closed')
331
- STDERR.puts "Exception in read_loop:"
332
- STDERR.puts "#{e}"
333
- STDERR.puts "\t#{e.backtrace.join("\n\t")}"
334
- end
335
- break
336
- end
337
- end
338
- end
339
- end
340
317
  end
341
318
  end
342
319
 
metadata CHANGED
@@ -1,66 +1,46 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby_expect
3
- version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- version: "1.0"
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.2'
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Andrew Bates
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2013-05-21 00:00:00 Z
11
+ date: 2014-10-27 00:00:00.000000000 Z
18
12
  dependencies: []
19
-
20
13
  description: Ruby implementation for send/expect interaction
21
14
  email: abates@omeganetserv.com
22
15
  executables: []
23
-
24
16
  extensions: []
25
-
26
17
  extra_rdoc_files: []
27
-
28
- files:
18
+ files:
29
19
  - lib/ruby_expect.rb
30
20
  - lib/ruby_expect/expect.rb
31
21
  - lib/ruby_expect/procedure.rb
32
22
  homepage: https://github.com/abates/ruby_expect
33
23
  licenses: []
34
-
24
+ metadata: {}
35
25
  post_install_message:
36
26
  rdoc_options: []
37
-
38
- require_paths:
27
+ require_paths:
39
28
  - lib
40
- required_ruby_version: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
43
31
  - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
49
- required_rubygems_version: !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
52
36
  - - ">="
53
- - !ruby/object:Gem::Version
54
- hash: 3
55
- segments:
56
- - 0
57
- version: "0"
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
58
39
  requirements: []
59
-
60
40
  rubyforge_project:
61
- rubygems_version: 1.8.24
41
+ rubygems_version: 2.2.2
62
42
  signing_key:
63
- specification_version: 3
64
- summary: This is a simple expect implementation that provides interactive access to IO objects
43
+ specification_version: 4
44
+ summary: This is a simple expect implementation that provides interactive access to
45
+ IO objects
65
46
  test_files: []
66
-