From 70bbad3cfd5a692c8e78ccf750eed3f1c7f186db Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 4 Mar 2005 06:47:45 +0000 Subject: * array.c: replace rb_protect_inspect() and rb_inspecting_p() by rb_exec_recursive() in eval.c. * eval.c (rb_exec_recursive): new function. * array.c (rb_ary_join): use rb_exec_recursive(). * array.c (rb_ary_inspect, rb_ary_hash): ditto. * file.c (rb_file_join): ditto. * hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto. * io.c (rb_io_puts): ditto. * object.c (rb_obj_inspect): ditto * struct.c (rb_struct_inspect): ditto. * lib/set.rb (SortedSet::setup): a hack to shut up warning. [ruby-talk:132866] * lib/time.rb (Time::strptime): add new function. inspired by [ruby-talk:132815]. * lib/parsedate.rb (ParseDate::strptime): ditto. * regparse.c: move st_*_strend() functions from st.c. fixed some potential memory leaks. * exception error messages updated. [ruby-core:04497] * ext/socket/socket.c (Init_socket): add bunch of Socket constants. Patch from Sam Roberts . [ruby-core:04409] * array.c (rb_ary_s_create): no need for negative argc check. [ruby-core:04463] * array.c (rb_ary_unshift_m): ditto. * lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass of StandardError class, not Exception class. [ruby-core:04429] * parse.y (fcall_gen): lvar(arg) will be evaluated as lvar.call(arg) when lvar is a defined local variable. [new] * object.c (rb_class_initialize): call inherited method before calling initializing block. * eval.c (rb_thread_start_1): initialize newly pushed frame. * lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE. fixed: [ruby-core:04444] * eval.c (is_defined): NODE_IASGN is an assignment. * ext/readline/readline.c (Readline.readline): use rl_outstream and rl_instream. [ruby-dev:25699] * ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check [ruby-dev:25675] * misc/ruby-mode.el: [ruby-core:04415] * lib/rdoc/generators/html_generator.rb: [ruby-core:04412] * lib/rdoc/generators/ri_generator.rb: ditto. * struct.c (make_struct): fixed: [ruby-core:04402] * ext/curses/curses.c (window_color_set): [ruby-core:04393] * ext/socket/socket.c (Init_socket): SO_REUSEPORT added. [ruby-talk:130092] * object.c: [ruby-doc:818] * parse.y (open_args): fix too verbose warnings for the space before argument parentheses. [ruby-dev:25492] * parse.y (parser_yylex): ditto. * parse.y (parser_yylex): the first expression in the parentheses should not be a command. [ruby-dev:25492] * lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330] * object.c (Init_Object): remove Object#type. [ruby-core:04335] * st.c (st_foreach): report success/failure by return value. [ruby-Bugs-1396] * parse.y: forgot to initialize parser struct. [ruby-dev:25492] * parse.y (parser_yylex): no tLABEL on EXPR_BEG. [ruby-talk:127711] * document updates - [ruby-core:04296], [ruby-core:04301], [ruby-core:04302], [ruby-core:04307] * dir.c (rb_push_glob): should work for NUL delimited patterns. * dir.c (rb_glob2): should aware of offset in the pattern. * string.c (rb_str_new4): should propagate taintedness. * env.h: rename member names in struct FRAME; last_func -> callee, orig_func -> this_func, last_class -> this_class. * struct.c (rb_struct_set): use original method name, not callee name, to retrieve member slot. [ruby-core:04268] * time.c (time_strftime): protect from format modification from GC finalizers. * object.c (Init_Object): remove rb_obj_id_obsolete() * eval.c (rb_mod_define_method): incomplete subclass check. [ruby-dev:25464] * gc.c (rb_data_object_alloc): klass may be NULL. [ruby-list:40498] * bignum.c (rb_big_rand): should return positive random number. [ruby-dev:25401] * bignum.c (rb_big_rand): do not use rb_big_modulo to generate random bignums. [ruby-dev:25396] * variable.c (rb_autoload): [ruby-dev:25373] * eval.c (svalue_to_avalue): [ruby-dev:25366] * string.c (rb_str_justify): [ruby-dev:25367] * io.c (rb_f_select): [ruby-dev:25312] * ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072] * struct.c (make_struct): [ruby-dev:25249] * dir.c (dir_open_dir): new function. [ruby-dev:25242] * io.c (rb_f_open): add type check for return value from to_open. * lib/pstore.rb (PStore#transaction): Use the empty content when a file is not found. [ruby-dev:24561] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/date.rb | 2 +- lib/fileutils.rb | 2 +- lib/irb/context.rb | 2 +- lib/open3.rb | 2 +- lib/parsedate.rb | 7 +- lib/pstore.rb | 12 ++- lib/rdoc/generators/html_generator.rb | 6 +- lib/rdoc/generators/ri_generator.rb | 2 +- lib/rdoc/parsers/parse_c.rb | 156 ++++++++++++++++++++++++++++++---- lib/rdoc/parsers/parse_rb.rb | 22 ++++- lib/rdoc/parsers/parse_simple.rb | 6 +- lib/rexml/document.rb | 8 +- lib/rexml/element.rb | 2 +- lib/rexml/instruction.rb | 4 +- lib/rexml/xmldecl.rb | 108 +++++++++++------------ lib/set.rb | 5 ++ lib/time.rb | 72 ++++++++++------ lib/timeout.rb | 52 +++++++----- lib/wsdl/soap/definitions.rb | 4 +- lib/xmlrpc/parser.rb | 2 +- 20 files changed, 330 insertions(+), 146 deletions(-) (limited to 'lib') diff --git a/lib/date.rb b/lib/date.rb index 9771825411..1cd4e08049 100644 --- a/lib/date.rb +++ b/lib/date.rb @@ -1300,7 +1300,7 @@ class DateTime < Date def to_date() Date.new0(self.class.jd_to_ajd(jd, 0, 0), 0, @sg) end def to_datetime() self end - class << self; undef_method :today end + class << self; undef_method :today end rescue nil # Create a new DateTime object representing the current time. # diff --git a/lib/fileutils.rb b/lib/fileutils.rb index adba38ed63..b4ed5f5153 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -370,7 +370,7 @@ module FileUtils # # # Examples of copying several files to target directory. # FileUtils.cp_r %w(mail.rb field.rb debug/), site_ruby + '/tmail' - # FileUtils.cp_r Dir.glob('*.rb'), '/home/aamine/lib/ruby', :noop, :verbose + # FileUtils.cp_r Dir.glob('*.rb'), '/home/aamine/lib/ruby', :noop => true, :verbose => true # # # If you want to copy all contents of a directory instead of the # # directory itself, c.f. src/x -> dest/x, src/y -> dest/y, diff --git a/lib/irb/context.rb b/lib/irb/context.rb index 9421608f85..01856cd2e7 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -38,7 +38,7 @@ module IRB @inspect_mode = IRB.conf[:INSPECT_MODE] self.math_mode = IRB.conf[:MATH_MODE] if IRB.conf[:MATH_MODE] - self.use_tracer = IRB.conf[:USE_TRACER] if IRB.conf[:USE_TRASER] + self.use_tracer = IRB.conf[:USE_TRACER] if IRB.conf[:USE_TRACER] self.use_loader = IRB.conf[:USE_LOADER] if IRB.conf[:USE_LOADER] self.eval_history = IRB.conf[:EVAL_HISTORY] if IRB.conf[:EVAL_HISTORY] diff --git a/lib/open3.rb b/lib/open3.rb index 1ddd213f61..69a29aace1 100644 --- a/lib/open3.rb +++ b/lib/open3.rb @@ -42,7 +42,7 @@ module Open3 exec(*cmd) } - exit! + exit!(0) } pw[0].close diff --git a/lib/parsedate.rb b/lib/parsedate.rb index 405ab46907..2c24ec1636 100644 --- a/lib/parsedate.rb +++ b/lib/parsedate.rb @@ -10,6 +10,11 @@ module ParseDate values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :wday) end - module_function :parsedate + def strptime(str, format) + Date._strptime(str, format). + values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :wday) + end + + module_function :parsedate, :strptime end diff --git a/lib/pstore.rb b/lib/pstore.rb index 50313dcb8f..51cef6e134 100644 --- a/lib/pstore.rb +++ b/lib/pstore.rb @@ -104,10 +104,14 @@ class PStore commit_new(file) if FileTest.exist?(new_file) content = file.read() else - file = File.open(@filename, File::RDONLY) - file.binmode - file.flock(File::LOCK_SH) - content = (File.read(new_file) rescue file.read()) + begin + file = File.open(@filename, File::RDONLY) + file.binmode + file.flock(File::LOCK_SH) + content = (File.read(new_file) rescue file.read()) + rescue Errno::ENOENT + content = "" + end end if content != "" diff --git a/lib/rdoc/generators/html_generator.rb b/lib/rdoc/generators/html_generator.rb index f9c72a4df2..d263a14784 100644 --- a/lib/rdoc/generators/html_generator.rb +++ b/lib/rdoc/generators/html_generator.rb @@ -314,7 +314,7 @@ module Generators def collect_methods list = @context.method_list unless @options.show_all - list = list.find_all {|m| m.visibility == :public || m.force_documentation } + list = list.find_all {|m| m.visibility == :public || m.visibility == :protected || m.force_documentation } end @methods = list.collect {|m| HtmlMethod.new(m, self, @options) } end @@ -681,13 +681,13 @@ module Generators res = [] atts.each do |att| next unless att.section == section - if att.visibility == :public || @options.show_all + if att.visibility == :public || att.visibility == :protected || @options.show_all entry = { "name" => CGI.escapeHTML(att.name), "rw" => att.rw, "a_desc" => markup(att.comment, true) } - unless att.visibility == :public + unless att.visibility == :public || att.visibility == :protected entry["rw"] << "-" end res << entry diff --git a/lib/rdoc/generators/ri_generator.rb b/lib/rdoc/generators/ri_generator.rb index 8d94579347..c4b4a7e17c 100644 --- a/lib/rdoc/generators/ri_generator.rb +++ b/lib/rdoc/generators/ri_generator.rb @@ -172,7 +172,7 @@ module Generators list = cls.method_list unless @options.show_all list = list.find_all do |m| - m.visibility == :public || m.force_documentation + m.visibility == :public || m.visibility == :protected || m.force_documentation end end diff --git a/lib/rdoc/parsers/parse_c.rb b/lib/rdoc/parsers/parse_c.rb index 6c9134fc62..25ce83dd8e 100644 --- a/lib/rdoc/parsers/parse_c.rb +++ b/lib/rdoc/parsers/parse_c.rb @@ -174,7 +174,7 @@ module RDoc # prepare to parse a C file def initialize(top_level, file_name, body, options, stats) @known_classes = KNOWN_CLASSES.dup - @body = handle_ifdefs_in(body) + @body = handle_tab_width(handle_ifdefs_in(body)) @options = options @stats = stats @top_level = top_level @@ -187,6 +187,7 @@ module RDoc def scan remove_commented_out_lines do_classes + do_constants do_methods do_includes do_aliases @@ -240,7 +241,7 @@ module RDoc if @body =~ %r{((?>/\*.*?\*/\s+)) (static\s+)?void\s+Init_#{class_name}\s*\(\)}xmi comment = $1 - elsif @body =~ %r{Document-(class|module):\s#{class_name}.*?\n((?>.*?\*/))}m + elsif @body =~ %r{Document-(class|module):\s#{class_name}\s*?\n((?>.*?\*/))}m comment = $2 end class_meth.comment = mangle_comment(comment) if comment @@ -249,13 +250,13 @@ module RDoc ############################################################ def do_classes - @body.scan(/(\w+)\s* = \s*rb_define_module\(\s*"(\w+)"\s*\)/mx) do + @body.scan(/(\w+)\s* = \s*rb_define_module\s*\(\s*"(\w+)"\s*\)/mx) do |var_name, class_name| handle_class_module(var_name, "module", class_name, nil, nil) end # The '.' lets us handle SWIG-generated files - @body.scan(/([\w\.]+)\s* = \s*rb_define_class + @body.scan(/([\w\.]+)\s* = \s*rb_define_class\s* \( \s*"(\w+)", \s*(\w+)\s* @@ -265,7 +266,7 @@ module RDoc handle_class_module(var_name, "class", class_name, parent, nil) end - @body.scan(/(\w+)\s*=\s*boot_defclass\(\s*"(\w+?)",\s*(\w+?)\)/) do + @body.scan(/(\w+)\s*=\s*boot_defclass\s*\(\s*"(\w+?)",\s*(\w+?)\s*\)/) do |var_name, class_name, parent| parent = nil if parent == "0" handle_class_module(var_name, "class", class_name, parent, nil) @@ -281,17 +282,39 @@ module RDoc handle_class_module(var_name, "module", class_name, nil, in_module) end - @body.scan(/([\w\.]+)\s* = \s*rb_define_class_under + @body.scan(/([\w\.]+)\s* = \s*rb_define_class_under\s* \( \s*(\w+), \s*"(\w+)", \s*(\w+)\s* - \)/mx) do + \s*\)/mx) do |var_name, in_module, class_name, parent| handle_class_module(var_name, "class", class_name, parent, in_module) end + end + + ########################################################### + + def do_constants + @body.scan(%r{\Wrb_define_ + ( + variable | + readonly_variable | + const | + global_const | + ) + \s*\( + (?:\s*(\w+),)? + \s*"(\w+)", + \s*(.*?)\s*\)\s*; + }xm) do + + |type, var_name, const_name, definition| + var_name = "rb_cObject" if !var_name or var_name == "rb_mKernel" + handle_constants(type, var_name, const_name, definition) + end end ############################################################ @@ -305,7 +328,7 @@ module RDoc module_function | private_method ) - \(\s*([\w\.]+), + \s*\(\s*([\w\.]+), \s*"([^"]+)", \s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?, \s*(-?\w+)\s*\) @@ -325,7 +348,21 @@ module RDoc meth_body, param_count, source_file) end - @body.scan(%r{rb_define_global_function\( + @body.scan(%r{rb_define_attr\( + \s*([\w\.]+), + \s*"([^"]+)", + \s*(\d+), + \s*(\d+)\s*\); + }xm) do #" + |var_name, attr_name, attr_reader, attr_writer| + + #var_name = "rb_cObject" if var_name == "rb_mKernel" + handle_attr(var_name, attr_name, + attr_reader.to_i != 0, + attr_writer.to_i != 0) + end + + @body.scan(%r{rb_define_global_function\s*\( \s*"([^"]+)", \s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?, \s*(-?\w+)\s*\) @@ -336,7 +373,7 @@ module RDoc meth_body, param_count, source_file) end - @body.scan(/define_filetest_function\( + @body.scan(/define_filetest_function\s*\( \s*"([^"]+)", \s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?, \s*(-?\w+)\s*\)/xm) do #" @@ -350,7 +387,7 @@ module RDoc ############################################################ def do_aliases - @body.scan(%r{rb_define_alias\(\s*(\w+),\s*"([^"]+)",\s*"([^"]+)"\s*\)}m) do + @body.scan(%r{rb_define_alias\s*\(\s*(\w+),\s*"([^"]+)",\s*"([^"]+)"\s*\)}m) do |var_name, new_name, old_name| @stats.num_methods += 1 class_name = @known_classes[var_name] || var_name @@ -362,6 +399,83 @@ module RDoc ############################################################ + def handle_constants(type, var_name, const_name, definition) + #@stats.num_constants += 1 + class_name = @known_classes[var_name] + + return unless class_name + + class_obj = find_class(var_name, class_name) + + unless class_obj + $stderr.puts("Enclosing class/module '#{const_name}' for not known") + return + end + + comment = find_const_comment(type, const_name) + + con = Constant.new(const_name, definition, mangle_comment(comment)) + class_obj.add_constant(con) + end + + ########################################################### + + def find_const_comment(type, const_name) + if @body =~ %r{((?>/\*.*?\*/\s+)) + rb_define_#{type}\((?:\s*(\w+),)?\s*"#{const_name}"\s*,.*?\)\s*;}xmi + $1 + elsif @body =~ %r{Document-(?:const|global|variable):\s#{const_name}\s*?\n((?>.*?\*/))}m + $1 + else + '' + end + end + + ########################################################### + + def handle_attr(var_name, attr_name, reader, writer) + rw = '' + if reader + #@stats.num_methods += 1 + rw << 'R' + end + if writer + #@stats.num_methods += 1 + rw << 'W' + end + + class_name = @known_classes[var_name] + + return unless class_name + + class_obj = find_class(var_name, class_name) + + if class_obj + comment = find_attr_comment(attr_name) + unless comment.empty? + comment = mangle_comment(comment) + end + att = Attr.new('', attr_name, rw, comment) + class_obj.add_attribute(att) + end + + end + + ########################################################### + + def find_attr_comment(attr_name) + if @body =~ %r{((?>/\*.*?\*/\s+)) + rb_define_attr\((?:\s*(\w+),)?\s*"#{attr_name}"\s*,.*?\)\s*;}xmi + $1 + elsif @body =~ %r{Document-attr:\s#{attr_name}\s*?\n((?>.*?\*/))}m + $1 + else + '' + end + end + + ########################################################### + def handle_method(type, var_name, meth_name, meth_body, param_count, source_file = nil) @stats.num_methods += 1 @@ -469,12 +583,10 @@ module RDoc ############################################################ def find_override_comment(meth_name) - comment = nil name = Regexp.escape(meth_name) - if @body =~ %r{Document-method:\s#{name}.*?\n((?>.*?\*/))}m - comment = $1 + if @body =~ %r{Document-method:\s#{name}\s*?\n((?>.*?\*/))}m + $1 end - comment end ############################################################ @@ -482,7 +594,7 @@ module RDoc # Look for includes of the form # rb_include_module(rb_cArray, rb_mEnumerable); def do_includes - @body.scan(/rb_include_module\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m| + @body.scan(/rb_include_module\s*\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m| if cls = @classes[c] m = KNOWN_CLASSES[m] || m cls.add_include(Include.new(m, "")) @@ -512,6 +624,18 @@ module RDoc @classes[raw_name] end + def handle_tab_width(body) + if /\t/ =~ body + tab_width = Options.instance.tab_width + body.split(/\n/).map do |line| + 1 while line.gsub!(/\t+/) { ' ' * (tab_width*$&.length - $`.length % tab_width)} && $~ #` + line + end .join("\n") + else + body + end + end + # Remove #ifdefs that would otherwise confuse us def handle_ifdefs_in(body) diff --git a/lib/rdoc/parsers/parse_rb.rb b/lib/rdoc/parsers/parse_rb.rb index 15b3484cb7..8e91c01e61 100644 --- a/lib/rdoc/parsers/parse_rb.rb +++ b/lib/rdoc/parsers/parse_rb.rb @@ -1883,6 +1883,7 @@ module RDoc name_t = get_tk back_tk = skip_tkspace meth = nil + added_container = false dot = get_tk if dot.kind_of?(TkDOT) or dot.kind_of?(TkCOLON2) @@ -1897,8 +1898,21 @@ module RDoc prev_container = container container = container.find_module_named(name_t.name) if !container - warn("Couldn't find #{name_t.name}. Assuming it's a module") - container = prev_container.add_module(NormalModule, name_t.name) + added_container = true + obj = name_t.name.split("::").inject(Object) do |state, item| + state.const_get(item) + end rescue nil + + type = obj.class == Class ? NormalClass : NormalModule + if not [Class, Module].include?(obj.class) + warn("Couldn't find #{name_t.name}. Assuming it's a module") + end + + if type == NormalClass then + container = prev_container.add_class(type, name_t.name, obj.superclass.name) + else + container = prev_container.add_module(type, name_t.name) + end end else # warn("Unexpected token '#{name_t2.inspect}'") @@ -1940,7 +1954,9 @@ module RDoc parse_method_parameters(meth) if meth.document_self - container.add_method(meth) + container.add_method(meth) + elsif added_container + container.document_self = false end # Having now read the method parameters and documentation modifiers, we diff --git a/lib/rdoc/parsers/parse_simple.rb b/lib/rdoc/parsers/parse_simple.rb index b01104574e..3f1a546964 100644 --- a/lib/rdoc/parsers/parse_simple.rb +++ b/lib/rdoc/parsers/parse_simple.rb @@ -30,8 +30,12 @@ module RDoc def scan # @body.gsub(/^(\s\n)+/, '') - @top_level.comment = @body + @top_level.comment = remove_private_comments(@body) @top_level end + + def remove_private_comments(comment) + comment.gsub(/^--.*?^\+\+/m, '').sub(/^--.*/m, '') + end end end diff --git a/lib/rexml/document.rb b/lib/rexml/document.rb index a7f056ad3f..39360d4f4a 100644 --- a/lib/rexml/document.rb +++ b/lib/rexml/document.rb @@ -156,12 +156,12 @@ module REXML # unable to parse proper XML, we have to provide a hack to generate XML # that IE's limited abilities can handle. This hack inserts a space # before the /> on empty tags. Defaults to false - def write( output=$stdout, indent=-1, transitive=false, ie_hack=false ) + def write( output=$stdout, indent_level=-1, transitive=false, ie_hack=false ) output = Output.new( output, xml_decl.encoding ) if xml_decl.encoding != "UTF-8" && !output.kind_of?(Output) @children.each { |node| - indent( output, indent ) if node.node_type == :element - if node.write( output, indent, transitive, ie_hack ) - output << "\n" unless indent<0 or node == @children[-1] + indent( output, indent_level ) if node.node_type == :element + if node.write( output, indent_level, transitive, ie_hack ) + output << "\n" unless indent_level<0 or node == @children[-1] end } end diff --git a/lib/rexml/element.rb b/lib/rexml/element.rb index b76c0179c7..e18f0b28c7 100644 --- a/lib/rexml/element.rb +++ b/lib/rexml/element.rb @@ -199,7 +199,7 @@ module REXML # b.namespace("y") # -> '2' def namespace(prefix=nil) if prefix.nil? - prefix = prefix() + prefix = self.prefix() end if prefix == '' prefix = "xmlns" diff --git a/lib/rexml/instruction.rb b/lib/rexml/instruction.rb index 0b770d4b3d..ebd868c95c 100644 --- a/lib/rexml/instruction.rb +++ b/lib/rexml/instruction.rb @@ -38,8 +38,8 @@ module REXML Instruction.new self end - def write writer, indent=-1, transitive=false, ie_hack=false - indent(writer, indent) + def write writer, indent_level=-1, transitive=false, ie_hack=false + indent(writer, indent_level) writer << START.sub(/\\/u, '') writer << @target writer << ' ' diff --git a/lib/rexml/xmldecl.rb b/lib/rexml/xmldecl.rb index 3f90e0160f..df2cbf0060 100644 --- a/lib/rexml/xmldecl.rb +++ b/lib/rexml/xmldecl.rb @@ -2,71 +2,71 @@ require 'rexml/encoding' require 'rexml/source' module REXML - # NEEDS DOCUMENTATION - class XMLDecl < Child - include Encoding + # NEEDS DOCUMENTATION + class XMLDecl < Child + include Encoding - DEFAULT_VERSION = "1.0"; - DEFAULT_ENCODING = "UTF-8"; - DEFAULT_STANDALONE = "no"; - START = '<\?xml'; - STOP = '\?>'; + DEFAULT_VERSION = "1.0"; + DEFAULT_ENCODING = "UTF-8"; + DEFAULT_STANDALONE = "no"; + START = '<\?xml'; + STOP = '\?>'; - attr_accessor :version, :standalone + attr_accessor :version, :standalone attr_reader :writeencoding - def initialize(version=DEFAULT_VERSION, encoding=nil, standalone=nil) + def initialize(version=DEFAULT_VERSION, encoding=nil, standalone=nil) @writethis = true @writeencoding = !encoding.nil? - if version.kind_of? XMLDecl - super() - @version = version.version - self.encoding = version.encoding + if version.kind_of? XMLDecl + super() + @version = version.version + self.encoding = version.encoding @writeencoding = version.writeencoding - @standalone = version.standalone - else - super() - @version = version - self.encoding = encoding - @standalone = standalone - end - @version = DEFAULT_VERSION if @version.nil? - end + @standalone = version.standalone + else + super() + @version = version + self.encoding = encoding + @standalone = standalone + end + @version = DEFAULT_VERSION if @version.nil? + end - def clone - XMLDecl.new(self) - end + def clone + XMLDecl.new(self) + end - def write writer, indent=-1, transitive=false, ie_hack=false + def write writer, indent_level=-1, transitive=false, ie_hack=false return nil unless @writethis or writer.kind_of? Output - indent( writer, indent ) - writer << START.sub(/\\/u, '') + indent( writer, indent_level ) + writer << START.sub(/\\/u, '') if writer.kind_of? Output writer << " #{content writer.encoding}" else writer << " #{content encoding}" end - writer << STOP.sub(/\\/u, '') - end + writer << STOP.sub(/\\/u, '') + end - def ==( other ) - other.kind_of?(XMLDecl) and - other.version == @version and - other.encoding == self.encoding and - other.standalone == @standalone - end + def ==( other ) + other.kind_of?(XMLDecl) and + other.version == @version and + other.encoding == self.encoding and + other.standalone == @standalone + end - def xmldecl version, encoding, standalone - @version = version - self.encoding = encoding - @standalone = standalone - end + def xmldecl version, encoding, standalone + @version = version + self.encoding = encoding + @standalone = standalone + end - def node_type - :xmldecl - end + def node_type + :xmldecl + end - alias :stand_alone? :standalone + alias :stand_alone? :standalone alias :old_enc= :encoding= def encoding=( enc ) @@ -94,12 +94,12 @@ module REXML @writethis = true end - private - def content(enc) - rv = "version='#@version'" - rv << " encoding='#{enc}'" if @writeencoding || enc !~ /utf-8/i - rv << " standalone='#@standalone'" if @standalone - rv - end - end + private + def content(enc) + rv = "version='#@version'" + rv << " encoding='#{enc}'" if @writeencoding || enc !~ /utf-8/i + rv << " standalone='#@standalone'" if @standalone + rv + end + end end diff --git a/lib/set.rb b/lib/set.rb index 8364d4a072..b8dd2ca569 100644 --- a/lib/set.rb +++ b/lib/set.rb @@ -438,6 +438,11 @@ class SortedSet < Set def setup # :nodoc: @@setup and return + module_eval { + # a hack to shut up warning + alias old_init initialize + remove_method :old_init + } begin require 'rbtree' diff --git a/lib/time.rb b/lib/time.rb index e0d831d3b0..ce3614bfce 100644 --- a/lib/time.rb +++ b/lib/time.rb @@ -94,6 +94,37 @@ class Time end private :zone_utc? + def make_time(year, mon, day, hour, min, sec, zone, now) + if now + begin + break if year; year = now.year + break if mon; mon = now.mon + break if day; day = now.day + break if hour; hour = now.hour + break if min; min = now.min + break if sec; sec = now.sec + end until true + end + + year ||= 1970 + mon ||= 1 + day ||= 1 + hour ||= 0 + min ||= 0 + sec ||= 0 + + off = nil + off = zone_offset(zone, year) if zone + + if off + t = Time.utc(year, mon, day, hour, min, sec) - off + t.localtime if !zone_utc?(zone) + t + else + Time.local(year, mon, day, hour, min, sec) + end + end + # # Parses +date+ using ParseDate.parsedate and converts it to a Time object. # @@ -147,35 +178,20 @@ class Time def parse(date, now=Time.now) year, mon, day, hour, min, sec, zone, _ = ParseDate.parsedate(date) year = yield(year) if year && block_given? + make_time(year, mon, day, hour, min, sec, zone, now) + end - if now - begin - break if year; year = now.year - break if mon; mon = now.mon - break if day; day = now.day - break if hour; hour = now.hour - break if min; min = now.min - break if sec; sec = now.sec - end until true - end - - year ||= 1970 - mon ||= 1 - day ||= 1 - hour ||= 0 - min ||= 0 - sec ||= 0 - - off = nil - off = zone_offset(zone, year) if zone - - if off - t = Time.utc(year, mon, day, hour, min, sec) - off - t.localtime if !zone_utc?(zone) - t - else - Time.local(year, mon, day, hour, min, sec) - end + # + # Parses +date+ using ParseDate.strptime and converts it to a Time object. + # + # If a block is given, the year described in +date+ is converted by the + # block. For example: + # + # Time.parse(...) {|y| y < 100 ? (y >= 69 ? y + 1900 : y + 2000) : y} + def strptime(date, format, now=Time.now) + year, mon, day, hour, min, sec, zone, _ = ParseDate.strptime(date, format) + year = yield(year) if year && block_given? + make_time(year, mon, day, hour, min, sec, zone, now) end MonthValue = { diff --git a/lib/timeout.rb b/lib/timeout.rb index 7e3ee81ed0..36811a1040 100644 --- a/lib/timeout.rb +++ b/lib/timeout.rb @@ -1,38 +1,39 @@ +# = timeout.rb # -# timeout.rb -- execution timeout +# execution timeout # -# Copyright (C) 2000 Network Applied Communication Laboratory, Inc. -# Copyright (C) 2000 Information-technology Promotion Agency, Japan -# -#= SYNOPSIS +# = Synopsis # # require 'timeout' -# status = timeout(5) { -# # something may take time +# status = Timeout::timeout(5) { +# # Something that should be interrupted if it takes too much time... # } # -#= DESCRIPTION -# -# timeout executes the block. If the block execution terminates successfully -# before timeout, it returns true. If not, it terminates the execution and -# raise TimeoutError exception. -# -#== Parameters -# -# : timout +# = Description # -# The time in seconds to wait for block termination. +# A way of performing a potentially long-running operation in a thread, and terminating +# it's execution if it hasn't finished by a fixed amount of time. # -# : [exception] +# Previous versions of timeout didn't provide use a module for namespace. This version +# provides both Timeout.timeout, and a backwards-compatible #timeout. # -# The exception class to be raised on timeout. +# = Copyright # -#=end +# Copyright:: (C) 2000 Network Applied Communication Laboratory, Inc. +# Copyright:: (C) 2000 Information-technology Promotion Agency, Japan module Timeout + # Raised by Timeout#timeout when the block times out. class Error