[BioRuby] open_uri (Fwd: [BioRuby-cvs] bioruby/lib/bio command.rb, 1.3, 1.4)
Naohisa Goto
ngoto at gen-info.osaka-u.ac.jp
Sun Mar 26 06:56:07 UTC 2006
> > + # Same as OpenURI.open_uri(*arg).
> > + # If open-uri.rb is already loaded, ::OpenURI is used.
> > + # Otherwise, internal OpenURI in sandbox is used because
> > + # open-uri.rb redefines Kernel.open.
>
> Your code seems to contain a lot of hacks, finding open-uri.rb from Ruby's load path,
> searching a particular method from it etc...
Yes, it's very complicated. It's easier to copy-and-pastepart of
open-uri.rb but this may cause copyright problem.
The easiest way is to write "Please be careful that BioRuby now
require open-uri and the bahavior of open() is changed."
in the documents of BioRuby and uses OpenURI.open_uri.
In very rare case, the require "oprn-uri" changes behaviors.
For example,
% mkdir -p http://www.google.com
% echo "hello world" > http://www.google.com/index.html
% ls -R
.:
http:/
./http::
www.google.com/
./http:/www.google.com:
index.html
% irb
irb(main):001:0> open("http://www.google.com/index.html"){|f| f.read }
=> "hello world\n"
irb(main):002:0> require "open-uri"
=> true
irb(main):003:0> open("http://www.google.com/index.html"){|f| f.read }
=> "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=S
hift_JIS\"><title>Google</title><style><!--\nbody,td,a,p,.h{font-family:;}\n.h{f
ont-size: 20px;}\n.q{color:#0000cc;}\n//-->\n</style>\n<script>\n<!--\nfunction
(snip)
However, I think this is very rare case. In addition, to open a local
file, it is recommended using File.open, because Kernel#open
accepts shell special characters such as "|rm -rf *".
(For the same reason, it is recommended to use OpenURI.open_uri
to open a URI.)
> I don't understand what the complicated part of your Sandbox module actually does
> (or intends), but if your purpose is just to avoid redefine of Kenel.open, to put
> something like
>
> > require 'open-uri'
> >
> > module Kernel
> > private
> > alias open_uri open
> > alias open open_uri_original_open
> > end
>
> isn't enough?
No. Above code kills open_uri's extension to the Kernel#open,
and users who want to use the extended Kernel#open will be failed.
--
Naohisa GOTO
ngoto at gen-info.osaka-u.ac.jp
Department of Genome Informatics, Genome Information Research Center,
Research Institute for Microbial Diseases, Osaka University, Japan
More information about the BioRuby
mailing list