[前][次][番号順一覧][スレッド一覧]

ruby-changes:6165

From: kou <ko1@a...>
Date: Sun, 29 Jun 2008 18:13:18 +0900 (JST)
Subject: [ruby-changes:6165] Ruby:r17677 (ruby_1_8): * NEWS: add an entry for rss.

kou	2008-06-29 18:12:56 +0900 (Sun, 29 Jun 2008)

  New Revision: 17677

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/NEWS
    branches/ruby_1_8/lib/rss/atom.rb
    branches/ruby_1_8/lib/rss/maker/base.rb
    branches/ruby_1_8/lib/rss/maker/itunes.rb
    branches/ruby_1_8/lib/rss/parser.rb
    branches/ruby_1_8/lib/rss/rss.rb
    branches/ruby_1_8/test/rss/rss-assertions.rb
    branches/ruby_1_8/test/rss/test_atom.rb
    branches/ruby_1_8/test/rss/test_maker_0.9.rb
    branches/ruby_1_8/test/rss/test_maker_1.0.rb
    branches/ruby_1_8/test/rss/test_maker_2.0.rb
    branches/ruby_1_8/test/rss/test_maker_dc.rb
    branches/ruby_1_8/test/rss/test_maker_itunes.rb
    branches/ruby_1_8/test/rss/test_parser_1.0.rb
    branches/ruby_1_8/test/rss/test_version.rb

  Log:
    * NEWS: add an entry for rss.
    
    * lib/rss/, test/rss/: merge from trunk.
    - 0.2.4 -> 0.2.5.
    - RSS::Maker.make raise an exception not returns nil for invalid
    feed making.
    - RSS::Maker.make requires block.
    - don't use instance_variable to initialize variables. (speed up)


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/rss/test_maker_itunes.rb?r1=17677&r2=17676&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/rss/test_parser_1.0.rb?r1=17677&r2=17676&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/rss/parser.rb?r1=17677&r2=17676&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=17677&r2=17676&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/rss/test_version.rb?r1=17677&r2=17676&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/rss/test_maker_0.9.rb?r1=17677&r2=17676&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/rss/test_maker_2.0.rb?r1=17677&r2=17676&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/rss/rss-assertions.rb?r1=17677&r2=17676&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/rss/test_maker_1.0.rb?r1=17677&r2=17676&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/rss/test_atom.rb?r1=17677&r2=17676&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/rss/rss.rb?r1=17677&r2=17676&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/rss/maker/itunes.rb?r1=17677&r2=17676&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/NEWS?r1=17677&r2=17676&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/rss/maker/base.rb?r1=17677&r2=17676&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/rss/atom.rb?r1=17677&r2=17676&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/rss/test_maker_dc.rb?r1=17677&r2=17676&diff_format=u

Index: ruby_1_8/NEWS
===================================================================
--- ruby_1_8/NEWS	(revision 17676)
+++ ruby_1_8/NEWS	(revision 17677)
@@ -22,6 +22,14 @@
 
     Return an enumerator if no block is given.
 
+* rss
+
+  * 0.2.4 -> 0.2.5
+
+  * RSS::Maker.make
+    * raise an exception not returns nil for invalid feed making.
+    * requires block.
+
 == Changes since the 1.8.6 release
 
 === Configuration changes
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 17676)
+++ ruby_1_8/ChangeLog	(revision 17677)
@@ -1,3 +1,14 @@
+Sun Jun 29 18:09:00 2008  Kouhei Sutou  <kou@c...>
+
+	* NEWS: add an entry for rss.
+
+	* lib/rss/, test/rss/: merge from trunk.
+	- 0.2.4 -> 0.2.5.
+	- RSS::Maker.make raise an exception not returns nil for invalid
+	feed making.
+	- RSS::Maker.make requires block.
+	- don't use instance_variable to initialize variables. (speed up)
+
 Sun Jun 29 10:59:12 2008  Tanaka Akira  <akr@f...>
 
 	* math.c (domain_check): fix preprocess condition.
Index: ruby_1_8/lib/rss/parser.rb
===================================================================
--- ruby_1_8/lib/rss/parser.rb	(revision 17676)
+++ ruby_1_8/lib/rss/parser.rb	(revision 17677)
@@ -34,8 +34,8 @@
   class NotValidXMLParser < Error
     def initialize(parser)
       super("#{parser} is not an available XML parser. " <<
-            "Available XML parser"<<
-            (AVAILABLE_PARSERS.size > 1 ? "s are ": " is ") <<
+            "Available XML parser" <<
+            (AVAILABLE_PARSERS.size > 1 ? "s are " : " is ") <<
             "#{AVAILABLE_PARSERS.inspect}.")
     end
   end
@@ -113,7 +113,7 @@
       source.is_a?(String) and /</ =~ source
     end
 
