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
merging in from -httptests, etag, lastmodified and "proper" status code 
support are now in rfp
Jeff Hodges (author)
Sun Oct 21 04:21:24 -0700 2007
commit  b6c7aff38e3e37bba056c689b979de49e79a12f7
tree    d974abf85e290cb2ee8e894eedfce9ff4c74b817
parent  7cd15ad0d742bfa5994c8858c4d186490e3fc8e5
...
88
89
90
91
 
 
92
93
94
...
148
149
150
 
151
152
153
 
154
155
156
 
157
 
158
 
159
160
 
161
162
163
...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
 
 
 
 
 
 
 
 
181
 
 
182
183
184
185
186
187
188
189
190
191
192
 
 
 
 
 
193
194
195
 
196
197
198
199
200
 
201
202
203
 
204
205
206
...
88
89
90
 
91
92
93
94
95
...
149
150
151
152
153
154
155
156
157
 
 
158
159
160
161
162
163
 
164
165
166
167
...
171
172
173
 
 
 
 
 
 
 
 
 
174
 
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
 
 
 
 
 
192
193
194
195
196
197
198
 
199
200
201
202
203
204
205
206
207
 
208
209
210
211
0
@@ -88,7 +88,8 @@ module FeedParser
0
     "John Beimler <http://john.beimler.org/>",
0
     "Fazal Majid <http://www.majid.info/mylos/weblog/>",
0
     "Aaron Swartz <http://aaronsw.com/>",
0
- "Kevin Marks <http://epeus.blogspot.com/>"
0
+ "Kevin Marks <http://epeus.blogspot.com/>",
0
+ "Jesse Newland <http://jnewland.com/>"
0
   ]
0
   # HTTP "User-Agent" header to send to servers when downloading feeds.
0
   # If you are embedding feedparser in a larger application, you should
0
@@ -148,16 +149,19 @@ module FeedParser
0
     $compatible = options[:compatible].nil? ? $compatible : options[:compatible]# Use the default compatibility if compatible is nil
0
     strictklass = options[:strict] || StrictFeedParser
0
     looseklass = options[:loose] || LooseFeedParser
0
+
0
     result = FeedParserDict.new
0
     result['feed'] = FeedParserDict.new
0
     result['entries'] = []
0
+
0
     if options[:modified]
0
- options[:modified] = Time.parse(options[:modified]).utc.rfc2822
0
- # FIXME this ignores all of our time parsing work. Does it matter?
0
+ options[:modified] = py2rtime(parse_date(options[:modified])).httpdate
0
     end
0
+
0
     result['bozo'] = false
0
+
0
     handlers = options[:handlers]
0
- if handlers.class != Array # FIXME why does this happen?
0
+ if handlers.class != Array
0
       handlers = [handlers]
0
     end
0
 
0
@@ -167,40 +171,41 @@ module FeedParser
0
         $stderr << "Opening local file #{furi}\n" if $debug
0
         f = open(parsed_furi.path) # OpenURI doesn't behave well when passing HTTP options to a file.
0
       else
0
- # And when you do pass them, make sure they aren't just nil (this still true?)
0
- newd = {}
0
- newd["If-None-Match"] = options[:etag] unless options[:etag].nil?
0
- newd["If-Modified-Since"] = options[:modified] unless options[:modified].nil?
0
- newd["User-Agent"] = (options[:agent] || USER_AGENT).to_s
0
- newd["Referer"] = options[:referrer] unless options[:referrer].nil?
0
- newd["Content-Location"] = options[:content_location] unless options[:content_location].nil?
0
- newd["Content-Language"] = options[:content_language] unless options[:content_language].nil?
0
- newd["Content-type"] = options[:content_type] unless options[:content_type].nil?
0
         
0
- f = open(furi, newd)
0
+ hout = {} # Dictionary of headers to send out
0
+ hout["If-None-Match"] = options[:etag] unless options[:etag].nil?
0
+ hout["If-Modified-Since"] = options[:modified] unless options[:modified].nil?
0
+ hout["User-Agent"] = (options[:agent] || USER_AGENT).to_s
0
+ hout["Referer"] = options[:referrer] unless options[:referrer].nil?
0
+ hout["Content-Location"] = options[:content_location] unless options[:content_location].nil?
0
+ hout["Content-Language"] = options[:content_language] unless options[:content_language].nil?
0
+ hout["Content-type"] = options[:content_type] unless options[:content_type].nil?
0
         
