1
0
Fork 0
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.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
gsinclair 2004-03-24 11:53:31 +00:00
parent 5e23ff603f
commit 42ad5216ec
9 changed files with 968 additions and 974 deletions

View file

@ -1,3 +1,14 @@
Wed Mar 24 20:49: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.
Wed Mar 24 18:48:05 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb ($ruby, $topdir, $hdrdir): should not be affected by

View file

@ -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>
# 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
VERSION_CODE = '000911'.freeze
VERSION = VERSION_CODE.scan(/../).collect{|n| n.to_i}.join('.').freeze
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/generic'
require 'uri/ftp'

View file

@ -1,19 +1,19 @@
# = uri/common.rb
#
# $Id$
#
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
# Author:: Akira Yamada <akira@ruby-lang.org>
# Revision:: $Id$
# License::
# You can redistribute it and/or modify it under the same term as Ruby.
#
=begin
== URI
=end
module URI
module REGEXP
#
# Patterns used to parse URI's
#
module PATTERN
# :stopdoc:
# RFC 2396 (URI Generic Syntax)
# RFC 2732 (IPv6 Literal Addresses in URL's)
# RFC 2373 (IPv6 Addressing Architecture)
@ -179,8 +179,11 @@ module URI
(?:\\?(#{PATTERN::QUERY}))? (?# 7: query)
(?:\\#(#{PATTERN::FRAGMENT}))? (?# 8: fragment)
"
# :startdoc:
end # PATTERN
# :stopdoc:
# for URI::split
ABS_URI = Regexp.new('^' + PATTERN::X_ABS_URI + '$', #'
Regexp::EXTENDED, 'N').freeze
@ -208,6 +211,7 @@ module URI
REL_PATH = Regexp.new("^#{PATTERN::REL_PATH}$", false, 'N').freeze #"
QUERY = Regexp.new("^#{PATTERN::QUERY}$", false, 'N').freeze #"
FRAGMENT = Regexp.new("^#{PATTERN::FRAGMENT}$", false, 'N').freeze #"
# :startdoc:
end # REGEXP
module Util
@ -245,6 +249,34 @@ module URI
module Escape
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)
unless unsafe.kind_of?(Regexp)
# perhaps unsafe is String object
@ -259,7 +291,27 @@ module URI
end
end
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)
str.gsub(ESCAPED) do
$&[1,2].hex.chr
@ -273,19 +325,54 @@ module URI
@@schemes = {}
#
# Base class for all URI exceptions.
#
class Error < StandardError; end
class InvalidURIError < Error; end # it is not URI.
class InvalidComponentError < Error; end # it is not component of URI.
class BadURIError < Error; end # the URI is valid but it is bad for the position.
=begin
=== Methods
--- URI::split(uri)
=end
#
# Not a URI.
#
class InvalidURIError < Error; end
#
# Not a URI component.
#
class InvalidComponentError < Error; end
#
# URI is valid, bad usage is not.
#
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)
case uri
when ''
@ -358,11 +445,37 @@ module URI
return ret
end
=begin
--- URI::parse(uri_str)
=end
#
# == Synopsis
#
# URI::parse(uri_str)
#
# == 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)
scheme, userinfo, host, port,
registry, path, opaque, query, fragment = self.split(uri)
@ -378,11 +491,27 @@ module URI
end
end
=begin
--- URI::join(str[, str, ...])
=end
#
# == Synopsis
#
# URI::join(str[, str, ...])
#
# == 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)
u = self.parse(str[0])
str[1 .. -1].each do |x|
@ -391,11 +520,30 @@ module URI
u
end
=begin
--- URI::extract(str[, schemes])
=end
#
# == Synopsis
#
# URI::extract(str[, schemes][,&blk])
#
# == 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)
if block_given?
str.scan(regexp(schemes)) { yield $& }
@ -407,30 +555,37 @@ module URI
end
end
=begin
--- URI::regexp([match_schemes])
Returns a Regexp object which matches to URI-like strings.
If MATCH_SCHEMES given, resulting regexp matches to URIs
whose scheme is one of the MATCH_SCHEMES.
The Regexp object returned by this method includes arbitrary
number of capture group (parentheses). Never rely on its
number.
# extract first URI from html_string
html_string.slice(URI.regexp)
# 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
=end
#
# == Synopsis
#
# URI::regexp([match_schemes])
#
# == Args
#
# +match_schemes+::
# Array of schemes. If given, resulting regexp matches to URIs
# whose scheme is one of the match_schemes.
#
# == Description
# Returns a Regexp object which matches to URI-like strings.
# The Regexp object returned by this method includes arbitrary
# number of capture group (parentheses). Never rely on it's number.
#
# == Usage
#
# require 'uri'
#
# # extract first URI from html_string
# html_string.slice(URI.regexp)
#
# # 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)
unless schemes
ABS_URI_REF
@ -439,4 +594,4 @@ module URI
end
end
end # URI
end

