diff options
author | mneumann <mneumann@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-06-24 20:27:43 +0000 |
---|---|---|
committer | mneumann <mneumann@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-06-24 20:27:43 +0000 |
commit | 686c038347b41761032c728ca5babc18a35ad142 (patch) | |
tree | 3b53de37a575c315b6daebd746ee91461dbc0833 /lib/xmlrpc/parser.rb | |
parent | 1ee06ebecf3b3b96de788c8dedd3b0de3cb0be18 (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/xmlrpc/parser.rb')
-rw-r--r-- | lib/xmlrpc/parser.rb | 79 |
1 files changed, 42 insertions, 37 deletions
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 |