Skip to content
Permalink
Browse files
Update to release stdlib from MRI 2.2.0p0.
  • Loading branch information
headius committed Dec 27, 2014
1 parent d151b1d commit 27eaf2479ef20f0eeb46550048775142819a6e97
@@ -797,8 +797,9 @@ def initialize(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout')
@safe_level = safe_level
compiler = make_compiler(trim_mode)
set_eoutvar(compiler, eoutvar)
@src, @enc = *compiler.compile(str)
@src, @encoding = *compiler.compile(str)
@filename = nil
@lineno = 0
end

##
@@ -811,10 +812,22 @@ def make_compiler(trim_mode)
# The Ruby code generated by ERB
attr_reader :src

# The encoding to eval
attr_reader :encoding

# The optional _filename_ argument passed to Kernel#eval when the ERB code
# is run
attr_accessor :filename

# The optional _lineno_ argument passed to Kernel#eval when the ERB code
# is run
attr_accessor :lineno

def location=((filename, lineno))
@filename = filename
@lineno = lineno if lineno
end

#
# Can be used to set _eoutvar_ as described in ERB::new. It's probably
# easier to just use the constructor though, since calling this method
@@ -844,10 +857,10 @@ def result(b=new_toplevel)
if @safe_level
proc {
$SAFE = @safe_level
eval(@src, b, (@filename || '(erb)'), 0)
eval(@src, b, (@filename || '(erb)'), @lineno)
}.call
else
eval(@src, b, (@filename || '(erb)'), 0)
eval(@src, b, (@filename || '(erb)'), @lineno)
end
end

@@ -869,7 +882,7 @@ def new_toplevel
# print MyClass.new.render('foo', 123)
def def_method(mod, methodname, fname='(ERB)')
src = self.src
magic_comment = "#coding:#{@enc}\n"
magic_comment = "#coding:#{@encoding}\n"
mod.module_eval do
eval(magic_comment + "def #{methodname}\n" + src + "\nend\n", binding, fname, -2)
end
@@ -37,7 +37,7 @@ def read_new(sock) #:nodoc: internal use only

def read_status_line(sock)
str = sock.readline
m = /\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)\s*(.*)\z/in.match(str) or
m = /\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)(?:\s+(.*))?\z/in.match(str) or
raise Net::HTTPBadResponse, "wrong status line: #{str.dump}"
m.captures
end
@@ -295,10 +295,12 @@ def OpenURI.open_http(buf, target, proxy, options) # :nodoc:
http.verify_mode = options[:ssl_verify_mode] || OpenSSL::SSL::VERIFY_PEER
store = OpenSSL::X509::Store.new
if options[:ssl_ca_cert]
if File.directory? options[:ssl_ca_cert]
store.add_path options[:ssl_ca_cert]
else
store.add_file options[:ssl_ca_cert]
Array(options[:ssl_ca_cert]).each do |cert|
if File.directory? cert
store.add_path cert
else
store.add_file cert
end
end
else
store.set_default_paths
@@ -680,7 +682,7 @@ module OpenRead
#
# [:ssl_ca_cert]
# Synopsis:
# :ssl_ca_cert=>filename
# :ssl_ca_cert=>filename or an Array of filenames
#
# :ssl_ca_cert is used to specify CA certificate for SSL.
# If it is given, default certificates are not used.
@@ -272,18 +272,18 @@ def rewind
end

# Iterates the given block for each prime number.
def each(&block)
return self.dup unless block
def each
return self.dup unless block_given?
if @ubound
last_value = nil
loop do
prime = succ
break last_value if prime > @ubound
last_value = block.call(prime)
last_value = yield prime
end
else
loop do
block.call(succ)
yield succ
end
end
end
@@ -350,19 +350,17 @@ def initialize
end

