Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/uri
File: ftp.rb
# frozen_string_literal: false
[0] Fix | Delete
# = uri/ftp.rb
[1] Fix | Delete
#
[2] Fix | Delete
# Author:: Akira Yamada <akira@ruby-lang.org>
[3] Fix | Delete
# License:: You can redistribute it and/or modify it under the same term as Ruby.
[4] Fix | Delete
# Revision:: $Id$
[5] Fix | Delete
#
[6] Fix | Delete
# See URI for general documentation
[7] Fix | Delete
#
[8] Fix | Delete
[9] Fix | Delete
require_relative 'generic'
[10] Fix | Delete
[11] Fix | Delete
module URI
[12] Fix | Delete
[13] Fix | Delete
#
[14] Fix | Delete
# FTP URI syntax is defined by RFC1738 section 3.2.
[15] Fix | Delete
#
[16] Fix | Delete
# This class will be redesigned because of difference of implementations;
[17] Fix | Delete
# the structure of its path. draft-hoffman-ftp-uri-04 is a draft but it
[18] Fix | Delete
# is a good summary about the de facto spec.
[19] Fix | Delete
# http://tools.ietf.org/html/draft-hoffman-ftp-uri-04
[20] Fix | Delete
#
[21] Fix | Delete
class FTP < Generic
[22] Fix | Delete
# A Default port of 21 for URI::FTP.
[23] Fix | Delete
DEFAULT_PORT = 21
[24] Fix | Delete
[25] Fix | Delete
#
[26] Fix | Delete
# An Array of the available components for URI::FTP.
[27] Fix | Delete
#
[28] Fix | Delete
COMPONENT = [
[29] Fix | Delete
:scheme,
[30] Fix | Delete
:userinfo, :host, :port,
[31] Fix | Delete
:path, :typecode
[32] Fix | Delete
].freeze
[33] Fix | Delete
[34] Fix | Delete
#
[35] Fix | Delete
# Typecode is "a", "i", or "d".
[36] Fix | Delete
#
[37] Fix | Delete
# * "a" indicates a text file (the FTP command was ASCII)
[38] Fix | Delete
# * "i" indicates a binary file (FTP command IMAGE)
[39] Fix | Delete
# * "d" indicates the contents of a directory should be displayed
[40] Fix | Delete
#
[41] Fix | Delete
TYPECODE = ['a', 'i', 'd'].freeze
[42] Fix | Delete
[43] Fix | Delete
# Typecode prefix ";type=".
[44] Fix | Delete
TYPECODE_PREFIX = ';type='.freeze
[45] Fix | Delete
[46] Fix | Delete
def self.new2(user, password, host, port, path,
[47] Fix | Delete
typecode = nil, arg_check = true) # :nodoc:
[48] Fix | Delete
# Do not use this method! Not tested. [Bug #7301]
[49] Fix | Delete
# This methods remains just for compatibility,
[50] Fix | Delete
# Keep it undocumented until the active maintainer is assigned.
[51] Fix | Delete
typecode = nil if typecode.size == 0
[52] Fix | Delete
if typecode && !TYPECODE.include?(typecode)
[53] Fix | Delete
raise ArgumentError,
[54] Fix | Delete
"bad typecode is specified: #{typecode}"
[55] Fix | Delete
end
[56] Fix | Delete
[57] Fix | Delete
# do escape
[58] Fix | Delete
[59] Fix | Delete
self.new('ftp',
[60] Fix | Delete
[user, password],
[61] Fix | Delete
host, port, nil,
[62] Fix | Delete
typecode ? path + TYPECODE_PREFIX + typecode : path,
[63] Fix | Delete
nil, nil, nil, arg_check)
[64] Fix | Delete
end
[65] Fix | Delete
[66] Fix | Delete
#
[67] Fix | Delete
# == Description
[68] Fix | Delete
#
[69] Fix | Delete
# Creates a new URI::FTP object from components, with syntax checking.
[70] Fix | Delete
#
[71] Fix | Delete
# The components accepted are +userinfo+, +host+, +port+, +path+, and
[72] Fix | Delete
# +typecode+.
[73] Fix | Delete
#
[74] Fix | Delete
# The components should be provided either as an Array, or as a Hash
[75] Fix | Delete
# with keys formed by preceding the component names with a colon.
[76] Fix | Delete
#
[77] Fix | Delete
# If an Array is used, the components must be passed in the
[78] Fix | Delete
# order <code>[userinfo, host, port, path, typecode]</code>.
[79] Fix | Delete
#
[80] Fix | Delete
# If the path supplied is absolute, it will be escaped in order to
[81] Fix | Delete
# make it absolute in the URI.
[82] Fix | Delete
#
[83] Fix | Delete
# Examples:
[84] Fix | Delete
#
[85] Fix | Delete
# require 'uri'
[86] Fix | Delete
#
[87] Fix | Delete
# uri1 = URI::FTP.build(['user:password', 'ftp.example.com', nil,
[88] Fix | Delete
# '/path/file.zip', 'i'])
[89] Fix | Delete
# uri1.to_s # => "ftp://user:password@ftp.example.com/%2Fpath/file.zip;type=i"
[90] Fix | Delete
#
[91] Fix | Delete
# uri2 = URI::FTP.build({:host => 'ftp.example.com',
[92] Fix | Delete
# :path => 'ruby/src'})
[93] Fix | Delete
# uri2.to_s # => "ftp://ftp.example.com/ruby/src"
[94] Fix | Delete
#
[95] Fix | Delete
def self.build(args)
[96] Fix | Delete
[97] Fix | Delete
# Fix the incoming path to be generic URL syntax
[98] Fix | Delete
# FTP path -> URL path
[99] Fix | Delete
# foo/bar /foo/bar
[100] Fix | Delete
# /foo/bar /%2Ffoo/bar
[101] Fix | Delete
#
[102] Fix | Delete
if args.kind_of?(Array)
[103] Fix | Delete
args[3] = '/' + args[3].sub(/^\//, '%2F')
[104] Fix | Delete
else
[105] Fix | Delete
args[:path] = '/' + args[:path].sub(/^\//, '%2F')
[106] Fix | Delete
end
[107] Fix | Delete
[108] Fix | Delete
tmp = Util::make_components_hash(self, args)
[109] Fix | Delete
[110] Fix | Delete
if tmp[:typecode]
[111] Fix | Delete
if tmp[:typecode].size == 1
[112] Fix | Delete
tmp[:typecode] = TYPECODE_PREFIX + tmp[:typecode]
[113] Fix | Delete
end
[114] Fix | Delete
tmp[:path] << tmp[:typecode]
[115] Fix | Delete
end
[116] Fix | Delete
[117] Fix | Delete
return super(tmp)
[118] Fix | Delete
end
[119] Fix | Delete
[120] Fix | Delete
#
[121] Fix | Delete
# == Description
[122] Fix | Delete
#
[123] Fix | Delete
# Creates a new URI::FTP object from generic URL components with no
[124] Fix | Delete
# syntax checking.
[125] Fix | Delete
#
[126] Fix | Delete
# Unlike build(), this method does not escape the path component as
[127] Fix | Delete
# required by RFC1738; instead it is treated as per RFC2396.
[128] Fix | Delete
#
[129] Fix | Delete
# Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
[130] Fix | Delete
# +opaque+, +query+, and +fragment+, in that order.
[131] Fix | Delete
#
[132] Fix | Delete
def initialize(scheme,
[133] Fix | Delete
userinfo, host, port, registry,
[134] Fix | Delete
path, opaque,
[135] Fix | Delete
query,
[136] Fix | Delete
fragment,
[137] Fix | Delete
parser = nil,
[138] Fix | Delete
arg_check = false)
[139] Fix | Delete
raise InvalidURIError unless path
[140] Fix | Delete
path = path.sub(/^\//,'')
[141] Fix | Delete
path.sub!(/^%2F/,'/')
[142] Fix | Delete
super(scheme, userinfo, host, port, registry, path, opaque,
[143] Fix | Delete
query, fragment, parser, arg_check)
[144] Fix | Delete
@typecode = nil
[145] Fix | Delete
if tmp = @path.index(TYPECODE_PREFIX)
[146] Fix | Delete
typecode = @path[tmp + TYPECODE_PREFIX.size..-1]
[147] Fix | Delete
@path = @path[0..tmp - 1]
[148] Fix | Delete
[149] Fix | Delete
if arg_check
[150] Fix | Delete
self.typecode = typecode
[151] Fix | Delete
else
[152] Fix | Delete
self.set_typecode(typecode)
[153] Fix | Delete
end
[154] Fix | Delete
end
[155] Fix | Delete
end
[156] Fix | Delete
[157] Fix | Delete
# typecode accessor.
[158] Fix | Delete
#
[159] Fix | Delete
# See URI::FTP::COMPONENT.
[160] Fix | Delete
attr_reader :typecode
[161] Fix | Delete
[162] Fix | Delete
# Validates typecode +v+,
[163] Fix | Delete
# returns +true+ or +false+.
[164] Fix | Delete
#
[165] Fix | Delete
def check_typecode(v)
[166] Fix | Delete
if TYPECODE.include?(v)
[167] Fix | Delete
return true
[168] Fix | Delete
else
[169] Fix | Delete
raise InvalidComponentError,
[170] Fix | Delete
"bad typecode(expected #{TYPECODE.join(', ')}): #{v}"
[171] Fix | Delete
end
[172] Fix | Delete
end
[173] Fix | Delete
private :check_typecode
[174] Fix | Delete
[175] Fix | Delete
# Private setter for the typecode +v+.
[176] Fix | Delete
#
[177] Fix | Delete
# See also URI::FTP.typecode=.
[178] Fix | Delete
#
[179] Fix | Delete
def set_typecode(v)
[180] Fix | Delete
@typecode = v
[181] Fix | Delete
end
[182] Fix | Delete
protected :set_typecode
[183] Fix | Delete
[184] Fix | Delete
#
[185] Fix | Delete
# == Args
[186] Fix | Delete
#
[187] Fix | Delete
# +v+::
[188] Fix | Delete
# String
[189] Fix | Delete
#
[190] Fix | Delete
# == Description
[191] Fix | Delete
#
[192] Fix | Delete
# Public setter for the typecode +v+
[193] Fix | Delete
# (with validation).
[194] Fix | Delete
#
[195] Fix | Delete
# See also URI::FTP.check_typecode.
[196] Fix | Delete
#
[197] Fix | Delete
# == Usage
[198] Fix | Delete
#
[199] Fix | Delete
# require 'uri'
[200] Fix | Delete
#
[201] Fix | Delete
# uri = URI.parse("ftp://john@ftp.example.com/my_file.img")
[202] Fix | Delete
# #=> #<URI::FTP ftp://john@ftp.example.com/my_file.img>
[203] Fix | Delete
# uri.typecode = "i"
[204] Fix | Delete
# uri
[205] Fix | Delete
# #=> #<URI::FTP ftp://john@ftp.example.com/my_file.img;type=i>
[206] Fix | Delete
#
[207] Fix | Delete
def typecode=(typecode)
[208] Fix | Delete
check_typecode(typecode)
[209] Fix | Delete
set_typecode(typecode)
[210] Fix | Delete
typecode
[211] Fix | Delete
end
[212] Fix | Delete
[213] Fix | Delete
def merge(oth) # :nodoc:
[214] Fix | Delete
tmp = super(oth)
[215] Fix | Delete
if self != tmp
[216] Fix | Delete
tmp.set_typecode(oth.typecode)
[217] Fix | Delete
end
[218] Fix | Delete
[219] Fix | Delete
return tmp
[220] Fix | Delete
end
[221] Fix | Delete
[222] Fix | Delete
# Returns the path from an FTP URI.
[223] Fix | Delete
#
[224] Fix | Delete
# RFC 1738 specifically states that the path for an FTP URI does not
[225] Fix | Delete
# include the / which separates the URI path from the URI host. Example:
[226] Fix | Delete
#
[227] Fix | Delete
# <code>ftp://ftp.example.com/pub/ruby</code>
[228] Fix | Delete
#
[229] Fix | Delete
# The above URI indicates that the client should connect to
[230] Fix | Delete
# ftp.example.com then cd to pub/ruby from the initial login directory.
[231] Fix | Delete
#
[232] Fix | Delete
# If you want to cd to an absolute directory, you must include an
[233] Fix | Delete
# escaped / (%2F) in the path. Example:
[234] Fix | Delete
#
[235] Fix | Delete
# <code>ftp://ftp.example.com/%2Fpub/ruby</code>
[236] Fix | Delete
#
[237] Fix | Delete
# This method will then return "/pub/ruby".
[238] Fix | Delete
#
[239] Fix | Delete
def path
[240] Fix | Delete
return @path.sub(/^\//,'').sub(/^%2F/,'/')
[241] Fix | Delete
end
[242] Fix | Delete
[243] Fix | Delete
# Private setter for the path of the URI::FTP.
[244] Fix | Delete
def set_path(v)
[245] Fix | Delete
super("/" + v.sub(/^\//, "%2F"))
[246] Fix | Delete
end
[247] Fix | Delete
protected :set_path
[248] Fix | Delete
[249] Fix | Delete
# Returns a String representation of the URI::FTP.
[250] Fix | Delete
def to_s
[251] Fix | Delete
save_path = nil
[252] Fix | Delete
if @typecode
[253] Fix | Delete
save_path = @path
[254] Fix | Delete
@path = @path + TYPECODE_PREFIX + @typecode
[255] Fix | Delete
end
[256] Fix | Delete
str = super
[257] Fix | Delete
if @typecode
[258] Fix | Delete
@path = save_path
[259] Fix | Delete
end
[260] Fix | Delete
[261] Fix | Delete
return str
[262] Fix | Delete
end
[263] Fix | Delete
end
[264] Fix | Delete
@@schemes['FTP'] = FTP
[265] Fix | Delete
end
[266] Fix | Delete
[267] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function