View file

@ -1,25 +1,18 @@
#
# $Id$
# = uri/ftp.rb
#
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
# You can redistribute it and/or modify it under the same term as Ruby.
# Author:: Akira Yamada <akira@ruby-lang.org>
# License:: You can redistribute it and/or modify it under the same term as Ruby.
# Revision:: $Id$
#
require 'uri/generic'
module URI
=begin
== URI::FTP
=== Super Class
((<URI::Generic>))
=end
#
# RFC1738 section 3.2.
#
class FTP < Generic
DEFAULT_PORT = 21
@ -28,25 +21,17 @@ module URI
:userinfo, :host, :port,
:path, :typecode
].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_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,
typecode = nil, arg_check = true)
typecode = nil if typecode.size == 0
@ -64,6 +49,13 @@ module URI
nil, nil, nil, arg_check)
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)
tmp = Util::make_components_hash(self, args)
@ -77,6 +69,20 @@ module URI
return super(tmp)
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)
super(*arg)
@typecode = nil
@ -94,10 +100,6 @@ module URI
end
attr_reader :typecode
#
# methods for typecode
#
def check_typecode(v)
if TYPECODE.include?(v)
return true
@ -119,9 +121,7 @@ module URI
typecode
end
=begin
=end
def merge(oth)
def merge(oth) # :nodoc:
tmp = super(oth)
if self != tmp
tmp.set_typecode(oth.typecode)
@ -130,8 +130,6 @@ module URI
return tmp
end
=begin
=end
def to_s
save_path = nil
if @typecode
@ -145,6 +143,6 @@ module URI
return str
end
end # FTP
end
@@schemes['FTP'] = FTP
end # URI
end

View file