0
+ f = open(furi, hout)
0
+ result['status'] = f.status[0]
0
       end
0
 
0
       data = f.read
0
       f.close
0
       
0
     rescue OpenURI::HTTPError => e
0
- unless e.to_s[0..2].to_i == 0
0
- result['status'] = e.to_s[0..2].to_i
0
- data = ''
0
- f = nil
0
- end
0
+ result['status'] = e.io.status[0]
0
+ result['bozo'] = true
0
+ result['bozo_exception'] = e
0
+ data = ''
0
+ f = nil
0
       
0
     rescue => e
0
- $stderr << "Rescued in parse: "+e.to_s+"\n" if $debug # My addition
0
+ $stderr << "Rescued in parse: "+e.to_s+"\n" if $debug
0
       result['bozo'] = true
0
       result['bozo_exception'] = e
0
       data = ''
0
       f = nil
0
     end
0
+
0
     if f.respond_to?(:meta)
0
       result['etag'] = f.meta['etag']
0
- result['modified'] = f.meta['modified']
0
+ result['modified'] = f.meta['last-modified']
0
       result['url'] = f.base_uri.to_s
0
       result['status'] ||= f.status[0].to_i
0
       result['headers'] = f.meta
...
1
 
2
3
4
...
 
1
2
3
4
0
@@ -1,4 +1,4 @@
0
-#!/usr/bin/ruby
0
+#!/usr/bin/env ruby
0
 
0
 module FeedParserUtilities
0
   # Adapted from python2.4's encodings/aliases.py
...
1
 
2
3
4
...
 
1
2
3
4
0
@@ -1,4 +1,4 @@
0
-#!/usr/bin/ruby
0
+#!/usr/bin/env ruby
0
 
0
 # Add some helper methods to make AttributeList (all of those damn attrs
0
 # and attrsD used by StrictFeedParser) act more like a Hash.
...
1
 
2
3
4
...
 
1
2
3
4
0
@@ -1,4 +1,4 @@
0
-#!/usr/bin/ruby
0
+#!/usr/bin/env ruby
0
 
0
 
0
 class BetterSGMLParserError < Exception; end;
...
1
 
2
3
4
...
54
55
56
57
 
58
59
60
...
 
1
2
3
4
...
54
55
56
 
57
58
59
60
0
@@ -1,4 +1,4 @@
0
-#!/usr/bin/ruby
0
+#!/usr/bin/env ruby
0
 
0
 module FeedParserUtilities
0
 
0
@@ -54,7 +54,7 @@ module FeedParserUtilities
0
     begin
0
       if xml_data[0..3] == "\x4c\x6f\xa7\x94"
0
         # EBCDIC
0
- xml_data = _ebcdic_to_ascii(xml_data)
0
+ xml_data = __ebcdic_to_ascii(xml_data)
0
       elsif xml_data[0..3] == "\x00\x3c\x00\x3f"
0
         # UTF-16BE
0
         sniffed_xml_encoding = 'utf-16be'
...
1
 
2
3
4
...
 
1
2
3
4
0
@@ -1,4 +1,4 @@
0
-#!/usr/bin/ruby
0
+#!/usr/bin/env ruby
0
 module FeedParser
0
   class FeedParserDict < Hash
0
 =begin
...
1
 
2
3
4
...
 
1
2
3
4
0
@@ -1,4 +1,4 @@
0
-#!/usr/bin/ruby
0
+#!/usr/bin/env ruby
0
 # From Robert Aman's GentleCMS URI.
0
 # GentleCMS, Copyright (c) 2006 Robert Aman
0
 #
...
1
 
2
3
4
...
 
1
2
3
4
0
@@ -1,4 +1,4 @@
0
-#!/usr/bin/ruby
0
+#!/usr/bin/env ruby
0
 module FeedParserUtilities
0
   def stripDoctype(data)
0
     #Strips DOCTYPE from XML document, returns (rss_version, stripped_data)
...
1
 
2
3
4
...
 