-    # Attempt to convert rss to a URI, but just return it if 
+    # Attempt to convert rss to a URI, but just return it if
     # there's a ::URI::Error
     def to_uri(rss)
       return rss if rss.is_a?(::URI::Generic)
@@ -220,9 +220,7 @@
         name = (@@class_names[uri] || {})[tag_name]
         return name if name
 
-        tag_name = tag_name.gsub(/[_\-]([a-z]?)/) do
-          $1.upcase
-        end
+        tag_name = tag_name.gsub(/[_\-]([a-z]?)/) {$1.upcase}
         tag_name[0, 1].upcase + tag_name[1..-1]
       end
 
@@ -389,9 +387,7 @@
     def start_else_element(local, prefix, attrs, ns)
       class_name = self.class.class_name(_ns(ns, prefix), local)
       current_class = @last_element.class
-      if class_name and
-          (current_class.const_defined?(class_name) or
-           current_class.constants.include?(class_name))
+      if known_class?(current_class, class_name)
         next_class = current_class.const_get(class_name)
         start_have_something_element(local, prefix, attrs, ns, next_class)
       else
@@ -407,6 +403,20 @@
       end
     end
 
+    if Module.method(:const_defined?).arity == -1
+      def known_class?(target_class, class_name)
+        class_name and
+          (target_class.const_defined?(class_name, false) or
+           target_class.constants.include?(class_name.to_sym))
+      end
+    else
+      def known_class?(target_class, class_name)
+        class_name and
+          (target_class.const_defined?(class_name) or
+           target_class.constants.include?(class_name))
+      end
+    end
+
     NAMESPLIT = /^(?:([\w:][-\w\d.]*):)?([\w:][-\w\d.]*)/
     def split_name(name)
       name =~ NAMESPLIT
@@ -504,7 +514,7 @@
         else
           if klass.have_content?
             if @last_element.need_base64_encode?
-              text = Base64.decode64(text.lstrip)
+              text = text.lstrip.unpack("m").first
             end
             @last_element.content = text
           end
Index: ruby_1_8/lib/rss/maker/itunes.rb
===================================================================
--- ruby_1_8/lib/rss/maker/itunes.rb	(revision 17676)
+++ ruby_1_8/lib/rss/maker/itunes.rb	(revision 17677)
@@ -176,7 +176,7 @@
 
         %w(hour minute second).each do |name|
           attr_reader(name)
-          add_need_initialize_variable(name, '0')
+          add_need_initialize_variable(name, 0)
         end
 
         def content=(content)
Index: ruby_1_8/lib/rss/maker/base.rb
===================================================================
--- ruby_1_8/lib/rss/maker/base.rb	(revision 17676)
+++ ruby_1_8/lib/rss/maker/base.rb	(revision 17677)
@@ -31,7 +31,9 @@
           self::OTHER_ELEMENTS << variable_name
         end
 
-        def add_need_initialize_variable(variable_name, init_value="nil")
+        def add_need_initialize_variable(variable_name, init_value=nil,
+                                         &init_block)
+          init_value ||= init_block
           self::NEED_INITIALIZE_VARIABLES << [variable_name, init_value]
         end
 
@@ -45,7 +47,7 @@
           def_delegators("@#{plural}", :push, :pop, :shift, :unshift)
           def_delegators("@#{plural}", :each, :size, :empty?, :clear)
 
-          add_need_initialize_variable(plural, "[]")
+          add_need_initialize_variable(plural) {[]}
 
           module_eval(<<-EOC, __FILE__, __LINE__ + 1)
             def new_#{name}
@@ -74,7 +76,9 @@
         def def_classed_element_without_accessor(name, class_name=nil)
           class_name ||= Utils.to_class_name(name)
           add_other_element(name)
-          add_need_initialize_variable(name, "make_#{name}")
+          add_need_initialize_variable(name) do |object|
+            object.send("make_#{name}")
+          end
           module_eval(<<-EOC, __FILE__, __LINE__ + 1)
             private
             def setup_#{name}(feed, current)
@@ -185,7 +189,19 @@
       private
       def initialize_variables
         self.class.need_initialize_variables.each do |variable_name, init_value|
-          instance_eval("@#{variable_name} = #{init_value}", __FILE__, __LINE__)
+          if init_value.nil?
+            value = nil
+          else
+            if init_value.respond_to?(:call)
+              value = init_value.call(self)
+            elsif init_value.is_a?(String)
+              # just for backward compatibility
+              value = instance_eval(init_value, __FILE__, __LINE__)
+            else
+              value = init_value
+            end
+          end
+          instance_variable_set("@#{variable_name}", value)
         end
       end
 
@@ -238,7 +254,8 @@
 
       def variables
         self.class.need_initialize_variables.find_all do |name, init|
