From 8ee383397d39cecc3cdf4dc30526907a208c46ce Mon Sep 17 00:00:00 2001 From: kou Date: Sun, 29 Jun 2008 09:02:32 +0000 Subject: [PATCH] * lib/rss/parser.rb, lib/rss/utils.rb: merge documents from ruby_1_8. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ lib/rss/parser.rb | 33 +++++++++++++++++++++++++++++---- lib/rss/utils.rb | 5 +++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 183a6f7399..66de79ce97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sun Jun 29 18:01:30 2008 Kouhei Sutou + + * lib/rss/parser.rb, lib/rss/utils.rb: merge documents from ruby_1_8. + Sun Jun 29 17:44:23 2008 Kouhei Sutou * lib/rss/parser.rb (RSS::ListenerMixin#known_class): define to diff --git a/lib/rss/parser.rb b/lib/rss/parser.rb index 2e137da3ed..8e91fb6ef6 100644 --- a/lib/rss/parser.rb +++ b/lib/rss/parser.rb @@ -8,6 +8,10 @@ module RSS class NotWellFormedError < Error attr_reader :line, :element + + # Create a new NotWellFormedError for an error at +line+ + # in +element+. If a block is given the return value of + # the block ends up in the error message. def initialize(line=nil, element=nil) message = "This is not well formed XML" if element or line @@ -22,15 +26,15 @@ module RSS class XMLParserNotFound < Error def initialize - super("available XML parser does not found in " << + super("available XML parser was not found in " << "#{AVAILABLE_PARSER_LIBRARIES.inspect}.") end end class NotValidXMLParser < Error def initialize(parser) - super("#{parser} is not available XML parser. " << - "available XML parser is " << + super("#{parser} is not an available XML parser. " << + "Available XML parser is " << "#{AVAILABLE_PARSERS.inspect}.") end end @@ -56,6 +60,8 @@ module RSS @@default_parser || AVAILABLE_PARSERS.first end + # Set @@default_parser to new_value if it is one of the + # available parsers. Else raise NotValidXMLParser error. def default_parser=(new_value) if AVAILABLE_PARSERS.include?(new_value) @@default_parser = new_value @@ -83,6 +89,10 @@ module RSS end private + + # Try to get the XML associated with +rss+. + # Return +rss+ if it already looks like XML, or treat it as a URI, + # or a file to get the XML, def normalize_rss(rss) return rss if maybe_xml?(rss) @@ -97,10 +107,13 @@ module RSS end end + # maybe_xml? tests if source is a string that looks like XML. def maybe_xml?(source) source.is_a?(String) and /' for use in HTML. def html_escape(s) s.to_s.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/