1
2
3
4
0
@@ -1,4 +1,4 @@
0
-#!/usr/bin/ruby
0
+#!/usr/bin/env ruby
0
 module FeedParser
0
 module FeedParserMixin
0
   include FeedParserUtilities
...
1
 
2
3
4
...
 
1
2
3
4
0
@@ -1,4 +1,4 @@
0
-#!/usr/bin/ruby
0
+#!/usr/bin/env ruby
0
 
0
 module FeedParser
0
   class StrictFeedParser < XML::SAX::HandlerBase # expat
...
1
 
2
3
4
...
 
1
2
3
4
0
@@ -1,4 +1,4 @@
0
-#!/usr/bin/ruby
0
+#!/usr/bin/env ruby
0
 # This used to be based on Michael Moen's Hpricot#scrub, but that seems to
0
 # have only been part of its evolution. Hpricot#scrub is cool code, though.
0
 # http://underpantsgnome.com/2007/01/20/hpricot-scrub
...
1
 
2
3
4
...
 
1
2
3
4
0
@@ -1,4 +1,4 @@
0
-#!/usr/bin/ruby
0
+#!/usr/bin/env ruby
0
 require 'time'
0
 
0
 module FeedParser
...
1
2
3
4
5
6
7
8
9
 
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
 
114
115
116
117
 
118
119
...
 
 
 
 
 
 
 
 
 
1
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
4
5
6
7
8
9
10
0
@@ -1,119 +1,10 @@
0
-#!/usr/bin/ruby
0
-# This is the same server code that runs in rfeedparsertest.rb, but split
0
-# off so that we can fully check each test individually (i.e. get the HTTP
0
-# headers right).
0
-# This really needs to be merged into rfeedparsertest.rb
0
-require 'rubygems'
0
-gem 'mongrel'
0
-require 'mongrel'
0
-require File.dirname(__FILE__)+'/../lib/rfeedparser'
0
+#!/usr/bin/env ruby
0
 