-          "nil" == init
+          # init == "nil" is just for backward compatibility
+          init.nil? or init == "nil"
         end.collect do |name, init|
           name
         end
@@ -364,7 +381,9 @@
 
       %w(xml_stylesheets channel image items textinput).each do |element|
         attr_reader element
-        add_need_initialize_variable(element, "make_#{element}")
+        add_need_initialize_variable(element) do |object|
+          object.send("make_#{element}")
+        end
         module_eval(<<-EOC, __FILE__, __LINE__)
           private
           def setup_#{element}(feed)
@@ -392,12 +411,8 @@
       end
       
       def make
-        if block_given?
-          yield(self)
-          to_feed
-        else
-          nil
-        end
+        yield(self)
+        to_feed
       end
 
       def to_feed
@@ -405,11 +420,8 @@
         setup_xml_stylesheets(feed)
         setup_elements(feed)
         setup_other_elements(feed)
-        if feed.valid?
-          feed
-        else
-          nil
-        end
+        feed.validate
+        feed
       end
       
       private
Index: ruby_1_8/lib/rss/atom.rb
===================================================================
--- ruby_1_8/lib/rss/atom.rb	(revision 17676)
+++ ruby_1_8/lib/rss/atom.rb	(revision 17677)
@@ -1,4 +1,3 @@
-require 'base64'
 require 'rss/parser'
 
 module RSS
Index: ruby_1_8/lib/rss/rss.rb
===================================================================
--- ruby_1_8/lib/rss/rss.rb	(revision 17676)
+++ ruby_1_8/lib/rss/rss.rb	(revision 17677)
@@ -45,6 +45,7 @@
   end
 end
 
+
 require "English"
 require "rss/utils"
 require "rss/converter"
@@ -52,7 +53,7 @@
 
 module RSS
 
-  VERSION = "0.2.4"
+  VERSION = "0.2.5"
 
   URI = "http://purl.org/rss/1.0/"
 
@@ -1200,7 +1201,7 @@
         __send__(self.class.xml_getter).to_s
       else
         _content = content
-        _content = Base64.encode64(_content) if need_base64_encode?
+        _content = [_content].pack("m").delete("\n") if need_base64_encode?
         h(_content)
       end
     end
Index: ruby_1_8/test/rss/test_maker_2.0.rb
===================================================================
--- ruby_1_8/test/rss/test_maker_2.0.rb	(revision 17676)
+++ ruby_1_8/test/rss/test_maker_2.0.rb	(revision 17677)
@@ -6,8 +6,9 @@
   class TestMaker20 < TestCase
 
     def test_rss
-      rss = RSS::Maker.make("2.0")
-      assert_nil(rss)
+      assert_raise(LocalJumpError) do
+        RSS::Maker.make("2.0")
+      end
       
       rss = RSS::Maker.make("2.0") do |maker|
         setup_dummy_channel(maker)
Index: ruby_1_8/test/rss/rss-assertions.rb
===================================================================
--- ruby_1_8/test/rss/rss-assertions.rb	(revision 17676)
+++ ruby_1_8/test/rss/rss-assertions.rb	(revision 17677)
@@ -570,7 +570,7 @@
           text << char
           char.succ!
         end
-        base64_content = Base64.encode64(Zlib::Deflate.deflate(text))
+        base64_content = [Zlib::Deflate.deflate(text)].pack("m").delete("\n")
 
         [false, true].each do |with_space|
           xml_content = base64_content
@@ -1272,22 +1272,32 @@
                                     invalid_feed_checker=nil)
       _wrap_assertion do
         elements = []
-        invalid_feed = false
-        feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
-          yield maker
-          targets = chain_reader(maker, maker_readers)
-          targets.each do |target|
-            element = maker_extractor.call(target)
-            elements << element if element
+        invalid_feed_exception = nil
+        feed = nil
+        begin
+          feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
+            yield maker
+            targets = chain_reader(maker, maker_readers)
+            targets.each do |target|
+              element = maker_extractor.call(target)
+              elements << element if element
+            end
+            if invalid_feed_checker
+              invalid_feed_exception = invalid_feed_checker.call(targets)
+            end
           end
-          if invalid_feed_checker
-            invalid_feed = invalid_feed_checker.call(targets)
+        rescue RSS::Error
+          if invalid_feed_exception.is_a?(RSS::TooMuchTagError)
+            assert_too_much_tag(invalid_feed_exception.tag,
+                                invalid_feed_exception.parent) do
+              raise
+            end
+          else
+            raise
           end
         end
 
-        if invalid_feed
-          assert_nil(feed)
-        else
+        if invalid_feed_exception.nil?
           actual_elements = chain_reader(feed, feed_readers) || []
           actual_elements = actual_elements.collect do |target|
             feed_extractor.call(target)
@@ -1542,18 +1552,24 @@
           :length => target.length,
         }
       end
