1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@930 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
wakou 2000-09-11 22:02:37 +00:00
parent 6fc752bf7d
commit a5afbd50a7
2 changed files with 94 additions and 49 deletions

View file

@ -1,10 +1,10 @@
=begin
== CGI SUPPORT LIBRARY
== NAME
cgi.rb
cgi.rb - cgi support library
Version 1.7.0
Version 2.0.0
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
@ -176,6 +176,7 @@ HTTP_REFERER HTTP_USER_AGENT
=end
raise "Please, use ruby1.5.4 or later." if RUBY_VERSION < "1.5.4"
require 'English'
@ -184,10 +185,10 @@ class CGI
CR = "\015"
LF = "\012"
EOL = CR + LF
VERSION = "1.7.0"
RELEASE_DATE = "2000-06-19"
VERSION_CODE = 170
RELEASE_CODE = 20000619
VERSION = "2.0.0"
RELEASE_DATE = "2000-09-12"
VERSION_CODE = 200
RELEASE_CODE = 20000912
NEEDS_BINMODE = true if /WIN/ni === RUBY_PLATFORM
PATH_SEPARATOR = {'UNIX'=>'/', 'WINDOWS'=>'\\', 'MACINTOSH'=>':'}
@ -239,13 +240,9 @@ class CGI
url_encoded_string = CGI::escape("string")
=end
def CGI::escape(string)
string.gsub(/([^a-zA-Z0-9_.-])/n) do
if " " == $1
"+"
else
sprintf("%%%02X", $1.unpack("C")[0])
end
end
string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
'%' + $1.unpack('H2' * $1.size).join('%').upcase
end.tr(' ', '+')
end
@ -254,8 +251,8 @@ class CGI
string = CGI::unescape("url encoded string")
=end
def CGI::unescape(string)
string.gsub(/\+/n, ' ').gsub(/%([0-9a-fA-F]{2})/n) do
[$1.hex].pack("c")
string.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n) do
[$1.delete('%')].pack('H*')
end
end
@ -285,13 +282,24 @@ class CGI
if Integer($1) < 256
Integer($1).chr
else
if $KCODE[0] == ?u or $KCODE[0] == ?U
if Integer($1) < 65536 and ($KCODE[0] == ?u or $KCODE[0] == ?U)
[Integer($1)].pack("U")
else
"#" + $1
"&##{$1};"
end
end
when /\A#x([0-9a-f]+)\z/ni then $1.hex.chr
when /\A#x([0-9a-f]+)\z/ni then
if $1.hex < 256
$1.hex.chr
else
if $1.hex < 65536 and ($KCODE[0] == ?u or $KCODE[0] == ?U)
[$1.hex].pack("U")
else
"&#x#{$1};"
end
end
else
"&#{$1};"
end
end
end
@ -299,15 +307,19 @@ class CGI
=begin
=== ESCAPE ELEMENT
print CGI::escapeElement("<BR><A HREF="url"></A>", "A", "IMG")
print CGI::escapeElement('<BR><A HREF="url"></A>', "A", "IMG")
# "<BR>&lt;A HREF="url"&gt;&lt;/A&gt"
print CGI::escapeElement("<BR><A HREF="url"></A>", ["A", "IMG"])
print CGI::escapeElement('<BR><A HREF="url"></A>', ["A", "IMG"])
# "<BR>&lt;A HREF="url"&gt;&lt;/A&gt"
=end
def CGI::escapeElement(string, *element)
string.gsub(/<\/?(?:#{element.join("|")})(?!\w)(?:.|\n)*?>/ni) do
CGI::escapeHTML($&)
unless element.empty?
string.gsub(/<\/?(?:#{element.join("|")})(?!\w)(?:.|\n)*?>/ni) do
CGI::escapeHTML($&)
end
else
string
end
end
@ -315,11 +327,11 @@ class CGI
=begin
=== UNESCAPE ELEMENT
print CGI::unescapeElement(
CGI::escapeHTML("<BR><A HREF="url"></A>"), "A", "IMG")
CGI::escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
# "&lt;BR&gt;<A HREF="url"></A>"
print CGI::unescapeElement(
CGI::escapeHTML("<BR><A HREF="url"></A>"), ["A", "IMG"])
CGI::escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
# "&lt;BR&gt;<A HREF="url"></A>"
=end
def CGI::unescapeElement(string, *element)
@ -332,11 +344,11 @@ class CGI
=begin
=== MAKE RFC1123 DATE STRING
CGI::rfc1123_date(Time.now)
# Sut, 1 Jan 2000 00:00:00 GMT
# Sat, 1 Jan 2000 00:00:00 GMT
=end
def CGI::rfc1123_date(time)
t = time.clone.gmtime
return format("%s, %.2d %s %d %.2d:%.2d:%.2d GMT",
return format("%s, %d %s %d %.2d:%.2d:%.2d GMT",
RFC822_DAYS[t.wday], t.day, RFC822_MONTHS[t.month-1], t.year,
t.hour, t.min, t.sec)
end
@ -1732,7 +1744,7 @@ convert string charset, and set language to "ja".
module Html4
def doctype
%|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">|
%|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">|
end
def element_init
@ -1778,7 +1790,7 @@ convert string charset, and set language to "ja".
module Html4Tr
def doctype
%|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">|
%|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">|
end
def element_init
@ -1826,7 +1838,7 @@ convert string charset, and set language to "ja".
module Html4Fr
def doctype
%|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN" "http://www.w3.org/TR/REC-html40/frameset.dtd">|
%|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">|
end
def element_init
@ -1908,6 +1920,21 @@ end
== HISTORY
* Tue Sep 12 06:56:51 JST 2000 - wakou
* version 2.0.0
* require ruby1.5.4 or later. (ruby1.4 doesn't have block_given? method.)
* improvement: CGI::escape(), CGI::unescape().
thanks to WATANABE Hirofumi <eban@os.rim.or.jp>
* bug fix: CGI::escapeElement().
* improvement: CGI::unescapeHTML().
thanks to Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* 2000/08/09 04:32:22 - matz
* improvement: CGI::pretty()
* 2000/06/23 07:01:34 - matz
* change: iterator? --> block_given?
* Sun Jun 18 23:31:44 JST 2000 - wakou
* version 1.7.0
* change: version syntax. old: x.yz, now: x.y.z

View file

@ -1,10 +1,10 @@
=begin
== SIMPLE TELNET CLIENT LIBRARY
== NAME
net/telnet.rb
net/telnet.rb - simple telnet client library
Version 1.5.0
Version 1.6.0
Wakou Aoyama <wakou@fsinet.or.jp>
@ -71,7 +71,7 @@ of cource, set sync=true or flush is necessary.
line = host.cmd("string")
line = host.cmd({"String" => "string",
"Prompt" => /[$%#>] \z/n,
"Match" => /[$%#>] \z/n,
"Timeout" => 10})
@ -79,7 +79,7 @@ of cource, set sync=true or flush is necessary.
host.cmd("string"){|c| print c }
host.cmd({"String" => "string",
"Prompt" => /[$%#>] \z/n,
"Match" => /[$%#>] \z/n,
"Timeout" => 10}){|c| print c }
of cource, set sync=true or flush is necessary.
@ -88,7 +88,17 @@ of cource, set sync=true or flush is necessary.
=== SEND STRING
host.print("string")
# == host.write("string\n")
host.puts("string")
Telnet#puts() adds "\n" to the last of "string".
WARNING: Telnet#print() NOT adds "\n" to the last of "string", in the future.
If "Telnetmode" option is true, then escape IAC code ("\xFF"). If
"Binmode" option is false, then convert "\n" to EOL(end of line) code.
If "WILL SGA" and "DO BIN", then EOL is CR. If "WILL SGA", then EOL is
CR + NULL. If the other cases, EOL is CR + LF.
=== TOGGLE TELNET COMMAND INTERPRETATION
@ -109,25 +119,19 @@ of cource, set sync=true or flush is necessary.
host.login("username", "password")
host.login({"Name" => "username",
"Password" => "password",
"Prompt" => /[$%#>] \z/n,
"Timeout" => 10})
"Password" => "password"})
if no password prompt:
host.login("username")
host.login({"Name" => "username",
"Prompt" => /[$%#>] \z/n,
"Timeout" => 10})
host.login({"Name" => "username"})
==== REALTIME OUTPUT
host.login("username", "password"){|c| print c }
host.login({"Name" => "username",
"Password" => "password",
"Prompt" => /[$%#>] \z/n,
"Timeout" => 10}){|c| print c }
"Password" => "password"}){|c| print c }
of cource, set sync=true or flush is necessary.
@ -235,10 +239,10 @@ module Net
CR = "\015"
LF = "\012"
EOL = CR + LF
VERSION = "1.5.0"
RELEASE_DATE = "2000-06-19"
VERSION_CODE = 150
RELEASE_CODE = 20000619
VERSION = "1.6.0"
RELEASE_DATE = "2000-09-12"
VERSION_CODE = 160
RELEASE_CODE = 20000912
def initialize(options)
@options = options
@ -507,6 +511,10 @@ module Net
end
def print(string)
if $VERBOSE
$stderr.puts 'WARNING: Telnet#print("string") NOT adds "\n" to the last of "string", in the future.'
$stderr.puts ' cf. Telnet#puts().'
end
string = string + "\n"
string = string.gsub(/#{IAC}/no, IAC + IAC) if @options["Telnetmode"]
@ -526,6 +534,10 @@ module Net
end
end
def puts(string)
self.print(string)
end
def cmd(options)
match = @options["Prompt"]
time_out = @options["Timeout"]
@ -584,6 +596,12 @@ end
== HISTORY
* Tue Sep 12 06:52:48 JST 2000 - wakou
* version 1.6.0
* correct: document.
thanks to Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* add: Telnet#puts().
* Sun Jun 18 23:31:44 JST 2000 - wakou
* version 1.5.0
* change: version syntax. old: x.yz, now: x.y.z