public
Rubygem
Fork of jmhodges/rfeedparser
Description: rFeedParser is a translation of the Universal Feed Parser from Python into Ruby. It has nearly the exact same behavior.
Homepage: http://rfeedparser.rubyforge.org
Clone URL: git://github.com/technomancy/rfeedparser.git
Being smart about how to load libxml vs expat, falling back on loose 
parser if neither loads.
technomancy (author)
Tue May 06 15:27:37 -0700 2008
commit  e112b6e782527a47edfb1348466cd6fc71cd9430
tree    740cd81b04f4fdee7370a9bf66f7be2296619a34
parent  16bf0cf0be319a248fc409bda93013b59dbe064f
...
64
65
66
 
 
 
 
 
 
 
67
68
69
70
71
72
73
74
75
76
...
233
234
235
236
237
 
238
239
240
...
412
413
414
 
 
415
416
417
418
419
420
421
422
423
424
425
426
 
 
427
428
429
...
64
65
66
67
68
69
70
71
72
73
74
75
 
 
 
 
 
76
77
78
...
235
236
237
 
 
238
239
240
241
...
413
414
415
416
417
418
419
420
421
422
 
 
 
 
 
 
 
423
424
425
426
427
0
@@ -64,13 +64,15 @@ begin
0
   require 'rfeedparser/libxml_parser'
0
   StrictFeedParser = FeedParser::LibXml::StrictFeedParser
0
 rescue LoadError
0
+ puts "Could not load libxml; trying expat"
0
+ begin
0
+ require 'rfeedparser/expat_parser'
0
+ StrictFeedParser = FeedParser::Expat::StrictFeedParser
0
+ rescue LoadError
0
+ puts "Could not load expat either; will use loose parser."
0
+ end
0
 end
0
 
0
-begin
0
- require 'rfeedparser/expat_parser'
0
- StrictFeedParser = FeedParser::Expat::StrictFeedParser unless defined? StrictFeedParser
0
-rescue LoadError
0
-end
0
 
0
 require 'rfeedparser/monkey_patches'
0
 
0
@@ -233,8 +235,7 @@ module FeedParser
0
     # Use the default compatibility if compatible is nil
0
     $compatible = options[:compatible].nil? ? $compatible : options[:compatible]
0
 
0
- # TODO: don't even try strict if it's not defined
0
- strictklass = options[:strict] || StrictFeedParser
0
+ strictklass = options[:strict] || StrictFeedParser rescue nil
0
     looseklass = options[:loose] || LooseFeedParser
0
     options[:handlers] = options[:handlers] || []
0
     
0
@@ -412,18 +413,15 @@ module FeedParser
0
       result['encoding'] = proposed_encoding
0
     end
0
 
0
+ use_strict_parser = false if !defined? StrictFeedParser
0
+
0
     if use_strict_parser
0
       begin
0
         parser = StrictFeedParser.new(baseuri, baselang)
0
         feedparser = parser.handler
0
         parser.parse(data)
0
-
0
- rescue StandardError, XML::SAX::SAXParseException => parseerr # resparse
0
-
0
- if $debug
0
- $stderr << "xml parsing failed\n"
0
- $stderr << parseerr.to_s+"\n" # Hrmph.
0
- end
0
+ rescue => err
0
+ $stderr << "xml parsing failed: #{err.message}\n#{err.backtrace.join("\n")}" if $debug
0
         result['bozo'] = true
0
         result['bozo_exception'] = feedparser.exc || e
0
         use_strict_parser = false
...
27
28
29
30
 
 
 
 
 
 
 
31
32
33
...
27
28
29
 
30
31
32
33
34
35
36
37
38
39
0
@@ -27,7 +27,13 @@ module FeedParser
0
 
0
        inputdata = XML::SAX::InputSource.new('parsedfeed')
0
        inputdata.setByteStream(StringIO.new(data))
0
- saxparser.parse(inputdata)
0
+ begin
0
+ saxparser.parse(inputdata)
0
+ rescue err => XML::SAX::SAXParseException
0
+ # This does not inherit from StandardError as it should, so
0
+ # we have to catch and re-raise specially.
0
+ raise err.to_s
0
+ end
0
      end
0
    end
0
 

Comments

    No one has commented yet.