[BioRuby-cvs] bioruby/lib/bio command.rb,1.5,1.6

Naohisa Goto ngoto at dev.open-bio.org
Wed Apr 26 12:04:15 UTC 2006


Update of /home/repository/bioruby/bioruby/lib/bio
In directory dev.open-bio.org:/tmp/cvs-serv32140/lib/bio

Modified Files:
	command.rb 
Log Message:
Experimentally added Bio::Command::NetTools.net_http_start() method. Note that it would be removed or the method name would be changed.


Index: command.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/command.rb,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** command.rb	28 Mar 2006 14:00:48 -0000	1.5
--- command.rb	26 Apr 2006 12:04:13 -0000	1.6
***************
*** 13,16 ****
--- 13,17 ----
  require 'uri'
  require 'open-uri'
+ require 'net/http'
  
  module Bio
***************
*** 162,165 ****
--- 163,190 ----
      OpenURI.open_uri(uri).read
    end
+ 
+   # Same as:
+   #  uri = URI.parse(uri); Net::HTTP.start(uri.host, uri.port)
+   # and 
+   # it uses proxy if an environment variable (same as OpenURI.open_uri)
+   # is set.
+   # uri must be a string or a URI object.
+   def self.net_http_start(uri, &block)
+     unless uri.kind_of?(URI::Generic)
+       uri = URI.parse(uri)
+     end
+     if uri.scheme != 'http' then
+       raise "only http is supported: #{uri.inspect}"
+     end
+     # Note: URI#find_proxy is an unofficial method defined in open-uri.rb.
+     # If the spec of open-uri.rb would be changed, we should change below.
+     if proxyuri = uri.find_proxy then
+       raise 'Non-HTTP proxy' if proxyuri.class != URI::HTTP
+       http = Net::HTTP.Proxy(proxyuri.host, proxyuri.port)
+     else
+       http = Net::HTTP
+     end
+     http.start(uri.host, uri.port, &block)
+   end
  end #module NetTools
  




More information about the bioruby-cvs mailing list