expect4r 0.0.5.dev → 0.0.6.dev

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.
data/lib/expect/io.rb CHANGED
@@ -255,7 +255,20 @@ module Expect4r
255
255
  exp_puts 'yes'
256
256
  when /(Login incorrect|denied, please try again)/
257
257
  spawnee_reset
258
- end
258
+ else
259
+ # For objects that include Expect4r but do not subclass base Login class.
260
+ @matches ||= []
261
+ @matches.each { |match, _send|
262
+ if read_pipe._io_string =~ match
263
+ read_pipe._io_save no_echo, "match #{match}"
264
+ if _send.is_a?(Proc)
265
+ exp_puts _send.call
266
+ else
267
+ exp_puts _send
268
+ end
269
+ end
270
+ }
271
+ end
259
272
  end
260
273
  end
261
274
  case ev
@@ -320,7 +333,11 @@ module Expect4r
320
333
  @matches.each { |match, _send|
321
334
  if r._io_string =~ match
322
335
  r._io_save no_echo, "match #{match}"
323
- exp_puts _send
336
+ if _send.is_a?(Proc)
337
+ exp_puts _send.call
338
+ else
339
+ exp_puts _send
340
+ end
324
341
  end
325
342
  }
326
343
  end
@@ -512,7 +529,7 @@ module Expect4r
512
529
  @ps1 = /(.*)(>|#|\$)\s*$/
513
530
  @more = / --More-- /
514
531
  @matches=Set.new
515
- BaseLoginObject.add(self)
532
+ Base.add(self)
516
533
  self
517
534
  end
518
535
 
data/lib/misc/passwd.rb CHANGED
@@ -24,13 +24,15 @@ begin
24
24
 
25
25
  rescue LoadError => e
26
26
 
27
- module Expect4r
28
- def self.cipher(arg, pwd='')
29
- arg
30
- end
31
- def self.decipher(arg,pwd='')
32
- arg
33
- end
34
- end
27
+ # module Expect4r
28
+ # def self.cipher(arg, pwd='')
29
+ # arg
30
+ # end
31
+ # def self.decipher(arg,pwd='')
32
+ # arg
33
+ # end
34
+ # end
35
+
36
+ raise
35
37
 
36
38
  end
@@ -83,7 +83,7 @@ module Modes
83
83
  return :config if config?
84
84
  to_exec
85
85
  putline 'configure terminal' if exec?
86
- raise RuntimeError, "unable to got to config mode" unless config?
86
+ raise RuntimeError, "unable to get to config mode" unless config?
87
87
  :config
88
88
  end
89
89
 
@@ -92,14 +92,14 @@ module Modes
92
92
  if config?
93
93
  1.upto(config_lvl?) { putline 'exit'}
94
94
  end
95
- raise RuntimeError, "unable to got to exec mode" unless exec?
95
+ raise RuntimeError, "unable to get to exec mode" unless exec?
96
96
  :exec
97
97
  end
98
98
 
99
99
  def to_user
100
100
  return if user?
101
101
  putline "exit"
102
- raise RuntimeError, "unable to got to user mode" unless exec?
102
+ raise RuntimeError, "unable to get to user mode" unless exec?
103
103
  :user
104
104
  end
105
105
 
@@ -90,7 +90,7 @@ module Modes
90
90
  return :config if config?
91
91
  to_exec
92
92
  putline 'configure'
93
- raise RuntimeError, "unable to got to config mode" unless config?
93
+ raise RuntimeError, "unable to get to config mode" unless config?
94
94
  :config
95
95
  end
96
96
 
@@ -98,7 +98,7 @@ module Modes
98
98
  return :shell if shell?
99
99
  to_exec
100
100
  putline 'run'
101
- raise RuntimeError, "unable to got to shell mode" unless shell?
101
+ raise RuntimeError, "unable to get to shell mode" unless shell?
102
102
  :shell
103
103
  end
104
104
 
@@ -106,7 +106,7 @@ module Modes
106
106
  return :exec if exec?
107
107
  putline "exit" if shell?
108
108
  putline "abort" if config?
109
- raise RuntimeError, "unable to got to exec mode" unless exec?
109
+ raise RuntimeError, "unable to get to exec mode" unless exec?
110
110
  :exec
111
111
  end
112
112
 
@@ -47,6 +47,10 @@ class Expect4r::J < ::Expect4r::BaseLoginObject
47
47
  putline 'exit'
48
48
  end
49
49
 
50
+ def cli
51
+ putline 'cli'
52
+ end
53
+
50
54
  def commit(arg={})
51
55
  return unless config?
52
56
  @matches << [/Exit with uncommitted changes.+\(yes\)/, 'yes']
@@ -86,7 +86,13 @@ end
86
86
  # returns *true* if router is in <tt>:shell</tt> mode, *false* otherwise.
87
87
  #
88
88
  def shell?
89
- @lp == '% ' ? true : false
89
+ if @lp == '% '
90
+ true
91
+ elsif logged_as_root? and @lp =~ /root@.+% $/
92
+ true
93
+ else
94
+ false
95
+ end
90
96
  end
91
97
 
92
98
  def set_cli_logical_router(logical_router)
@@ -111,7 +117,7 @@ def to_config
111
117
  return :config if config?
112
118
  to_exec
113
119
  putline 'edit', :debug=>1
114
- raise RuntimeError, "unable to got to config mode" unless config?
120
+ raise RuntimeError, "unable to get to config mode" unless config?
115
121
  :config
116
122
  end
117
123
 
@@ -120,15 +126,19 @@ def to_shell
120
126
  return :shell if shell?
121
127
  to_exec
122
128
  putline 'start shell'
123
- raise RuntimeError, "unable to got to shell mode" unless shell?
129
+ raise RuntimeError, "unable to get to shell mode" unless shell?
124
130
  :shell
125
131
  end
126
132
 
133
+ def logged_as_root?
134
+ @_is_root_ ||= @lp =~ /root@/
135
+ end
136
+
127
137
  def to_exec
128
138
  return :exec if exec?
129
139
  top if config?
130
- exit
131
- raise RuntimeError, "unable to got to exec mode" unless exec?
140
+ logged_as_root? ? cli : exit
141
+ raise RuntimeError, "unable to get to exec mode" unless exec?
132
142
  :exec
133
143
  end
134
144
 
@@ -5,5 +5,7 @@ class TestMiscPasswd < Test::Unit::TestCase
5
5
  def test_cipher
6
6
  assert_not_equal 'my password', Expect4r.cipher('my password')
7
7
  assert_equal 'my password', Expect4r.decipher(Expect4r.cipher('my password'))
8
+ assert_not_equal 'my password', Expect4r.cipher('my password', 'abcdef')
9
+ assert_equal 'my password', Expect4r.decipher(Expect4r.cipher('my password'))
8
10
  end
9
11
  end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
8
+ - 6
9
9
  - dev
10
- version: 0.0.5.dev
10
+ version: 0.0.6.dev
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jean-Michel Esnault
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-13 00:00:00 -08:00
18
+ date: 2010-11-29 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency