mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/open-uri.rb: Documentation for OpenURI
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37273 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
167c4781a0
commit
dd05478f24
2 changed files with 19 additions and 8 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Sat Oct 20 11:00:00 2012 Zachary Scott <zachary@zacharyscott.net>
|
||||||
|
|
||||||
|
* lib/open-uri.rb: Documentation for OpenURI
|
||||||
|
|
||||||
Sat Oct 20 06:18:34 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
Sat Oct 20 06:18:34 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
* hash.c (initialize_copy): unset the default proc if there isn't one
|
* hash.c (initialize_copy): unset the default proc if there isn't one
|
||||||
|
|
|
@ -20,10 +20,11 @@ module Kernel
|
||||||
#
|
#
|
||||||
# Otherwise, the original Kernel#open is called.
|
# Otherwise, the original Kernel#open is called.
|
||||||
#
|
#
|
||||||
# Since open-uri.rb provides URI::HTTP#open, URI::HTTPS#open and
|
# OpenURI::OpenRead#open provides URI::HTTP#open, URI::HTTPS#open and
|
||||||
# URI::FTP#open, Kernel[#.]open can accept URIs and strings that begin with
|
# URI::FTP#open, Kernel#open.
|
||||||
# http://, https:// and ftp://. In these cases, the opened file object is
|
#
|
||||||
# extended by OpenURI::Meta.
|
# We can accept URIs and strings that begin with http://, https:// and
|
||||||
|
# ftp://. In these cases, the opened file object is extended by OpenURI::Meta.
|
||||||
def open(name, *rest, &block) # :doc:
|
def open(name, *rest, &block) # :doc:
|
||||||
if name.respond_to?(:open)
|
if name.respond_to?(:open)
|
||||||
name.open(*rest, &block)
|
name.open(*rest, &block)
|
||||||
|
@ -38,7 +39,7 @@ module Kernel
|
||||||
module_function :open
|
module_function :open
|
||||||
end
|
end
|
||||||
|
|
||||||
# OpenURI is an easy-to-use wrapper for net/http, net/https and net/ftp.
|
# OpenURI is an easy-to-use wrapper for Net::HTTP, Net::HTTPS and Net::FTP.
|
||||||
#
|
#
|
||||||
# == Example
|
# == Example
|
||||||
#
|
#
|
||||||
|
@ -70,12 +71,14 @@ end
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
# The environment variables such as http_proxy, https_proxy and ftp_proxy
|
# The environment variables such as http_proxy, https_proxy and ftp_proxy
|
||||||
# are in effect by default. :proxy => nil disables proxy.
|
# are in effect by default. Here we disable proxy:
|
||||||
#
|
#
|
||||||
# open("http://www.ruby-lang.org/en/raa.html", :proxy => nil) {|f|
|
# open("http://www.ruby-lang.org/en/raa.html", :proxy => nil) {|f|
|
||||||
# # ...
|
# # ...
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
|
# See OpenURI::OpenRead.open and Kernel#open for more on available options.
|
||||||
|
#
|
||||||
# URI objects can be opened in a similar way.
|
# URI objects can be opened in a similar way.
|
||||||
#
|
#
|
||||||
# uri = URI.parse("http://www.ruby-lang.org/en/")
|
# uri = URI.parse("http://www.ruby-lang.org/en/")
|
||||||
|
@ -359,6 +362,8 @@ module OpenURI
|
||||||
attr_reader :io
|
attr_reader :io
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised on redirection,
|
||||||
|
# only occurs when +redirect+ option for HTTP is +false+.
|
||||||
class HTTPRedirect < HTTPError
|
class HTTPRedirect < HTTPError
|
||||||
def initialize(message, io, uri)
|
def initialize(message, io, uri)
|
||||||
super(message, io)
|
super(message, io)
|
||||||
|
@ -367,7 +372,7 @@ module OpenURI
|
||||||
attr_reader :uri
|
attr_reader :uri
|
||||||
end
|
end
|
||||||
|
|
||||||
class Buffer # :nodoc:
|
class Buffer # :nodoc: all
|
||||||
def initialize
|
def initialize
|
||||||
@io = StringIO.new
|
@io = StringIO.new
|
||||||
@size = 0
|
@size = 0
|
||||||
|
@ -456,10 +461,12 @@ module OpenURI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :stopdoc:
|
||||||
RE_LWS = /[\r\n\t ]+/n
|
RE_LWS = /[\r\n\t ]+/n
|
||||||
RE_TOKEN = %r{[^\x00- ()<>@,;:\\"/\[\]?={}\x7f]+}n
|
RE_TOKEN = %r{[^\x00- ()<>@,;:\\"/\[\]?={}\x7f]+}n
|
||||||
RE_QUOTED_STRING = %r{"(?:[\r\n\t !#-\[\]-~\x80-\xff]|\\[\x00-\x7f])*"}n
|
RE_QUOTED_STRING = %r{"(?:[\r\n\t !#-\[\]-~\x80-\xff]|\\[\x00-\x7f])*"}n
|
||||||
RE_PARAMETERS = %r{(?:;#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?=#{RE_LWS}?(?:#{RE_TOKEN}|#{RE_QUOTED_STRING})#{RE_LWS}?)*}n
|
RE_PARAMETERS = %r{(?:;#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?=#{RE_LWS}?(?:#{RE_TOKEN}|#{RE_QUOTED_STRING})#{RE_LWS}?)*}n
|
||||||
|
# :startdoc:
|
||||||
|
|
||||||
def content_type_parse # :nodoc:
|
def content_type_parse # :nodoc:
|
||||||
v = @meta['content-type']
|
v = @meta['content-type']
|
||||||
|
|
Loading…
Add table
Reference in a new issue