@ -1,37 +1,27 @@
#
# $Id$
# = uri/generic.rb
#
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
# You can redistribute it and/or modify it under the same term as Ruby.
# Author:: Akira Yamada <akira@ruby-lang.org>
# License:: You can redistribute it and/or modify it under the same term as Ruby.
# Revision:: $Id$
#
require 'uri/common'
module URI
=begin
== URI::Generic
=== Super Class
Object
=end
#
# Base class for all URI classes.
#
class Generic
include URI
include REGEXP
=begin
=== Class Methods
--- URI::Generic::default_port
=end
DEFAULT_PORT = nil
#
# Returns default port
#
def self.default_port
self::DEFAULT_PORT
end
@ -40,9 +30,6 @@ Object
self.class.default_port
end
=begin
--- URI::Generic::component
=end
COMPONENT = [
:scheme,
:userinfo, :host, :port, :registry,
@ -51,37 +38,34 @@ Object
:fragment
].freeze
#
# Components of the URI in the order.
#
def self.component
self::COMPONENT
end
=begin
--- URI::Generic::use_registry
=end
USE_REGISTRY = false
#
# DOC: FIXME!
#
def self.use_registry
self::USE_REGISTRY
end
=begin
--- URI::Generic::build2
At first, try to create a new URI::Generic object using
URI::Generic::build. But, if you get a exception
URI::InvalidComponentError, then re-try to create an object with
escaped components.
--- URI::Generic::build
Create a new URI::Generic object from components of URI::Generic
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
#
# == Synopsis
#
# See #new
#
# == Description
#
# At first, tries to create a new URI::Generic instance using
# URI::Generic::build. But, if exception URI::InvalidComponentError is raised,
# then it URI::Escape.escape all URI components and tries again.
#
#
def self.build2(args)
begin
return self.build(args)
@ -108,6 +92,18 @@ Object
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)
if args.kind_of?(Array) &&
args.size == ::URI::Generic::COMPONENT.size
@ -128,7 +124,34 @@ Object
tmp << true
return self.new(*tmp)
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,
userinfo, host, port, registry,
path, opaque,
@ -168,7 +191,8 @@ Object
self.set_fragment(fragment)
end
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
@scheme.freeze if @scheme
@ -196,35 +220,10 @@ Object
end
private :replace!
=begin
=== Instance Methods
=end
=begin
--- URI::Generic#component
=end
def component
self.class.component
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)
if v && SCHEME !~ v
raise InvalidComponentError,
@ -246,24 +245,6 @@ Object
v
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)
if !password
user, password = split_userinfo(user)
@ -313,6 +294,9 @@ Object
end
private :check_password
#
# Sets userinfo, argument is string like 'name:pass'
#
def userinfo=(userinfo)
if userinfo.nil?
return nil
@ -393,17 +377,6 @@ Object
@password
end
=begin
--- URI::Generic#host
--- URI::Generic#host=(v)
=end
#
# methods for host
#
def check_host(v)
return v unless v
@ -430,17 +403,6 @@ Object
v
end
=begin
--- URI::Generic#port
--- URI::Generic#port=(v)
=end
#
# methods for port
#
def check_port(v)
return v unless v
@ -474,17 +436,6 @@ Object
port
end
=begin
--- URI::Generic#registry
--- URI::Generic#registry=(v)
=end
#
# methods for registry
#
def check_registry(v)
return v unless v
@ -514,17 +465,6 @@ Object
v
end
=begin
--- URI::Generic#path
--- URI::Generic#path=(v)
=end
#
# methods for path
#
def check_path(v)
# raise if both hier and opaque are not nil, because:
# absoluteURI = scheme ":" ( hier_part | opaque_part )
@ -561,17 +501,6 @@ Object
v
end
=begin
--- URI::Generic#query
--- URI::Generic#query=(v)
=end
#
# methods for query
#
def check_query(v)
return v unless v
@ -603,17 +532,6 @@ Object
v
end
=begin
--- URI::Generic#opaque
--- URI::Generic#opaque=(v)
=end
#
# methods for opaque
#
def check_opaque(v)
return v unless v
@ -643,17 +561,6 @@ Object
v
end
=begin
--- URI::Generic#fragment
--- URI::Generic#fragment=(v)
=end
#
# methods for fragment
#
def check_fragment(v)
return v unless v
@ -677,11 +584,9 @@ Object
v
end
=begin
--- URI::Generic#hierarchical?
=end
#
# Checks if URI has a path
#
def hierarchical?
if @path
true
@ -690,11 +595,9 @@ Object
end
end
=begin
--- URI::Generic#absolute?
=end
#
# Checks if URI is an absolute one
#
def absolute?
if @scheme
true
@ -704,22 +607,13 @@ Object
end
alias absolute absolute?
=begin
--- URI::Generic#relative?
=end
#
# Checks if URI is relative
#
def relative?
!absolute?
end
=begin
--- URI::Generic#merge(rel)
--- URI::Generic#merge!(rel)
--- URI::Generic#+(rel)
=end
def split_path(path)
path.split(%r{/+}, -1)
end
@ -784,6 +678,25 @@ Object
end
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)
t = merge(oth)
if self == t
@ -794,7 +707,24 @@ Object
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)
base, rel = merge0(oth)
if base == rel
@ -871,12 +801,6 @@ Object
end
private :merge0
=begin
--- URI::Generic#route_from(src)
--- URI::Generic#-(src)
=end
def route_from_path(src, dst)
# RFC2396, Section 4.2
return '' if src == dst
@ -969,8 +893,24 @@ Object
return oth, rel
end
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)
# you can modify `rel', but can not `oth'.
oth, rel = route_from0(oth)
@ -986,16 +926,27 @@ Object
return rel
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
=begin
--- URI::Generic#route_to(dst)
=end
# calculate relative path to oth from self
#
# == Args
#
# +oth+::
# URI or String
#
# == 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)
case oth
when Generic
@ -1009,18 +960,18 @@ Object
oth.route_from(self)
end
=begin
--- URI::Generic#normalize
--- URI::Generic#normalize!
=end
#
# Returns normalized URI
#
def normalize
uri = dup
uri.normalize!
uri
end
#
# Destructive version of #normalize
#
def normalize!
if path && path == ''
set_path('/')
@ -1030,11 +981,6 @@ Object
end
end
=begin
--- URI::Generic#to_s
=end
def path_query
str = @path
if @query
@ -1044,6 +990,9 @@ Object
end
private :path_query
#
# Constructs String from URI
#
def to_s
str = ''
if @scheme
@ -1085,11 +1034,9 @@ Object
str
end
=begin
--- URI::Generic#==(oth)
=end
#
# Compares to URI's
#
def ==(oth)
if self.class == oth.class
self.normalize.component_ary == oth.normalize.component_ary
@ -1116,9 +1063,23 @@ Object
end
protected :component_ary
=begin
--- URI::Generic#select(*components)
=end
# == Args
#
# +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)
components.collect do |c|
if component.include?(c)
@ -1130,14 +1091,10 @@ Object
end
end
=begin
=end
def inspect
sprintf("#<%s:0x%x URL:%s>", self.class.to_s, self.object_id, self.to_s)
end
=begin
=end
def coerce(oth)
case oth
when String
@ -1148,5 +1105,5 @@ Object
return oth, self
end
end # Generic
end # URI
end
end

