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
switch to using the Addressable gem instead of ForgivingURI. Still failing 
a lot of tests
technomancy (author)
Tue May 06 15:01:55 -0700 2008
commit  dd1dc51f69649c2a14910cfb18dd1fde4962a545
tree    52ff7f42685bbb53bdf31bc98c6f9a42028ca8af
parent  e112b6e782527a47edfb1348466cd6fc71cd9430
...
1
2
3
4
 
 
 
 
 
5
6
7
...
1
2
3
 
4
5
6
7
8
9
10
11
0
@@ -1,7 +1,11 @@
0
 require 'rubygems'
0
 require 'rake/testtask'
0
 require 'rake/gempackagetask'
0
-require 'lib/rfeedparser'
0
+begin
0
+ require 'lib/rfeedparser'
0
+rescue LoadError
0
+ puts "Problem loading rfeedparser; try rake setup"
0
+end
0
 
0
 spec = Gem::Specification.new do |s|
0
   s.name = "rfeedparser"
...
43
44
45
 
 
 
46
47
48
...
52
53
54
55
56
57
58
...
119
120
121
122
 
123
124
125
...
180
181
182
183
184
 
 
185
186
187
188
189
190
 
 
 
 
191
192
193
...
43
44
45
46
47
48
49
50
51
...
55
56
57
 
58
59
60
...
121
122
123
 
124
125
126
127
...
182
183
184
 
 
185
186
187
188
 
 
 
 
189
190
191
192
193
194
195
0
@@ -43,6 +43,9 @@ require 'htmlentities'
0
 gem 'activesupport', ">=1.4.1"
0
 require 'active_support'
0
 
0
+gem 'addressable', ">= 1.0.4"
0
+require 'addressable/uri'
0
+
0
 gem 'rchardet', ">=1.0"
0
 require 'rchardet'
0
 $chardet = true
0
@@ -52,7 +55,6 @@ $compatible = true
0
 
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
@@ -119,7 +121,7 @@ module FeedParser
0
   USER_AGENT = "rFeedParser/#{VERSION} +http://rfeedparser.rubyforge.org/"
0
 
0
   # HTTP "Accept" header to send to servers when downloading feeds. If you don't
0
- # want to send an Accept header, set this to None.
0
+ # want to send an Accept header, set this to nil.
0
   ACCEPT_HEADER = "application/atom+xml,application/rdf+xml,application/rss+xml,application/x-netcdf,application/xml;q=0.9,text/xml;q=0.2,*/*;q=0.1"
0
 
0
 
0
@@ -180,14 +182,14 @@ module FeedParser
0
     url_file_stream_or_string.strip!
0
     
0
     
0
- furi = ForgivingURI.parse(url_file_stream_or_string)
0
- if furi && ['http','https','ftp'].include?(furi.scheme)
0
+ uri = Addressable::URI.parse(url_file_stream_or_string)
0
+ if uri && ['http','https','ftp'].include?(uri.scheme)
0
       auth = nil
0
 
0
- if furi.host && furi.password
0
- auth = Base64::encode64("#{furi.user}:#{furi.password}").strip
0
- furi.password = nil
0
- url_file_stream_or_string = furi.to_s
0
+ if uri.host && uri.password
0
+ auth = Base64::encode64("#{uri.user}:#{uri.password}").strip
0
+ uri.password = nil
0
+ url_file_stream_or_string = uri.to_s
0
       end
0
 
0
       req_headers = {}
...
58
59
60
61
 
62
63
64
...
58
59
60
 
61
62
63
64
0
@@ -58,7 +58,7 @@ module FeedParserUtilities
0
       ename, eattr = l
0
       h.search(ename).each do |elem|
0
         euri = elem.attributes[eattr]
0
- uri = ForgivingURI.parse(URI.encode(euri)) rescue nil
0
+ uri = Addressable::URI.parse(Addressable::URI.encode(euri)) rescue nil
0
         if euri and not euri.empty? and uri and uri.relative?
0
           elem.raw_attributes[eattr] = urljoin(baseURI, euri)
0
         end
...
1240
1241
1242
1243
1244
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1240
1241
1242
 
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
0
@@ -1240,4 +1240,18 @@ module FeedParserMixin
0
   end
0
   
0
 end # End FeedParserMixin
0
-end
0
\ No newline at end of file
0
+end
0
+
0
+def urljoin(base, uri)
0
+ urifixer = /^([A-Za-z][A-Za-z0-9+-.]*:\/\/)(\/*)(.*?)/u
0
+ uri = uri.sub(urifixer, '\1\3')
0
+ pbase = ForgivingURI.parse(base) rescue nil
0
+ if pbase && pbase.absolute?
0
+ puri = ForgivingURI.parse(uri) rescue nil
0
+ if puri && puri.relative?
0
+ # ForgivingURI.join does the wrong thing. What the hell.
0
+ return ForgivingURI.join(base, uri).to_s.gsub(/[^:]\/{2,}/, '')
0
+ end
0
+ end
0
+ return uri
0
+end

Comments

    No one has commented yet.