Navigation Menu

Skip to content

Commit

Permalink
Update stdlib from ruby 2.1 HEAD.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Oct 28, 2014
1 parent 3750915 commit bacbde8
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 36 deletions.
17 changes: 10 additions & 7 deletions lib/ruby/2.1/csv.rb
Expand Up @@ -1148,9 +1148,9 @@ def self.generate(*args)
io.seek(0, IO::SEEK_END)
args.unshift(io)
else
encoding = (args[-1] = args[-1].dup).delete(:encoding) if args.last.is_a?(Hash)
encoding = args[-1][:encoding] if args.last.is_a?(Hash)
str = ""
str.encode!(encoding) if encoding
str.force_encoding(encoding) if encoding
args.unshift(str)
end
csv = new(*args) # wrap
Expand Down Expand Up @@ -1515,7 +1515,7 @@ def initialize(data, options = Hash.new)
init_headers(options)
init_comments(options)

options.delete(:encoding)
@force_encoding = !!(encoding || options.delete(:encoding))
options.delete(:internal_encoding)
options.delete(:external_encoding)
unless options.empty?
Expand Down Expand Up @@ -1655,10 +1655,13 @@ def <<(row)

output = row.map(&@quote).join(@col_sep) + @row_sep # quote and separate
if @io.is_a?(StringIO) and
output.encoding != raw_encoding and
(compatible_encoding = Encoding.compatible?(@io.string, output))
@io.set_encoding(compatible_encoding)
@io.seek(0, IO::SEEK_END)
output.encoding != (encoding = raw_encoding)
if @force_encoding
output = output.encode(encoding)
elsif (compatible_encoding = Encoding.compatible?(@io.string, output))
@io.set_encoding(compatible_encoding)
@io.seek(0, IO::SEEK_END)
end
end
@io << output

Expand Down
2 changes: 1 addition & 1 deletion lib/ruby/2.1/erb.rb
Expand Up @@ -837,7 +837,7 @@ def run(b=new_toplevel)
# the results of that code. (See ERB::new for details on how this process
# can be affected by _safe_level_.)
#
# _b_ accepts a Binding or Proc object which is used to set the context of
# _b_ accepts a Binding object which is used to set the context of
# code evaluation.
#
def result(b=new_toplevel)
Expand Down
14 changes: 10 additions & 4 deletions lib/ruby/2.1/fileutils.rb
Expand Up @@ -277,7 +277,7 @@ def rmdir(list, options = {})
Dir.rmdir(dir)
end
end
rescue Errno::ENOTEMPTY, Errno::ENOENT
rescue Errno::ENOTEMPTY, Errno::EEXIST, Errno::ENOENT
end
end
end
Expand Down Expand Up @@ -864,7 +864,8 @@ def install(src, dest, options = {})
fu_check_options options, OPT_TABLE['install']
fu_output_message "install -c#{options[:preserve] && ' -p'}#{options[:mode] ? (' -m 0%o' % options[:mode]) : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
return if options[:noop]
fu_each_src_dest(src, dest) do |s, d, st|
fu_each_src_dest(src, dest) do |s, d|
st = File.stat(s)
unless File.exist?(d) and compare_file(s, d)
remove_file d, true
copy_file s, d
Expand Down Expand Up @@ -1262,7 +1263,12 @@ def dereference?
end

def exist?
lstat! ? true : false
begin
lstat
true
rescue Errno::ENOENT
false
end
end

def file?
Expand Down Expand Up @@ -1580,7 +1586,7 @@ def fu_list(arg) #:nodoc:
def fu_each_src_dest(src, dest) #:nodoc:
fu_each_src_dest0(src, dest) do |s, d|
raise ArgumentError, "same file: #{s} and #{d}" if fu_same?(s, d)
yield s, d, File.stat(s)
yield s, d
end
end
private_module_function :fu_each_src_dest
Expand Down
1 change: 1 addition & 0 deletions lib/ruby/2.1/find.rb
Expand Up @@ -40,6 +40,7 @@ def find(*paths) # :yield: path
fs_encoding = Encoding.find("filesystem")

