0
-"""Universal feed parser in Ruby
0
+# Universal feed parser in Ruby
0
+# Handles RSS 0.9x, RSS 1.0, RSS 2.0, CDF, Atom 0.3, and Atom 1.0 feeds
0
+# Visit http://feedparser.org/ for the latest version in Python
0
+# Visit http://feedparser.org/docs/ for the latest documentation
0
+# Email Jeff Hodges at jeff@obquo.com for questions
0
-Handles RSS 0.9x, RSS 1.0, RSS 2.0, CDF, Atom 0.3, and Atom 1.0 feeds
0
-Visit http://feedparser.org/ for the latest version in Python
0
-Visit http://feedparser.org/docs/ for the latest documentation
0
-Email Jeff Hodges at jeff@obquo.com for questions
0
require 'cgi' # escaping html
0
+# If available, Nikolai's UTF-8 library will ease use of utf-8 documents.
0
+# See http://git.bitwi.se/ruby-character-encodings.git/.
0
+ gem 'character-encodings', ">=0.2.0"
0
+ require 'encoding/character/utf-8'
0
+# TODO: require these in the files that need them, not in the toplevel
0
-
gem 'character-encodings', ">=0.2.0"0
gem 'htmltools', ">=1.10"
0
+require 'html/sgml-parser'
0
gem 'htmlentities', ">=4.0.0"
0
-gem 'activesupport', ">=1.4.1"
0
-gem 'rchardet', ">=1.0"
0
-require 'xml/saxdriver' # calling expat through the xmlparser gem
0
+gem 'activesupport', ">=1.4.1"
0
+require 'active_support'
0
+gem 'rchardet', ">=1.0"
0
-require 'encoding/character/utf-8'
0
-require 'html/sgml-parser'
0
-require 'active_support'
0
-$LOAD_PATH
<< File.expand_path(File.dirname(__FILE__))
0
+$LOAD_PATH
.unshift File.expand_path(File.dirname(__FILE__))
0
require 'rfeedparser/utilities'
0
require 'rfeedparser/forgiving_uri'
0
require 'rfeedparser/better_sgmlparser'
0
require 'rfeedparser/better_attributelist'
0
require 'rfeedparser/feedparserdict'
0
require 'rfeedparser/parser_mixin'
0
-require 'rfeedparser/parsers'
0
-require 'rfeedparser/monkey_patches'
0
+require 'rfeedparser/loose_feed_parser'
0
+ require 'rfeedparser/libxml_parser'
0
+ StrictFeedParser = FeedParser::LibXml::StrictFeedParser
0
+ require 'rfeedparser/expat_parser'
0
+ StrictFeedParser = FeedParser::Expat::StrictFeedParser
0
+require 'rfeedparser/monkey_patches'
0
extend FeedParserUtilities
0
@@ -213,7 +232,8 @@ module FeedParser
0
# Use the default compatibility if compatible is nil
0
$compatible = options[:compatible].nil? ? $compatible : options[:compatible]
0
+ # TODO: don't even try strict if it's not defined
0
strictklass = options[:strict] || StrictFeedParser
0
looseklass = options[:loose] || LooseFeedParser
0
options[:handlers] = options[:handlers] || []
0
@@ -393,18 +413,10 @@ module FeedParser
0
- # initialize the SAX parser
0
- saxparser = XML::SAX::Helpers::ParserFactory.makeParser("XML::Parser::SAXDriver")
0
- feedparser = strictklass.new(baseuri, baselang, 'utf-8')
0
- saxparser.setDocumentHandler(feedparser)
0
- saxparser.setDTDHandler(feedparser)
0
- saxparser.setEntityResolver(feedparser)
0
- saxparser.setErrorHandler(feedparser)
0
- inputdata = XML::SAX::InputSource.new('parsedfeed')
0
- inputdata.setByteStream(StringIO.new(data))
0
- saxparser.parse(inputdata)
0
+ parser = StrictFeedParser.new(baseuri, baselang)
0
+ feedparser = parser.handler
0
rescue StandardError, XML::SAX::SAXParseException => parseerr # resparse
Comments
No one has commented yet.