aamine
* lib/net/protocol.rb, smtp.rb, pop.rb, http.rb: 1.1.26. * lib/net/protocol.rb, smtp.rb, pop.rb, http.rb: add module Net::NetPrivate and its inner classes {Read,Write}Adapter, Command, Socket, SMTPCommand, POP3Command, APOPCommand, HTTPCommand git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
960676a2de
commit
beffb7f835
@ -1,3 +1,12 @@
|
|||||||
|
Wed Jul 12 15:04:11 2000 Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
||||||
|
|
||||||
|
* lib/net/protocol.rb, smtp.rb, pop.rb, http.rb: 1.1.26.
|
||||||
|
|
||||||
|
* lib/net/protocol.rb, smtp.rb, pop.rb, http.rb:
|
||||||
|
add module Net::NetPrivate and its inner classes
|
||||||
|
{Read,Write}Adapter, Command, Socket,
|
||||||
|
SMTPCommand, POP3Command, APOPCommand, HTTPCommand
|
||||||
|
|
||||||
Tue Jul 11 16:54:17 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
|
Tue Jul 11 16:54:17 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||||
|
|
||||||
* parse.y (yylex): `@<digit>' is no longer a valid instance
|
* parse.y (yylex): `@<digit>' is no longer a valid instance
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
=begin
|
=begin
|
||||||
|
|
||||||
= net/http.rb
|
= net/http.rb version 1.1.27
|
||||||
|
|
||||||
maintained by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
maintained by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
||||||
This file is derived from "http-access.rb".
|
This file is derived from "http-access.rb".
|
||||||
@ -25,8 +25,6 @@ You can freely distribute/modify this library.
|
|||||||
: port
|
: port
|
||||||
HTTP default port, 80
|
HTTP default port, 80
|
||||||
|
|
||||||
: command_type
|
|
||||||
Command class for Net::HTTP, HTTPCommand
|
|
||||||
|
|
||||||
== Methods
|
== Methods
|
||||||
|
|
||||||
@ -116,9 +114,9 @@ You can freely distribute/modify this library.
|
|||||||
|
|
||||||
ex.
|
ex.
|
||||||
|
|
||||||
http.post2( '/index.html', 'data data data...' ) do |f|
|
http.post2( '/index.html', 'data data data...' ) do |adapter|
|
||||||
f.header
|
adapter.header
|
||||||
f.body
|
adapter.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -214,13 +212,13 @@ module Net
|
|||||||
class HTTP < Protocol
|
class HTTP < Protocol
|
||||||
|
|
||||||
protocol_param :port, '80'
|
protocol_param :port, '80'
|
||||||
protocol_param :command_type, '::Net::HTTPCommand'
|
protocol_param :command_type, '::Net::NetPrivate::HTTPCommand'
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
def procdest( dest, block )
|
def procdest( dest, block )
|
||||||
if block then
|
if block then
|
||||||
return ReadAdapter.new( block ), nil
|
return NetPrivate::ReadAdapter.new( block ), nil
|
||||||
else
|
else
|
||||||
dest ||= ''
|
dest ||= ''
|
||||||
return dest, dest
|
return dest, dest
|
||||||
@ -420,43 +418,6 @@ module Net
|
|||||||
HTTPSession = HTTP
|
HTTPSession = HTTP
|
||||||
|
|
||||||
|
|
||||||
class HTTPReadAdapter
|
|
||||||
|
|
||||||
def initialize( command )
|
|
||||||
@command = command
|
|
||||||
@header = @body = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def inspect
|
|
||||||
"#<#{type}>"
|
|
||||||
end
|
|
||||||
|
|
||||||
def header
|
|
||||||
unless @header then
|
|
||||||
@header = @command.get_response
|
|
||||||
end
|
|
||||||
@header
|
|
||||||
end
|
|
||||||
alias response header
|
|
||||||
|
|
||||||
def body( dest = nil, &block )
|
|
||||||
dest, ret = HTTP.procdest( dest, block )
|
|
||||||
unless @body then
|
|
||||||
@body = @command.get_body( response, dest )
|
|
||||||
end
|
|
||||||
@body
|
|
||||||
end
|
|
||||||
alias entity body
|
|
||||||
|
|
||||||
def off
|
|
||||||
body
|
|
||||||
@command = nil
|
|
||||||
@header
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
class HTTPResponse < Response
|
class HTTPResponse < Response
|
||||||
|
|
||||||
def initialize( code_type, bexist, code, msg )
|
def initialize( code_type, bexist, code, msg )
|
||||||
@ -470,7 +431,7 @@ module Net
|
|||||||
attr_accessor :body
|
attr_accessor :body
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
"#<Net::HTTPResponse #{code}>"
|
"#<#{type.name} #{code}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def []( key )
|
def []( key )
|
||||||
@ -559,6 +520,47 @@ module Net
|
|||||||
HTTPVersionNotSupported = HTTPFatalErrorCode.mkchild
|
HTTPVersionNotSupported = HTTPFatalErrorCode.mkchild
|
||||||
|
|
||||||
|
|
||||||
|
class HTTPReadAdapter
|
||||||
|
|
||||||
|
def initialize( command )
|
||||||
|
@command = command
|
||||||
|
@header = @body = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def inspect
|
||||||
|
"#<#{type}>"
|
||||||
|
end
|
||||||
|
|
||||||
|
def header
|
||||||
|
unless @header then
|
||||||
|
@header = @command.get_response
|
||||||
|
end
|
||||||
|
@header
|
||||||
|
end
|
||||||
|
alias response header
|
||||||
|
|
||||||
|
def body( dest = nil, &block )
|
||||||
|
dest, ret = HTTP.procdest( dest, block )
|
||||||
|
unless @body then
|
||||||
|
@body = @command.get_body( response, dest )
|
||||||
|
end
|
||||||
|
@body
|
||||||
|
end
|
||||||
|
alias entity body
|
||||||
|
|
||||||
|
def off
|
||||||
|
body
|
||||||
|
@command = nil
|
||||||
|
@header
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module NetPrivate
|
||||||
|
|
||||||
|
|
||||||
class HTTPCommand < Command
|
class HTTPCommand < Command
|
||||||
|
|
||||||
HTTPVersion = '1.1'
|
HTTPVersion = '1.1'
|
||||||
@ -819,4 +821,6 @@ module Net
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end # module Net::NetPrivate
|
||||||
|
|
||||||
end # module Net
|
end # module Net
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
=begin
|
=begin
|
||||||
|
|
||||||
= net/pop.rb
|
= net/pop.rb version 1.1.27
|
||||||
|
|
||||||
written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ module Net
|
|||||||
class POP3 < Protocol
|
class POP3 < Protocol
|
||||||
|
|
||||||
protocol_param :port, '110'
|
protocol_param :port, '110'
|
||||||
protocol_param :command_type, '::Net::POP3Command'
|
protocol_param :command_type, '::Net::NetPrivate::POP3Command'
|
||||||
|
|
||||||
protocol_param :mail_type, '::Net::POPMail'
|
protocol_param :mail_type, '::Net::POPMail'
|
||||||
|
|
||||||
@ -155,6 +155,12 @@ module Net
|
|||||||
POP3Session = POP3
|
POP3Session = POP3
|
||||||
|
|
||||||
|
|
||||||
|
class APOP < POP3
|
||||||
|
protocol_param :command_type, 'Net::NetPrivate::APOPCommand'
|
||||||
|
end
|
||||||
|
|
||||||
|
APOPSession = APOP
|
||||||
|
|
||||||
|
|
||||||
class POPMail
|
class POPMail
|
||||||
|
|
||||||
@ -174,7 +180,7 @@ module Net
|
|||||||
|
|
||||||
def all( dest = '' )
|
def all( dest = '' )
|
||||||
if iterator? then
|
if iterator? then
|
||||||
dest = ReadAdapter.new( Proc.new )
|
dest = NetPrivate::ReadAdapter.new( Proc.new )
|
||||||
end
|
end
|
||||||
@command.retr( @num, dest )
|
@command.retr( @num, dest )
|
||||||
end
|
end
|
||||||
@ -207,12 +213,7 @@ module Net
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class APOP < POP3
|
module NetPrivate
|
||||||
protocol_param :command_type, 'Net::APOPCommand'
|
|
||||||
end
|
|
||||||
|
|
||||||
APOPSession = APOP
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class POP3Command < Command
|
class POP3Command < Command
|
||||||
@ -311,7 +312,6 @@ module Net
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class APOPCommand < POP3Command
|
class APOPCommand < POP3Command
|
||||||
|
|
||||||
def initialize( sock )
|
def initialize( sock )
|
||||||
@ -334,4 +334,7 @@ module Net
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
|
end # module Net::NetPrivate
|
||||||
|
|
||||||
|
end # module Net
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
=begin
|
=begin
|
||||||
|
|
||||||
= net/protocol.rb
|
= net/protocol.rb version 1.1.27
|
||||||
|
|
||||||
written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ module Net
|
|||||||
|
|
||||||
class Protocol
|
class Protocol
|
||||||
|
|
||||||
Version = '1.1.26'
|
Version = '1.1.27'
|
||||||
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
@ -137,7 +137,7 @@ module Net
|
|||||||
|
|
||||||
protocol_param :port, 'nil'
|
protocol_param :port, 'nil'
|
||||||
protocol_param :command_type, 'nil'
|
protocol_param :command_type, 'nil'
|
||||||
protocol_param :socket_type, '::Net::Socket'
|
protocol_param :socket_type, '::Net::NetPrivate::Socket'
|
||||||
|
|
||||||
|
|
||||||
def initialize( addr = nil, port = nil )
|
def initialize( addr = nil, port = nil )
|
||||||
@ -220,72 +220,6 @@ module Net
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Command
|
|
||||||
|
|
||||||
def initialize( sock )
|
|
||||||
@socket = sock
|
|
||||||
@last_reply = nil
|
|
||||||
@critical = false
|
|
||||||
end
|
|
||||||
|
|
||||||
attr_accessor :socket
|
|
||||||
attr_reader :last_reply
|
|
||||||
|
|
||||||
def inspect
|
|
||||||
"#<#{type}>"
|
|
||||||
end
|
|
||||||
|
|
||||||
# abstract quit
|
|
||||||
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
# abstract get_reply()
|
|
||||||
|
|
||||||
def check_reply( *oks )
|
|
||||||
@last_reply = get_reply
|
|
||||||
reply_must( @last_reply, *oks )
|
|
||||||
end
|
|
||||||
|
|
||||||
def reply_must( rep, *oks )
|
|
||||||
oks.each do |i|
|
|
||||||
if i === rep then
|
|
||||||
return rep
|
|
||||||
end
|
|
||||||
end
|
|
||||||
rep.error!
|
|
||||||
end
|
|
||||||
|
|
||||||
def getok( line, ok = SuccessCode )
|
|
||||||
@socket.writeline line
|
|
||||||
check_reply ok
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def critical
|
|
||||||
return if @critical
|
|
||||||
@critical = true
|
|
||||||
r = yield
|
|
||||||
@critical = false
|
|
||||||
r
|
|
||||||
end
|
|
||||||
|
|
||||||
def critical?
|
|
||||||
@critical
|
|
||||||
end
|
|
||||||
|
|
||||||
def begin_critical
|
|
||||||
ret = @critical
|
|
||||||
@critical = true
|
|
||||||
not ret
|
|
||||||
end
|
|
||||||
|
|
||||||
def end_critical
|
|
||||||
@critical = false
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
class Response
|
class Response
|
||||||
|
|
||||||
@ -379,6 +313,9 @@ module Net
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module NetPrivate
|
||||||
|
|
||||||
|
|
||||||
class WriteAdapter
|
class WriteAdapter
|
||||||
|
|
||||||
def initialize( sock, mid )
|
def initialize( sock, mid )
|
||||||
@ -414,6 +351,73 @@ module Net
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
class Command
|
||||||
|
|
||||||
|
def initialize( sock )
|
||||||
|
@socket = sock
|
||||||
|
@last_reply = nil
|
||||||
|
@critical = false
|
||||||
|
end
|
||||||
|
|
||||||
|
attr_accessor :socket
|
||||||
|
attr_reader :last_reply
|
||||||
|
|
||||||
|
def inspect
|
||||||
|
"#<#{type}>"
|
||||||
|
end
|
||||||
|
|
||||||
|
# abstract quit
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# abstract get_reply()
|
||||||
|
|
||||||
|
def check_reply( *oks )
|
||||||
|
@last_reply = get_reply
|
||||||
|
reply_must( @last_reply, *oks )
|
||||||
|
end
|
||||||
|
|
||||||
|
def reply_must( rep, *oks )
|
||||||
|
oks.each do |i|
|
||||||
|
if i === rep then
|
||||||
|
return rep
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rep.error!
|
||||||
|
end
|
||||||
|
|
||||||
|
def getok( line, ok = SuccessCode )
|
||||||
|
@socket.writeline line
|
||||||
|
check_reply ok
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def critical
|
||||||
|
return if @critical
|
||||||
|
@critical = true
|
||||||
|
r = yield
|
||||||
|
@critical = false
|
||||||
|
r
|
||||||
|
end
|
||||||
|
|
||||||
|
def critical?
|
||||||
|
@critical
|
||||||
|
end
|
||||||
|
|
||||||
|
def begin_critical
|
||||||
|
ret = @critical
|
||||||
|
@critical = true
|
||||||
|
not ret
|
||||||
|
end
|
||||||
|
|
||||||
|
def end_critical
|
||||||
|
@critical = false
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
class Socket
|
class Socket
|
||||||
|
|
||||||
def initialize( addr, port, pipe = nil )
|
def initialize( addr, port, pipe = nil )
|
||||||
@ -756,6 +760,9 @@ module Net
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end # module Net::NetPrivate
|
||||||
|
|
||||||
|
|
||||||
def Net.quote( str )
|
def Net.quote( str )
|
||||||
str = str.gsub( "\n", '\\n' )
|
str = str.gsub( "\n", '\\n' )
|
||||||
str.gsub!( "\r", '\\r' )
|
str.gsub!( "\r", '\\r' )
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
=begin
|
=begin
|
||||||
|
|
||||||
= net/smtp.rb
|
= net/smtp.rb version 1.1.27
|
||||||
|
|
||||||
written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ module Net
|
|||||||
class SMTP < Protocol
|
class SMTP < Protocol
|
||||||
|
|
||||||
protocol_param :port, '25'
|
protocol_param :port, '25'
|
||||||
protocol_param :command_type, '::Net::SMTPCommand'
|
protocol_param :command_type, '::Net::NetPrivate::SMTPCommand'
|
||||||
|
|
||||||
|
|
||||||
def initialize( addr = nil, port = nil )
|
def initialize( addr = nil, port = nil )
|
||||||
@ -157,6 +157,9 @@ module Net
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module NetPrivate
|
||||||
|
|
||||||
|
|
||||||
class SMTPCommand < Command
|
class SMTPCommand < Command
|
||||||
|
|
||||||
def initialize( sock )
|
def initialize( sock )
|
||||||
@ -286,4 +289,7 @@ module Net
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
|
end # module Net::NetPrivate
|
||||||
|
|
||||||
|
end # module Net
|
||||||
|
Loading…
x
Reference in New Issue
Block a user