paths.collect!{|d| raise Errno::ENOENT unless File.exist?(d); d.dup}.each do |path|
path = path.to_path if path.respond_to? :to_path
enc = path.encoding == Encoding::US_ASCII ? fs_encoding : path.encoding
ps = [path]
while file = ps.shift
Expand Down
12 changes: 6 additions & 6 deletions lib/ruby/2.1/gserver.rb
Expand Up @@ -37,7 +37,7 @@
# super(port, *args)
# end
# def serve(io)
# io.puts(Time.now.to_s)
# io.puts(Time.now.to_i)
# end
# end
#
Expand Down Expand Up @@ -144,7 +144,7 @@ def join
attr_reader :port
# Host on which to bind, as a String
attr_reader :host
# Maximum number of connections to accept at at ime, as a Fixnum
# Maximum number of connections to accept at a time, as a Fixnum
attr_reader :maxConnections
# IO Device on which log messages should be written
attr_accessor :stdlog
Expand All @@ -156,7 +156,7 @@ def join

# Called when a client connects, if auditing is enabled.
#
# +client+:: a TCPSocket instances representing the client that connected
# +client+:: a TCPSocket instance representing the client that connected
#
# Return true to allow this client to connect, false to prevent it.
def connecting(client)
Expand Down Expand Up @@ -192,7 +192,7 @@ def stopping()
# Called if #debug is true whenever an unhandled exception is raised.
# This implementation simply logs the backtrace.
#
# +detail+:: The Exception that was caught
# +detail+:: the Exception that was caught
def error(detail)
log(detail.backtrace.join("\n"))
end
Expand All @@ -212,9 +212,9 @@ def log(msg)

# Create a new server
#
# +port+:: the port, as a Fixnum, on which to listen.
# +port+:: the port, as a Fixnum, on which to listen
# +host+:: the host to bind to
# +maxConnections+:: The maximum number of simultaneous connections to
# +maxConnections+:: the maximum number of simultaneous connections to
# accept
# +stdlog+:: IO device on which to log messages
# +audit+:: if true, lifecycle callbacks will be called. See #audit
Expand Down
6 changes: 3 additions & 3 deletions lib/ruby/2.1/matrix.rb
Expand Up @@ -1764,9 +1764,9 @@ def inner_product(v)
#
def cross_product(v)
Vector.Raise ErrDimensionMismatch unless size == v.size && v.size == 3
Vector[ v[1]*@elements[2] - v[2]*@elements[1],
v[2]*@elements[0] - v[0]*@elements[2],
v[0]*@elements[1] - v[1]*@elements[0] ]
Vector[ v[2]*@elements[1] - v[1]*@elements[2],
v[0]*@elements[2] - v[2]*@elements[0],
v[1]*@elements[0] - v[0]*@elements[1] ]
end

#
Expand Down
11 changes: 7 additions & 4 deletions lib/ruby/2.1/net/ftp.rb
Expand Up @@ -1105,13 +1105,16 @@ def read(len = nil)
end

def gets
return readuntil("\n")
rescue EOFError
return nil
line = readuntil("\n", true)
return line.empty? ? nil : line
end

def readline
return readuntil("\n")
line = gets
if line.nil?
raise EOFError, "end of file reached"
end
return line
end
end
# :startdoc:
Expand Down
9 changes: 9 additions & 0 deletions lib/ruby/2.1/net/imap.rb
Expand Up @@ -2372,6 +2372,8 @@ def body_type_1part
return body_type_msg
when /\A(?:ATTACHMENT)\z/ni
return body_type_attachment
when /\A(?:MIXED)\z/ni
return body_type_mixed
else
return body_type_basic
end
Expand Down Expand Up @@ -2454,6 +2456,13 @@ def body_type_attachment
return BodyTypeAttachment.new(mtype, nil, param)
end

def body_type_mixed
mtype = "MULTIPART"
msubtype = case_insensitive_string
param, disposition, language, extension = body_ext_mpart
return BodyTypeBasic.new(mtype, msubtype, param, nil, nil, nil, nil, nil, disposition, language, extension)
end

def body_type_mpart
parts = []
while true
Expand Down
5 changes: 4 additions & 1 deletion lib/ruby/2.1/pathname.rb
Expand Up @@ -22,7 +22,8 @@ class Pathname
end