def succ
loop do
if (@step)
@prime += @step
@step = 6 - @step
else
case @prime
when 1; @prime = 2
when 2; @prime = 3
when 3; @prime = 5; @step = 2
end
if (@step)
@prime += @step
@step = 6 - @step
else
case @prime
when 1; @prime = 2
when 2; @prime = 3
when 3; @prime = 5; @step = 2
end
return @prime
end
return @prime
end
alias next succ
def rewind
@@ -479,7 +477,7 @@ def succ
#
# Iterates the given block over all prime numbers. Note that enumeration
# starts from the current position of internal pointer, not rewound.
def each(&block)
def each
return @generator.dup unless block_given?
loop do
yield succ
@@ -543,7 +543,7 @@ def set_password(v)
# if properly formatted as 'user:password'
def split_userinfo(ui)
return nil, nil unless ui
user, password = ui.split(/:/, 2)
user, password = ui.split(':'.freeze, 2)

return user, password
end
@@ -695,13 +695,7 @@ def check_port(v)
# see also URI::Generic.port=
#
def set_port(v)
unless !v || v.kind_of?(Fixnum)
if v.empty?
v = nil
else
v = v.to_i
end
end
v = v.empty? ? nil : v.to_i unless !v || v.kind_of?(Fixnum)
@port = v
end
protected :set_port
@@ -768,13 +762,14 @@ def check_path(v)

