summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormneumann <mneumann@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-06-24 20:27:43 +0000
committermneumann <mneumann@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-06-24 20:27:43 +0000
commit686c038347b41761032c728ca5babc18a35ad142 (patch)
tree3b53de37a575c315b6daebd746ee91461dbc0833 /lib
parent1ee06ebecf3b3b96de788c8dedd3b0de3cb0be18 (diff)
* 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
Diffstat (limited to 'lib')
-rw-r--r--lib/xmlrpc/client.rb27
-rw-r--r--lib/xmlrpc/create.rb17
-rw-r--r--lib/xmlrpc/datetime.rb4
-rw-r--r--lib/xmlrpc/parser.rb79
-rw-r--r--lib/xmlrpc/server.rb12
-rw-r--r--lib/xmlrpc/utils.rb9
6 files changed, 88 insertions, 60 deletions
diff --git a/lib/xmlrpc/client.rb b/lib/xmlrpc/client.rb
index 18cf4b0cf3..074f5014cf 100644
--- a/lib/xmlrpc/client.rb
+++ b/lib/xmlrpc/client.rb
@@ -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
diff --git a/lib/xmlrpc/create.rb b/lib/xmlrpc/create.rb
index 072e72ab46..0bfa4ab551 100644
--- a/lib/xmlrpc/create.rb
+++ b/lib/xmlrpc/create.rb
@@ -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
diff --git a/lib/xmlrpc/datetime.rb b/lib/xmlrpc/datetime.rb
index e3bc6943f0..298263fe8a 100644
--- a/lib/xmlrpc/datetime.rb
+++ b/lib/xmlrpc/datetime.rb
@@ -126,6 +126,10 @@ class DateTime
[@year, @month, @day, @hour, @min, @sec]
end
+ def ==(o)
+ Array(self) == Array(o)
+ end
+
end
diff --git a/lib/xmlrpc/parser.rb b/lib/xmlrpc/parser.rb
index 49b99b2958..d27d7c3827 100644
--- a/lib/xmlrpc/parser.rb
+++ b/lib/xmlrpc/parser.rb
@@ -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)}
-
- 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
+ obj = mod.allocate
+
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
diff --git a/lib/xmlrpc/server.rb b/lib/xmlrpc/server.rb
index 0ef3ca4c93..785880d301 100644
--- a/lib/xmlrpc/server.rb
+++ b/lib/xmlrpc/server.rb
@@ -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
diff --git a/lib/xmlrpc/utils.rb b/lib/xmlrpc/utils.rb
index 14dd08b21d..85c6bba372 100644
--- a/lib/xmlrpc/utils.rb
+++ b/lib/xmlrpc/utils.rb
@@ -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