- require English.rb


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
wakou 2000-05-09 22:08:25 +00:00
Родитель 655e96fa59
Коммит 6f4170c2a7
1 изменённых файлов: 27 добавлений и 25 удалений

Просмотреть файл

@ -5,7 +5,7 @@ $Date$
net/telnet.rb net/telnet.rb
Version 1.31 Version 1.32
Wakou Aoyama <wakou@fsinet.or.jp> Wakou Aoyama <wakou@fsinet.or.jp>
@ -157,6 +157,12 @@ of cource, set sync=true or flush is necessary.
== HISTORY == HISTORY
=== Version 1.32
2000/05/09 22:02:56
- require English.rb
=== Version 1.31 === Version 1.31
2000/05/02 21:48:39 2000/05/02 21:48:39
@ -369,6 +375,7 @@ if ommit password, then not require password prompt.
require "socket" require "socket"
require "delegate" require "delegate"
require "timeout" require "timeout"
require "English"
module Net module Net
class Telnet < SimpleDelegator class Telnet < SimpleDelegator
@ -443,7 +450,7 @@ module Net
EOL = CR + LF EOL = CR + LF
v = $-v v = $-v
$-v = false $-v = false
VERSION = "1.31" VERSION = "1.32"
RELEASE_DATE = "$Date$" RELEASE_DATE = "$Date$"
$-v = v $-v = v
@ -482,7 +489,7 @@ module Net
hexvals = line.unpack('H*')[0] hexvals = line.unpack('H*')[0]
hexvals.concat ' ' * (32 - hexvals.length) hexvals.concat ' ' * (32 - hexvals.length)
hexvals = format "%s %s %s %s " * 4, *hexvals.unpack('a2' * 16) hexvals = format "%s %s %s %s " * 4, *hexvals.unpack('a2' * 16)
line.gsub! /[\000-\037\177-\377]/n, '.' line = line.gsub(/[\000-\037\177-\377]/n, '.')
printf "%s 0x%5.5x: %s%s\n", dir, addr, hexvals, line printf "%s 0x%5.5x: %s%s\n", dir, addr, hexvals, line
addr += 16 addr += 16
offset += 16 offset += 16
@ -510,15 +517,15 @@ module Net
if @options["Timeout"] == false if @options["Timeout"] == false
@sock = TCPsocket.open(@options["Host"], @options["Port"]) @sock = TCPsocket.open(@options["Host"], @options["Port"])
else else
timeout(@options["Timeout"]){ timeout(@options["Timeout"]) do
@sock = TCPsocket.open(@options["Host"], @options["Port"]) @sock = TCPsocket.open(@options["Host"], @options["Port"])
} end
end end
rescue TimeoutError rescue TimeoutError
raise TimeoutError, "timed-out; opening of the host" raise TimeoutError, "timed-out; opening of the host"
rescue rescue
@log.write($!.to_s + "\n") if @options.has_key?("Output_log") @log.write($ERROR_INFO.to_s + "\n") if @options.has_key?("Output_log")
@dumplog.log_dump('#', $!.to_s + "\n") if @options.has_key?("Dump_log") @dumplog.log_dump('#', $ERROR_INFO.to_s + "\n") if @options.has_key?("Dump_log")
raise raise
end end
@sock.sync = true @sock.sync = true
@ -552,20 +559,18 @@ module Net
end end
def preprocess(string) def preprocess(string)
str = string.dup
# combine CR+NULL into CR # combine CR+NULL into CR
str.gsub!(/#{CR}#{NULL}/no, CR) if @options["Telnetmode"] string = string.gsub(/#{CR}#{NULL}/no, CR) if @options["Telnetmode"]
# combine EOL into "\n" # combine EOL into "\n"
str.gsub!(/#{EOL}/no, "\n") unless @options["Binmode"] string = string.gsub(/#{EOL}/no, "\n") unless @options["Binmode"]
str.gsub!(/#{IAC}( string.gsub(/#{IAC}(
[#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]| [#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]|
[#{DO}#{DONT}#{WILL}#{WONT}] [#{DO}#{DONT}#{WILL}#{WONT}]
[#{OPT_BINARY}-#{OPT_NEW_ENVIRON}#{OPT_EXOPL}]| [#{OPT_BINARY}-#{OPT_NEW_ENVIRON}#{OPT_EXOPL}]|
#{SB}[^#{IAC}]*#{IAC}#{SE} #{SB}[^#{IAC}]*#{IAC}#{SE}
)/xno){ )/xno) do
if IAC == $1 # handle escaped IAC characters if IAC == $1 # handle escaped IAC characters
IAC IAC
elsif AYT == $1 # respond to "IAC AYT" (are you there) elsif AYT == $1 # respond to "IAC AYT" (are you there)
@ -607,9 +612,7 @@ module Net
else else
'' ''
end end
} end
str
end # preprocess end # preprocess
def waitfor(options) def waitfor(options)
@ -681,24 +684,23 @@ module Net
end end
def print(string) def print(string)
str = string.dup + "\n" string = string + "\n"
string = string.gsub(/#{IAC}/no, IAC + IAC) if @options["Telnetmode"]
str.gsub!(/#{IAC}/no, IAC + IAC) if @options["Telnetmode"] if @options["Binmode"]
self.write(string)
unless @options["Binmode"] else
if @telnet_option["BINARY"] and @telnet_option["SGA"] if @telnet_option["BINARY"] and @telnet_option["SGA"]
# IAC WILL SGA IAC DO BIN send EOL --> CR # IAC WILL SGA IAC DO BIN send EOL --> CR
str.gsub!(/\n/n, CR) self.write(string.gsub(/\n/n, CR))
elsif @telnet_option["SGA"] elsif @telnet_option["SGA"]
# IAC WILL SGA send EOL --> CR+NULL # IAC WILL SGA send EOL --> CR+NULL
str.gsub!(/\n/n, CR + NULL) self.write(string.gsub(/\n/n, CR + NULL))
else else
# NONE send EOL --> CR+LF # NONE send EOL --> CR+LF
str.gsub!(/\n/n, EOL) self.write(string.gsub(/\n/n, EOL))
end end
end end
self.write(str)
end end
def cmd(options) def cmd(options)