From: Luiz Angelo Daros de Luca Date: 2009-05-14T04:07:53+09:00 Subject: [ruby-core:23446] Some expect.rb miprovements --001e680f11407a717a0469cfed92 Content-Type: multipart/alternative; boundary=001e680f11407a716b0469cfed90 --001e680f11407a716b0469cfed90 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hello, I was using expect.rb to substitute expect command (as I'm not in a mood to learn Tcl). However, it demands some attention. I took expect(1) command as a idea, but not a rule, of how expect should behave. First, a little bug that incorrect pattern classes are not treated correctly. It would result in a "e_pat unspecified" which gives no clues of what happened. Now I raise an exception. I let the another one parameter, timeout, unchecked cause the error messagem like "String can't be coerced into Fixnum" would give a good hint of what is wrong. I changed pat and e_pat to pattern to meet some other similar parameter references. Back to the timeout parameter, timeout was not a global timeout but a single char timeout. If the io keeps giving input, it never stops. For example: While using expect.rb to interact with a dlink switch telnet, if it generates any log information on the terminal (as it does constantly like "link down") before the timeout time, even if my expression never occurs, the timeout is never over. I changed this to use timeout as a global timeout as expect command does. Keeping on timeout stuff, if it read some input and times out, where this buffer goes? In expect.rb, it is just lost. For the expect command, this buffer can be used in the next matching. I use a instance variable to keep and reuse the unused buffer on the next expect call. I changed the default timeout value to meet the expect command default one. If someone really wants to use 9999999 seconds, just go ahead ans specify it on parameters. However, interactive scripts generally deal with unexpected behaviors. 30s, as expect command uses, seems to be reasonable. I also added some documentation that was missing. This is my first patch sent to ruby. I should submit this to redmine.ruby-lang.org, isn't it? But which version? Contribution documentation seems to be a litte disperse. Cheers, --- Luiz Angelo Daros de Luca, Me. luizluca@gmail.com --001e680f11407a716b0469cfed90 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hello,

I was using expect.rb to substitute expect command (as I'= m not in a mood to learn Tcl). However, it demands some attention.

I= took expect(1) command as a idea, but not a rule, of how expect should beh= ave.

First, a little bug that incorrect pattern classes are not treated corr= ectly. It would result in a "e_pat unspecified" which gives no cl= ues of what happened. Now I raise an exception. I let the another one param= eter, timeout, unchecked cause the error messagem like "String can'= ;t be coerced into Fixnum" would give a good hint of what is wrong.
I changed pat and e_pat to pattern to meet some other similar parameter= references.

Back to the timeout parameter, timeout was not a global= timeout but a single char timeout. If the io keeps giving input, it never = stops. For example: While using expect.rb to interact with a dlink switch t= elnet, if it generates any log information on the terminal (as it does cons= tantly like "link down") before the timeout time, even if my expr= ession never occurs, the timeout is never over. I changed this to use timeo= ut as a global timeout as expect command does.

Keeping on timeout stuff, if it read some input and times out, where th= is buffer goes? In expect.rb, it is just lost. For the expect command, this= buffer can be used in the next matching. I use a instance variable to keep= and reuse the unused buffer on the next expect call.=A0

I changed the default timeout value to meet the expect command default = one. If someone really wants to use 9999999 seconds, just go ahead ans spec= ify it on parameters. However, interactive scripts generally deal with unex= pected behaviors. 30s, as expect command uses, seems to be reasonable.

I also added some documentation that was missing.

This is my fir= st patch sent to ruby. I should submit this to redmine.ruby-lang.org, isn't it? But which version? Co= ntribution documentation seems to be a litte disperse.

Cheers,

---
=A0 =A0 Luiz Angelo Daros de Luca,= Me.
=A0 =A0 =A0 =A0 =A0 =A0luizluca@gmail.com
--001e680f11407a716b0469cfed90-- --001e680f11407a717a0469cfed92 Content-Type: text/x-patch; charset=US-ASCII; name="expect.patch" Content-Disposition: attachment; filename="expect.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_fuoe22bb0 LS0tIGV4cGVjdC5yYi5vcmlnCTIwMDktMDUtMTMgMTU6MTQ6MDUuMDAwMDAwMDAwIC0wMzAwCisr KyBleHBlY3QucmIJMjAwOS0wNS0xMyAxNTo1MDo1Ny4wMDAwMDAwMDAgLTAzMDAKQEAgLTEsMjYg KzEsNDMgQEAKICRleHBlY3RfdmVyYm9zZSA9IGZhbHNlCiAKIGNsYXNzIElPCi0gIGRlZiBleHBl Y3QocGF0LHRpbWVvdXQ9OTk5OTk5OSkKKworICAjIFJlYWRzIGlvcyB1bnRpbCBwYXR0ZXJuIG1h dGNoZXMgb3IgdGhlIHRpbWVvdXQgaXM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dGFydHRpbWUgPSBUaW1l Lm5vdwogICAgIHdoaWxlIHRydWUKLSAgICAgIGlmICFJTy5zZWxlY3QoW3NlbGZdLG5pbCxuaWws dGltZW91dCkgb3IgZW9mPyB0aGVuCi0gICAgICAgIHJlc3VsdCA9IG5pbAotICAgICAgICBicmVh aworICAgICAgaWYgbm90IEB1bnVzZWRCdWYuZW1wdHk/CisgICAgICAgIGMgPSBAdW51c2VkQnVm LnNsaWNlISgwKS5jaHIKKyAgICAgIGVsc2UKKyAgICAgICAgcmVtYWluaW5nID0gdGltZW91dC0o VGltZS5uZXctc3RhcnR0aW1lKQorICAgICAgICBpZiByZW1haW5pbmcgPD0gMCBvciAhSU8uc2Vs ZWN0KFtzZWxmXSxuaWwsbmlsLHJlbWFpbmluZykgb3IgZW9mPyB0aGVuCisgICAgICAgICAgcmVz dWx0ID0gbmlsCisgICAgICAgICAgQHVudXNlZEJ1ZiA9IGJ1ZgorICAgICAgICAgIGJyZWFrCisg ICAgICAgIGVuZAorICAgICAgICBjID0gZ2V0Yy5jaHIKICAgICAgIGVuZAotICAgICAgYyA9IGdl dGMuY2hyCiAgICAgICBidWYgPDwgYwogICAgICAgaWYgJGV4cGVjdF92ZXJib3NlCiAgICAgICAg IFNURE9VVC5wcmludCBjCiAgICAgICAgIFNURE9VVC5mbHVzaAogICAgICAgZW5kCi0gICAgICBp ZiBtYXQ9ZV9wYXQubWF0Y2goYnVmKSB0aGVuCisgICAgICBpZiBtYXQ9cGF0dGVybi5tYXRjaChi dWYpIHRoZW4KICAgICAgICAgcmVzdWx0ID0gW2J1ZiwqbWF0LnRvX2FbMS4uLTFdXQogICAgICAg ICBicmVhawogICAgICAgZW5kCg== --001e680f11407a717a0469cfed92--