wishdev-rio 0.4.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +341 -0
- data/README +81 -0
- data/Rakefile +281 -0
- data/build_doc.rb +94 -0
- data/doc/ANNOUNCE +159 -0
- data/doc/RELEASE_NOTES +308 -0
- data/doc/RIOIS +215 -0
- data/doc/generators/template/html/rio.css +428 -0
- data/doc/generators/template/html/rio.rb +523 -0
- data/doc/generators/template/html/ugly.rb +132 -0
- data/doc/pkg_def.rb +60 -0
- data/doc/rfc1738.txt +1403 -0
- data/doc/rfc959.txt +3933 -0
- data/ex/catcsv.rb +64 -0
- data/ex/colx.rb +8 -0
- data/ex/findinruby +15 -0
- data/ex/findruby +14 -0
- data/ex/passwd_report.rb +8 -0
- data/ex/prompt.rb +25 -0
- data/ex/rgb.txt.gz +0 -0
- data/ex/riocat +42 -0
- data/ex/riogunzip +31 -0
- data/ex/riogzip +24 -0
- data/ex/rioprompt.rb +10 -0
- data/ex/targz2zip +17 -0
- data/ex/tonl +10 -0
- data/lib/rio/abstract_method.rb +56 -0
- data/lib/rio/argv.rb +56 -0
- data/lib/rio/arycopy.rb +43 -0
- data/lib/rio/assert.rb +114 -0
- data/lib/rio/base.rb +56 -0
- data/lib/rio/callstr.rb +46 -0
- data/lib/rio/const.rb +51 -0
- data/lib/rio/construct.rb +50 -0
- data/lib/rio/constructor.rb +258 -0
- data/lib/rio/context/autoclose.rb +72 -0
- data/lib/rio/context/copying.rb +55 -0
- data/lib/rio/context/cxx.rb +66 -0
- data/lib/rio/context/dir.rb +120 -0
- data/lib/rio/context/gzip.rb +50 -0
- data/lib/rio/context/methods.rb +182 -0
- data/lib/rio/context/skip.rb +66 -0
- data/lib/rio/context/stream.rb +229 -0
- data/lib/rio/context.rb +117 -0
- data/lib/rio/cp.rb +370 -0
- data/lib/rio/def.rb +53 -0
- data/lib/rio/dir.rb +144 -0
- data/lib/rio/doc/EXAMPLES.rb +299 -0
- data/lib/rio/doc/HOWTO.rb +737 -0
- data/lib/rio/doc/INDEX.rb +311 -0
- data/lib/rio/doc/INTRO.rb +1068 -0
- data/lib/rio/doc/OPTIONAL.rb +130 -0
- data/lib/rio/doc/SYNOPSIS.rb +183 -0
- data/lib/rio/doc.rb +45 -0
- data/lib/rio/entrysel.rb +246 -0
- data/lib/rio/exception/copy.rb +97 -0
- data/lib/rio/exception/notimplemented.rb +57 -0
- data/lib/rio/exception/notsupported.rb +46 -0
- data/lib/rio/exception/open.rb +61 -0
- data/lib/rio/exception/state.rb +73 -0
- data/lib/rio/exception.rb +41 -0
- data/lib/rio/ext/csv.rb +351 -0
- data/lib/rio/ext/if.rb +45 -0
- data/lib/rio/ext/mp3info.rb +80 -0
- data/lib/rio/ext/splitlines.rb +253 -0
- data/lib/rio/ext/yaml/doc.rb +133 -0
- data/lib/rio/ext/yaml/tie.rb +149 -0
- data/lib/rio/ext/yaml.rb +164 -0
- data/lib/rio/ext/zipfile/fs.rb +116 -0
- data/lib/rio/ext/zipfile/rl.rb +251 -0
- data/lib/rio/ext/zipfile/rootdir.rb +117 -0
- data/lib/rio/ext/zipfile/state.rb +161 -0
- data/lib/rio/ext/zipfile/wrap.rb +204 -0
- data/lib/rio/ext/zipfile.rb +110 -0
- data/lib/rio/ext.rb +138 -0
- data/lib/rio/factory.rb +436 -0
- data/lib/rio/file.rb +118 -0
- data/lib/rio/filter/closeoneof.rb +103 -0
- data/lib/rio/filter/gzip.rb +70 -0
- data/lib/rio/filter.rb +94 -0
- data/lib/rio/fs/base.rb +41 -0
- data/lib/rio/fs/impl.rb +122 -0
- data/lib/rio/fs/native.rb +75 -0
- data/lib/rio/fs/stream.rb +61 -0
- data/lib/rio/fs/url.rb +63 -0
- data/lib/rio/ftp/conncache.rb +101 -0
- data/lib/rio/ftp/dir.rb +94 -0
- data/lib/rio/ftp/fs.rb +180 -0
- data/lib/rio/ftp/ftpfile.rb +20 -0
- data/lib/rio/grande.rb +97 -0
- data/lib/rio/handle.rb +100 -0
- data/lib/rio/if/basic.rb +64 -0
- data/lib/rio/if/csv.rb +76 -0
- data/lib/rio/if/dir.rb +157 -0
- data/lib/rio/if/file.rb +89 -0
- data/lib/rio/if/fileordir.rb +268 -0
- data/lib/rio/if/grande.rb +729 -0
- data/lib/rio/if/grande_entry.rb +379 -0
- data/lib/rio/if/grande_stream.rb +693 -0
- data/lib/rio/if/internal.rb +125 -0
- data/lib/rio/if/path.rb +462 -0
- data/lib/rio/if/rubyio.rb +681 -0
- data/lib/rio/if/string.rb +83 -0
- data/lib/rio/if/temp.rb +45 -0
- data/lib/rio/if/test.rb +282 -0
- data/lib/rio/if/yaml.rb +206 -0
- data/lib/rio/if.rb +64 -0
- data/lib/rio/ioh.rb +162 -0
- data/lib/rio/iomode.rb +109 -0
- data/lib/rio/ios/fail.rb +106 -0
- data/lib/rio/ios/generic.rb +119 -0
- data/lib/rio/ios/mode.rb +60 -0
- data/lib/rio/ios/null.rb +119 -0
- data/lib/rio/iowrap.rb +128 -0
- data/lib/rio/kernel.rb +54 -0
- data/lib/rio/local.rb +62 -0
- data/lib/rio/match.rb +53 -0
- data/lib/rio/matchrecord.rb +283 -0
- data/lib/rio/no_warn.rb +49 -0
- data/lib/rio/nullio.rb +159 -0
- data/lib/rio/open3.rb +68 -0
- data/lib/rio/ops/construct.rb +61 -0
- data/lib/rio/ops/create.rb +77 -0
- data/lib/rio/ops/dir.rb +346 -0
- data/lib/rio/ops/either.rb +134 -0
- data/lib/rio/ops/file.rb +102 -0
- data/lib/rio/ops/path.rb +296 -0
- data/lib/rio/ops/stream/input.rb +267 -0
- data/lib/rio/ops/stream/output.rb +100 -0
- data/lib/rio/ops/stream/read.rb +86 -0
- data/lib/rio/ops/stream/write.rb +57 -0
- data/lib/rio/ops/stream.rb +87 -0
- data/lib/rio/ops/symlink.rb +80 -0
- data/lib/rio/path/reset.rb +69 -0
- data/lib/rio/path.rb +129 -0
- data/lib/rio/piper/cp.rb +80 -0
- data/lib/rio/piper.rb +122 -0
- data/lib/rio/prompt.rb +66 -0
- data/lib/rio/rectype.rb +88 -0
- data/lib/rio/rl/base.rb +118 -0
- data/lib/rio/rl/builder.rb +117 -0
- data/lib/rio/rl/chmap.rb +66 -0
- data/lib/rio/rl/fs2url.rb +82 -0
- data/lib/rio/rl/ioi.rb +78 -0
- data/lib/rio/rl/path.rb +110 -0
- data/lib/rio/rl/pathmethods.rb +116 -0
- data/lib/rio/rl/uri.rb +200 -0
- data/lib/rio/rl/withpath.rb +296 -0
- data/lib/rio/scheme/aryio.rb +88 -0
- data/lib/rio/scheme/cmdio.rb +80 -0
- data/lib/rio/scheme/cmdpipe.rb +118 -0
- data/lib/rio/scheme/fd.rb +65 -0
- data/lib/rio/scheme/ftp.rb +141 -0
- data/lib/rio/scheme/http.rb +78 -0
- data/lib/rio/scheme/null.rb +55 -0
- data/lib/rio/scheme/path.rb +98 -0
- data/lib/rio/scheme/stderr.rb +55 -0
- data/lib/rio/scheme/stdio.rb +71 -0
- data/lib/rio/scheme/strio.rb +87 -0
- data/lib/rio/scheme/sysio.rb +63 -0
- data/lib/rio/scheme/tcp.rb +75 -0
- data/lib/rio/scheme/temp.rb +200 -0
- data/lib/rio/state/error.rb +72 -0
- data/lib/rio/state.rb +242 -0
- data/lib/rio/stream/base.rb +54 -0
- data/lib/rio/stream/duplex.rb +79 -0
- data/lib/rio/stream/open.rb +202 -0
- data/lib/rio/stream.rb +181 -0
- data/lib/rio/symantics.rb +45 -0
- data/lib/rio/tempdir.rb +132 -0
- data/lib/rio/to_rio/all.rb +39 -0
- data/lib/rio/to_rio/array.rb +39 -0
- data/lib/rio/to_rio/io.rb +40 -0
- data/lib/rio/to_rio/object.rb +42 -0
- data/lib/rio/to_rio/string.rb +40 -0
- data/lib/rio/to_rio.rb +67 -0
- data/lib/rio/uri/file.rb +198 -0
- data/lib/rio/util.rb +48 -0
- data/lib/rio/version.rb +51 -0
- data/lib/rio.rb +162 -0
- data/setup.rb +1360 -0
- data/test/bin/count_lines.rb +11 -0
- data/test/bin/find_lines.rb +13 -0
- data/test/bin/list_dir.rb +14 -0
- data/test/ftp/all.rb +9 -0
- data/test/ftp/anon_copy_data.rb +36 -0
- data/test/ftp/anon_misc.rb +124 -0
- data/test/ftp/anon_read.rb +105 -0
- data/test/ftp/anon_special.rb +68 -0
- data/test/ftp/anon_write.rb +70 -0
- data/test/ftp/ftp2ftp.rb +51 -0
- data/test/ftp/initftpfiles.rb +14 -0
- data/test/ftp/testdef.rb +55 -0
- data/test/gem_runtests.rb +15 -0
- data/test/http/all.rb +4 -0
- data/test/http/copy-from-http.rb +141 -0
- data/test/http/uri-meta.rb +72 -0
- data/test/lib/temp_server.rb +46 -0
- data/test/runalltests.rb +17 -0
- data/test/runftptests.rb +14 -0
- data/test/runhttp.rb +11 -0
- data/test/runhttptests.rb +14 -0
- data/test/runtests.rb +52 -0
- data/test/tc/abs.rb +355 -0
- data/test/tc/all.rb +80 -0
- data/test/tc/base.rb +31 -0
- data/test/tc/base2.rb +87 -0
- data/test/tc/cd1.rb +113 -0
- data/test/tc/clearsel.rb +68 -0
- data/test/tc/clone.rb +208 -0
- data/test/tc/closeoncopy.rb +102 -0
- data/test/tc/closeoneof.rb +194 -0
- data/test/tc/cmdpipe.rb +149 -0
- data/test/tc/copy-dir-samevar.rb +91 -0
- data/test/tc/copy-from.rb +129 -0
- data/test/tc/copy-to.rb +91 -0
- data/test/tc/copy.rb +74 -0
- data/test/tc/copyarray.rb +188 -0
- data/test/tc/copydest.rb +50 -0
- data/test/tc/copydir.rb +166 -0
- data/test/tc/copydirlines.rb +121 -0
- data/test/tc/copylines.rb +46 -0
- data/test/tc/copynonex.rb +118 -0
- data/test/tc/copysymlink.rb +39 -0
- data/test/tc/create.rb +114 -0
- data/test/tc/csv.rb +226 -0
- data/test/tc/csv2.rb +138 -0
- data/test/tc/csv_columns.rb +37 -0
- data/test/tc/csvutil.rb +56 -0
- data/test/tc/dir.rb +76 -0
- data/test/tc/dir_iter.rb +383 -0
- data/test/tc/dirautoclose.rb +67 -0
- data/test/tc/dirent.rb +178 -0
- data/test/tc/dirss.rb +81 -0
- data/test/tc/each.rb +111 -0
- data/test/tc/each_break.rb +243 -0
- data/test/tc/edf.rb +81 -0
- data/test/tc/empty.rb +51 -0
- data/test/tc/emptyriodir.rb +129 -0
- data/test/tc/entary.rb +227 -0
- data/test/tc/entsel.rb +110 -0
- data/test/tc/eq.rb +101 -0
- data/test/tc/expand_path.rb +69 -0
- data/test/tc/ext.rb +136 -0
- data/test/tc/fileno.rb +94 -0
- data/test/tc/files_select.rb +92 -0
- data/test/tc/get.rb +152 -0
- data/test/tc/getrec.rb +137 -0
- data/test/tc/gzip.rb +109 -0
- data/test/tc/io_each_byte.rb +60 -0
- data/test/tc/io_read.rb +80 -0
- data/test/tc/iometh.rb +149 -0
- data/test/tc/likeio.rb +116 -0
- data/test/tc/line_record_row.rb +51 -0
- data/test/tc/lineno.rb +196 -0
- data/test/tc/lines.rb +66 -0
- data/test/tc/misc.rb +432 -0
- data/test/tc/nolines.rb +204 -0
- data/test/tc/noqae.rb +879 -0
- data/test/tc/null.rb +45 -0
- data/test/tc/once.rb +6 -0
- data/test/tc/overload.rb +140 -0
- data/test/tc/pa.rb +158 -0
- data/test/tc/path_parts.rb +175 -0
- data/test/tc/pathop.rb +60 -0
- data/test/tc/paths.rb +145 -0
- data/test/tc/pid.rb +31 -0
- data/test/tc/piper.rb +143 -0
- data/test/tc/programs_util.rb +24 -0
- data/test/tc/qae.rb +493 -0
- data/test/tc/qae_riovar.rb +499 -0
- data/test/tc/readline.rb +30 -0
- data/test/tc/records.rb +68 -0
- data/test/tc/rename.rb +233 -0
- data/test/tc/rename_assign.rb +45 -0
- data/test/tc/riorl.rb +181 -0
- data/test/tc/route.rb +51 -0
- data/test/tc/selnosel.rb +33 -0
- data/test/tc/skip.rb +89 -0
- data/test/tc/skiplines.rb +71 -0
- data/test/tc/split.rb +28 -0
- data/test/tc/splitlines.rb +65 -0
- data/test/tc/splitpath.rb +83 -0
- data/test/tc/sub.rb +46 -0
- data/test/tc/symlink.rb +176 -0
- data/test/tc/symlink0.rb +348 -0
- data/test/tc/symlink1.rb +114 -0
- data/test/tc/synopsis.rb +75 -0
- data/test/tc/temp.rb +152 -0
- data/test/tc/tempdir.rb +60 -0
- data/test/tc/tempfile.rb +66 -0
- data/test/tc/testcase.rb +170 -0
- data/test/tc/tonl.rb +37 -0
- data/test/tc/truncate.rb +39 -0
- data/test/tc/yaml.rb +275 -0
- metadata +387 -0
data/lib/rio/rl/uri.rb
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
#--
|
2
|
+
# ===============================================================================
|
3
|
+
# Copyright (c) 2005,2006,2007 Christopher Kleckner
|
4
|
+
# All rights reserved
|
5
|
+
#
|
6
|
+
# This file is part of the Rio library for ruby.
|
7
|
+
#
|
8
|
+
# Rio is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# Rio is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with Rio; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
# ===============================================================================
|
22
|
+
#++
|
23
|
+
#
|
24
|
+
# To create the documentation for Rio run the command
|
25
|
+
# ruby build_doc.rb
|
26
|
+
# from the distribution directory.
|
27
|
+
#
|
28
|
+
# Suggested Reading
|
29
|
+
# * RIO::Doc::SYNOPSIS
|
30
|
+
# * RIO::Doc::INTRO
|
31
|
+
# * RIO::Doc::HOWTO
|
32
|
+
# * RIO::Doc::EXAMPLES
|
33
|
+
# * RIO::Rio
|
34
|
+
#
|
35
|
+
|
36
|
+
|
37
|
+
require 'rio/rl/base'
|
38
|
+
require 'rio/rl/withpath'
|
39
|
+
require 'rio/fs/url'
|
40
|
+
require 'rio/fs/native'
|
41
|
+
require 'rio/uri/file'
|
42
|
+
|
43
|
+
module RIO
|
44
|
+
module RL
|
45
|
+
class URIBase < WithPath
|
46
|
+
SCHEME = URI::REGEXP::PATTERN::SCHEME
|
47
|
+
HOST = URI::REGEXP::PATTERN::HOST
|
48
|
+
|
49
|
+
attr_accessor :uri
|
50
|
+
def initialize(u,*args)
|
51
|
+
# u should be a ::URI or something that can be parsed to one
|
52
|
+
#p callstr('initialize',u,*args)
|
53
|
+
@base = nil
|
54
|
+
@fs = nil
|
55
|
+
args = _get_opts_from_args(args)
|
56
|
+
init_from_args_(u,*args)
|
57
|
+
super
|
58
|
+
unless self.absolute? or @base
|
59
|
+
@base = ::URI::parse('file://'+RL.fs2url(fs.getwd)+'/')
|
60
|
+
end
|
61
|
+
@uri.path = '/' if @uri.absolute? and @uri.path == ''
|
62
|
+
end
|
63
|
+
def arg0_info_(arg0,*args)
|
64
|
+
#p "arg0_info_(#{arg0.inspect},#{args.inspect})"
|
65
|
+
vuri,vbase,vfs = nil,nil,nil
|
66
|
+
case arg0
|
67
|
+
when RIO::Rio
|
68
|
+
return _init_from_arg(arg0.rl)
|
69
|
+
when URIBase
|
70
|
+
vuri,vbase,vfs = arg0.uri,arg0.base,arg0.fs
|
71
|
+
when ::URI
|
72
|
+
vuri = arg0
|
73
|
+
when ::String
|
74
|
+
vuri = uri_from_string_(arg0) || ::URI.parse(arg0)
|
75
|
+
else
|
76
|
+
raise(ArgumentError,"'#{arg0}'[#{arg0.class}] can not be used to create a Rio")
|
77
|
+
end
|
78
|
+
#puts "uri.rb arg0_info_: vuri=#{vuri}"
|
79
|
+
[vuri,vbase,vfs]
|
80
|
+
end
|
81
|
+
def init_from_args_(arg0,*args)
|
82
|
+
#p "init_from_args_(#{arg0.inspect})"
|
83
|
+
#p callstr('init_from_args_',arg0.inspect,args)
|
84
|
+
vuri,vbase,vfs = self.arg0_info_(arg0,*args)
|
85
|
+
#p vuri,vbase
|
86
|
+
#p vuri
|
87
|
+
@uri = vuri
|
88
|
+
#p 'HERE'
|
89
|
+
#p vuri
|
90
|
+
#p args unless args.nil? || args.empty?
|
91
|
+
self.join(*args)
|
92
|
+
@base = vbase unless @base or vbase.nil?
|
93
|
+
fs = vfs if vfs
|
94
|
+
end
|
95
|
+
def _get_base_from_arg(arg)
|
96
|
+
#p "_get_base: #{arg.inspect}"
|
97
|
+
case arg
|
98
|
+
when RIO::Rio
|
99
|
+
arg.abs.to_uri
|
100
|
+
when URIBase
|
101
|
+
arg.abs.uri
|
102
|
+
when ::URI
|
103
|
+
arg if arg.absolute?
|
104
|
+
when ::String
|
105
|
+
uri_from_string_(arg) || ::URI.parse([RL.fs2url(::Dir.getwd+'/'),arg].join('/').squeeze('/'))
|
106
|
+
else
|
107
|
+
raise(ArgumentError,"'#{arg}' is not a valid base path")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
def _get_opts_from_args(args)
|
111
|
+
if !args.empty? and args[-1].kind_of?(::Hash)
|
112
|
+
opts = args.pop
|
113
|
+
if b = opts[:base]
|
114
|
+
@base = _get_base_from_arg(b)
|
115
|
+
#@base.path.sub!(%r{/*$},'/')
|
116
|
+
end
|
117
|
+
if fs = opts[:fs]
|
118
|
+
@fs = fs
|
119
|
+
end
|
120
|
+
end
|
121
|
+
args
|
122
|
+
end
|
123
|
+
def initialize_copy(*args)
|
124
|
+
super
|
125
|
+
@uri = @uri.clone unless @uri.nil?
|
126
|
+
@base = @base.clone unless @base.nil?
|
127
|
+
end
|
128
|
+
def absolute?()
|
129
|
+
uri.absolute?
|
130
|
+
end
|
131
|
+
alias :abs? :absolute?
|
132
|
+
def openfs_()
|
133
|
+
#p callstr('openfs_')
|
134
|
+
@fs || RIO::FS::Native.create()
|
135
|
+
end
|
136
|
+
def url()
|
137
|
+
self.uri.to_s
|
138
|
+
end
|
139
|
+
def to_s()
|
140
|
+
self.url
|
141
|
+
end
|
142
|
+
def urlpath() uri.path end
|
143
|
+
def urlpath=(arg)
|
144
|
+
#p uri,arg
|
145
|
+
uri.path = arg
|
146
|
+
end
|
147
|
+
def path()
|
148
|
+
case scheme
|
149
|
+
when 'file','path' then fspath()
|
150
|
+
else urlpath()
|
151
|
+
end
|
152
|
+
end
|
153
|
+
def path=(pth)
|
154
|
+
case scheme
|
155
|
+
when 'file','path' then self.fspath = pth
|
156
|
+
else self.urlpath = pth
|
157
|
+
end
|
158
|
+
end
|
159
|
+
def scheme() uri.scheme end
|
160
|
+
def host() uri.host end
|
161
|
+
def host=(arg) uri.host = arg end
|
162
|
+
def opaque()
|
163
|
+
u = uri.clone
|
164
|
+
u.query = nil
|
165
|
+
u.to_s.sub(/^#{SCHEME}:/,'')
|
166
|
+
end
|
167
|
+
def pathroot()
|
168
|
+
u = uri.clone
|
169
|
+
u.query = nil
|
170
|
+
case scheme
|
171
|
+
when 'file'
|
172
|
+
if self.urlpath =~ %r%^(/[a-zA-Z]):% then $1+':/'
|
173
|
+
else '/'
|
174
|
+
end
|
175
|
+
else
|
176
|
+
u.path = '/'
|
177
|
+
u.to_s
|
178
|
+
end
|
179
|
+
end
|
180
|
+
def urlroot()
|
181
|
+
return nil unless absolute?
|
182
|
+
cp = self.clone
|
183
|
+
cp.urlpath = self.pathroot
|
184
|
+
cp.url
|
185
|
+
end
|
186
|
+
def base()
|
187
|
+
@base || self.uri
|
188
|
+
end
|
189
|
+
def base=(arg)
|
190
|
+
#p "uri.rb:base= arg=#{arg.inspect}"
|
191
|
+
@base = _uri(arg)
|
192
|
+
end
|
193
|
+
def join(*args)
|
194
|
+
return self if args.empty?
|
195
|
+
join_(args.map{ |arg| arg.to_s})
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
@@ -0,0 +1,296 @@
|
|
1
|
+
#--
|
2
|
+
# ===============================================================================
|
3
|
+
# Copyright (c) 2005,2006,2007 Christopher Kleckner
|
4
|
+
# All rights reserved
|
5
|
+
#
|
6
|
+
# This file is part of the Rio library for ruby.
|
7
|
+
#
|
8
|
+
# Rio is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# Rio is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with Rio; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
# ===============================================================================
|
22
|
+
#++
|
23
|
+
#
|
24
|
+
# To create the documentation for Rio run the command
|
25
|
+
# ruby build_doc.rb
|
26
|
+
# from the distribution directory.
|
27
|
+
#
|
28
|
+
# Suggested Reading
|
29
|
+
# * RIO::Doc::SYNOPSIS
|
30
|
+
# * RIO::Doc::INTRO
|
31
|
+
# * RIO::Doc::HOWTO
|
32
|
+
# * RIO::Doc::EXAMPLES
|
33
|
+
# * RIO::Rio
|
34
|
+
#
|
35
|
+
|
36
|
+
|
37
|
+
require 'rio/rl/base'
|
38
|
+
require 'rio/exception/notimplemented'
|
39
|
+
require 'rio/rl/builder'
|
40
|
+
|
41
|
+
module RIO
|
42
|
+
module RL
|
43
|
+
module PathUtil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
#
|
48
|
+
|
49
|
+
module RIO
|
50
|
+
module RL
|
51
|
+
class WithPath < RIO::RL::Base
|
52
|
+
include RIO::RL::PathUtil
|
53
|
+
include RIO::Error::NotImplemented
|
54
|
+
|
55
|
+
# returns an appriate FS object for the scheme
|
56
|
+
def openfs_() nodef() end
|
57
|
+
|
58
|
+
# returns the path portion of a URL. All spaces would be %20
|
59
|
+
# returns a String
|
60
|
+
def urlpath() nodef() end
|
61
|
+
def urlpath=(arg) nodef(arg) end
|
62
|
+
|
63
|
+
# For RLs that are on the file system this is fspath()
|
64
|
+
# For RLs that are remote (http,ftp) this is urlpath()
|
65
|
+
# For RLs that have no path this is nil
|
66
|
+
# returns a String
|
67
|
+
def path() nodef{} end
|
68
|
+
def path=(arg) nodef(arg) end
|
69
|
+
|
70
|
+
# returns A URI object representation of the RL if one exists
|
71
|
+
# otherwise it returns nil
|
72
|
+
# returns a URI
|
73
|
+
def uri() nodef() end
|
74
|
+
|
75
|
+
# when the URL is legal it is the URI scheme
|
76
|
+
# otherwise it is one of Rio's schemes
|
77
|
+
# returns a String
|
78
|
+
def scheme() nodef() end
|
79
|
+
|
80
|
+
# returns the host portion of the URI if their is one
|
81
|
+
# otherwise it returns nil
|
82
|
+
# returns a String
|
83
|
+
def host() nodef() end
|
84
|
+
def host=(arg) nodef(arg) end
|
85
|
+
|
86
|
+
# returns the portion of the URL starting after the colon
|
87
|
+
# following the scheme, and ending before the query portion
|
88
|
+
# of the URL
|
89
|
+
# returns a String
|
90
|
+
def opaque() nodef() end
|
91
|
+
|
92
|
+
# returns the portion of the path that when prepended to the
|
93
|
+
# path would make it usable.
|
94
|
+
# For paths on the file system this would be '/'
|
95
|
+
# For http and ftp paths it would be http://host/
|
96
|
+
# For zipfile paths it would be ''
|
97
|
+
# For windows paths with a drive it would be 'C:/'
|
98
|
+
# For windows UNC paths it would be '//host/'
|
99
|
+
# returns a String
|
100
|
+
def pathroot() nodef() end
|
101
|
+
|
102
|
+
|
103
|
+
# returns the base of a path.
|
104
|
+
# merging the value returned with this yields the absolute path
|
105
|
+
def base(thebase=nil) nodef(thebase) end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
module RIO
|
112
|
+
module RL
|
113
|
+
class WithPath < RIO::RL::Base
|
114
|
+
SCHEME = URI::REGEXP::PATTERN::SCHEME
|
115
|
+
HOST = URI::REGEXP::PATTERN::HOST
|
116
|
+
|
117
|
+
# returns the path as the file system sees it. Spaces are spaces and not
|
118
|
+
# %20 etc. This is the path that would be passed to the fs object.
|
119
|
+
# For windows RLs this includes the '//host' part and the 'C:' part
|
120
|
+
# returns a String
|
121
|
+
def fspath()
|
122
|
+
RL.url2fs(self.urlpath)
|
123
|
+
end
|
124
|
+
|
125
|
+
def fspath=(fpth)
|
126
|
+
#p "FSPATH= #{fpth} => #{RL.fs2url(fpth)}"
|
127
|
+
case fpth
|
128
|
+
when %r{^//(#{HOST})(/.*)?$}
|
129
|
+
self.host = $1
|
130
|
+
self.urlpath = RL.fs2url($2||'')
|
131
|
+
else
|
132
|
+
self.urlpath = RL.fs2url(fpth)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
def is_root?(upth)
|
136
|
+
upth =~ %r%^(/?[a-zA-Z]:)?/% or upth =~ %r%^//(#{HOST})%
|
137
|
+
end
|
138
|
+
|
139
|
+
# The value of urlpath() with any trailing slash removed
|
140
|
+
# returns a String
|
141
|
+
def path_no_slash()
|
142
|
+
pth = self.urlpath
|
143
|
+
#p "path_no_slash: #{is_root?(pth)} #{pth}"
|
144
|
+
is_root?(pth) ? pth : pth.sub(/\/$/,'')
|
145
|
+
end
|
146
|
+
# The value of fspath() with any trailing slash removed
|
147
|
+
# returns a String
|
148
|
+
def fspath_no_slash()
|
149
|
+
pth = self.fspath
|
150
|
+
#p "path_no_slash: #{is_root?(pth)} #{pth}"
|
151
|
+
is_root?(pth) ? pth : pth.sub(/\/$/,'')
|
152
|
+
end
|
153
|
+
def pathdepth()
|
154
|
+
pth = self.path_no_slash
|
155
|
+
is_root?(pth) ? 0 : pth.count('/')
|
156
|
+
end
|
157
|
+
|
158
|
+
def _uri(arg)
|
159
|
+
arg.kind_of?(::URI) ? arg.clone : ::URI.parse(arg.to_s)
|
160
|
+
end
|
161
|
+
# returns the absolute path. combines the urlpath with the
|
162
|
+
# argument, or the value returned by base() to create an
|
163
|
+
# absolute path.
|
164
|
+
# returns a RL
|
165
|
+
def abs(thebase=nil)
|
166
|
+
thebase ||= self.base
|
167
|
+
base_uri = _uri(thebase)
|
168
|
+
path_uri = self.uri.clone
|
169
|
+
#p "abs: base_uri=#{base_uri.inspect}"
|
170
|
+
#p "abs: path_uri=#{path_uri.inspect}"
|
171
|
+
if path_uri.scheme == 'file' and base_uri.scheme != 'file'
|
172
|
+
abs_uri = base_uri.merge(path_uri.path)
|
173
|
+
else
|
174
|
+
abs_uri = base_uri.merge(path_uri)
|
175
|
+
end
|
176
|
+
#p "abs: abs_uri=#{abs_uri.inspect}"
|
177
|
+
_build(abs_uri,{:fs => self.fs})
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
# returns an array of parts of a RL.
|
182
|
+
# 'a/b/c' => ['a','b','c']
|
183
|
+
# For absolute paths the first component is the pathroot
|
184
|
+
# '/topdir/dir/file' => ['/','topdir','dir','file']
|
185
|
+
# 'http://host/dir/file' => ['http://host/','dir','file']
|
186
|
+
# '//host/a/b' => ['file://host/','a','b']
|
187
|
+
# each element of the array is an RL whose base is
|
188
|
+
# set such that the correct absolute path would be returned
|
189
|
+
# returns an array of RLs
|
190
|
+
def _parts()
|
191
|
+
pr = self.pathroot
|
192
|
+
ur = self.urlroot.sub(/#{pr}$/,'')
|
193
|
+
up = self.urlpath.sub(/^#{pr}/,'')
|
194
|
+
|
195
|
+
[ur,pr,up]
|
196
|
+
end
|
197
|
+
def split()
|
198
|
+
if absolute?
|
199
|
+
parts = self._parts
|
200
|
+
sparts = []
|
201
|
+
sparts << parts[0] + parts[1]
|
202
|
+
sparts += parts[2].split('/')
|
203
|
+
else
|
204
|
+
sparts = self.urlpath.split('/')
|
205
|
+
end
|
206
|
+
rlparts = sparts.map { |str| self.class.new(str) }
|
207
|
+
(1...sparts.length).each { |i|
|
208
|
+
base_str = rlparts[i-1].abs.url
|
209
|
+
base_str += '/' unless base_str[-1] == ?/
|
210
|
+
rlparts[i].base = base_str
|
211
|
+
}
|
212
|
+
rlparts
|
213
|
+
|
214
|
+
end
|
215
|
+
|
216
|
+
# changes this RLs path so that is consists of this RL's path
|
217
|
+
# combined with those of its arguments.
|
218
|
+
def join(*args)
|
219
|
+
return self if args.empty?
|
220
|
+
#sa = args.map { |arg| ::URI.escape(arg.to_s,ESCAPE) }
|
221
|
+
sa = args.map { |arg| arg.to_s }
|
222
|
+
join_(sa)
|
223
|
+
end
|
224
|
+
def join_(sa)
|
225
|
+
sa.unshift(self.urlpath) unless self.urlpath.empty?
|
226
|
+
self.urlpath = sa.join('/').squeeze('/')
|
227
|
+
self
|
228
|
+
end
|
229
|
+
protected :join_
|
230
|
+
|
231
|
+
# returns the directory portion of the path
|
232
|
+
# like File#dirname
|
233
|
+
# returns a RL
|
234
|
+
def dirname()
|
235
|
+
new_rl = self.clone
|
236
|
+
#p "dirname: fspath_no_slash(#{self.fspath_no_slash} dn(#{fs.dirname(self.fspath_no_slash)})"
|
237
|
+
pth = self.fspath_no_slash
|
238
|
+
if pth =~ %r{^//(#{HOST})(/.*)}
|
239
|
+
new_rl.fspath = "//#{$1}#{fs.dirname($2)}"
|
240
|
+
else
|
241
|
+
new_rl.fspath = fs.dirname(pth)
|
242
|
+
end
|
243
|
+
new_rl
|
244
|
+
end
|
245
|
+
|
246
|
+
# returns the tail portion of the path minus the extension
|
247
|
+
# returns a RL
|
248
|
+
def basename(ext)
|
249
|
+
#p callstr('basename',ext)
|
250
|
+
base_rl = self.abs
|
251
|
+
base_rl.fspath = fs.dirname(base_rl.fspath_no_slash)
|
252
|
+
path_str = fs.basename(self.fspath_no_slash,ext)
|
253
|
+
_build(path_str,{:base => base_rl.uri, :fs => self.fs})
|
254
|
+
end
|
255
|
+
def build_arg0_(path_str)
|
256
|
+
path_str
|
257
|
+
end
|
258
|
+
|
259
|
+
# returns the tail portion of the path
|
260
|
+
# returns a RL
|
261
|
+
def filename()
|
262
|
+
basename('')
|
263
|
+
end
|
264
|
+
|
265
|
+
|
266
|
+
# calls URI#merge
|
267
|
+
# returns a RL
|
268
|
+
def merge(other) _build(self.uri.merge(other.uri)) end
|
269
|
+
|
270
|
+
# calls URI#route_from
|
271
|
+
# returns a RL
|
272
|
+
def route_from(other) _build(self.uri.route_from(other.uri),{:base => other.uri}) end
|
273
|
+
|
274
|
+
# calls URI#route_to
|
275
|
+
# returns a RL
|
276
|
+
def route_to(other) _build(self.uri.route_to(other.uri),{:base => self.uri}) end
|
277
|
+
|
278
|
+
def _build(*args) RIO::RL::Builder.build(*args) end
|
279
|
+
|
280
|
+
def uri_from_string_(str)
|
281
|
+
#p "uri_from_string(#{str})"
|
282
|
+
case str
|
283
|
+
when %r%^file://(#{HOST})?(/.*)?$% then ::URI.parse(str)
|
284
|
+
when %r/^[a-zA-Z]:/ then
|
285
|
+
::URI.parse(str)
|
286
|
+
when %r/^#{SCHEME}:/ then ::URI.parse(str)
|
287
|
+
#when %r{^/} then ::URI.parse('file://'+str+( ( str[-1,0] == '/' ) ? "" : "/"))
|
288
|
+
when %r{^/} then ::URI.parse('file://'+RL.fs2url(str))
|
289
|
+
else ::URI.parse(str)
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
|