mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
wakou
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@930 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6fc752bf7d
commit
a5afbd50a7
2 changed files with 94 additions and 49 deletions
83
lib/cgi.rb
83
lib/cgi.rb
|
@ -1,10 +1,10 @@
|
||||||
=begin
|
=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.
|
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
||||||
|
|
||||||
|
@ -176,6 +176,7 @@ HTTP_REFERER HTTP_USER_AGENT
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
|
raise "Please, use ruby1.5.4 or later." if RUBY_VERSION < "1.5.4"
|
||||||
|
|
||||||
require 'English'
|
require 'English'
|
||||||
|
|
||||||
|
@ -184,10 +185,10 @@ class CGI
|
||||||
CR = "\015"
|
CR = "\015"
|
||||||
LF = "\012"
|
LF = "\012"
|
||||||
EOL = CR + LF
|
EOL = CR + LF
|
||||||
VERSION = "1.7.0"
|
VERSION = "2.0.0"
|
||||||
RELEASE_DATE = "2000-06-19"
|
RELEASE_DATE = "2000-09-12"
|
||||||
VERSION_CODE = 170
|
VERSION_CODE = 200
|
||||||
RELEASE_CODE = 20000619
|
RELEASE_CODE = 20000912
|
||||||
|
|
||||||
NEEDS_BINMODE = true if /WIN/ni === RUBY_PLATFORM
|
NEEDS_BINMODE = true if /WIN/ni === RUBY_PLATFORM
|
||||||
PATH_SEPARATOR = {'UNIX'=>'/', 'WINDOWS'=>'\\', 'MACINTOSH'=>':'}
|
PATH_SEPARATOR = {'UNIX'=>'/', 'WINDOWS'=>'\\', 'MACINTOSH'=>':'}
|
||||||
|
@ -239,13 +240,9 @@ class CGI
|
||||||
url_encoded_string = CGI::escape("string")
|
url_encoded_string = CGI::escape("string")
|
||||||
=end
|
=end
|
||||||
def CGI::escape(string)
|
def CGI::escape(string)
|
||||||
string.gsub(/([^a-zA-Z0-9_.-])/n) do
|
string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
|
||||||
if " " == $1
|
'%' + $1.unpack('H2' * $1.size).join('%').upcase
|
||||||
"+"
|
end.tr(' ', '+')
|
||||||
else
|
|
||||||
sprintf("%%%02X", $1.unpack("C")[0])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -254,8 +251,8 @@ class CGI
|
||||||
string = CGI::unescape("url encoded string")
|
string = CGI::unescape("url encoded string")
|
||||||
=end
|
=end
|
||||||
def CGI::unescape(string)
|
def CGI::unescape(string)
|
||||||
string.gsub(/\+/n, ' ').gsub(/%([0-9a-fA-F]{2})/n) do
|
string.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n) do
|
||||||
[$1.hex].pack("c")
|
[$1.delete('%')].pack('H*')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -285,13 +282,24 @@ class CGI
|
||||||
if Integer($1) < 256
|
if Integer($1) < 256
|
||||||
Integer($1).chr
|
Integer($1).chr
|
||||||
else
|
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")
|
[Integer($1)].pack("U")
|
||||||
else
|
else
|
||||||
"#" + $1
|
"&##{$1};"
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -299,27 +307,31 @@ class CGI
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
=== ESCAPE ELEMENT
|
=== ESCAPE ELEMENT
|
||||||
print CGI::escapeElement("<BR><A HREF="url"></A>", "A", "IMG")
|
print CGI::escapeElement('<BR><A HREF="url"></A>', "A", "IMG")
|
||||||
# "<BR><A HREF="url"></A>"
|
# "<BR><A HREF="url"></A>"
|
||||||
|
|
||||||
print CGI::escapeElement("<BR><A HREF="url"></A>", ["A", "IMG"])
|
print CGI::escapeElement('<BR><A HREF="url"></A>', ["A", "IMG"])
|
||||||
# "<BR><A HREF="url"></A>"
|
# "<BR><A HREF="url"></A>"
|
||||||
=end
|
=end
|
||||||
def CGI::escapeElement(string, *element)
|
def CGI::escapeElement(string, *element)
|
||||||
|
unless element.empty?
|
||||||
string.gsub(/<\/?(?:#{element.join("|")})(?!\w)(?:.|\n)*?>/ni) do
|
string.gsub(/<\/?(?:#{element.join("|")})(?!\w)(?:.|\n)*?>/ni) do
|
||||||
CGI::escapeHTML($&)
|
CGI::escapeHTML($&)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
string
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
=== UNESCAPE ELEMENT
|
=== UNESCAPE ELEMENT
|
||||||
print CGI::unescapeElement(
|
print CGI::unescapeElement(
|
||||||
CGI::escapeHTML("<BR><A HREF="url"></A>"), "A", "IMG")
|
CGI::escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
|
||||||
# "<BR><A HREF="url"></A>"
|
# "<BR><A HREF="url"></A>"
|
||||||
|
|
||||||
print CGI::unescapeElement(
|
print CGI::unescapeElement(
|
||||||
CGI::escapeHTML("<BR><A HREF="url"></A>"), ["A", "IMG"])
|
CGI::escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
|
||||||
# "<BR><A HREF="url"></A>"
|
# "<BR><A HREF="url"></A>"
|
||||||
=end
|
=end
|
||||||
def CGI::unescapeElement(string, *element)
|
def CGI::unescapeElement(string, *element)
|
||||||
|
@ -332,11 +344,11 @@ class CGI
|
||||||
=begin
|
=begin
|
||||||
=== MAKE RFC1123 DATE STRING
|
=== MAKE RFC1123 DATE STRING
|
||||||
CGI::rfc1123_date(Time.now)
|
CGI::rfc1123_date(Time.now)
|
||||||
# Sut, 1 Jan 2000 00:00:00 GMT
|
# Sat, 1 Jan 2000 00:00:00 GMT
|
||||||
=end
|
=end
|
||||||
def CGI::rfc1123_date(time)
|
def CGI::rfc1123_date(time)
|
||||||
t = time.clone.gmtime
|
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,
|
RFC822_DAYS[t.wday], t.day, RFC822_MONTHS[t.month-1], t.year,
|
||||||
t.hour, t.min, t.sec)
|
t.hour, t.min, t.sec)
|
||||||
end
|
end
|
||||||
|
@ -1732,7 +1744,7 @@ convert string charset, and set language to "ja".
|
||||||
module Html4
|
module Html4
|
||||||
|
|
||||||
def doctype
|
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
|
end
|
||||||
|
|
||||||
def element_init
|
def element_init
|
||||||
|
@ -1778,7 +1790,7 @@ convert string charset, and set language to "ja".
|
||||||
module Html4Tr
|
module Html4Tr
|
||||||
|
|
||||||
def doctype
|
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
|
end
|
||||||
|
|
||||||
def element_init
|
def element_init
|
||||||
|
@ -1826,7 +1838,7 @@ convert string charset, and set language to "ja".
|
||||||
module Html4Fr
|
module Html4Fr
|
||||||
|
|
||||||
def doctype
|
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
|
end
|
||||||
|
|
||||||
def element_init
|
def element_init
|
||||||
|
@ -1908,6 +1920,21 @@ end
|
||||||
|
|
||||||
== HISTORY
|
== 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
|
* Sun Jun 18 23:31:44 JST 2000 - wakou
|
||||||
* version 1.7.0
|
* version 1.7.0
|
||||||
* change: version syntax. old: x.yz, now: x.y.z
|
* change: version syntax. old: x.yz, now: x.y.z
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
=begin
|
=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>
|
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")
|
||||||
line = host.cmd({"String" => "string",
|
line = host.cmd({"String" => "string",
|
||||||
"Prompt" => /[$%#>] \z/n,
|
"Match" => /[$%#>] \z/n,
|
||||||
"Timeout" => 10})
|
"Timeout" => 10})
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ of cource, set sync=true or flush is necessary.
|
||||||
|
|
||||||
host.cmd("string"){|c| print c }
|
host.cmd("string"){|c| print c }
|
||||||
host.cmd({"String" => "string",
|
host.cmd({"String" => "string",
|
||||||
"Prompt" => /[$%#>] \z/n,
|
"Match" => /[$%#>] \z/n,
|
||||||
"Timeout" => 10}){|c| print c }
|
"Timeout" => 10}){|c| print c }
|
||||||
|
|
||||||
of cource, set sync=true or flush is necessary.
|
of cource, set sync=true or flush is necessary.
|
||||||
|
@ -88,7 +88,17 @@ of cource, set sync=true or flush is necessary.
|
||||||
=== SEND STRING
|
=== SEND STRING
|
||||||
|
|
||||||
host.print("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
|
=== TOGGLE TELNET COMMAND INTERPRETATION
|
||||||
|
@ -109,25 +119,19 @@ of cource, set sync=true or flush is necessary.
|
||||||
|
|
||||||
host.login("username", "password")
|
host.login("username", "password")
|
||||||
host.login({"Name" => "username",
|
host.login({"Name" => "username",
|
||||||
"Password" => "password",
|
"Password" => "password"})
|
||||||
"Prompt" => /[$%#>] \z/n,
|
|
||||||
"Timeout" => 10})
|
|
||||||
|
|
||||||
if no password prompt:
|
if no password prompt:
|
||||||
|
|
||||||
host.login("username")
|
host.login("username")
|
||||||
host.login({"Name" => "username",
|
host.login({"Name" => "username"})
|
||||||
"Prompt" => /[$%#>] \z/n,
|
|
||||||
"Timeout" => 10})
|
|
||||||
|
|
||||||
|
|
||||||
==== REALTIME OUTPUT
|
==== REALTIME OUTPUT
|
||||||
|
|
||||||
host.login("username", "password"){|c| print c }
|
host.login("username", "password"){|c| print c }
|
||||||
host.login({"Name" => "username",
|
host.login({"Name" => "username",
|
||||||
"Password" => "password",
|
"Password" => "password"}){|c| print c }
|
||||||
"Prompt" => /[$%#>] \z/n,
|
|
||||||
"Timeout" => 10}){|c| print c }
|
|
||||||
|
|
||||||
of cource, set sync=true or flush is necessary.
|
of cource, set sync=true or flush is necessary.
|
||||||
|
|
||||||
|
@ -235,10 +239,10 @@ module Net
|
||||||
CR = "\015"
|
CR = "\015"
|
||||||
LF = "\012"
|
LF = "\012"
|
||||||
EOL = CR + LF
|
EOL = CR + LF
|
||||||
VERSION = "1.5.0"
|
VERSION = "1.6.0"
|
||||||
RELEASE_DATE = "2000-06-19"
|
RELEASE_DATE = "2000-09-12"
|
||||||
VERSION_CODE = 150
|
VERSION_CODE = 160
|
||||||
RELEASE_CODE = 20000619
|
RELEASE_CODE = 20000912
|
||||||
|
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
@options = options
|
@options = options
|
||||||
|
@ -507,6 +511,10 @@ module Net
|
||||||
end
|
end
|
||||||
|
|
||||||
def print(string)
|
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 + "\n"
|
||||||
string = string.gsub(/#{IAC}/no, IAC + IAC) if @options["Telnetmode"]
|
string = string.gsub(/#{IAC}/no, IAC + IAC) if @options["Telnetmode"]
|
||||||
|
|
||||||
|
@ -526,6 +534,10 @@ module Net
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def puts(string)
|
||||||
|
self.print(string)
|
||||||
|
end
|
||||||
|
|
||||||
def cmd(options)
|
def cmd(options)
|
||||||
match = @options["Prompt"]
|
match = @options["Prompt"]
|
||||||
time_out = @options["Timeout"]
|
time_out = @options["Timeout"]
|
||||||
|
@ -584,6 +596,12 @@ end
|
||||||
|
|
||||||
== HISTORY
|
== 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
|
* Sun Jun 18 23:31:44 JST 2000 - wakou
|
||||||
* version 1.5.0
|
* version 1.5.0
|
||||||
* change: version syntax. old: x.yz, now: x.y.z
|
* change: version syntax. old: x.yz, now: x.y.z
|
||||||
|
|
Loading…
Add table
Reference in a new issue