View file

@ -1,25 +1,18 @@
#
# $Id$
# = uri/http.rb
#
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
# You can redistribute it and/or modify it under the same term as Ruby.
# Author:: Akira Yamada <akira@ruby-lang.org>
# License:: You can redistribute it and/or modify it under the same term as Ruby.
# Revision:: $Id$
#
require 'uri/generic'
module URI
=begin
== URI::HTTP
=== Super Class
((<URI::Generic>))
=end
#
# RFC1738 section 3.3.
#
class HTTP < Generic
DEFAULT_PORT = 80
@ -31,37 +24,33 @@ module URI
:fragment
].freeze
=begin
=== Class Methods
--- URI::HTTP::build
Create a new URI::HTTP object from components of URI::HTTP with
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
#
# == Description
#
# Create a new URI::HTTP object from components of URI::HTTP with
# check. It is scheme, userinfo, host, port, path, query and
# fragment. It provided by an Array of a Hash.
#
def self.build(args)
tmp = Util::make_components_hash(self, args)
return super(tmp)
end
#
# == Description
#
# Create a new URI::HTTP object from ``generic'' components with no
# check.
#
def initialize(*arg)
super(*arg)
end
=begin
=== Instance Methods
--- URI::HTTP#request_uri
=end
#
# == Description
#
# Returns: path + '?' + query
#
def request_uri
r = path_query
if r[0] != ?/
@ -70,7 +59,7 @@ module URI
r
end
end # HTTP
end
@@schemes['HTTP'] = HTTP
end # URI
end

View file

@ -1,26 +1,16 @@
#
# $Id$
# = uri/https.rb
#
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
# You can redistribute it and/or modify it under the same term as Ruby.
# Author:: Akira Yamada <akira@ruby-lang.org>
# License:: You can redistribute it and/or modify it under the same term as Ruby.
# Revision:: $Id$
#
require 'uri/http'
module URI
=begin
== URI::HTTPS
=== Super Class
((<URI::HTTP>))
=end
class HTTPS < HTTP
DEFAULT_PORT = 443
end
@@schemes['HTTPS'] = HTTPS
end # URI
end

View file

