From 1ed39b739237bffd9c78e696c09462ce67017b95 Mon Sep 17 00:00:00 2001 From: nahi Date: Fri, 5 Dec 2003 13:26:26 +0000 Subject: * lib/soap/netHttpClient.rb: proxy support did not work. fixed. * lib/soap/property.rb: add class methods for loading property from stream/file/propertyfile. propertyfile is a file which is located at somedir in $:. * lib/soap/soap.rb, lib/soap/wsdlDriver.rb, lib/soap/rpc/driver.rb, lib/wsdl/importer.rb: load property from propertyfile 'soap/property' e.g. /usr/local/lib/ruby/site_ruby/1.8/soap/property. * test/soap/test_property.rb, test/soap/test_streamhandler.rb: new file. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/soap/property.rb | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'lib/soap/property.rb') diff --git a/lib/soap/property.rb b/lib/soap/property.rb index 84fa876cae..b67ffa8361 100644 --- a/lib/soap/property.rb +++ b/lib/soap/property.rb @@ -12,6 +12,44 @@ module SOAP class Property include Enumerable + # Property file format: + # line separator is \r?\n. 1 line per a property. + # line which begins with '#' is comment line. empty line is ignored. + # key/value separator is ':', '=', or \s. + # '\' as escape character. but line separator cannot be escaped. + # \s at the head/tail of key/value are trimmed. + def self.load(stream) + prop = new + stream.each_with_index do |line, lineno| + line.sub!(/\r?\n\z/, '') + next if /^(#.*|)$/ =~ line + if /^\s*([^=:\s\\]+(?:\\.[^=:\s\\]*)*)\s*[=:\s]\s*(.*)$/ =~ line + key, value = $1, $2 + key = eval("\"#{key}\"") + value = eval("\"#{value.strip}\"") + prop[key] = value + else + raise TypeError.new("property format error at line #{lineno + 1}: `#{line}'") + end + end + prop + end + + def self.open(filename) + File.open(filename) do |f| + load(f) + end + end + + def self.loadproperty(propname) + $:.each do |path| + if File.file?(file = File.join(path, propname)) + return open(file) + end + end + nil + end + def initialize @store = Hash.new @hook = Hash.new @@ -193,7 +231,7 @@ private when Symbol [name] when String - name.split(/\./) + name.scan(/[^.\\]+(?:\\.[^.\\])*/) # split with unescaped '.' when Array name else @@ -212,7 +250,7 @@ private end def to_key(name) - name.to_s.downcase.intern + name.to_s.downcase end def generate_new_key -- cgit v1.2.3