1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/xmlrpc/*, test/xmlrpc/*: backported changes from HEAD into 1.8

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mneumann 2005-06-24 20:27:43 +00:00
parent 1ee06ebecf
commit 686c038347
7 changed files with 92 additions and 60 deletions

View file

@ -1,3 +1,7 @@
Fri Jun 24 22:06:47 CEST 2005 Michael Neumann <mneumann@ruby-lang.org>
* lib/xmlrpc/*, test/xmlrpc/*: backported changes from HEAD into 1.8
Fri Jun 24 13:06:45 2005 akira yamada <akira@ruby-lang.org>
* lib/uri/common.rb, lib/uri/generic.rb: fixed typo in documents and

View file

@ -69,6 +69,7 @@ call on the remote-side and of course the parameters for the remote procedure.
Parameter ((|timeout|)) is the time to wait for a XML-RPC response, defaults to 30.
--- XMLRPC::Client.new2( uri, proxy=nil, timeout=nil)
--- XMLRPC::Client.new_from_uri( uri, proxy=nil, timeout=nil)
: uri
URI specifying protocol (http or https), host, port, path, user and password.
Example: https://user:password@host:port/path
@ -80,6 +81,7 @@ call on the remote-side and of course the parameters for the remote procedure.
Defaults to 30.
--- XMLRPC::Client.new3( hash={} )
--- XMLRPC::Client.new_from_hash( hash={} )
Parameter ((|hash|)) has following case-insensitive keys:
* host
* path
@ -135,6 +137,8 @@ call on the remote-side and of course the parameters for the remote procedure.
(({XMLRPC::FaultException})).
Both are explained in ((<call|XMLRPC::Client#call>)).
Simple to remember: The "2" in "call2" denotes the number of values it returns.
--- XMLRPC::Client#multicall( *methods )
You can use this method to execute several methods on a XMLRPC server which supports
the multi-call extension.
@ -331,7 +335,9 @@ module XMLRPC
end
def self.new2(uri, proxy=nil, timeout=nil)
class << self
def new2(uri, proxy=nil, timeout=nil)
if match = /^([^:]+):\/\/(([^@]+)@)?([^\/]+)(\/.*)?$/.match(uri)
proto = match[1]
user, passwd = (match[3] || "").split(":")
@ -350,9 +356,10 @@ module XMLRPC
self.new(host, path, port, proxy_host, proxy_port, user, passwd, (proto == "https"), timeout)
end
def self.new3(hash={})
alias new_from_uri new2
def new3(hash={})
# convert all keys into lowercase strings
h = {}
@ -362,6 +369,10 @@ module XMLRPC
h['use_ssl'], h['timeout'])
end
alias new_from_hash new3
end
# Attribute Accessors -------------------------------------------------------------------
@ -457,19 +468,19 @@ module XMLRPC
# Proxy generating methods ------------------------------------------
def proxy(prefix, *args)
def proxy(prefix=nil, *args)
Proxy.new(self, prefix, args, :call)
end
def proxy2(prefix, *args)
def proxy2(prefix=nil, *args)
Proxy.new(self, prefix, args, :call2)
end
def proxy_async(prefix, *args)
def proxy_async(prefix=nil, *args)
Proxy.new(self, prefix, args, :call_async)
end
def proxy2_async(prefix, *args)
def proxy2_async(prefix=nil, *args)
Proxy.new(self, prefix, args, :call2_async)
end
@ -586,7 +597,7 @@ module XMLRPC
def initialize(server, prefix, args=[], meth=:call, delim=".")
@server = server
@prefix = prefix + delim
@prefix = prefix ? prefix + delim : ""
@args = args
@meth = meth
end

View file

@ -86,6 +86,18 @@ module XMLRPC
end # class XMLParser
Classes = [Simple, XMLParser]
# yields an instance of each installed XML writer
def self.each_installed_writer
XMLRPC::XMLWriter::Classes.each do |klass|
begin
yield klass.new
rescue LoadError
end
end
end
end # module XMLWriter
class Create
@ -248,7 +260,10 @@ module XMLRPC
if Config::ENABLE_MARSHALLING and param.class.included_modules.include? XMLRPC::Marshallable
# convert Ruby object into Hash
ret = {"___class___" => param.class.name}
param.__get_instance_variables.each {|name, val|
param.instance_variables.each {|v|
name = v[1..-1]
val = param.instance_variable_get(v)
if val.nil?
ret[name] = val if Config::ENABLE_NIL_CREATE
else

View file

@ -126,6 +126,10 @@ class DateTime
[@year, @month, @day, @hour, @min, @sec]
end
def ==(o)
Array(self) == Array(o)
end
end

View file

@ -54,6 +54,8 @@ module XMLRPC
class FaultException < StandardError
attr_reader :faultCode, :faultString
alias message faultString
def initialize(faultCode, faultString)
@faultCode = faultCode
@faultString = faultString
@ -84,18 +86,32 @@ module XMLRPC
end
def self.dateTime(str)
if str =~ /^(-?\d\d\d\d)(\d\d)(\d\d)T(\d\d):(\d\d):(\d\d)$/ then
# TODO: Time.gm ??? .local ???
case str
when /^(-?\d\d\d\d)-?(\d\d)-?(\d\d)T(\d\d):(\d\d):(\d\d)(?:Z|([+-])(\d\d):?(\d\d))?$/
a = [$1, $2, $3, $4, $5, $6].collect{|i| i.to_i}
if $7
ofs = $8.to_i*3600 + $9.to_i*60
ofs = -ofs if $7=='+'
utc = Time.utc(a.reverse) + ofs
a = [ utc.year, utc.month, utc.day, utc.hour, utc.min, utc.sec ]
end
XMLRPC::DateTime.new(*a)
when /^(-?\d\d)-?(\d\d)-?(\d\d)T(\d\d):(\d\d):(\d\d)(Z|([+-]\d\d):(\d\d))?$/
a = [$1, $2, $3, $4, $5, $6].collect{|i| i.to_i}
if a[0] < 70
a[0] += 2000
else
a[0] += 1900
end
if $7
ofs = $8.to_i*3600 + $9.to_i*60
ofs = -ofs if $7=='+'
utc = Time.utc(a.reverse) + ofs
a = [ utc.year, utc.month, utc.day, utc.hour, utc.min, utc.sec ]
end
XMLRPC::DateTime.new(*a)
#if a[0] >= 1970 then
# Time.gm(*a)
#else
# Date.new(*a[0,3])
#end
else
raise "wrong dateTime.iso8601 format"
raise "wrong dateTime.iso8601 format " + str
end
end
@ -112,31 +128,13 @@ module XMLRPC
begin
mod = Module
klass.split("::").each {|const| mod = mod.const_get(const.strip)}
obj = mod.allocate
Thread.critical = true
# let initialize take 0 parameters
mod.module_eval %{
begin
alias __initialize initialize
rescue NameError
end
def initialize; end
}
obj = mod.new
# restore old initialize
mod.module_eval %{
undef initialize
begin
alias initialize __initialize
rescue NameError
end
}
Thread.critical = false
hash.delete "___class___"
hash.each {|k,v| obj.__set_instance_variable(k, v) }
hash.each {|key, value|
obj.instance_variable_set("@#{ key }", value) if key =~ /^([\w_][\w_0-9]*)$/
}
obj
rescue
hash
@ -582,12 +580,9 @@ module XMLRPC
class XMLStreamParser < AbstractStreamParser
def initialize
require "xmlparser"
eval %{
class XMLRPCParser < ::XMLParser
include StreamParserMixin
end
@parser_class = Class.new(::XMLParser) {
include StreamParserMixin
}
@parser_class = XMLRPCParser
end
end # class XMLStreamParser
# ---------------------------------------------------------------------------
@ -801,6 +796,16 @@ module XMLRPC
NQXMLStreamParser, NQXMLTreeParser,
REXMLStreamParser, XMLScanStreamParser]
# yields an instance of each installed parser
def self.each_installed_parser
XMLRPC::XMLParser::Classes.each do |klass|
begin
yield klass.new
rescue LoadError
end
end
end
end # module XMLParser

View file

@ -448,7 +448,7 @@ class CGIServer < BasicServer
length = ENV['CONTENT_LENGTH'].to_i
http_error(405, "Method Not Allowed") unless ENV['REQUEST_METHOD'] == "POST"
http_error(400, "Bad Request") unless ENV['CONTENT_TYPE'] == "text/xml"
http_error(400, "Bad Request") unless parse_content_type(ENV['CONTENT_TYPE']).first == "text/xml"
http_error(411, "Length Required") unless length > 0
# TODO: do we need a call to binmode?
@ -792,27 +792,27 @@ class WEBrickServlet < BasicServer
def service(request, response)
if request.request_method != "POST"
raise HTTPStatus::MethodNotAllowed,
raise WEBrick::HTTPStatus::MethodNotAllowed,
"unsupported method `#{request.request_method}'."
end
if parse_content_type(request['Content-type']).first != "text/xml"
raise HTTPStatus::BadRequest
raise WEBrick::HTTPStatus::BadRequest
end
length = (request['Content-length'] || 0).to_i
raise HTTPStatus::LengthRequired unless length > 0
raise WEBrick::HTTPStatus::LengthRequired unless length > 0
data = request.body
if data.nil? or data.size != length
raise HTTPStatus::BadRequest
raise WEBrick::HTTPStatus::BadRequest
end
resp = process(data)
if resp.nil? or resp.size <= 0
raise HTTPStatus::InternalServerError
raise WEBrick::HTTPStatus::InternalServerError
end
response.status = 200

View file

@ -17,13 +17,6 @@ module XMLRPC
# key/value pair "___class___" => ClassName
#
module Marshallable
def __get_instance_variables
instance_variables.collect {|var| [var[1..-1], eval(var)] }
end
def __set_instance_variable(key, value)
eval("@#$1 = value") if key =~ /^([\w_][\w_0-9]*)$/
end
end
@ -138,7 +131,7 @@ module XMLRPC
def get_methods(obj, delim=".")
prefix = @prefix + delim
obj.class.public_instance_methods.collect { |name|
obj.class.public_instance_methods(false).collect { |name|
[prefix + name, obj.method(name).to_proc, nil, nil]
}
end