0
-$PORT = 8097
0
-
0
-def uconvert(one, two, three); FeedParser::uconvert(one, two, three); end
0
-def _ebcdic_to_ascii(one); FeedParser::_ebcdic_to_ascii(one); end
0
-
0
-def translate_data(data)
0
- if data[0..3] == "\x4c\x6f\xa7\x94"
0
- # EBCDIC
0
- data = _ebcdic_to_ascii(data)
0
- elsif data[0..3] == "\x00\x3c\x00\x3f"
0
- # UTF-16BE
0
- data = uconvert(data, 'utf-16be', 'utf-8')
0
- elsif data.size >= 4 and data[0..1] == "\xfe\xff" and data[2..3] != "\x00\x00"
0
- # UTF-16BE with BOM
0
- data = uconvert(data[2..-1], 'utf-16be', 'utf-8')
0
- elsif data[0..3] == "\x3c\x00\x3f\x00"
0
- # UTF-16LE
0
- data = uconvert(data, 'utf-16le', 'utf-8')
0
- elsif data.size >=4 and data[0..1] == "\xff\xfe" and data[2..3] != "\x00\x00"
0
- # UTF-16LE with BOM
0
- data = uconvert(data[2..-1], 'utf-16le', 'utf-8')
0
- elsif data[0..3] == "\x00\x00\x00\x3c"
0
- # UTF-32BE
0
- data = uconvert(data, 'utf-32be', 'utf-8')
0
- elsif data[0..3] == "\x3c\x00\x00\x00"
0
- # UTF-32LE
0
- data = uconvert(data, 'utf-32le', 'utf-8')
0
- elsif data[0..3] == "\x00\x00\xfe\xff"
0
- # UTF-32BE with BOM
0
- data = uconvert(data[4..-1], 'utf-32BE', 'utf-8')
0
- elsif data[0..3] == "\xef\xfe\x00\x00"
0
- # UTF-32LE with BOM
0
- data = uconvert(data[4..-1], 'utf-32le', 'utf-8')
0
- elsif data[0..2] == "\xef\xbb\xbf"
0
- # UTF-8 with BOM
0
- data = data[3..-1]
0
- end
0
- return data
0
-end
0
-
0
-def scrape_headers(xmlfile)
0
- # Called by the server
0
- xm = open(xmlfile)
0
- data = xm.read
0
- htaccess = File.dirname(xmlfile)+"/.htaccess"
0
- xml_headers = {}
0
- server_headers = {}
0
- the_type = nil
0
- if File.exists? htaccess
0
- fn = xm.path.split(File::Separator)[-1] # I can't find the right method for this
0
- ht_file = open(htaccess)
0
- type_match = ht_file.read.match(/^\s*<Files\s+#{fn}>\s*\n\s*AddType\s+(.*?)\s+.xml/m)
0
- the_type = type_match[1].strip.gsub(/^("|')/,'').gsub(/("|')$/,'').strip if type_match and type_match[1]
0
- if type_match and the_type
0
- #content_type, charset = type_match[1].split(';')
0
- server_headers["Content-Type"] = the_type
0
- end
0
- end
0
- data = translate_data(data)
0
- da = data.scan /^Header:\s*([^:]+):(.+)\s$/
0
- unless da.nil? or da.empty?
0
- da.flatten!
0
- da.each{|e| e.strip!;e.gsub!(/(Content-type|content-type|content-Type)/, "Content-Type")}
0
- xml_headers = Hash[*da] # Asterisk magic!
0
- end
0
- return xml_headers.merge(server_headers)
0
-end
0
-
0
-
0
-class FeedParserTestRequestHandler < Mongrel::DirHandler
0
- def process(request, response)
0
- req_method = request.params[Mongrel::Const::REQUEST_METHOD] || Mongrel::Const::GET
0
- req_path = can_serve request.params[Mongrel::Const::PATH_INFO]
0
- if not req_path
0
- # not found, return a 404
0
- response.start(404) do |head, out|
0
- out << "File not found"
0
- end
0
- else
0
- begin
0
- if File.directory? req_path
0
- send_dir_listing(request.params[Mongrel::Const::REQUEST_URI], req_path, response)
0
- elsif req_method == Mongrel::Const::HEAD
0
- response.start do |head,out|
0
- xml_head = scape_headers(req_path)
0
- xml_head.each_key{|k| head[k] = xml_head[k] }
0
- end
0
- send_file(req_path, request, response, true)
0
- elsif req_method == Mongrel::Const::GET
0
- response.start do |head,out|
0
- xml_head = scrape_headers(req_path)
0
- xml_head.each_key{|k| head[k] = xml_head[k] }
0
- end
0
- send_file(req_path, request, response, false)
0
- else
0
- response.start(403) {|head,out| out.write(ONLY_HEAD_GET) }
0
- end
0
- rescue => details
0
- STDERR.puts "MON Error sending file #{req_path}: #{details}"
0
- end
0
- end
0
- end
0
-end
0
+require File.join(File.dirname(__FILE__), 'rfeedparser_test_helper')
0
 
0
 # Start up the mongrel server and tell it how to send the tests
0
 server = Mongrel::HttpServer.new("0.0.0.0", $PORT)
0
 Mongrel::DirHandler::add_mime_type('.xml','application/xml')
0
+Mongrel::DirHandler::add_mime_type('.xml_redirect','application/xml')
0
 server.register("/", FeedParserTestRequestHandler.new('.'))
0
 server.run.join
...
1
2
3
 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
 
168
169
170
...
194
195
196
 
197
198
...
1
2
 
3
4
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
7
8
9
...
33
34
35
36
37
38
0
@@ -1,170 +1,9 @@
0
 #!/usr/bin/env ruby
0
 # This is based off of Sam Ruby's xml_filetest.rb
0
-# I've adapted it for feedparser.rb
0
+# I've adapted it for rfeedparser
0
 # http://intertwingly.net/blog/2005/10/30/Testing-FeedTools-Dynamically/
0
 
0
-require 'test/unit'
0
-require File.dirname(__FILE__)+'/../lib/rfeedparser'
0
-
0
-begin
0
- require 'rubygems'
0
- gem 'mongrel'
0
- require 'mongrel'
0
-rescue => details
0
- STDERR.puts "Whoops, had an error with loading mongrel as a gem. Trying just 'require'. Mongrel is required for testing."
0
- require 'mongrel'
0
-end
0
-
0
-def uconvert(one, two, three); FeedParser::uconvert(one, two, three); end
0
-def _ebcdic_to_ascii(one); FeedParser::_ebcdic_to_ascii(one); end
0
-
0
-$PORT = 8097 # Not configurable, hard coded in the xml files
0
-
0
-def translate_data(data)
0
- if data[0..3] == "\x4c\x6f\xa7\x94"
0
- # EBCDIC
0
- data = _ebcdic_to_ascii(data)
0
- elsif data[0..3] == "\x00\x3c\x00\x3f"
0
- # UTF-16BE
0
- data = uconvert(data, 'utf-16be', 'utf-8')
0
- elsif data.size >= 4 and data[0..1] == "\xfe\xff" and data[2..3] != "\x00\x00"
0
- # UTF-16BE with BOM
0
- data = uconvert(data[2..-1], 'utf-16be', 'utf-8')
0
- elsif data[0..3] == "\x3c\x00\x3f\x00"
0
- # UTF-16LE
0
- data = uconvert(data, 'utf-16le', 'utf-8')
0
- elsif data.size >=4 and data[0..1] == "\xff\xfe" and data[2..3] != "\x00\x00"
0
- # UTF-16LE with BOM
0
- data = uconvert(data[2..-1], 'utf-16le', 'utf-8')
0
- elsif data[0..3] == "\x00\x00\x00\x3c"
0
- # UTF-32BE
0
- data = uconvert(data, 'utf-32be', 'utf-8')
0
- elsif data[0..3] == "\x3c\x00\x00\x00"
0
- # UTF-32LE
0
- data = uconvert(data, 'utf-32le', 'utf-8')
0
- elsif data[0..3] == "\x00\x00\xfe\xff"
0
- # UTF-32BE with BOM
0
- data = uconvert(data[4..-1], 'utf-32BE', 'utf-8')
0
- elsif data[0..3] == "\xff\xfe\x00\x00"
0
- # UTF-32LE with BOM
0
- data = uconvert(data[4..-1], 'utf-32LE', 'utf-8')
0
- elsif data[0..2] == "\xef\xbb\xbf"
0
- # UTF-8 with BOM
0
- data = data[3..-1]
0
- else
0
- # ASCII-compatible
0
- end
0
- return data
0
-end
0
-
0
-def scrape_headers(xmlfile)
0
- # Called by the server
0
- xm = open(xmlfile)
0
- data = xm.read
0
- htaccess = File.dirname(xmlfile)+"/.htaccess"
0
- xml_headers = {}
0
- server_headers = {}
0
- the_type = nil
0
- if File.exists? htaccess
0
- fn = xm.path.split(File::Separator)[-1] # I can't find the right method for this
0
- ht_file = open(htaccess)
0
- type_match = ht_file.read.match(/^\s*<Files\s+#{fn}>\s*\n\s*AddType\s+(.*?)\s+.xml/m)
0
- the_type = type_match[1].strip.gsub(/^("|')/,'').gsub(/("|')$/,'').strip if type_match and type_match[1]
0
- if type_match and the_type
0
- #content_type, charset = type_match[1].split(';')
0
- server_headers["Content-Type"] = the_type
0
- end
0
- end
0
- data = translate_data(data)
0
- da = data.scan /^Header:\s*([^:]+):(.+)\s$/
0
- unless da.nil? or da.empty?
0
- da.flatten!
0
- da.each{|e| e.strip!;e.gsub!(/(Content-type|content-type|content-Type)/, "Content-Type")}
0
- xml_headers = Hash[*da] # Asterisk magic!
0
- end
0
- return xml_headers.merge(server_headers)
0
-end
0
-
0
-def scrape_assertion_strings(xmlfile)
0
- # Called by the testing client
0
- data = open(xmlfile).read
0
- data = translate_data(data)
0
- test = data.scan /Description:\s*(.*?)\s*Expect:\s*(.*)\s*-->/
0
- description, evalString = test.first.map{ |s| s.strip }
0
-
0
- # Here we translate the expected values in Python to Ruby
0
- evalString.gsub!(/\bu'(.*?)'/) do |m|
0
- esc = $1.to_s.dup
0
- esc.gsub!(/\\u([0-9a-fA-F]{4})/){ |m| [$1.hex].pack('U*') }
0
- " '"+esc+"'"
0
- end
0
- evalString.gsub!(/\bu"(.*?)"/) do |m|
0
- esc = $1.to_s.dup
0
- esc.gsub!(/\\u([0-9a-fA-F]{4})/){ |m| [$1.hex].pack('U*') }
0
- " \""+esc+"\""
0
- end
0
- # The above does the following: u'string' => 'string'
0
- # u'ba\u20acha' => 'ba€ha' # Same for double quoted strings
0
-
0
- evalString.gsub!(/\\x([0-9a-fA-F]{2})/){ |m| [$1.hex].pack('U*') } # "ba\xa3la" => "ba£la"
0
- evalString.gsub! /'\s*:\s+/, "' => " # {'foo': 'bar'} => {'foo' => 'bar'}
0
- evalString.gsub! /"\s*:\s+/, "\" => " # {"foo": 'bar'} => {"foo" => 'bar'}
0
- evalString.gsub! /\=\s*\((.*?)\)/, '= [\1]' # = (2004, 12, 4) => = [2004, 12, 4]
0
- evalString.gsub!(/"""(.*?)"""/) do # """<a b="foo">""" => "<a b="foo">"
0
- "\""+$1.gsub!(/"/,"\\\"")+"\"" # haha, ugly!
0
- end
0
- evalString.gsub! /(\w|\])\s*\=\= 0\s*$/, '\1 == false' # ] == 0 => ] == false
0
- evalString.gsub! /(\w|\])\s*\=\= 1\s*$/, '\1 == true' # ] == 1 => ] == true
0
- evalString.gsub! /len\((.*?)\)\s*\=\=\s*(\d{1,3})/, '\1.length == \2' # len(ary) == 1 => ary.length == 1
0
- evalString.gsub! /None/, "nil" # None => nil # well, duh
0
- return description, evalString
0
-end
0
-
0
-class FeedParserTestRequestHandler < Mongrel::DirHandler
0
- def process(request, response)
0
- req_method = request.params[Mongrel::Const::REQUEST_METHOD] || Mongrel::Const::GET
0
- req_path = can_serve request.params[Mongrel::Const::PATH_INFO]
0
- if not req_path
0
- # not found, return a 404
0
- response.start(404) do |head, out|
0
- out << "File not found"
0
- end
0
- else
0
- begin
0
- if File.directory? req_path
0
- send_dir_listing(request.params[Mongrel::Const::REQUEST_URI], req_path, response)
0
- elsif req_method == Mongrel::Const::HEAD
0
- response.start do |head,out|
0
- xml_head = scrape_headers(req_path)
0
- xml_head.each_key{|k| head[k] = xml_head[k] }
0
- end
0
-
0
- send_file(req_path, request, response, true)
0
- elsif req_method == Mongrel::Const::GET
0
- response.start do |head,out|
0
- xml_head = scrape_headers(req_path)
0
- xml_head.each_key{|k| head[k] = xml_head[k] }
0
- end
0
-
0
- send_file(req_path, request, response, false)
0
- else
0
- response.start(403) {|head,out| out.write(ONLY_HEAD_GET) }
0
- end
0
- rescue => details
0
- STDERR.puts "Error sending file #{req_path}: #{details}"
0
- end
0
- end
0
- end
0
-end
0
-
0
-
0
-class XMLTests < Test::Unit::TestCase
0
- # Empty, but here for clarity
0
- def setup
0
- end
0
- def teardown
0
- end
0
-end
0
+require File.join(File.dirname(__FILE__),'rfeedparser_test_helper')
0
 
0
 # default methods to be public
0
 XMLTests.send(:public)
0
@@ -194,5 +33,6 @@ end
0
 # Start up the mongrel server and tell it how to send the tests
0
 server = Mongrel::HttpServer.new("0.0.0.0",$PORT)
0
 Mongrel::DirHandler::add_mime_type('.xml','application/xml')
0
+Mongrel::DirHandler::add_mime_type('.xml_redirect','application/xml')
0
 server.register("/", FeedParserTestRequestHandler.new("."))
0
 server.run

Comments

    No one has commented yet.