# If scheme is ftp, path may be relative.
# See RFC 1738 section 3.2.2, and RFC 2396.
if @scheme && @scheme != "ftp"
if v && v != '' && parser.regexp[:ABS_PATH] !~ v
if @scheme && @scheme != "ftp".freeze
if v && v != ''.freeze && parser.regexp[:ABS_PATH] !~ v
raise InvalidComponentError,
"bad component(expected absolute path component): #{v}"
end
else
if v && v != '' && parser.regexp[:ABS_PATH] !~ v && parser.regexp[:REL_PATH] !~ v
if v && v != ''.freeze && parser.regexp[:ABS_PATH] !~ v &&
parser.regexp[:REL_PATH] !~ v
raise InvalidComponentError,
"bad component(expected relative path component): #{v}"
end
@@ -849,9 +844,9 @@ def query=(v)
x = v.to_str
v = x.dup if x.equal? v
v.encode!(Encoding::UTF_8) rescue nil
v.delete!("\t\r\n")
v.delete!("\t\r\n".freeze)
v.force_encoding(Encoding::ASCII_8BIT)
v.gsub!(/(?!%\h\h|[!$-&(-;=?-Z_a-~])./n.freeze){'%%%02X'.freeze % $&.ord}
v.gsub!(/(?!%\h\h|[!$-&(-;=?-_a-~])./n.freeze){'%%%02X'.freeze % $&.ord}
v.force_encoding(Encoding::US_ASCII)
@query = v
end
@@ -939,9 +934,9 @@ def fragment=(v)
x = v.to_str
v = x.dup if x.equal? v
v.encode!(Encoding::UTF_8) rescue nil
v.delete!("\t\r\n")
v.delete!("\t\r\n".freeze)
v.force_encoding(Encoding::ASCII_8BIT)
v.gsub!(/(?!%\h\h|[!-~])./n){'%%%02X' % $&.ord}
v.gsub!(/(?!%\h\h|[!-~])./n){'%%%02X'.freeze % $&.ord}
v.force_encoding(Encoding::US_ASCII)
@fragment = v
end
@@ -4,49 +4,64 @@ class RFC3986_Parser # :nodoc:
# this regexp is modified not to host is not empty string
RFC3986_URI = /\A(?<URI>(?<scheme>[A-Za-z][+\-.0-9A-Za-z]*):(?<hier-part>\/\/(?<authority>(?:(?<userinfo>(?:%\h\h|[!$&-.0-;=A-Z_a-z~])*)@)?(?<host>(?<IP-literal>\[(?:(?<IPv6address>(?:\h{1,4}:){6}(?<ls32>\h{1,4}:\h{1,4}|(?<IPv4address>(?<dec-octet>[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]|\d)\.\g<dec-octet>\.\g<dec-octet>\.\g<dec-octet>))|::(?:\h{1,4}:){5}\g<ls32>|\h{1,4}?::(?:\h{1,4}:){4}\g<ls32>|(?:(?:\h{1,4}:)?\h{1,4})?::(?:\h{1,4}:){3}\g<ls32>|(?:(?:\h{1,4}:){,2}\h{1,4})?::(?:\h{1,4}:){2}\g<ls32>|(?:(?:\h{1,4}:){,3}\h{1,4})?::\h{1,4}:\g<ls32>|(?:(?:\h{1,4}:){,4}\h{1,4})?::\g<ls32>|(?:(?:\h{1,4}:){,5}\h{1,4})?::\h{1,4}|(?:(?:\h{1,4}:){,6}\h{1,4})?::)|(?<IPvFuture>v\h+\.[!$&-.0-;=A-Z_a-z~]+))\])|\g<IPv4address>|(?<reg-name>(?:%\h\h|[!$&-.0-9;=A-Z_a-z~])+))?(?::(?<port>\d*))?)(?<path-abempty>(?:\/(?<segment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*))*)|(?<path-absolute>\/(?:(?<segment-nz>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])+)(?:\/\g<segment>)*)?)|(?<path-rootless>\g<segment-nz>(?:\/\g<segment>)*)|(?<path-empty>))(?:\?(?<query>[^#]*))?(?:\#(?<fragment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*))?)\z/
RFC3986_relative_ref = /\A(?<relative-ref>(?<relative-part>\/\/(?<authority>(?:(?<userinfo>(?:%\h\h|[!$&-.0-;=A-Z_a-z~])*)@)?(?<host>(?<IP-literal>\[(?<IPv6address>(?:\h{1,4}:){6}(?<ls32>\h{1,4}:\h{1,4}|(?<IPv4address>(?<dec-octet>[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]|\d)\.\g<dec-octet>\.\g<dec-octet>\.\g<dec-octet>))|::(?:\h{1,4}:){5}\g<ls32>|\h{1,4}?::(?:\h{1,4}:){4}\g<ls32>|(?:(?:\h{1,4}:){,1}\h{1,4})?::(?:\h{1,4}:){3}\g<ls32>|(?:(?:\h{1,4}:){,2}\h{1,4})?::(?:\h{1,4}:){2}\g<ls32>|(?:(?:\h{1,4}:){,3}\h{1,4})?::\h{1,4}:\g<ls32>|(?:(?:\h{1,4}:){,4}\h{1,4})?::\g<ls32>|(?:(?:\h{1,4}:){,5}\h{1,4})?::\h{1,4}|(?:(?:\h{1,4}:){,6}\h{1,4})?::)|(?<IPvFuture>v\h+\.[!$&-.0-;=A-Z_a-z~]+)\])|\g<IPv4address>|(?<reg-name>(?:%\h\h|[!$&-.0-9;=A-Z_a-z~])+))?(?::(?<port>\d*))?)(?<path-abempty>(?:\/(?<segment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*))*)|(?<path-absolute>\/(?:(?<segment-nz>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])+)(?:\/\g<segment>)*)?)|(?<path-noscheme>(?<segment-nz-nc>(?:%\h\h|[!$&-.0-9;=@-Z_a-z~])+)(?:\/\g<segment>)*)|(?<path-empty>))(?:\?(?<query>[^#]*))?(?:\#(?<fragment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*))?)\z/
attr_reader :regexp

def initialize
@regexp = default_regexp.each_value(&:freeze).freeze
end

def split(uri) #:nodoc:
begin
uri = uri.to_str
rescue NoMethodError
raise InvalidURIError, "bad URI(is not URI?): #{uri}"
end
unless uri.ascii_only?
uri.ascii_only? or
raise InvalidURIError, "URI must be ascii only #{uri.dump}"
end
if m = RFC3986_URI.match(uri)
ary = []
ary << m["scheme"]
if m["path-rootless"] # opaque
ary << nil # userinfo
ary << nil # host
ary << nil # port
ary << nil # registry
ary << nil # path
ary << m["path-rootless"]
ary[-1] << '?' << m["query"] if m["query"]
ary << nil # query
ary << m["fragment"]
query = m["query".freeze]
scheme = m["scheme".freeze]
opaque = m["path-rootless".freeze]
if opaque
opaque << "?#{query}" if query
[ scheme,
nil, # userinfo
nil, # host
nil, # port
nil, # registry
nil, # path
opaque,
nil, # query
m["fragment".freeze]
]
else # normal
ary << m["userinfo"]
ary << m["host"]
ary << m["port"]
ary << nil # registry
ary << (m["path-abempty"] || m["path-absolute"] || m["path-empty"])
ary << nil # opaque
ary << m["query"]
ary << m["fragment"]
[ scheme,
m["userinfo".freeze],
m["host".freeze],
m["port".freeze],
nil, # registry
(m["path-abempty".freeze] ||
m["path-absolute".freeze] ||
m["path-empty".freeze]),
nil, # opaque
query,
m["fragment".freeze]
]
end
elsif m = RFC3986_relative_ref.match(uri)
ary = [nil]
ary << m["userinfo"]
ary << m["host"]
ary << m["port"]
ary << nil # registry
ary << (m["path-abempty"] || m["path-absolute"] || m["path-noscheme"] || m["path-empty"])
ary << nil # opaque
ary << m["query"]
ary << m["fragment"]
[ nil, # scheme
m["userinfo".freeze],
m["host".freeze],
m["port".freeze],
nil, # registry,
(m["path-abempty".freeze] ||
m["path-absolute".freeze] ||
m["path-noscheme".freeze] ||
m["path-empty".freeze]),
nil, # opaque
m["query".freeze],
m["fragment".freeze]
]
else
raise InvalidURIError, "bad URI(is not URI?): #{uri}"
end
@@ -55,11 +70,11 @@ def split(uri) #:nodoc:
def parse(uri) # :nodoc:
scheme, userinfo, host, port,
registry, path, opaque, query, fragment = self.split(uri)

if scheme && URI.scheme_list.include?(scheme.upcase)
URI.scheme_list[scheme.upcase].new(scheme, userinfo, host, port,
registry, path, opaque, query,
fragment, self)
scheme_list = URI.scheme_list
if scheme && scheme_list.include?(uc = scheme.upcase)
scheme_list[uc].new(scheme, userinfo, host, port,
registry, path, opaque, query,
fragment, self)
else
Generic.new(scheme, userinfo, host, port,
registry, path, opaque, query,
@@ -78,7 +93,9 @@ def inspect
@@to_s.bind(self).call
end

def regexp
private

def default_regexp # :nodoc:
{
SCHEME: /\A[A-Za-z][A-Za-z0-9+\-.]*\z/,
USERINFO: /\A(?:%\h\h|[!$&-.0-;=A-Z_a-z~])*\z/,
@@ -92,8 +109,6 @@ def regexp
}
end

private

def convert_to_uri(uri)
if uri.is_a?(URI::Generic)
uri
@@ -170,12 +170,20 @@ class Error < ::StandardError
FormatMessageA = Win32API.new('kernel32.dll', 'FormatMessageA', 'LPLLPLP', 'L')
def initialize(code)
@code = code
msg = WCHAR_NUL * 1024
len = FormatMessageW.call(0x1200, 0, code, 0, msg, 1024, 0)
msg = msg.byteslice(0, len * WCHAR_SIZE)
msg.delete!(WCHAR_CR)
msg.chomp!
super msg.encode(LOCALE)
buff = WCHAR_NUL * 1024
lang = 0
begin
len = FormatMessageW.call(0x1200, 0, code, lang, buff, 1024, 0)
msg = buff.byteslice(0, len * WCHAR_SIZE)
msg.delete!(WCHAR_CR)
msg.chomp!
msg.encode!(LOCALE)
rescue EncodingError
raise unless lang == 0
lang = 0x0409 # en_US
retry
end
super msg
end
attr_reader :code
end

0 comments on commit 27eaf24

Please sign in to comment.