SAME_PATHS = if File::FNM_SYSCASE.nonzero?
proc {|a, b| a.casecmp(b).zero?}
# Avoid #zero? here because #casecmp can return nil.
proc {|a, b| a.casecmp(b) == 0}
else
proc {|a, b| a == b}
end
Expand Down Expand Up @@ -113,6 +114,7 @@ def cleanpath_aggressive # :nodoc:
end
end
end
pre.tr!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
if /#{SEPARATOR_PAT}/o =~ File.basename(pre)
names.shift while names[0] == '..'
end
Expand Down Expand Up @@ -161,6 +163,7 @@ def cleanpath_conservative # :nodoc:
pre, base = r
names.unshift base if base != '.'
end
pre.tr!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
if /#{SEPARATOR_PAT}/o =~ File.basename(pre)
names.shift while names[0] == '..'
end
Expand Down
4 changes: 3 additions & 1 deletion lib/ruby/2.1/resolv.rb
Expand Up @@ -657,7 +657,9 @@ def self.bind_random_port(udpsock, bind_host="0.0.0.0") # :nodoc:
begin
port = rangerand(1024..65535)
udpsock.bind(bind_host, port)
rescue Errno::EADDRINUSE, Errno::EACCES
rescue Errno::EADDRINUSE, # POSIX
Errno::EACCES, # SunOS: See PRIV_SYS_NFS in privileges(5)
Errno::EPERM # FreeBSD: security.mac.portacl.port_high is configurable. See mac_portacl(4).
retry
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/ruby/2.1/rexml/entity.rb
Expand Up @@ -138,8 +138,14 @@ def value
matches = @value.scan(PEREFERENCE_RE)
rv = @value.clone
if @parent
sum = 0
matches.each do |entity_reference|
entity_value = @parent.entity( entity_reference[0] )
if sum + entity_value.bytesize > Security.entity_expansion_text_limit
raise "entity expansion has grown too large"
else
sum += entity_value.bytesize
end
rv.gsub!( /%#{entity_reference.join};/um, entity_value )
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby/2.1/rinda/tuplespace.rb
Expand Up @@ -76,7 +76,7 @@ def expired?
# Reset the expiry time according to +sec_or_renewer+.
#
# +nil+:: it is set to expire in the far future.
# +false+:: it has expired.
# +true+:: it has expired.
# Numeric:: it will expire in that many seconds.
#
# Otherwise the argument refers to some kind of renewer object
Expand Down
5 changes: 5 additions & 0 deletions lib/ruby/2.1/test/unit/parallel.rb
Expand Up @@ -155,6 +155,11 @@ def _report(res, *args) # :nodoc:
end

def puke(klass, meth, e) # :nodoc:
if e.is_a?(MiniTest::Skip)
new_e = MiniTest::Skip.new(e.message)
new_e.set_backtrace(e.backtrace)
e = new_e
end
@partial_report << [klass.name, meth, e.is_a?(MiniTest::Assertion) ? e : ProxyError.new(e)]
super
end
Expand Down
14 changes: 7 additions & 7 deletions lib/ruby/2.1/time.rb
Expand Up @@ -278,13 +278,13 @@ def make_time(year, mon, day, hour, min, sec, sec_fraction, zone, now)
# supplied with those of +now+. For the lower components, the minimum
# values (1 or 0) are assumed if broken or missing. For example:
#
# # Suppose it is "Thu Nov 29 14:33:20 GMT 2001" now and
# # your time zone is GMT:
# now = Time.parse("Thu Nov 29 14:33:20 GMT 2001")
# Time.parse("16:30", now) #=> 2001-11-29 16:30:00 +0900
# Time.parse("7/23", now) #=> 2001-07-23 00:00:00 +0900
# Time.parse("Aug 31", now) #=> 2001-08-31 00:00:00 +0900
# Time.parse("Aug 2000", now) #=> 2000-08-01 00:00:00 +0900
# # Suppose it is "Thu Nov 29 14:33:20 2001" now and
# # your time zone is EST which is GMT-5.
# now = Time.parse("Thu Nov 29 14:33:20 2001")
# Time.parse("16:30", now) #=> 2001-11-29 16:30:00 -0500
# Time.parse("7/23", now) #=> 2001-07-23 00:00:00 -0500
# Time.parse("Aug 31", now) #=> 2001-08-31 00:00:00 -0500
# Time.parse("Aug 2000", now) #=> 2000-08-01 00:00:00 -0500
#
# Since there are numerous conflicts among locally defined time zone
# abbreviations all over the world, this method is not intended to
Expand Down
4 changes: 3 additions & 1 deletion lib/ruby/2.1/webrick/utils.rb
Expand Up @@ -75,7 +75,9 @@ def create_listeners(address, port, logger=nil)
sockets = Socket.tcp_server_sockets(address, port)
sockets = sockets.map {|s|
s.autoclose = false
TCPServer.for_fd(s.fileno)
ts = TCPServer.for_fd(s.fileno)
s.close
ts
}
return sockets
end
Expand Down

0 comments on commit bacbde8

Please sign in to comment.