+
+      if feed_readers.first == "entries"
+        parent = "entry"
+      else
+        parent = feed_type
+      end
       invalid_feed_checker = Proc.new do |targets|
         infos = {}
-        invalid = false
+        invalid_exception = nil
         targets.each do |target|
           key = [target.hreflang, target.type]
           if infos.has_key?(key)
-            invalid = true
+            invalid_exception = RSS::TooMuchTagError.new("link", parent)
             break
           end
           infos[key] = true if target.rel.nil? or target.rel == "alternate"
         end
-        invalid
+        invalid_exception
       end
       invalid_feed_checker = nil if allow_duplication
       _assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
Index: ruby_1_8/test/rss/test_maker_dc.rb
===================================================================
--- ruby_1_8/test/rss/test_maker_dc.rb	(revision 17676)
+++ ruby_1_8/test/rss/test_maker_dc.rb	(revision 17677)
@@ -86,9 +86,8 @@
         elems.each do |name, values, plural|
           dc_elems = item.__send__("dc_#{plural}")
           values.each do |value|
-            dc_elems.__send__("new_#{name}") do |elem|
-              elem.value = value
-            end
+            elem = dc_elems.__send__("new_#{name}")
+            elem.value = value
           end
         end
 
Index: ruby_1_8/test/rss/test_maker_1.0.rb
===================================================================
--- ruby_1_8/test/rss/test_maker_1.0.rb	(revision 17676)
+++ ruby_1_8/test/rss/test_maker_1.0.rb	(revision 17677)
@@ -6,6 +6,10 @@
   class TestMaker10 < TestCase
 
     def test_rdf
+      assert_raise(LocalJumpError) do
+        RSS::Maker.make("1.0")
+      end
+
       rss = RSS::Maker.make("1.0") do |maker|
         setup_dummy_channel(maker)
         setup_dummy_item(maker)
@@ -48,9 +52,6 @@
       link = "http://hoge.com"
       description = "fugafugafugafuga"
 
-      rss = RSS::Maker.make("1.0")
-      assert_nil(rss)
-      
       rss = RSS::Maker.make("1.0") do |maker|
         maker.channel.about = about
         maker.channel.title = title
Index: ruby_1_8/test/rss/test_maker_0.9.rb
===================================================================
--- ruby_1_8/test/rss/test_maker_0.9.rb	(revision 17676)
+++ ruby_1_8/test/rss/test_maker_0.9.rb	(revision 17677)
@@ -6,8 +6,9 @@
   class TestMaker09 < TestCase
 
     def test_rss
-      rss = RSS::Maker.make("0.91")
-      assert_nil(rss)
+      assert_raise(LocalJumpError) do
+        RSS::Maker.make("0.91")
+      end
       
       rss = RSS::Maker.make("0.9") do |maker|
         setup_dummy_channel(maker)
Index: ruby_1_8/test/rss/test_version.rb
===================================================================
--- ruby_1_8/test/rss/test_version.rb	(revision 17676)
+++ ruby_1_8/test/rss/test_version.rb	(revision 17677)
@@ -3,7 +3,7 @@
 module RSS
   class TestVersion < TestCase
     def test_version
-      assert_equal("0.2.4", ::RSS::VERSION)
+      assert_equal("0.2.5", ::RSS::VERSION)
     end
   end
 end
Index: ruby_1_8/test/rss/test_maker_itunes.rb
===================================================================
--- ruby_1_8/test/rss/test_maker_itunes.rb	(revision 17676)
+++ ruby_1_8/test/rss/test_maker_itunes.rb	(revision 17677)
@@ -462,7 +462,7 @@
                                      "all of your answers here.",
                                      maker_readers, feed_readers)
         _assert_maker_itunes_summary("This week we talk about surviving in a " +
-                                     "Red state if youe a Blue person. Or " +
+                                     "Red state if you're a Blue person. Or " +
                                      "vice versa.",
                                      maker_readers, feed_readers)
       end
Index: ruby_1_8/test/rss/test_atom.rb
===================================================================
--- ruby_1_8/test/rss/test_atom.rb	(revision 17676)
+++ ruby_1_8/test/rss/test_atom.rb	(revision 17677)
@@ -658,7 +658,7 @@
         content.content = original_content
         xml = REXML::Document.new(content.to_s).root
         assert_rexml_element([], {"type" => type},
-                             Base64.encode64(original_content), xml)
+                             [original_content].pack("m").delete("\n"), xml)
       end
     end
 
Index: ruby_1_8/test/rss/test_parser_1.0.rb
===================================================================
--- ruby_1_8/test/rss/test_parser_1.0.rb	(revision 17676)
+++ ruby_1_8/test/rss/test_parser_1.0.rb	(revision 17677)
@@ -509,3 +509,4 @@
     end
   end
 end
+

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]