mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/uri] Revert "Fix to support Ruby 3.0 Ractor"
* This reverts commit 1faa4fdc161d7aeebdb5de0c407b923beaecf898.
* It has too many problems, see https://github.com/ruby/uri/pull/22 for discussion.
b959da2dc9
This commit is contained in:
parent
a288c21a5d
commit
090d799c24
12 changed files with 24 additions and 45 deletions
|
@ -29,8 +29,8 @@
|
||||||
# module URI
|
# module URI
|
||||||
# class RSYNC < Generic
|
# class RSYNC < Generic
|
||||||
# DEFAULT_PORT = 873
|
# DEFAULT_PORT = 873
|
||||||
# URI.refresh_scheme_list
|
|
||||||
# end
|
# end
|
||||||
|
# @@schemes['RSYNC'] = RSYNC
|
||||||
# end
|
# end
|
||||||
# #=> URI::RSYNC
|
# #=> URI::RSYNC
|
||||||
#
|
#
|
||||||
|
|
|
@ -16,7 +16,6 @@ module URI
|
||||||
REGEXP = RFC2396_REGEXP
|
REGEXP = RFC2396_REGEXP
|
||||||
Parser = RFC2396_Parser
|
Parser = RFC2396_Parser
|
||||||
RFC3986_PARSER = RFC3986_Parser.new
|
RFC3986_PARSER = RFC3986_Parser.new
|
||||||
Ractor.make_shareable(RFC3986_PARSER) if defined?(Ractor)
|
|
||||||
|
|
||||||
# URI::Parser.new
|
# URI::Parser.new
|
||||||
DEFAULT_PARSER = Parser.new
|
DEFAULT_PARSER = Parser.new
|
||||||
|
@ -28,7 +27,6 @@ module URI
|
||||||
DEFAULT_PARSER.regexp.each_pair do |sym, str|
|
DEFAULT_PARSER.regexp.each_pair do |sym, str|
|
||||||
const_set(sym, str)
|
const_set(sym, str)
|
||||||
end
|
end
|
||||||
Ractor.make_shareable(DEFAULT_PARSER) if defined?(Ractor)
|
|
||||||
|
|
||||||
module Util # :nodoc:
|
module Util # :nodoc:
|
||||||
def make_components_hash(klass, array_hash)
|
def make_components_hash(klass, array_hash)
|
||||||
|
@ -64,30 +62,10 @@ module URI
|
||||||
|
|
||||||
include REGEXP
|
include REGEXP
|
||||||
|
|
||||||
SCHEME_LIST_MUTEX = Mutex.new
|
@@schemes = {}
|
||||||
private_constant :SCHEME_LIST_MUTEX
|
|
||||||
|
|
||||||
# Returns a Hash of the defined schemes.
|
# Returns a Hash of the defined schemes.
|
||||||
# The list is lazily calculated.
|
|
||||||
def self.scheme_list
|
def self.scheme_list
|
||||||
return const_get(:SCHEMES) if defined?(SCHEMES)
|
@@schemes
|
||||||
|
|
||||||
SCHEME_LIST_MUTEX.synchronize do
|
|
||||||
const_set(:SCHEMES, ObjectSpace.
|
|
||||||
each_object(Class).
|
|
||||||
select { |klass| klass < URI::Generic }.
|
|
||||||
each_with_object({}) { |klass, acc| acc[klass.name.split('::').last.upcase] = klass }.
|
|
||||||
freeze)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Re-calculate scheme list
|
|
||||||
def self.refresh_scheme_list
|
|
||||||
SCHEME_LIST_MUTEX.synchronize do
|
|
||||||
remove_const(:SCHEMES) if defined?(SCHEMES)
|
|
||||||
end
|
|
||||||
|
|
||||||
scheme_list
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -95,7 +73,11 @@ module URI
|
||||||
# from +URI.scheme_list+.
|
# from +URI.scheme_list+.
|
||||||
#
|
#
|
||||||
def self.for(scheme, *arguments, default: Generic)
|
def self.for(scheme, *arguments, default: Generic)
|
||||||
uri_class = scheme_list[scheme.to_s.upcase] || default
|
if scheme
|
||||||
|
uri_class = @@schemes[scheme.upcase] || default
|
||||||
|
else
|
||||||
|
uri_class = default
|
||||||
|
end
|
||||||
|
|
||||||
return uri_class.new(scheme, *arguments)
|
return uri_class.new(scheme, *arguments)
|
||||||
end
|
end
|
||||||
|
|
|
@ -89,4 +89,6 @@ module URI
|
||||||
def set_password(v)
|
def set_password(v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@schemes['FILE'] = File
|
||||||
end
|
end
|
||||||
|
|
|
@ -262,4 +262,5 @@ module URI
|
||||||
return str
|
return str
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@schemes['FTP'] = FTP
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,4 +81,7 @@ module URI
|
||||||
url.start_with?(?/.freeze) ? url : ?/ + url
|
url.start_with?(?/.freeze) ? url : ?/ + url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@schemes['HTTP'] = HTTP
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,4 +18,5 @@ module URI
|
||||||
# A Default port of 443 for URI::HTTPS
|
# A Default port of 443 for URI::HTTPS
|
||||||
DEFAULT_PORT = 443
|
DEFAULT_PORT = 443
|
||||||
end
|
end
|
||||||
|
@@schemes['HTTPS'] = HTTPS
|
||||||
end
|
end
|
||||||
|
|
|
@ -256,4 +256,6 @@ module URI
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@schemes['LDAP'] = LDAP
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,4 +17,5 @@ module URI
|
||||||
# A Default port of 636 for URI::LDAPS
|
# A Default port of 636 for URI::LDAPS
|
||||||
DEFAULT_PORT = 636
|
DEFAULT_PORT = 636
|
||||||
end
|
end
|
||||||
|
@@schemes['LDAPS'] = LDAPS
|
||||||
end
|
end
|
||||||
|
|
|
@ -288,4 +288,6 @@ module URI
|
||||||
end
|
end
|
||||||
alias to_rfc822text to_mailtext
|
alias to_rfc822text to_mailtext
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@schemes['MAILTO'] = MailTo
|
||||||
end
|
end
|
||||||
|
|
|
@ -78,4 +78,7 @@ module URI
|
||||||
url.start_with?(?/.freeze) ? url : ?/ + url
|
url.start_with?(?/.freeze) ? url : ?/ + url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@schemes['WS'] = WS
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,4 +18,5 @@ module URI
|
||||||
# A Default port of 443 for URI::WSS
|
# A Default port of 443 for URI::WSS
|
||||||
DEFAULT_PORT = 443
|
DEFAULT_PORT = 443
|
||||||
end
|
end
|
||||||
|
@@schemes['WSS'] = WSS
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,25 +33,6 @@ class TestCommon < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ractor
|
|
||||||
return unless defined?(Ractor)
|
|
||||||
r = Ractor.new { URI.parse("https://ruby-lang.org/").inspect }
|
|
||||||
assert_equal(URI.parse("https://ruby-lang.org/").inspect, r.take)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_register_scheme
|
|
||||||
assert_equal(["FILE", "FTP", "HTTP", "HTTPS", "LDAP", "LDAPS", "MAILTO", "WS"].sort, URI.scheme_list.keys.sort)
|
|
||||||
|
|
||||||
begin
|
|
||||||
URI::Generic.const_set :FOOBAR, Class.new(URI::Generic)
|
|
||||||
URI.refresh_scheme_list
|
|
||||||
assert_equal(["FILE", "FTP", "HTTP", "HTTPS", "LDAP", "LDAPS", "MAILTO", "WS", "FOOBAR"].sort, URI.scheme_list.keys.sort)
|
|
||||||
ensure
|
|
||||||
URI::Generic.send(:remove_const, :FOOBAR)
|
|
||||||
URI.refresh_scheme_list
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_regexp
|
def test_regexp
|
||||||
EnvUtil.suppress_warning do
|
EnvUtil.suppress_warning do
|
||||||
assert_instance_of Regexp, URI.regexp
|
assert_instance_of Regexp, URI.regexp
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue