summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-02-05 10:27:34 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-02-05 10:27:34 +0000
commit9b64dfe3b8f0343ebf97ae80d3a4ec3f4bd115b3 (patch)
tree7acd7b77321fdbc63149b47fde3bace6f7733614 /lib
parent06d4e3b42d836b762c29cdc9dc7181caf14dcdec (diff)
990205
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/README23
-rw-r--r--lib/cgi-lib.rb41
-rw-r--r--lib/parsedate.rb15
-rw-r--r--lib/telnet.rb267
4 files changed, 189 insertions, 157 deletions
diff --git a/lib/README b/lib/README
index 09e5946..765c380 100644
--- a/lib/README
+++ b/lib/README
@@ -1,11 +1,11 @@
English.rb access global variables by english names
Env.rb access environment variables as globals
README this file
-base64.rb encode/decode base64 (bit obsolete)
+base64.rb encode/decode base64 (obsolete)
cgi-lib.rb decode CGI data
complex.rb complex number suppor
date.rb date object (compatible)
-date2.rb date object based on Julian date
+date2.rb yet another (better) date object
debug.rb ruby debugger
delegate.rb delegate messages to other object
e2mmap.rb exception utilities
@@ -15,6 +15,7 @@ finalize.rb add finalizer to the object
find.rb traverse directory tree
ftools.rb file tools
ftplib.rb ftp access library
+getoptlong.rb GNU getoptlong compatible
getopts.rb parse command line options
importenv.rb access environment variables as globals
jcode.rb japanese text handling (replace String methods)
@@ -29,12 +30,12 @@ open3.rb open subprocess connection stdin/stdout/stderr
ostruct.rb python style object
parsearg.rb argument parser using getopts
parsedate.rb parse date string
-ping.rb
+ping.rb check whether host is up, using TCP echo.
profile.rb ruby profiler
pstore.rb persistent object strage using marshal
rational.rb rational number support
readbytes.rb define IO#readbytes
-shell.rb shell like operation under Ruby (imcomlete)
+shell.rb shell like operation under Ruby (imcomplete)
shellwords.rb split into words like shell
singleton.rb singleton design pattern library
sync.rb 2 phase lock
@@ -43,19 +44,5 @@ tempfile.rb temporary file that automatically removed
thread.rb thread support
thwait.rb thread syncronization class
timeout.rb provids timeout
-tk.rb Tk interface
-tkafter.rb
-tkbgerror.rb Tk error module
-tkcanvas.rb Tk canvas interface
-tkclass.rb provides generic names for Tk classes
-tkdialog.rb Tk dialog class
-tkentry.rb Tk entry class
-tkfont.rb Tk font support
-tkmenubar.rb TK menubar utility
-tkmngfocus.rb focus manager
-tkpalette.rb pallete support
-tkscrollbox.rb scroll box, also example of compound widget
-tktext.rb text classes
-tkvirtevent.rb virtual event support
tracer.rb execution tracer
weakref.rb weak reference class
diff --git a/lib/cgi-lib.rb b/lib/cgi-lib.rb
index ef717b2..2089a9c 100644
--- a/lib/cgi-lib.rb
+++ b/lib/cgi-lib.rb
@@ -25,6 +25,20 @@
#
# print CGI.header("HTTP/1.0 200 OK", "Content-Type: text/html")
# print CGI.header # == print CGI.header("Content-Type: text/html")
+#
+# make HTML tag string
+# CGI.tag("element", {"attribute_name"=>"attribute_value"}){"content"}
+#
+# print CGI.tag("HTML"){
+# CGI.tag("HEAD"){ CGI.tag("TITLE"){"TITLE"} } +
+# CGI.tag("BODY"){
+# CGI.tag("FORM", {"ACTION"=>"test.rb", "METHOD"=>"POST"}){
+# CGI.tag("INPUT", {"TYPE"=>"submit", "VALUE"=>"submit"})
+# } +
+# CGI.tag("HR")
+# }
+# }
+
# if running on Windows(IIS or PWS) then change cwd.
if ENV['SERVER_SOFTWARE'] =~ /^Microsoft-/ then
@@ -67,7 +81,13 @@ class CGI < SimpleDelegator
str.gsub!(/%([0-9a-fA-F]{2})/){ [$1.hex].pack("c") }
str
end
- module_function :escape, :unescape
+
+ # escape HTML
+ def escapeHTML(str)
+ str.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
+ end
+
+ module_function :escape, :unescape, :escapeHTML
def initialize(input = $stdin)
@@ -97,12 +117,12 @@ class CGI < SimpleDelegator
if ENV.has_key?('HTTP_COOKIE')
@cookie = {}
ENV['HTTP_COOKIE'].split("; ").each do |x|
- key, val = x.split(/=/,2).collect{|x|unescape(x)}
- if @cookie.include?(key)
- @cookie[key] += "\0" + (val or "")
- else
- @cookie[key] = (val or "")
- end
+ key, val = x.split(/=/,2).collect{|x|unescape(x)}
+ if @cookie.include?(key)
+ @cookie[key] += "\0" + (val or "")
+ else
+ @cookie[key] = (val or "")
+ end
end
end
end
@@ -123,6 +143,13 @@ class CGI < SimpleDelegator
(options['secure'] ? '; secure' : '')
end
+ def CGI.tag(element, attributes = {})
+ "<" + escapeHTML(element) + attributes.collect{|name, value|
+ " " + escapeHTML(name) + '="' + escapeHTML(value) + '"'
+ }.to_s + ">" +
+ (iterator? ? yield.to_s + "</" + escapeHTML(element) + ">" : "")
+ end
+
def CGI.message(msg, title = "", header = ["Content-Type: text/html"])
print CGI.header(*header)
print "<html><head><title>"
diff --git a/lib/parsedate.rb b/lib/parsedate.rb
index 5ffd2da..e27735b 100644
--- a/lib/parsedate.rb
+++ b/lib/parsedate.rb
@@ -9,7 +9,7 @@ module ParseDate
'thu' => 4, 'fri' => 5, 'sat' => 6 }
DAYPAT = DAYS.keys.join('|')
- def parsedate(date)
+ def parsedate(date, guess=false)
# part of ISO 8601
# yyyy-mm-dd | yyyy-mm | yyyy
# date hh:mm:ss | date Thh:mm:ss
@@ -63,6 +63,19 @@ module ParseDate
mon = MONTHS[$2.downcase]
year = $3.to_i
end
+ if guess
+ if year < 100
+ if year >= 69
+ year += 1900
+ else
+ year += 2000
+ end
+ end
+ elsif date.sub!(/(\d+)-(#{MONTHPAT})-(\d+)/i, ' ')
+ mday = $1.to_i
+ mon = MONTHS[$2.downcase]
+ year = $3.to_i
+ end
return year, mon, mday, hour, min, sec, zone, wday
end
diff --git a/lib/telnet.rb b/lib/telnet.rb
index 0336bda..10a528e 100644
--- a/lib/telnet.rb
+++ b/lib/telnet.rb
@@ -1,134 +1,139 @@
-#
-# telnet.rb
-# ver0.16 1998/10/09
-# Wakou Aoyama <wakou@fsinet.or.jp>
-#
-# ver0.16 1998/10/09
-# preprocess method change for the better
-# add binmode method.
-# change default Binmode
-# TRUE --> FALSE
-#
-# ver0.15 1998/10/04
-# add telnetmode method.
-#
-# ver0.141 1998/09/22
-# change default prompt
-# /[$%#>] $/ --> /[$%#>] \Z/
-#
-# ver0.14 1998/09/01
-# IAC WILL SGA send EOL --> CR+NULL
-# IAC WILL SGA IAC DO BIN send EOL --> CR
-# NONE send EOL --> LF
-# add Dump_log option.
-#
-# ver0.13 1998/08/25
-# add print method.
-#
-# ver0.122 1998/08/05
-# support for HP-UX 10.20 thanks to WATANABE Tetsuya <tetsu@jpn.hp.com>
-# socket.<< --> socket.write
-#
-# ver0.121 1998/07/15
-# string.+= --> string.concat
-#
-# ver0.12 1998/06/01
-# add timeout, waittime.
-#
-# ver0.11 1998/04/21
-# add realtime output.
-#
-# ver0.10 1998/04/13
-# first release.
-#
-# == make new Telnet object
-# host = Telnet.new({"Binmode" => FALSE, default: FALSE
-# "Host" => "localhost", default: "localhost"
-# "Output_log" => "output_log", default: not output
-# "Dump_log" => "dump_log", default: not output
-# "Port" => 23, default: 23
-# "Prompt" => /[$%#>] \Z/, default: /[$%#>] \Z/
-# "Telnetmode" => TRUE, default: TRUE
-# "Timeout" => 10, default: 10
-# "Waittime" => 0}) default: 0
-#
-# if set "Telnetmode" option FALSE. not TELNET command interpretation.
-# "Waittime" is time to confirm "Prompt". There is a possibility that
-# the same character as "Prompt" is included in the data, and, when
-# the network or the host is very heavy, the value is enlarged.
-#
-# == wait for match
-# line = host.waitfor(/match/)
-# line = host.waitfor({"Match" => /match/,
-# "String" => "string",
-# "Timeout" => secs})
-# if set "String" option. Match = Regexp.new(quote(string))
-#
-# realtime output. of cource, set sync=TRUE or flush is necessary.
-# host.waitfor(/match/){|c| print c }
-# host.waitfor({"Match" => /match/,
-# "String" => "string",
-# "Timeout" => secs}){|c| print c}
-#
-# == send string and wait prompt
-# line = host.cmd("string")
-# line = host.cmd({"String" => "string",
-# "Prompt" => /[$%#>] \Z/,
-# "Timeout" => 10})
-#
-# realtime output. of cource, set sync=TRUE or flush is necessary.
-# host.cmd("string"){|c| print c }
-# host.cmd({"String" => "string",
-# "Prompt" => /[$%#>] \Z/,
-# "Timeout" => 10}){|c| print c }
-#
-# == send string
-# host.print("string")
-#
-# == turn telnet command interpretation
-# host.telnetmode # turn on/off
-# host.telnetmode(TRUE) # on
-# host.telnetmode(FALSE) # off
-#
-# == toggle newline translation
-# host.binmode # turn TRUE/FALSE
-# host.binmode(TRUE) # no translate newline
-# host.binmode(FALSE) # translate newline
-#
-# == login
-# host.login("username", "password")
-# host.login({"Name" => "username",
-# "Password" => "password",
-# "Prompt" => /[$%#>] \Z/,
-# "Timeout" => 10})
-#
-# realtime output. of cource, set sync=TRUE or flush is necessary.
-# host.login("username", "password"){|c| print c }
-# host.login({"Name" => "username",
-# "Password" => "password",
-# "Prompt" => /[$%#>] \Z/,
-# "Timeout" => 10}){|c| print c }
-#
-# and Telnet object has socket class methods
-#
-# == sample
-# localhost = Telnet.new({"Host" => "localhost",
-# "Timeout" => 10,
-# "Prompt" => /[$%#>] \Z/})
-# localhost.login("username", "password"){|c| print c }
-# localhost.cmd("command"){|c| print c }
-# localhost.close
-#
-# == sample 2
-# checks a POP server to see if you have mail.
-#
-# pop = Telnet.new({"Host" => "your_destination_host_here",
-# "Port" => 110,
-# "Telnetmode" => FALSE,
-# "Prompt" => /^\+OK/})
-# pop.cmd("user " + "your_username_here"){|c| print c}
-# pop.cmd("pass " + "your_password_here"){|c| print c}
-# pop.cmd("list"){|c| print c}
+=begin
+
+telnet.rb ver0.161 1999/02/03
+Wakou Aoyama <wakou@fsinet.or.jp>
+
+ver0.161 1999/02/03
+select --> IO::select
+
+ver0.16 1998/10/09
+preprocess method change for the better
+add binmode method.
+change default Binmode
+TRUE --> FALSE
+
+ver0.15 1998/10/04
+add telnetmode method.
+
+ver0.141 1998/09/22
+change default prompt
+/[$%#>] $/ --> /[$%#>] \Z/
+
+ver0.14 1998/09/01
+IAC WILL SGA send EOL --> CR+NULL
+IAC WILL SGA IAC DO BIN send EOL --> CR
+NONE send EOL --> LF
+add Dump_log option.
+
+ver0.13 1998/08/25
+add print method.
+
+ver0.122 1998/08/05
+support for HP-UX 10.20 thanks to WATANABE Tetsuya <tetsu@jpn.hp.com>
+socket.<< --> socket.write
+
+ver0.121 1998/07/15
+string.+= --> string.concat
+
+ver0.12 1998/06/01
+add timeout, waittime.
+
+ver0.11 1998/04/21
+add realtime output.
+
+ver0.10 1998/04/13
+first release.
+
+== make new Telnet object
+host = Telnet.new({"Binmode" => FALSE, default: FALSE
+ "Host" => "localhost", default: "localhost"
+ "Output_log" => "output_log", default: not output
+ "Dump_log" => "dump_log", default: not output
+ "Port" => 23, default: 23
+ "Prompt" => /[$%#>] \Z/, default: /[$%#>] \Z/
+ "Telnetmode" => TRUE, default: TRUE
+ "Timeout" => 10, default: 10
+ "Waittime" => 0}) default: 0
+
+if set "Telnetmode" option FALSE. not TELNET command interpretation.
+"Waittime" is time to confirm "Prompt". There is a possibility that
+the same character as "Prompt" is included in the data, and, when
+the network or the host is very heavy, the value is enlarged.
+
+== wait for match
+line = host.waitfor(/match/)
+line = host.waitfor({"Match" => /match/,
+ "String" => "string",
+ "Timeout" => secs})
+if set "String" option. Match = Regexp.new(quote(string))
+
+realtime output. of cource, set sync=TRUE or flush is necessary.
+host.waitfor(/match/){|c| print c }
+host.waitfor({"Match" => /match/,
+ "String" => "string",
+ "Timeout" => secs}){|c| print c}
+
+== send string and wait prompt
+line = host.cmd("string")
+line = host.cmd({"String" => "string",
+ "Prompt" => /[$%#>] \Z/,
+ "Timeout" => 10})
+
+realtime output. of cource, set sync=TRUE or flush is necessary.
+host.cmd("string"){|c| print c }
+host.cmd({"String" => "string",
+ "Prompt" => /[$%#>] \Z/,
+ "Timeout" => 10}){|c| print c }
+
+== send string
+host.print("string")
+
+== turn telnet command interpretation
+host.telnetmode # turn on/off
+host.telnetmode(TRUE) # on
+host.telnetmode(FALSE) # off
+
+== toggle newline translation
+host.binmode # turn TRUE/FALSE
+host.binmode(TRUE) # no translate newline
+host.binmode(FALSE) # translate newline
+
+== login
+host.login("username", "password")
+host.login({"Name" => "username",
+ "Password" => "password",
+ "Prompt" => /[$%#>] \Z/,
+ "Timeout" => 10})
+
+realtime output. of cource, set sync=TRUE or flush is necessary.
+host.login("username", "password"){|c| print c }
+host.login({"Name" => "username",
+ "Password" => "password",
+ "Prompt" => /[$%#>] \Z/,
+ "Timeout" => 10}){|c| print c }
+
+and Telnet object has socket class methods
+
+== sample
+localhost = Telnet.new({"Host" => "localhost",
+ "Timeout" => 10,
+ "Prompt" => /[$%#>] \Z/})
+localhost.login("username", "password"){|c| print c }
+localhost.cmd("command"){|c| print c }
+localhost.close
+
+== sample 2
+checks a POP server to see if you have mail.
+
+pop = Telnet.new({"Host" => "your_destination_host_here",
+ "Port" => 110,
+ "Telnetmode" => FALSE,
+ "Prompt" => /^\+OK/})
+pop.cmd("user " + "your_username_here"){|c| print c}
+pop.cmd("pass " + "your_password_here"){|c| print c}
+pop.cmd("list"){|c| print c}
+
+=end
require "socket"
require "delegate"