@ -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'
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://<host>/<dn>[?<attrs>[?<scope>[?<filter>[?<extensions>]]]]
#
class LDAP < Generic
DEFAULT_PORT = 389
@ -44,16 +38,6 @@ URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
SCOPE_BASE = 'base',
].freeze
=begin
=== Class Methods
--- URI::LDAP::build
--- URI::LDAP::new
=end
def self.build(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
private :build_path_query
=begin
=== Instance Methods
--- URI::LDAP#dn
--- URI::LDAP#dn=(v)
=end
def dn
@dn
end
@ -143,14 +117,6 @@ URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
val
end
=begin
--- URI::LDAP#attributes
--- URI::LDAP#attributes=(v)
=end
def attributes
@attributes
end
@ -167,14 +133,6 @@ URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
val
end
=begin
--- URI::LDAP#scope
--- URI::LDAP#scope=(v)
=end
def scope
@scope
end
@ -191,14 +149,6 @@ URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
val
end
=begin
--- URI::LDAP#filter
--- URI::LDAP#filter=(v)
=end
def filter
@filter
end
@ -215,14 +165,6 @@ URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
val
end
=begin
--- URI::LDAP#extensions
--- URI::LDAP#extensions=(v)
=end
def extensions
@extensions
end

View file

@ -1,35 +1,26 @@
#
# $Id$
# = uri/mailto.rb
#
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
# You can redistribute it and/or modify it under the same term as Ruby.
# Author:: Akira Yamada <akira@ruby-lang.org>
# License:: You can redistribute it and/or modify it under the same term as Ruby.
# Revision:: $Id$
#
require 'uri/generic'
module URI
=begin
== URI::MailTo
=== Super Class
((<URI::Generic>))
=end
#
# RFC2368, The mailto URL scheme
#
class MailTo < Generic
include REGEXP
DEFAULT_PORT = nil
COMPONENT = [
:scheme,
:to, :headers
].freeze
COMPONENT = [ :scheme, :to, :headers ].freeze
# :stopdoc:
# "hname" and "hvalue" are encodings of an RFC 822 header name and
# value, respectively. As with "to", all URL reserved characters must
# be encoded.
@ -52,7 +43,7 @@ module URI
# to = #mailbox
# mailtoURL = "mailto:" [ to ] [ headers ]
MAILBOX_PATTERN = "(?:#{PATTERN::ESCAPED}|[^(),%?=&])".freeze
MAILTO_REGEXP = Regexp.new("
MAILTO_REGEXP = Regexp.new(" # :nodoc:
\\A
(#{MAILBOX_PATTERN}*?) (?# 1: to)
(?:
@ -65,25 +56,17 @@ module URI
)?
\\z
", Regexp::EXTENDED, 'N').freeze
# :startdoc:
=begin
=== Class Methods
--- URI::MailTo::build
Create a new URI::MailTo object from components of URI::MailTo
with check. It is to and headers. It provided by an Array of a
Hash. You can provide headers as an String like
"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
#
# == Description
#
# Creates a new URI::MailTo object from components of URI::MailTo
# with check. It is to and headers. It provided by an Array of a
# Hash. You can provide headers as String like
# "subject=subscribe&cc=addr" or Array like [["subject",
# "subscribe"], ["cc", "addr"]]
#
def self.build(args)
tmp = Util::make_components_hash(self, args)
@ -118,6 +101,13 @@ module URI
return super(tmp)
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)
super(*arg)
@ -141,20 +131,6 @@ module URI
attr_reader :to
attr_reader :headers
=begin
=== Instance Methods
--- URI::MailTo#to
--- URI::MailTo#to=(v)
=end
#
# methods for to
#
def check_to(v)
return true unless v
return true if v.size == 0
@ -179,18 +155,6 @@ module URI
v
end
=begin
--- URI::MailTo#headers
--- URI::MailTo#headers=(v)
=end
#
# methods for headers
#
def check_headers(v)
return true unless v
return true if v.size == 0
@ -239,12 +203,14 @@ module URI
''
end
end
=begin
--- URI::MailTo#to_mailtext
=end
#
# == Usage
# require 'uri'
#
# uri = URI.parse("mailto:ruby-list@ruby-lang.org?Subject=subscribe&cc=myaddr")
# uri.to_mailtext
# # => "To: ruby-list@ruby-lang.org\nSubject: subscribe\nCc: myaddr\n\n\n"
#
def to_mailtext
to = URI::unescape(@to)
head = ''
@ -267,7 +233,7 @@ module URI
"
end
alias to_rfc822text to_mailtext
end # MailTo
end
@@schemes['MAILTO'] = MailTo
end # URI
end