mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/uri.rb: Documented (thanks Dmitry V. Sabanin).
* lib/uri/common.rb: Ditto. * lib/uri/ftp.rb: Ditto. * lib/uri/generic.rb: Ditto. * lib/uri/http.rb: Ditto. * lib/uri/https.rb: Ditto. * lib/uri/ldap.rb: Ditto. * lib/uri/mailto.rb: Ditto. (All backported from 1.9) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6016 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
87d0ac02d4
commit
30d4c49b46
9 changed files with 968 additions and 968 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
||||||
|
Wed Mar 24 21:17:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
|
||||||
|
|
||||||
|
* lib/uri.rb: Documented (thanks Dmitry V. Sabanin).
|
||||||
|
* lib/uri/common.rb: Ditto.
|
||||||
|
* lib/uri/ftp.rb: Ditto.
|
||||||
|
* lib/uri/generic.rb: Ditto.
|
||||||
|
* lib/uri/http.rb: Ditto.
|
||||||
|
* lib/uri/https.rb: Ditto.
|
||||||
|
* lib/uri/ldap.rb: Ditto.
|
||||||
|
* lib/uri/mailto.rb: Ditto.
|
||||||
|
(All backported from 1.9)
|
||||||
|
|
||||||
Wed Mar 24 18:48:26 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Mar 24 18:48:26 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/mkmf.rb ($ruby, $topdir, $hdrdir): should not be affected by
|
* lib/mkmf.rb ($ruby, $topdir, $hdrdir): should not be affected by
|
||||||
|
|
32
lib/uri.rb
32
lib/uri.rb
|
@ -1,37 +1,23 @@
|
||||||
#
|
#
|
||||||
# $Id$
|
# = uri.rb
|
||||||
#
|
#
|
||||||
|
# URI support for Ruby
|
||||||
|
#
|
||||||
|
# Author:: Akira Yamada <akira@ruby-lang.org>
|
||||||
|
# Documentation:: Akira Yamada <akira@ruby-lang.org>, Dmitry V. Sabanin <sdmitry@lrn.ru>
|
||||||
|
# License::
|
||||||
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
|
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
|
||||||
# You can redistribute it and/or modify it under the same term as Ruby.
|
# You can redistribute it and/or modify it under the same term as Ruby.
|
||||||
|
# Revision:: $Id$
|
||||||
|
#
|
||||||
|
# See URI for documentation
|
||||||
#
|
#
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
|
|
||||||
You can redistribute it and/or modify it under the same term as Ruby.
|
|
||||||
|
|
||||||
= URI - URI support for Ruby
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
module URI
|
module URI
|
||||||
VERSION_CODE = '000911'.freeze
|
VERSION_CODE = '000911'.freeze
|
||||||
VERSION = VERSION_CODE.scan(/../).collect{|n| n.to_i}.join('.').freeze
|
VERSION = VERSION_CODE.scan(/../).collect{|n| n.to_i}.join('.').freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
== Components
|
|
||||||
|
|
||||||
* ((<URI>)) Module
|
|
||||||
* ((<URI::Generic>)) Class
|
|
||||||
* ((<URI::FTP>)) Class
|
|
||||||
* ((<URI::HTTP>)) Class
|
|
||||||
* ((<URI::HTTPS>)) Class
|
|
||||||
* ((<URI::LDAP>)) Class
|
|
||||||
* ((<URI::MailTo>)) Class
|
|
||||||
|
|
||||||
=end
|
|
||||||
require 'uri/common'
|
require 'uri/common'
|
||||||
require 'uri/generic'
|
require 'uri/generic'
|
||||||
require 'uri/ftp'
|
require 'uri/ftp'
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
|
# = uri/common.rb
|
||||||
#
|
#
|
||||||
# $Id$
|
# Author:: Akira Yamada <akira@ruby-lang.org>
|
||||||
#
|
# Revision:: $Id$
|
||||||
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
|
# License::
|
||||||
# You can redistribute it and/or modify it under the same term as Ruby.
|
# You can redistribute it and/or modify it under the same term as Ruby.
|
||||||
#
|
#
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
== URI
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
module URI
|
module URI
|
||||||
module REGEXP
|
module REGEXP
|
||||||
|
#
|
||||||
|
# Patterns used to parse URI's
|
||||||
|
#
|
||||||
module PATTERN
|
module PATTERN
|
||||||
|
# :stopdoc:
|
||||||
|
|
||||||
# RFC 2396 (URI Generic Syntax)
|
# RFC 2396 (URI Generic Syntax)
|
||||||
# RFC 2732 (IPv6 Literal Addresses in URL's)
|
# RFC 2732 (IPv6 Literal Addresses in URL's)
|
||||||
# RFC 2373 (IPv6 Addressing Architecture)
|
# RFC 2373 (IPv6 Addressing Architecture)
|
||||||
|
@ -179,8 +179,11 @@ module URI
|
||||||
(?:\\?(#{PATTERN::QUERY}))? (?# 7: query)
|
(?:\\?(#{PATTERN::QUERY}))? (?# 7: query)
|
||||||
(?:\\#(#{PATTERN::FRAGMENT}))? (?# 8: fragment)
|
(?:\\#(#{PATTERN::FRAGMENT}))? (?# 8: fragment)
|
||||||
"
|
"
|
||||||
|
# :startdoc:
|
||||||
end # PATTERN
|
end # PATTERN
|
||||||
|
|
||||||
|
# :stopdoc:
|
||||||
|
|
||||||
# for URI::split
|
# for URI::split
|
||||||
ABS_URI = Regexp.new('^' + PATTERN::X_ABS_URI + '$', #'
|
ABS_URI = Regexp.new('^' + PATTERN::X_ABS_URI + '$', #'
|
||||||
Regexp::EXTENDED, 'N').freeze
|
Regexp::EXTENDED, 'N').freeze
|
||||||
|
@ -208,6 +211,7 @@ module URI
|
||||||
REL_PATH = Regexp.new("^#{PATTERN::REL_PATH}$", false, 'N').freeze #"
|
REL_PATH = Regexp.new("^#{PATTERN::REL_PATH}$", false, 'N').freeze #"
|
||||||
QUERY = Regexp.new("^#{PATTERN::QUERY}$", false, 'N').freeze #"
|
QUERY = Regexp.new("^#{PATTERN::QUERY}$", false, 'N').freeze #"
|
||||||
FRAGMENT = Regexp.new("^#{PATTERN::FRAGMENT}$", false, 'N').freeze #"
|
FRAGMENT = Regexp.new("^#{PATTERN::FRAGMENT}$", false, 'N').freeze #"
|
||||||
|
# :startdoc:
|
||||||
end # REGEXP
|
end # REGEXP
|
||||||
|
|
||||||
module Util
|
module Util
|
||||||
|
@ -245,6 +249,34 @@ module URI
|
||||||
module Escape
|
module Escape
|
||||||
include REGEXP
|
include REGEXP
|
||||||
|
|
||||||
|
#
|
||||||
|
# == Synopsis
|
||||||
|
#
|
||||||
|
# URI.escape(str [, unsafe])
|
||||||
|
#
|
||||||
|
# == Args
|
||||||
|
#
|
||||||
|
# +str+::
|
||||||
|
# String to replaces in.
|
||||||
|
# +unsafe+::
|
||||||
|
# Regexp that matches all symbols that must be replaced with codes.
|
||||||
|
# By default uses <tt>REGEXP::SAFE</tt>.
|
||||||
|
#
|
||||||
|
# == Description
|
||||||
|
#
|
||||||
|
# Escapes the string, replacing all unsafe characters with codes.
|
||||||
|
#
|
||||||
|
# == Usage
|
||||||
|
#
|
||||||
|
# require 'uri'
|
||||||
|
#
|
||||||
|
# enc_uri = URI.escape("http://foobar.com/?a=\11\15")
|
||||||
|
# p enc_uri
|
||||||
|
# # => "http://foobar.com/?a=%09%0D"
|
||||||
|
#
|
||||||
|
# p URI.unescape(enc_uri)
|
||||||
|
# # => "http://foobar.com/?a=\t\r"
|
||||||
|
#
|
||||||
def escape(str, unsafe = UNSAFE)
|
def escape(str, unsafe = UNSAFE)
|
||||||
unless unsafe.kind_of?(Regexp)
|
unless unsafe.kind_of?(Regexp)
|
||||||
# perhaps unsafe is String object
|
# perhaps unsafe is String object
|
||||||
|
@ -259,7 +291,27 @@ module URI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias encode escape
|
alias encode escape
|
||||||
|
#
|
||||||
|
# == Synopsis
|
||||||
|
#
|
||||||
|
# URI.unescape(str)
|
||||||
|
#
|
||||||
|
# == Args
|
||||||
|
#
|
||||||
|
# +str+::
|
||||||
|
# Unescapes the string.
|
||||||
|
#
|
||||||
|
# == Usage
|
||||||
|
#
|
||||||
|
# require 'uri'
|
||||||
|
#
|
||||||
|
# enc_uri = URI.escape("http://foobar.com/?a=\11\15")
|
||||||
|
# p enc_uri
|
||||||
|
# # => "http://foobar.com/?a=%09%0D"
|
||||||
|
#
|
||||||
|
# p URI.unescape(enc_uri)
|
||||||
|
# # => "http://foobar.com/?a=\t\r"
|
||||||
|
#
|
||||||
def unescape(str)
|
def unescape(str)
|
||||||
str.gsub(ESCAPED) do
|
str.gsub(ESCAPED) do
|
||||||
$&[1,2].hex.chr
|
$&[1,2].hex.chr
|
||||||
|
@ -273,19 +325,54 @@ module URI
|
||||||
|
|
||||||
@@schemes = {}
|
@@schemes = {}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Base class for all URI exceptions.
|
||||||
|
#
|
||||||
class Error < StandardError; end
|
class Error < StandardError; end
|
||||||
class InvalidURIError < Error; end # it is not URI.
|
#
|
||||||
class InvalidComponentError < Error; end # it is not component of URI.
|
# Not a URI.
|
||||||
class BadURIError < Error; end # the URI is valid but it is bad for the position.
|
#
|
||||||
|
class InvalidURIError < Error; end
|
||||||
=begin
|
#
|
||||||
|
# Not a URI component.
|
||||||
=== Methods
|
#
|
||||||
|
class InvalidComponentError < Error; end
|
||||||
--- URI::split(uri)
|
#
|
||||||
|
# URI is valid, bad usage is not.
|
||||||
=end
|
#
|
||||||
|
class BadURIError < Error; end
|
||||||
|
|
||||||
|
#
|
||||||
|
# == Synopsis
|
||||||
|
#
|
||||||
|
# URI::split(uri)
|
||||||
|
#
|
||||||
|
# == Args
|
||||||
|
#
|
||||||
|
# +uri+::
|
||||||
|
# String with URI.
|
||||||
|
#
|
||||||
|
# == Description
|
||||||
|
#
|
||||||
|
# Splits the string on following parts and returns array with result:
|
||||||
|
#
|
||||||
|
# * Scheme
|
||||||
|
# * Userinfo
|
||||||
|
# * Host
|
||||||
|
# * Port
|
||||||
|
# * Registry
|
||||||
|
# * Path
|
||||||
|
# * Opaque
|
||||||
|
# * Query
|
||||||
|
# * Fragment
|
||||||
|
#
|
||||||
|
# == Usage
|
||||||
|
#
|
||||||
|
# require 'uri'
|
||||||
|
#
|
||||||
|
# p URI.split("http://www.ruby-lang.org/")
|
||||||
|
# # => ["http", nil, "www.ruby-lang.org", nil, nil, "/", nil, nil, nil]
|
||||||
|
#
|
||||||
def self.split(uri)
|
def self.split(uri)
|
||||||
case uri
|
case uri
|
||||||
when ''
|
when ''
|
||||||
|
@ -358,11 +445,37 @@ module URI
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
# == Synopsis
|
||||||
--- URI::parse(uri_str)
|
#
|
||||||
|
# URI::parse(uri_str)
|
||||||
=end
|
#
|
||||||
|
# == Args
|
||||||
|
#
|
||||||
|
# +uri_str+::
|
||||||
|
# String with URI.
|
||||||
|
#
|
||||||
|
# == Description
|
||||||
|
#
|
||||||
|
# Creates one of the URI's subclasses instance from the string.
|
||||||
|
#
|
||||||
|
# == Raises
|
||||||
|
#
|
||||||
|
# URI::InvalidURIError
|
||||||
|
# Raised if URI given is not a correct one.
|
||||||
|
#
|
||||||
|
# == Usage
|
||||||
|
#
|
||||||
|
# require 'uri'
|
||||||
|
#
|
||||||
|
# uri = URI.parse("http://www.ruby-lang.org/")
|
||||||
|
# p uri
|
||||||
|
# # => #<URI::HTTP:0x202281be URL:http://www.ruby-lang.org/>
|
||||||
|
# p uri.scheme
|
||||||
|
# # => "http"
|
||||||
|
# p uri.host
|
||||||
|
# # => "www.ruby-lang.org"
|
||||||
|
#
|
||||||
def self.parse(uri)
|
def self.parse(uri)
|
||||||
scheme, userinfo, host, port,
|
scheme, userinfo, host, port,
|
||||||
registry, path, opaque, query, fragment = self.split(uri)
|
registry, path, opaque, query, fragment = self.split(uri)
|
||||||
|
@ -378,11 +491,27 @@ module URI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
# == Synopsis
|
||||||
--- URI::join(str[, str, ...])
|
#
|
||||||
|
# URI::join(str[, str, ...])
|
||||||
=end
|
#
|
||||||
|
# == Args
|
||||||
|
#
|
||||||
|
# +str+::
|
||||||
|
# String(s) to work with
|
||||||
|
#
|
||||||
|
# == Description
|
||||||
|
#
|
||||||
|
# Joins URIs.
|
||||||
|
#
|
||||||
|
# == Usage
|
||||||
|
#
|
||||||
|
# require 'uri'
|
||||||
|
#
|
||||||
|
# p URI.join("http:/localhost/","main.rbx")
|
||||||
|
# # => #<URI::HTTP:0x2022ac02 URL:http:/localhost/main.php>
|
||||||
|
#
|
||||||
def self.join(*str)
|
def self.join(*str)
|
||||||
u = self.parse(str[0])
|
u = self.parse(str[0])
|
||||||
str[1 .. -1].each do |x|
|
str[1 .. -1].each do |x|
|
||||||
|
@ -391,11 +520,30 @@ module URI
|
||||||
u
|
u
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
# == Synopsis
|
||||||
--- URI::extract(str[, schemes])
|
#
|
||||||
|
# URI::extract(str[, schemes][,&blk])
|
||||||
=end
|
#
|
||||||
|
# == Args
|
||||||
|
#
|
||||||
|
# +str+::
|
||||||
|
# String to extract URIs from.
|
||||||
|
# +schemes+::
|
||||||
|
# Limit URI matching to a specific schemes.
|
||||||
|
#
|
||||||
|
# == Description
|
||||||
|
#
|
||||||
|
# Extracts URIs from a string. If block given, iterates through all matched URIs.
|
||||||
|
# Returns nil if block given or array with matches.
|
||||||
|
#
|
||||||
|
# == Usage
|
||||||
|
#
|
||||||
|
# require "uri"
|
||||||
|
#
|
||||||
|
# URI.extract("text here http://foo.bar.org/bla and here mailto:test@ruby.com and here also.")
|
||||||
|
# # => ["http://foo.bar.com/foobar", "mailto:foo@bar.com"]
|
||||||
|
#
|
||||||
def self.extract(str, schemes = nil, &block)
|
def self.extract(str, schemes = nil, &block)
|
||||||
if block_given?
|
if block_given?
|
||||||
str.scan(regexp(schemes)) { yield $& }
|
str.scan(regexp(schemes)) { yield $& }
|
||||||
|
@ -407,30 +555,37 @@ module URI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
# == Synopsis
|
||||||
--- URI::regexp([match_schemes])
|
#
|
||||||
|
# URI::regexp([match_schemes])
|
||||||
Returns a Regexp object which matches to URI-like strings.
|
#
|
||||||
If MATCH_SCHEMES given, resulting regexp matches to URIs
|
# == Args
|
||||||
whose scheme is one of the MATCH_SCHEMES.
|
#
|
||||||
|
# +match_schemes+::
|
||||||
The Regexp object returned by this method includes arbitrary
|
# Array of schemes. If given, resulting regexp matches to URIs
|
||||||
number of capture group (parentheses). Never rely on its
|
# whose scheme is one of the match_schemes.
|
||||||
number.
|
#
|
||||||
|
# == Description
|
||||||
# extract first URI from html_string
|
# Returns a Regexp object which matches to URI-like strings.
|
||||||
html_string.slice(URI.regexp)
|
# The Regexp object returned by this method includes arbitrary
|
||||||
|
# number of capture group (parentheses). Never rely on it's number.
|
||||||
# remove ftp URIs
|
#
|
||||||
html_string.sub(URI.regexp(['ftp'])
|
# == Usage
|
||||||
|
#
|
||||||
# You should not rely on the number of parentheses
|
# require 'uri'
|
||||||
html_string.scan(URI.regexp) do |*matches|
|
#
|
||||||
p $&
|
# # extract first URI from html_string
|
||||||
end
|
# html_string.slice(URI.regexp)
|
||||||
|
#
|
||||||
=end
|
# # remove ftp URIs
|
||||||
|
# html_string.sub(URI.regexp(['ftp'])
|
||||||
|
#
|
||||||
|
# # You should not rely on the number of parentheses
|
||||||
|
# html_string.scan(URI.regexp) do |*matches|
|
||||||
|
# p $&
|
||||||
|
# end
|
||||||
|
#
|
||||||
def self.regexp(schemes = nil)
|
def self.regexp(schemes = nil)
|
||||||
unless schemes
|
unless schemes
|
||||||
ABS_URI_REF
|
ABS_URI_REF
|
||||||
|
@ -439,4 +594,4 @@ module URI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end # URI
|
end
|
||||||
|
|
|
@ -1,25 +1,18 @@
|
||||||
#
|
#
|
||||||
# $Id$
|
# = uri/ftp.rb
|
||||||
#
|
#
|
||||||
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
|
# Author:: Akira Yamada <akira@ruby-lang.org>
|
||||||
# You can redistribute it and/or modify it under the same term as Ruby.
|
# License:: You can redistribute it and/or modify it under the same term as Ruby.
|
||||||
|
# Revision:: $Id$
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'uri/generic'
|
require 'uri/generic'
|
||||||
|
|
||||||
module URI
|
module URI
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
|
||||||
== URI::FTP
|
|
||||||
|
|
||||||
=== Super Class
|
|
||||||
|
|
||||||
((<URI::Generic>))
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
# RFC1738 section 3.2.
|
# RFC1738 section 3.2.
|
||||||
|
#
|
||||||
class FTP < Generic
|
class FTP < Generic
|
||||||
DEFAULT_PORT = 21
|
DEFAULT_PORT = 21
|
||||||
|
|
||||||
|
@ -28,25 +21,17 @@ module URI
|
||||||
:userinfo, :host, :port,
|
:userinfo, :host, :port,
|
||||||
:path, :typecode
|
:path, :typecode
|
||||||
].freeze
|
].freeze
|
||||||
|
#
|
||||||
|
# Typecode is, "a", "i" or "d".
|
||||||
|
# As for "a" the text, as for "i" binary,
|
||||||
|
# as for "d" the directory is displayed.
|
||||||
|
# "A" with the text, as for "i" being binary,
|
||||||
|
# is because the respective data type was called ASCII and
|
||||||
|
# IMAGE with the protocol of FTP.
|
||||||
|
#
|
||||||
TYPECODE = ['a', 'i', 'd'].freeze
|
TYPECODE = ['a', 'i', 'd'].freeze
|
||||||
TYPECODE_PREFIX = ';type='.freeze
|
TYPECODE_PREFIX = ';type='.freeze
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
=== Class Methods
|
|
||||||
|
|
||||||
--- URI::FTP::build
|
|
||||||
Create a new URI::FTP object from components of URI::FTP with
|
|
||||||
check. It is scheme, userinfo, host, port, path and typecode. It
|
|
||||||
provided by an Array or a Hash. typecode is "a", "i" or "d".
|
|
||||||
|
|
||||||
--- URI::FTP::new
|
|
||||||
Create a new URI::FTP object from ``generic'' components with no
|
|
||||||
check.
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
def self.new2(user, password, host, port, path,
|
def self.new2(user, password, host, port, path,
|
||||||
typecode = nil, arg_check = true)
|
typecode = nil, arg_check = true)
|
||||||
typecode = nil if typecode.size == 0
|
typecode = nil if typecode.size == 0
|
||||||
|
@ -64,6 +49,13 @@ module URI
|
||||||
nil, nil, nil, arg_check)
|
nil, nil, nil, arg_check)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# == Description
|
||||||
|
#
|
||||||
|
# Creates a new URI::FTP object from components of URI::FTP with
|
||||||
|
# check. It is scheme, userinfo, host, port, path and typecode. It
|
||||||
|
# provided by an Array or a Hash. typecode is "a", "i" or "d".
|
||||||
|
#
|
||||||
def self.build(args)
|
def self.build(args)
|
||||||
tmp = Util::make_components_hash(self, args)
|
tmp = Util::make_components_hash(self, args)
|
||||||
|
|
||||||
|
@ -77,6 +69,20 @@ module URI
|
||||||
return super(tmp)
|
return super(tmp)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# == Description
|
||||||
|
#
|
||||||
|
# Create a new URI::FTP object from ``generic'' components with no
|
||||||
|
# check.
|
||||||
|
#
|
||||||
|
# == Usage
|
||||||
|
#
|
||||||
|
# require 'uri'
|
||||||
|
# p ftp = URI.parse("ftp://ftp.ruby-lang.org/pub/ruby/;type=d")
|
||||||
|
# # => #<URI::FTP:0x201fad08 URL:ftp://ftp.ruby-lang.org/pub/ruby/;type=d>
|
||||||
|
# p ftp.typecode
|
||||||
|
# # => "d"
|
||||||
|
#
|
||||||
def initialize(*arg)
|
def initialize(*arg)
|
||||||
super(*arg)
|
super(*arg)
|
||||||
@typecode = nil
|
@typecode = nil
|
||||||
|
@ -94,10 +100,6 @@ module URI
|
||||||
end
|
end
|
||||||
attr_reader :typecode
|
attr_reader :typecode
|
||||||
|
|
||||||
#
|
|
||||||
# methods for typecode
|
|
||||||
#
|
|
||||||
|
|
||||||
def check_typecode(v)
|
def check_typecode(v)
|
||||||
if TYPECODE.include?(v)
|
if TYPECODE.include?(v)
|
||||||
return true
|
return true
|
||||||
|
@ -119,9 +121,7 @@ module URI
|
||||||
typecode
|
typecode
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
def merge(oth) # :nodoc:
|
||||||
=end
|
|
||||||
def merge(oth)
|
|
||||||
tmp = super(oth)
|
tmp = super(oth)
|
||||||
if self != tmp
|
if self != tmp
|
||||||
tmp.set_typecode(oth.typecode)
|
tmp.set_typecode(oth.typecode)
|
||||||
|
@ -130,8 +130,6 @@ module URI
|
||||||
return tmp
|
return tmp
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
=end
|
|
||||||
def to_s
|
def to_s
|
||||||
save_path = nil
|
save_path = nil
|
||||||
if @typecode
|
if @typecode
|
||||||
|
@ -145,6 +143,6 @@ module URI
|
||||||
|
|
||||||
return str
|
return str
|
||||||
end
|
end
|
||||||
end # FTP
|
end
|
||||||
@@schemes['FTP'] = FTP
|
@@schemes['FTP'] = FTP
|
||||||
end # URI
|
end
|
||||||
|
|
|
@ -1,37 +1,27 @@
|
||||||
#
|
#
|
||||||
# $Id$
|
# = uri/generic.rb
|
||||||
#
|
#
|
||||||
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
|
# Author:: Akira Yamada <akira@ruby-lang.org>
|
||||||
# You can redistribute it and/or modify it under the same term as Ruby.
|
# License:: You can redistribute it and/or modify it under the same term as Ruby.
|
||||||
|
# Revision:: $Id$
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'uri/common'
|
require 'uri/common'
|
||||||
|
|
||||||
module URI
|
module URI
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
# Base class for all URI classes.
|
||||||
== URI::Generic
|
#
|
||||||
|
|
||||||
=== Super Class
|
|
||||||
|
|
||||||
Object
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
class Generic
|
class Generic
|
||||||
include URI
|
include URI
|
||||||
include REGEXP
|
include REGEXP
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
=== Class Methods
|
|
||||||
|
|
||||||
--- URI::Generic::default_port
|
|
||||||
|
|
||||||
=end
|
|
||||||
DEFAULT_PORT = nil
|
DEFAULT_PORT = nil
|
||||||
|
|
||||||
|
#
|
||||||
|
# Returns default port
|
||||||
|
#
|
||||||
def self.default_port
|
def self.default_port
|
||||||
self::DEFAULT_PORT
|
self::DEFAULT_PORT
|
||||||
end
|
end
|
||||||
|
@ -40,9 +30,6 @@ Object
|
||||||
self.class.default_port
|
self.class.default_port
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
--- URI::Generic::component
|
|
||||||
=end
|
|
||||||
COMPONENT = [
|
COMPONENT = [
|
||||||
:scheme,
|
:scheme,
|
||||||
:userinfo, :host, :port, :registry,
|
:userinfo, :host, :port, :registry,
|
||||||
|
@ -51,37 +38,34 @@ Object
|
||||||
:fragment
|
:fragment
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
|
#
|
||||||
|
# Components of the URI in the order.
|
||||||
|
#
|
||||||
def self.component
|
def self.component
|
||||||
self::COMPONENT
|
self::COMPONENT
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
--- URI::Generic::use_registry
|
|
||||||
=end
|
|
||||||
USE_REGISTRY = false
|
USE_REGISTRY = false
|
||||||
|
|
||||||
|
#
|
||||||
|
# DOC: FIXME!
|
||||||
|
#
|
||||||
def self.use_registry
|
def self.use_registry
|
||||||
self::USE_REGISTRY
|
self::USE_REGISTRY
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
# == Synopsis
|
||||||
--- URI::Generic::build2
|
#
|
||||||
At first, try to create a new URI::Generic object using
|
# See #new
|
||||||
URI::Generic::build. But, if you get a exception
|
#
|
||||||
URI::InvalidComponentError, then re-try to create an object with
|
# == Description
|
||||||
escaped components.
|
#
|
||||||
|
# At first, tries to create a new URI::Generic instance using
|
||||||
--- URI::Generic::build
|
# URI::Generic::build. But, if exception URI::InvalidComponentError is raised,
|
||||||
Create a new URI::Generic object from components of URI::Generic
|
# then it URI::Escape.escape all URI components and tries again.
|
||||||
with check. It is scheme, userinfo, host, port, registry, path,
|
#
|
||||||
opaque, query and fragment. It provided by an Array of a Hash.
|
#
|
||||||
|
|
||||||
--- URI::Generic::new
|
|
||||||
Create new URI::Generic object from ``generic'' components with no
|
|
||||||
check.
|
|
||||||
|
|
||||||
=end
|
|
||||||
def self.build2(args)
|
def self.build2(args)
|
||||||
begin
|
begin
|
||||||
return self.build(args)
|
return self.build(args)
|
||||||
|
@ -108,6 +92,18 @@ Object
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# == Synopsis
|
||||||
|
#
|
||||||
|
# See #new
|
||||||
|
#
|
||||||
|
# == Description
|
||||||
|
#
|
||||||
|
# Creates a new URI::Generic instance from components of URI::Generic
|
||||||
|
# with check. Components are: scheme, userinfo, host, port, registry, path,
|
||||||
|
# opaque, query and fragment. You can provide arguments either by an Array or a Hash.
|
||||||
|
# See #new for hash keys to use or for order of array items.
|
||||||
|
#
|
||||||
def self.build(args)
|
def self.build(args)
|
||||||
if args.kind_of?(Array) &&
|
if args.kind_of?(Array) &&
|
||||||
args.size == ::URI::Generic::COMPONENT.size
|
args.size == ::URI::Generic::COMPONENT.size
|
||||||
|
@ -128,7 +124,34 @@ Object
|
||||||
tmp << true
|
tmp << true
|
||||||
return self.new(*tmp)
|
return self.new(*tmp)
|
||||||
end
|
end
|
||||||
|
#
|
||||||
|
# == Args
|
||||||
|
#
|
||||||
|
# +scheme+::
|
||||||
|
# Protocol scheme, i.e. 'http','ftp','mailto' and so on.
|
||||||
|
# +userinfo+::
|
||||||
|
# User name and password, i.e. 'sdmitry:bla'
|
||||||
|
# +host+::
|
||||||
|
# Server host name
|
||||||
|
# +port+::
|
||||||
|
# Server port
|
||||||
|
# +registry+::
|
||||||
|
# DOC: FIXME!
|
||||||
|
# +path+::
|
||||||
|
# Path on server
|
||||||
|
# +opaque+::
|
||||||
|
# DOC: FIXME!
|
||||||
|
# +query+::
|
||||||
|
# Query data
|
||||||
|
# +fragment+::
|
||||||
|
# A part of URI after '#' sign
|
||||||
|
# +arg_check+::
|
||||||
|
# Check arguments [false by default]
|
||||||
|
#
|
||||||
|
# == Description
|
||||||
|
#
|
||||||
|
# Creates a new URI::Generic instance from ``generic'' components without check.
|
||||||
|
#
|
||||||
def initialize(scheme,
|
def initialize(scheme,
|
||||||
userinfo, host, port, registry,
|
userinfo, host, port, registry,
|
||||||
path, opaque,
|
path, opaque,
|
||||||
|
@ -168,7 +191,8 @@ Object
|
||||||
self.set_fragment(fragment)
|
self.set_fragment(fragment)
|
||||||
end
|
end
|
||||||
if @registry && !self.class.use_registry
|
if @registry && !self.class.use_registry
|
||||||
raise InvalidURIError, "the scheme #{@scheme} does not accept registry part: #{@registry} (or bad hostname?)"
|
raise InvalidURIError,
|
||||||
|
"the scheme #{@scheme} does not accept registry part: #{@registry} (or bad hostname?)"
|
||||||
end
|
end
|
||||||
|
|
||||||
@scheme.freeze if @scheme
|
@scheme.freeze if @scheme
|
||||||
|
@ -196,35 +220,10 @@ Object
|
||||||
end
|
end
|
||||||
private :replace!
|
private :replace!
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
=== Instance Methods
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::Generic#component
|
|
||||||
|
|
||||||
=end
|
|
||||||
def component
|
def component
|
||||||
self.class.component
|
self.class.component
|
||||||
end
|
end
|
||||||
|
|
||||||
# set_XXX method sets value to @XXX instance variable with no check,
|
|
||||||
# so be careful if you use these methods. or, you use these method
|
|
||||||
# with check_XXX method, or you use XXX= methods.
|
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::Generic#scheme
|
|
||||||
|
|
||||||
--- URI::Generic#scheme=(v)
|
|
||||||
|
|
||||||
=end
|
|
||||||
#
|
|
||||||
# methods for scheme
|
|
||||||
#
|
|
||||||
def check_scheme(v)
|
def check_scheme(v)
|
||||||
if v && SCHEME !~ v
|
if v && SCHEME !~ v
|
||||||
raise InvalidComponentError,
|
raise InvalidComponentError,
|
||||||
|
@ -246,24 +245,6 @@ Object
|
||||||
v
|
v
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::Generic#userinfo
|
|
||||||
|
|
||||||
--- URI::Generic#userinfo=(v)
|
|
||||||
|
|
||||||
--- URI::Generic#user
|
|
||||||
|
|
||||||
--- URI::Generic#user=(v)
|
|
||||||
|
|
||||||
--- URI::Generic#password
|
|
||||||
|
|
||||||
--- URI::Generic#password=(v)
|
|
||||||
|
|
||||||
=end
|
|
||||||
#
|
|
||||||
# methods for userinfo
|
|
||||||
#
|
|
||||||
def check_userinfo(user, password = nil)
|
def check_userinfo(user, password = nil)
|
||||||
if !password
|
if !password
|
||||||
user, password = split_userinfo(user)
|
user, password = split_userinfo(user)
|
||||||
|
@ -313,6 +294,9 @@ Object
|
||||||
end
|
end
|
||||||
private :check_password
|
private :check_password
|
||||||
|
|
||||||
|
#
|
||||||
|
# Sets userinfo, argument is string like 'name:pass'
|
||||||
|
#
|
||||||
def userinfo=(userinfo)
|
def userinfo=(userinfo)
|
||||||
if userinfo.nil?
|
if userinfo.nil?
|
||||||
return nil
|
return nil
|
||||||
|
@ -393,17 +377,6 @@ Object
|
||||||
@password
|
@password
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::Generic#host
|
|
||||||
|
|
||||||
--- URI::Generic#host=(v)
|
|
||||||
|
|
||||||
=end
|
|
||||||
#
|
|
||||||
# methods for host
|
|
||||||
#
|
|
||||||
|
|
||||||
def check_host(v)
|
def check_host(v)
|
||||||
return v unless v
|
return v unless v
|
||||||
|
|
||||||
|
@ -430,17 +403,6 @@ Object
|
||||||
v
|
v
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::Generic#port
|
|
||||||
|
|
||||||
--- URI::Generic#port=(v)
|
|
||||||
|
|
||||||
=end
|
|
||||||
#
|
|
||||||
# methods for port
|
|
||||||
#
|
|
||||||
|
|
||||||
def check_port(v)
|
def check_port(v)
|
||||||
return v unless v
|
return v unless v
|
||||||
|
|
||||||
|
@ -474,17 +436,6 @@ Object
|
||||||
port
|
port
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::Generic#registry
|
|
||||||
|
|
||||||
--- URI::Generic#registry=(v)
|
|
||||||
|
|
||||||
=end
|
|
||||||
#
|
|
||||||
# methods for registry
|
|
||||||
#
|
|
||||||
|
|
||||||
def check_registry(v)
|
def check_registry(v)
|
||||||
return v unless v
|
return v unless v
|
||||||
|
|
||||||
|
@ -514,17 +465,6 @@ Object
|
||||||
v
|
v
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::Generic#path
|
|
||||||
|
|
||||||
--- URI::Generic#path=(v)
|
|
||||||
|
|
||||||
=end
|
|
||||||
#
|
|
||||||
# methods for path
|
|
||||||
#
|
|
||||||
|
|
||||||
def check_path(v)
|
def check_path(v)
|
||||||
# raise if both hier and opaque are not nil, because:
|
# raise if both hier and opaque are not nil, because:
|
||||||
# absoluteURI = scheme ":" ( hier_part | opaque_part )
|
# absoluteURI = scheme ":" ( hier_part | opaque_part )
|
||||||
|
@ -561,17 +501,6 @@ Object
|
||||||
v
|
v
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::Generic#query
|
|
||||||
|
|
||||||
--- URI::Generic#query=(v)
|
|
||||||
|
|
||||||
=end
|
|
||||||
#
|
|
||||||
# methods for query
|
|
||||||
#
|
|
||||||
|
|
||||||
def check_query(v)
|
def check_query(v)
|
||||||
return v unless v
|
return v unless v
|
||||||
|
|
||||||
|
@ -603,17 +532,6 @@ Object
|
||||||
v
|
v
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::Generic#opaque
|
|
||||||
|
|
||||||
--- URI::Generic#opaque=(v)
|
|
||||||
|
|
||||||
=end
|
|
||||||
#
|
|
||||||
# methods for opaque
|
|
||||||
#
|
|
||||||
|
|
||||||
def check_opaque(v)
|
def check_opaque(v)
|
||||||
return v unless v
|
return v unless v
|
||||||
|
|
||||||
|
@ -643,17 +561,6 @@ Object
|
||||||
v
|
v
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::Generic#fragment
|
|
||||||
|
|
||||||
--- URI::Generic#fragment=(v)
|
|
||||||
|
|
||||||
=end
|
|
||||||
#
|
|
||||||
# methods for fragment
|
|
||||||
#
|
|
||||||
|
|
||||||
def check_fragment(v)
|
def check_fragment(v)
|
||||||
return v unless v
|
return v unless v
|
||||||
|
|
||||||
|
@ -677,11 +584,9 @@ Object
|
||||||
v
|
v
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
# Checks if URI has a path
|
||||||
--- URI::Generic#hierarchical?
|
#
|
||||||
|
|
||||||
=end
|
|
||||||
def hierarchical?
|
def hierarchical?
|
||||||
if @path
|
if @path
|
||||||
true
|
true
|
||||||
|
@ -690,11 +595,9 @@ Object
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
# Checks if URI is an absolute one
|
||||||
--- URI::Generic#absolute?
|
#
|
||||||
|
|
||||||
=end
|
|
||||||
def absolute?
|
def absolute?
|
||||||
if @scheme
|
if @scheme
|
||||||
true
|
true
|
||||||
|
@ -704,22 +607,13 @@ Object
|
||||||
end
|
end
|
||||||
alias absolute absolute?
|
alias absolute absolute?
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
# Checks if URI is relative
|
||||||
--- URI::Generic#relative?
|
#
|
||||||
|
|
||||||
=end
|
|
||||||
def relative?
|
def relative?
|
||||||
!absolute?
|
!absolute?
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::Generic#merge(rel)
|
|
||||||
--- URI::Generic#merge!(rel)
|
|
||||||
--- URI::Generic#+(rel)
|
|
||||||
|
|
||||||
=end
|
|
||||||
def split_path(path)
|
def split_path(path)
|
||||||
path.split(%r{/+}, -1)
|
path.split(%r{/+}, -1)
|
||||||
end
|
end
|
||||||
|
@ -784,6 +678,25 @@ Object
|
||||||
end
|
end
|
||||||
private :merge_path
|
private :merge_path
|
||||||
|
|
||||||
|
#
|
||||||
|
# == Args
|
||||||
|
#
|
||||||
|
# +oth+::
|
||||||
|
# URI or String
|
||||||
|
#
|
||||||
|
# == Description
|
||||||
|
#
|
||||||
|
# Destructive form of #merge
|
||||||
|
#
|
||||||
|
# == Usage
|
||||||
|
#
|
||||||
|
# require 'uri'
|
||||||
|
#
|
||||||
|
# uri = URI.parse("http://my.rubysite.com")
|
||||||
|
# uri.merge!("/main.rbx?page=1")
|
||||||
|
# p uri
|
||||||
|
# # => #<URI::HTTP:0x2021f3b0 URL:http://my.rubysite.com/main.rbx?page=1>
|
||||||
|
#
|
||||||
def merge!(oth)
|
def merge!(oth)
|
||||||
t = merge(oth)
|
t = merge(oth)
|
||||||
if self == t
|
if self == t
|
||||||
|
@ -794,7 +707,24 @@ Object
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# abs(self) + rel(oth) => abs(new)
|
#
|
||||||
|
# == Args
|
||||||
|
#
|
||||||
|
# +oth+::
|
||||||
|
# URI or String
|
||||||
|
#
|
||||||
|
# == Description
|
||||||
|
#
|
||||||
|
# Merges two URI's.
|
||||||
|
#
|
||||||
|
# == Usage
|
||||||
|
#
|
||||||
|
# require 'uri'
|
||||||
|
#
|
||||||
|
# uri = URI.parse("http://my.rubysite.com")
|
||||||
|
# p uri.merge("/main.rbx?page=1")
|
||||||
|
# # => #<URI::HTTP:0x2021f3b0 URL:http://my.rubysite.com/main.rbx?page=1>
|
||||||
|
#
|
||||||
def merge(oth)
|
def merge(oth)
|
||||||
base, rel = merge0(oth)
|
base, rel = merge0(oth)
|
||||||
if base == rel
|
if base == rel
|
||||||
|
@ -871,12 +801,6 @@ Object
|
||||||
end
|
end
|
||||||
private :merge0
|
private :merge0
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::Generic#route_from(src)
|
|
||||||
--- URI::Generic#-(src)
|
|
||||||
|
|
||||||
=end
|
|
||||||
def route_from_path(src, dst)
|
def route_from_path(src, dst)
|
||||||
# RFC2396, Section 4.2
|
# RFC2396, Section 4.2
|
||||||
return '' if src == dst
|
return '' if src == dst
|
||||||
|
@ -969,8 +893,24 @@ Object
|
||||||
return oth, rel
|
return oth, rel
|
||||||
end
|
end
|
||||||
private :route_from0
|
private :route_from0
|
||||||
|
#
|
||||||
# calculate relative path from oth to self
|
# == Args
|
||||||
|
#
|
||||||
|
# +oth+::
|
||||||
|
# URI or String
|
||||||
|
#
|
||||||
|
# == Description
|
||||||
|
#
|
||||||
|
# Calculates relative path from oth to self
|
||||||
|
#
|
||||||
|
# == Usage
|
||||||
|
#
|
||||||
|
# require 'uri'
|
||||||
|
#
|
||||||
|
# uri = URI.parse('http://my.rubysite.com/main.rbx?page=1')
|
||||||
|
# p uri.route_from('http://my.rubysite.com')
|
||||||
|
# #=> #<URI::Generic:0x20218858 URL:/main.rbx?page=1>
|
||||||
|
#
|
||||||
def route_from(oth)
|
def route_from(oth)
|
||||||
# you can modify `rel', but can not `oth'.
|
# you can modify `rel', but can not `oth'.
|
||||||
oth, rel = route_from0(oth)
|
oth, rel = route_from0(oth)
|
||||||
|
@ -986,16 +926,27 @@ Object
|
||||||
|
|
||||||
return rel
|
return rel
|
||||||
end
|
end
|
||||||
# abs1 - abs2 => relative_path_to_abs1_from_abs2
|
|
||||||
# (see http://www.nikonet.or.jp/spring/what_v/what_v_4.htm :-)
|
|
||||||
alias - route_from
|
alias - route_from
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
# == Args
|
||||||
--- URI::Generic#route_to(dst)
|
#
|
||||||
|
# +oth+::
|
||||||
=end
|
# URI or String
|
||||||
# calculate relative path to oth from self
|
#
|
||||||
|
# == Description
|
||||||
|
#
|
||||||
|
# Calculates relative path to oth from self
|
||||||
|
#
|
||||||
|
# == Usage
|
||||||
|
#
|
||||||
|
# require 'uri'
|
||||||
|
#
|
||||||
|
# uri = URI.parse('http://my.rubysite.com')
|
||||||
|
# p uri.route_to('http://my.rubysite.com/main.rbx?page=1')
|
||||||
|
# #=> #<URI::Generic:0x2020c2f6 URL:/main.rbx?page=1>
|
||||||
|
#
|
||||||
def route_to(oth)
|
def route_to(oth)
|
||||||
case oth
|
case oth
|
||||||
when Generic
|
when Generic
|
||||||
|
@ -1009,18 +960,18 @@ Object
|
||||||
oth.route_from(self)
|
oth.route_from(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
# Returns normalized URI
|
||||||
--- URI::Generic#normalize
|
#
|
||||||
--- URI::Generic#normalize!
|
|
||||||
|
|
||||||
=end
|
|
||||||
def normalize
|
def normalize
|
||||||
uri = dup
|
uri = dup
|
||||||
uri.normalize!
|
uri.normalize!
|
||||||
uri
|
uri
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Destructive version of #normalize
|
||||||
|
#
|
||||||
def normalize!
|
def normalize!
|
||||||
if path && path == ''
|
if path && path == ''
|
||||||
set_path('/')
|
set_path('/')
|
||||||
|
@ -1030,11 +981,6 @@ Object
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::Generic#to_s
|
|
||||||
|
|
||||||
=end
|
|
||||||
def path_query
|
def path_query
|
||||||
str = @path
|
str = @path
|
||||||
if @query
|
if @query
|
||||||
|
@ -1044,6 +990,9 @@ Object
|
||||||
end
|
end
|
||||||
private :path_query
|
private :path_query
|
||||||
|
|
||||||
|
#
|
||||||
|
# Constructs String from URI
|
||||||
|
#
|
||||||
def to_s
|
def to_s
|
||||||
str = ''
|
str = ''
|
||||||
if @scheme
|
if @scheme
|
||||||
|
@ -1085,11 +1034,9 @@ Object
|
||||||
str
|
str
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
# Compares to URI's
|
||||||
--- URI::Generic#==(oth)
|
#
|
||||||
|
|
||||||
=end
|
|
||||||
def ==(oth)
|
def ==(oth)
|
||||||
if self.class == oth.class
|
if self.class == oth.class
|
||||||
self.normalize.component_ary == oth.normalize.component_ary
|
self.normalize.component_ary == oth.normalize.component_ary
|
||||||
|
@ -1116,9 +1063,23 @@ Object
|
||||||
end
|
end
|
||||||
protected :component_ary
|
protected :component_ary
|
||||||
|
|
||||||
=begin
|
# == Args
|
||||||
--- URI::Generic#select(*components)
|
#
|
||||||
=end
|
# +components+::
|
||||||
|
# Multiple Symbol arguments defined in URI::HTTP
|
||||||
|
#
|
||||||
|
# == Description
|
||||||
|
#
|
||||||
|
# Selects specified components from URI
|
||||||
|
#
|
||||||
|
# == Usage
|
||||||
|
#
|
||||||
|
# require 'uri'
|
||||||
|
#
|
||||||
|
# uri = URI.parse('http://myuser:mypass@my.rubysite.com/test.rbx')
|
||||||
|
# p uri.select(:userinfo, :host, :path)
|
||||||
|
# # => ["myuser:mypass", "my.rubysite.com", "/test.rbx"]
|
||||||
|
#
|
||||||
def select(*components)
|
def select(*components)
|
||||||
components.collect do |c|
|
components.collect do |c|
|
||||||
if component.include?(c)
|
if component.include?(c)
|
||||||
|
@ -1130,14 +1091,10 @@ Object
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
=end
|
|
||||||
def inspect
|
def inspect
|
||||||
sprintf("#<%s:0x%x URL:%s>", self.class.to_s, self.object_id, self.to_s)
|
sprintf("#<%s:0x%x URL:%s>", self.class.to_s, self.object_id, self.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
=end
|
|
||||||
def coerce(oth)
|
def coerce(oth)
|
||||||
case oth
|
case oth
|
||||||
when String
|
when String
|
||||||
|
@ -1148,5 +1105,5 @@ Object
|
||||||
|
|
||||||
return oth, self
|
return oth, self
|
||||||
end
|
end
|
||||||
end # Generic
|
end
|
||||||
end # URI
|
end
|
||||||
|
|
|
@ -1,25 +1,18 @@
|
||||||
#
|
#
|
||||||
# $Id$
|
# = uri/http.rb
|
||||||
#
|
#
|
||||||
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
|
# Author:: Akira Yamada <akira@ruby-lang.org>
|
||||||
# You can redistribute it and/or modify it under the same term as Ruby.
|
# License:: You can redistribute it and/or modify it under the same term as Ruby.
|
||||||
|
# Revision:: $Id$
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'uri/generic'
|
require 'uri/generic'
|
||||||
|
|
||||||
module URI
|
module URI
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
|
||||||
== URI::HTTP
|
|
||||||
|
|
||||||
=== Super Class
|
|
||||||
|
|
||||||
((<URI::Generic>))
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
# RFC1738 section 3.3.
|
# RFC1738 section 3.3.
|
||||||
|
#
|
||||||
class HTTP < Generic
|
class HTTP < Generic
|
||||||
DEFAULT_PORT = 80
|
DEFAULT_PORT = 80
|
||||||
|
|
||||||
|
@ -31,37 +24,33 @@ module URI
|
||||||
:fragment
|
:fragment
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
# == Description
|
||||||
=== Class Methods
|
#
|
||||||
|
# Create a new URI::HTTP object from components of URI::HTTP with
|
||||||
--- URI::HTTP::build
|
# check. It is scheme, userinfo, host, port, path, query and
|
||||||
Create a new URI::HTTP object from components of URI::HTTP with
|
# fragment. It provided by an Array of a Hash.
|
||||||
check. It is scheme, userinfo, host, port, path, query and
|
#
|
||||||
fragment. It provided by an Array of a Hash.
|
|
||||||
|
|
||||||
--- URI::HTTP::new
|
|
||||||
Create a new URI::HTTP object from ``generic'' components with no
|
|
||||||
check.
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
def self.build(args)
|
def self.build(args)
|
||||||
tmp = Util::make_components_hash(self, args)
|
tmp = Util::make_components_hash(self, args)
|
||||||
return super(tmp)
|
return super(tmp)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# == Description
|
||||||
|
#
|
||||||
|
# Create a new URI::HTTP object from ``generic'' components with no
|
||||||
|
# check.
|
||||||
|
#
|
||||||
def initialize(*arg)
|
def initialize(*arg)
|
||||||
super(*arg)
|
super(*arg)
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
# == Description
|
||||||
=== Instance Methods
|
#
|
||||||
|
# Returns: path + '?' + query
|
||||||
--- URI::HTTP#request_uri
|
#
|
||||||
|
|
||||||
=end
|
|
||||||
def request_uri
|
def request_uri
|
||||||
r = path_query
|
r = path_query
|
||||||
if r[0] != ?/
|
if r[0] != ?/
|
||||||
|
@ -70,7 +59,7 @@ module URI
|
||||||
|
|
||||||
r
|
r
|
||||||
end
|
end
|
||||||
end # HTTP
|
end
|
||||||
|
|
||||||
@@schemes['HTTP'] = HTTP
|
@@schemes['HTTP'] = HTTP
|
||||||
end # URI
|
end
|
||||||
|
|
|
@ -1,26 +1,16 @@
|
||||||
#
|
#
|
||||||
# $Id$
|
# = uri/https.rb
|
||||||
#
|
#
|
||||||
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
|
# Author:: Akira Yamada <akira@ruby-lang.org>
|
||||||
# You can redistribute it and/or modify it under the same term as Ruby.
|
# License:: You can redistribute it and/or modify it under the same term as Ruby.
|
||||||
|
# Revision:: $Id$
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'uri/http'
|
require 'uri/http'
|
||||||
|
|
||||||
module URI
|
module URI
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
== URI::HTTPS
|
|
||||||
|
|
||||||
=== Super Class
|
|
||||||
|
|
||||||
((<URI::HTTP>))
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
class HTTPS < HTTP
|
class HTTPS < HTTP
|
||||||
DEFAULT_PORT = 443
|
DEFAULT_PORT = 443
|
||||||
end
|
end
|
||||||
@@schemes['HTTPS'] = HTTPS
|
@@schemes['HTTPS'] = HTTPS
|
||||||
end # URI
|
end
|
||||||
|
|
|
@ -1,29 +1,23 @@
|
||||||
#
|
#
|
||||||
# $Id$
|
# = uri/ldap.rb
|
||||||
|
#
|
||||||
|
# Author::
|
||||||
|
# Takaaki Tateishi <ttate@jaist.ac.jp>
|
||||||
|
# Akira Yamada <akira@ruby-lang.org>
|
||||||
|
# License::
|
||||||
|
# URI::LDAP is copyrighted free software by Takaaki Tateishi and Akira Yamada.
|
||||||
|
# You can redistribute it and/or modify it under the same term as Ruby.
|
||||||
|
# Revision:: $Id$
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'uri/generic'
|
require 'uri/generic'
|
||||||
|
|
||||||
module URI
|
module URI
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
|
||||||
== URI::LDAP
|
|
||||||
|
|
||||||
URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
|
|
||||||
|
|
||||||
Copyright (c) 2001 Takaaki Tateishi <ttate@jaist.ac.jp> and
|
|
||||||
akira yamada <akira@ruby-lang.org>.
|
|
||||||
You can redistribute it and/or modify it under the same term as Ruby.
|
|
||||||
|
|
||||||
=== Super Class
|
|
||||||
|
|
||||||
((<URI::Generic>))
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
# LDAP URI SCHEMA (described in RFC2255)
|
# LDAP URI SCHEMA (described in RFC2255)
|
||||||
# ldap://<host>/<dn>[?<attrs>[?<scope>[?<filter>[?<extensions>]]]]
|
# ldap://<host>/<dn>[?<attrs>[?<scope>[?<filter>[?<extensions>]]]]
|
||||||
|
#
|
||||||
class LDAP < Generic
|
class LDAP < Generic
|
||||||
|
|
||||||
DEFAULT_PORT = 389
|
DEFAULT_PORT = 389
|
||||||
|
@ -44,16 +38,6 @@ URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
|
||||||
SCOPE_BASE = 'base',
|
SCOPE_BASE = 'base',
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
=== Class Methods
|
|
||||||
|
|
||||||
--- URI::LDAP::build
|
|
||||||
|
|
||||||
--- URI::LDAP::new
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
def self.build(args)
|
def self.build(args)
|
||||||
tmp = Util::make_components_hash(self, args)
|
tmp = Util::make_components_hash(self, args)
|
||||||
|
|
||||||
|
@ -117,16 +101,6 @@ URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
|
||||||
end
|
end
|
||||||
private :build_path_query
|
private :build_path_query
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
=== Instance Methods
|
|
||||||
|
|
||||||
--- URI::LDAP#dn
|
|
||||||
|
|
||||||
--- URI::LDAP#dn=(v)
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
def dn
|
def dn
|
||||||
@dn
|
@dn
|
||||||
end
|
end
|
||||||
|
@ -143,14 +117,6 @@ URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
|
||||||
val
|
val
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::LDAP#attributes
|
|
||||||
|
|
||||||
--- URI::LDAP#attributes=(v)
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
def attributes
|
def attributes
|
||||||
@attributes
|
@attributes
|
||||||
end
|
end
|
||||||
|
@ -167,14 +133,6 @@ URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
|
||||||
val
|
val
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::LDAP#scope
|
|
||||||
|
|
||||||
--- URI::LDAP#scope=(v)
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
def scope
|
def scope
|
||||||
@scope
|
@scope
|
||||||
end
|
end
|
||||||
|
@ -191,14 +149,6 @@ URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
|
||||||
val
|
val
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::LDAP#filter
|
|
||||||
|
|
||||||
--- URI::LDAP#filter=(v)
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
def filter
|
def filter
|
||||||
@filter
|
@filter
|
||||||
end
|
end
|
||||||
|
@ -215,14 +165,6 @@ URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
|
||||||
val
|
val
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::LDAP#extensions
|
|
||||||
|
|
||||||
--- URI::LDAP#extensions=(v)
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
def extensions
|
def extensions
|
||||||
@extensions
|
@extensions
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,35 +1,26 @@
|
||||||
#
|
#
|
||||||
# $Id$
|
# = uri/mailto.rb
|
||||||
#
|
#
|
||||||
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
|
# Author:: Akira Yamada <akira@ruby-lang.org>
|
||||||
# You can redistribute it and/or modify it under the same term as Ruby.
|
# License:: You can redistribute it and/or modify it under the same term as Ruby.
|
||||||
|
# Revision:: $Id$
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'uri/generic'
|
require 'uri/generic'
|
||||||
|
|
||||||
module URI
|
module URI
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
|
||||||
== URI::MailTo
|
|
||||||
|
|
||||||
=== Super Class
|
|
||||||
|
|
||||||
((<URI::Generic>))
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
# RFC2368, The mailto URL scheme
|
# RFC2368, The mailto URL scheme
|
||||||
|
#
|
||||||
class MailTo < Generic
|
class MailTo < Generic
|
||||||
include REGEXP
|
include REGEXP
|
||||||
|
|
||||||
DEFAULT_PORT = nil
|
DEFAULT_PORT = nil
|
||||||
|
|
||||||
COMPONENT = [
|
COMPONENT = [ :scheme, :to, :headers ].freeze
|
||||||
:scheme,
|
|
||||||
:to, :headers
|
|
||||||
].freeze
|
|
||||||
|
|
||||||
|
# :stopdoc:
|
||||||
# "hname" and "hvalue" are encodings of an RFC 822 header name and
|
# "hname" and "hvalue" are encodings of an RFC 822 header name and
|
||||||
# value, respectively. As with "to", all URL reserved characters must
|
# value, respectively. As with "to", all URL reserved characters must
|
||||||
# be encoded.
|
# be encoded.
|
||||||
|
@ -52,7 +43,7 @@ module URI
|
||||||
# to = #mailbox
|
# to = #mailbox
|
||||||
# mailtoURL = "mailto:" [ to ] [ headers ]
|
# mailtoURL = "mailto:" [ to ] [ headers ]
|
||||||
MAILBOX_PATTERN = "(?:#{PATTERN::ESCAPED}|[^(),%?=&])".freeze
|
MAILBOX_PATTERN = "(?:#{PATTERN::ESCAPED}|[^(),%?=&])".freeze
|
||||||
MAILTO_REGEXP = Regexp.new("
|
MAILTO_REGEXP = Regexp.new(" # :nodoc:
|
||||||
\\A
|
\\A
|
||||||
(#{MAILBOX_PATTERN}*?) (?# 1: to)
|
(#{MAILBOX_PATTERN}*?) (?# 1: to)
|
||||||
(?:
|
(?:
|
||||||
|
@ -61,25 +52,17 @@ module URI
|
||||||
)?
|
)?
|
||||||
\\z
|
\\z
|
||||||
", Regexp::EXTENDED, 'N').freeze
|
", Regexp::EXTENDED, 'N').freeze
|
||||||
|
# :startdoc:
|
||||||
|
|
||||||
=begin
|
#
|
||||||
|
# == Description
|
||||||
=== Class Methods
|
#
|
||||||
|
# Creates a new URI::MailTo object from components of URI::MailTo
|
||||||
--- URI::MailTo::build
|
# with check. It is to and headers. It provided by an Array of a
|
||||||
Create a new URI::MailTo object from components of URI::MailTo
|
# Hash. You can provide headers as String like
|
||||||
with check. It is to and headers. It provided by an Array of a
|
# "subject=subscribe&cc=addr" or Array like [["subject",
|
||||||
Hash. You can provide headers as an String like
|
# "subscribe"], ["cc", "addr"]]
|
||||||
"subject=subscribe&cc=addr" or an Array like [["subject",
|
#
|
||||||
"subscribe"], ["cc", "addr"]]
|
|
||||||
|
|
||||||
--- URI::MailTo::new
|
|
||||||
Create a new URI::MailTo object from ``generic'' components with
|
|
||||||
no check. Because, this method is usually called from URI::parse
|
|
||||||
and the method checks validity of each components.
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
def self.build(args)
|
def self.build(args)
|
||||||
tmp = Util::make_components_hash(self, args)
|
tmp = Util::make_components_hash(self, args)
|
||||||
|
|
||||||
|
@ -114,6 +97,13 @@ module URI
|
||||||
return super(tmp)
|
return super(tmp)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# == Description
|
||||||
|
#
|
||||||
|
# Creates a new URI::MailTo object from ``generic'' components with
|
||||||
|
# no check. Because, this method is usually called from URI::parse
|
||||||
|
# and the method checks validity of each components.
|
||||||
|
#
|
||||||
def initialize(*arg)
|
def initialize(*arg)
|
||||||
super(*arg)
|
super(*arg)
|
||||||
|
|
||||||
|
@ -137,20 +127,6 @@ module URI
|
||||||
attr_reader :to
|
attr_reader :to
|
||||||
attr_reader :headers
|
attr_reader :headers
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
=== Instance Methods
|
|
||||||
|
|
||||||
--- URI::MailTo#to
|
|
||||||
|
|
||||||
--- URI::MailTo#to=(v)
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
#
|
|
||||||
# methods for to
|
|
||||||
#
|
|
||||||
|
|
||||||
def check_to(v)
|
def check_to(v)
|
||||||
return true unless v
|
return true unless v
|
||||||
return true if v.size == 0
|
return true if v.size == 0
|
||||||
|
@ -175,18 +151,6 @@ module URI
|
||||||
v
|
v
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
--- URI::MailTo#headers
|
|
||||||
|
|
||||||
--- URI::MailTo#headers=(v)
|
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
#
|
|
||||||
# methods for headers
|
|
||||||
#
|
|
||||||
|
|
||||||
def check_headers(v)
|
def check_headers(v)
|
||||||
return true unless v
|
return true unless v
|
||||||
return true if v.size == 0
|
return true if v.size == 0
|
||||||
|
@ -228,14 +192,21 @@ module URI
|
||||||
'?' + @headers.collect{|x| x.join('=')}.join('&')
|
'?' + @headers.collect{|x| x.join('=')}.join('&')
|
||||||
else
|
else
|
||||||
''
|
''
|
||||||
|
end +
|
||||||
|
if @fragment
|
||||||
|
'#' + @fragment
|
||||||
|
else
|
||||||
|
''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
#
|
||||||
=begin
|
# == Usage
|
||||||
|
# require 'uri'
|
||||||
--- URI::MailTo#to_mailtext
|
#
|
||||||
|
# uri = URI.parse("mailto:ruby-list@ruby-lang.org?Subject=subscribe&cc=myaddr")
|
||||||
=end
|
# uri.to_mailtext
|
||||||
|
# # => "To: ruby-list@ruby-lang.org\nSubject: subscribe\nCc: myaddr\n\n\n"
|
||||||
|
#
|
||||||
def to_mailtext
|
def to_mailtext
|
||||||
to = URI::unescape(@to)
|
to = URI::unescape(@to)
|
||||||
head = ''
|
head = ''
|
||||||
|
@ -258,7 +229,7 @@ module URI
|
||||||
"
|
"
|
||||||
end
|
end
|
||||||
alias to_rfc822text to_mailtext
|
alias to_rfc822text to_mailtext
|
||||||
end # MailTo
|
end
|
||||||
|
|
||||||
@@schemes['MAILTO'] = MailTo
|
@@schemes['MAILTO'] = MailTo
|
||||||
end # URI
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue