lib/openwfe/utils.rb in openwferu-0.9.5 vs lib/openwfe/utils.rb in openwferu-0.9.6
- old
+ new
@@ -37,10 +37,14 @@
# "hecho en Costa Rica" and "made in Japan"
#
# john.mettraux@openwfe.org
#
+require 'tmpdir'
+require 'open-uri'
+
+
module OpenWFE
#
# Returns the first subelt of xmlElt that matches the given xpath.
# If xpath is null, the first elt will be returned.
@@ -151,10 +155,22 @@
def OpenWFE.to_dash (string)
string.gsub("_", "-")
end
#
+ # Returns an URI if the string is one, else returns nil.
+ # No exception is thrown by this method.
+ #
+ def OpenWFE.parse_uri (string)
+ begin
+ return URI::parse(string)
+ rescue Exception => e
+ end
+ return nil
+ end
+
+ #
# Returns true if the given string starts with the 'start' string.
#
def OpenWFE.starts_with (string, start)
#
# my favourite way of doing that would be by adding this
@@ -207,12 +223,19 @@
# else
# raw_expression.apply(wi)
# end
#
def OpenWFE.call_in_thread (caller_name, caller_object=nil, &block)
+
return unless block
+
Thread.new do
begin
+ #$SAFE = safe_level
+ #
+ # doesn't work : the block inherits the safety level
+ # of its surroundings, it's a closure, ne ?
+
block.call
rescue Exception => e
msg = "#{caller_name} caught an exception\n" + exception_to_s(e)
if caller_object and caller_object.respond_to? :lwarn
caller_object.lwarn { msg }