rbs 3.9.5 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.clang-format +74 -0
- data/.clangd +2 -0
- data/.github/workflows/c-check.yml +54 -0
- data/.github/workflows/comments.yml +3 -3
- data/.github/workflows/ruby.yml +34 -19
- data/.github/workflows/typecheck.yml +1 -1
- data/.github/workflows/windows.yml +1 -1
- data/.gitignore +4 -0
- data/CHANGELOG.md +49 -0
- data/README.md +38 -1
- data/Rakefile +152 -23
- data/config.yml +190 -62
- data/core/array.rbs +100 -46
- data/core/complex.rbs +32 -21
- data/core/dir.rbs +2 -2
- data/core/encoding.rbs +6 -9
- data/core/enumerable.rbs +90 -3
- data/core/enumerator.rbs +18 -1
- data/core/errno.rbs +8 -0
- data/core/errors.rbs +28 -1
- data/core/exception.rbs +2 -2
- data/core/fiber.rbs +5 -4
- data/core/file.rbs +27 -12
- data/core/file_test.rbs +1 -1
- data/core/float.rbs +209 -22
- data/core/gc.rbs +417 -281
- data/core/hash.rbs +1024 -727
- data/core/integer.rbs +78 -38
- data/core/io/buffer.rbs +18 -7
- data/core/io/wait.rbs +11 -33
- data/core/io.rbs +14 -12
- data/core/kernel.rbs +57 -51
- data/core/marshal.rbs +1 -1
- data/core/match_data.rbs +1 -1
- data/core/math.rbs +42 -3
- data/core/method.rbs +14 -6
- data/core/module.rbs +88 -17
- data/core/nil_class.rbs +3 -3
- data/core/numeric.rbs +16 -16
- data/core/object.rbs +3 -3
- data/core/object_space.rbs +21 -15
- data/{stdlib/pathname/0 → core}/pathname.rbs +255 -355
- data/core/proc.rbs +15 -8
- data/core/process.rbs +2 -2
- data/core/ractor.rbs +278 -437
- data/core/range.rbs +7 -8
- data/core/rational.rbs +37 -24
- data/core/rbs/unnamed/argf.rbs +2 -2
- data/core/rbs/unnamed/env_class.rbs +1 -1
- data/core/rbs/unnamed/random.rbs +4 -2
- data/core/regexp.rbs +25 -20
- data/core/ruby.rbs +53 -0
- data/core/ruby_vm.rbs +6 -4
- data/core/rubygems/errors.rbs +3 -70
- data/core/rubygems/rubygems.rbs +11 -79
- data/core/rubygems/version.rbs +2 -3
- data/core/set.rbs +488 -359
- data/core/string.rbs +3145 -1231
- data/core/struct.rbs +1 -1
- data/core/symbol.rbs +4 -4
- data/core/thread.rbs +92 -29
- data/core/time.rbs +35 -9
- data/core/trace_point.rbs +7 -4
- data/core/unbound_method.rbs +14 -6
- data/docs/aliases.md +79 -0
- data/docs/collection.md +2 -2
- data/docs/encoding.md +56 -0
- data/docs/gem.md +0 -1
- data/docs/sigs.md +3 -3
- data/ext/rbs_extension/ast_translation.c +1016 -0
- data/ext/rbs_extension/ast_translation.h +37 -0
- data/ext/rbs_extension/class_constants.c +155 -0
- data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +7 -1
- data/ext/rbs_extension/compat.h +10 -0
- data/ext/rbs_extension/extconf.rb +25 -1
- data/ext/rbs_extension/legacy_location.c +317 -0
- data/ext/rbs_extension/legacy_location.h +45 -0
- data/ext/rbs_extension/main.c +357 -14
- data/ext/rbs_extension/rbs_extension.h +6 -21
- data/ext/rbs_extension/rbs_string_bridging.c +9 -0
- data/ext/rbs_extension/rbs_string_bridging.h +24 -0
- data/include/rbs/ast.h +687 -0
- data/include/rbs/defines.h +86 -0
- data/include/rbs/lexer.h +199 -0
- data/include/rbs/location.h +59 -0
- data/include/rbs/parser.h +135 -0
- data/include/rbs/string.h +47 -0
- data/include/rbs/util/rbs_allocator.h +59 -0
- data/include/rbs/util/rbs_assert.h +20 -0
- data/include/rbs/util/rbs_buffer.h +83 -0
- data/include/rbs/util/rbs_constant_pool.h +6 -67
- data/include/rbs/util/rbs_encoding.h +282 -0
- data/include/rbs/util/rbs_unescape.h +24 -0
- data/include/rbs.h +1 -2
- data/lib/rbs/annotate/formatter.rb +3 -13
- data/lib/rbs/annotate/rdoc_annotator.rb +3 -1
- data/lib/rbs/annotate/rdoc_source.rb +1 -1
- data/lib/rbs/cli/validate.rb +2 -2
- data/lib/rbs/cli.rb +1 -1
- data/lib/rbs/collection/config/lockfile_generator.rb +1 -0
- data/lib/rbs/definition_builder/ancestor_builder.rb +5 -5
- data/lib/rbs/environment.rb +64 -59
- data/lib/rbs/environment_loader.rb +1 -1
- data/lib/rbs/errors.rb +1 -1
- data/lib/rbs/parser_aux.rb +5 -0
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +124 -38
- data/lib/rbs/test/type_check.rb +14 -0
- data/lib/rbs/types.rb +3 -1
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +1 -1
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +3 -3
- data/sig/annotate/formatter.rbs +2 -2
- data/sig/annotate/rdoc_annotater.rbs +1 -1
- data/sig/environment.rbs +57 -6
- data/sig/manifest.yaml +0 -1
- data/sig/parser.rbs +20 -0
- data/sig/resolver/type_name_resolver.rbs +38 -7
- data/sig/types.rbs +4 -1
- data/src/ast.c +1256 -0
- data/src/lexer.c +2956 -0
- data/src/lexer.re +147 -0
- data/src/lexstate.c +205 -0
- data/src/location.c +71 -0
- data/src/parser.c +3507 -0
- data/src/string.c +41 -0
- data/src/util/rbs_allocator.c +152 -0
- data/src/util/rbs_assert.c +19 -0
- data/src/util/rbs_buffer.c +54 -0
- data/src/util/rbs_constant_pool.c +18 -88
- data/src/util/rbs_encoding.c +21308 -0
- data/src/util/rbs_unescape.c +167 -0
- data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
- data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
- data/stdlib/cgi/0/core.rbs +2 -396
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/cgi-escape/0/escape.rbs +153 -0
- data/stdlib/coverage/0/coverage.rbs +3 -1
- data/stdlib/date/0/date.rbs +67 -59
- data/stdlib/date/0/date_time.rbs +1 -1
- data/stdlib/delegate/0/delegator.rbs +10 -7
- data/stdlib/erb/0/erb.rbs +737 -347
- data/stdlib/fileutils/0/fileutils.rbs +18 -13
- data/stdlib/forwardable/0/forwardable.rbs +3 -0
- data/stdlib/json/0/json.rbs +68 -48
- data/stdlib/net-http/0/net-http.rbs +3 -0
- data/stdlib/objspace/0/objspace.rbs +9 -4
- data/stdlib/open-uri/0/open-uri.rbs +40 -0
- data/stdlib/openssl/0/openssl.rbs +331 -228
- data/stdlib/optparse/0/optparse.rbs +3 -3
- data/stdlib/psych/0/psych.rbs +3 -3
- data/stdlib/rdoc/0/code_object.rbs +2 -2
- data/stdlib/rdoc/0/comment.rbs +2 -0
- data/stdlib/rdoc/0/options.rbs +76 -0
- data/stdlib/rdoc/0/rdoc.rbs +7 -5
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +25 -68
- data/stdlib/ripper/0/ripper.rbs +5 -2
- data/stdlib/singleton/0/singleton.rbs +3 -0
- data/stdlib/socket/0/socket.rbs +13 -1
- data/stdlib/socket/0/tcp_socket.rbs +10 -2
- data/stdlib/stringio/0/stringio.rbs +1176 -85
- data/stdlib/strscan/0/string_scanner.rbs +31 -31
- data/stdlib/tempfile/0/tempfile.rbs +3 -3
- data/stdlib/time/0/time.rbs +1 -1
- data/stdlib/timeout/0/timeout.rbs +63 -7
- data/stdlib/tsort/0/cyclic.rbs +3 -0
- data/stdlib/uri/0/common.rbs +11 -2
- data/stdlib/uri/0/file.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +17 -16
- data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
- data/stdlib/zlib/0/zstream.rbs +1 -0
- metadata +43 -18
- data/ext/rbs_extension/lexer.c +0 -2728
- data/ext/rbs_extension/lexer.h +0 -179
- data/ext/rbs_extension/lexer.re +0 -147
- data/ext/rbs_extension/lexstate.c +0 -175
- data/ext/rbs_extension/location.c +0 -325
- data/ext/rbs_extension/location.h +0 -85
- data/ext/rbs_extension/parser.c +0 -2982
- data/ext/rbs_extension/parser.h +0 -18
- data/ext/rbs_extension/parserstate.c +0 -411
- data/ext/rbs_extension/parserstate.h +0 -163
- data/ext/rbs_extension/unescape.c +0 -32
- data/include/rbs/ruby_objs.h +0 -72
- data/src/constants.c +0 -153
- data/src/ruby_objs.c +0 -799
|
@@ -35,6 +35,46 @@ module BigMath
|
|
|
35
35
|
#
|
|
36
36
|
def self?.PI: (Numeric prec) -> BigDecimal
|
|
37
37
|
|
|
38
|
+
# Computes the arccosine of `decimal` to the specified number of digits of
|
|
39
|
+
# precision, `numeric`.
|
|
40
|
+
#
|
|
41
|
+
# If `decimal` is NaN, returns NaN.
|
|
42
|
+
#
|
|
43
|
+
# BigMath.acos(BigDecimal('0.5'), 32).to_s
|
|
44
|
+
# #=> "0.10471975511965977461542144610932e1"
|
|
45
|
+
#
|
|
46
|
+
def self?.acos: (BigDecimal, Numeric) -> BigDecimal
|
|
47
|
+
|
|
48
|
+
# Computes the inverse hyperbolic cosine of `decimal` to the specified number of
|
|
49
|
+
# digits of precision, `numeric`.
|
|
50
|
+
#
|
|
51
|
+
# If `decimal` is NaN, returns NaN.
|
|
52
|
+
#
|
|
53
|
+
# BigMath.acosh(BigDecimal('2'), 32).to_s
|
|
54
|
+
# #=> "0.1316957896924816708625046347308e1"
|
|
55
|
+
#
|
|
56
|
+
def self?.acosh: (BigDecimal, Numeric) -> BigDecimal
|
|
57
|
+
|
|
58
|
+
# Computes the arcsine of `decimal` to the specified number of digits of
|
|
59
|
+
# precision, `numeric`.
|
|
60
|
+
#
|
|
61
|
+
# If `decimal` is NaN, returns NaN.
|
|
62
|
+
#
|
|
63
|
+
# BigMath.asin(BigDecimal('0.5'), 32).to_s
|
|
64
|
+
# #=> "0.52359877559829887307710723054658e0"
|
|
65
|
+
#
|
|
66
|
+
def self?.asin: (BigDecimal, Numeric) -> BigDecimal
|
|
67
|
+
|
|
68
|
+
# Computes the inverse hyperbolic sine of `decimal` to the specified number of
|
|
69
|
+
# digits of precision, `numeric`.
|
|
70
|
+
#
|
|
71
|
+
# If `decimal` is NaN, returns NaN.
|
|
72
|
+
#
|
|
73
|
+
# BigMath.asinh(BigDecimal('1'), 32).to_s
|
|
74
|
+
# #=> "0.88137358701954302523260932497979e0"
|
|
75
|
+
#
|
|
76
|
+
def self?.asinh: (BigDecimal, Numeric) -> BigDecimal
|
|
77
|
+
|
|
38
78
|
# <!--
|
|
39
79
|
# rdoc-file=ext/bigdecimal/lib/bigdecimal/math.rb
|
|
40
80
|
# - atan(decimal, numeric) -> BigDecimal
|
|
@@ -49,6 +89,32 @@ module BigMath
|
|
|
49
89
|
#
|
|
50
90
|
def self?.atan: (BigDecimal x, Numeric prec) -> BigDecimal
|
|
51
91
|
|
|
92
|
+
# Computes the arctangent of y and x to the specified number of digits of
|
|
93
|
+
# precision, `numeric`.
|
|
94
|
+
#
|
|
95
|
+
# BigMath.atan2(BigDecimal('-1'), BigDecimal('1'), 32).to_s
|
|
96
|
+
# #=> "-0.78539816339744830961566084581988e0"
|
|
97
|
+
#
|
|
98
|
+
def self?.atan2: (BigDecimal, BigDecimal, Numeric) -> BigDecimal
|
|
99
|
+
|
|
100
|
+
# Computes the inverse hyperbolic tangent of `decimal` to the specified number
|
|
101
|
+
# of digits of precision, `numeric`.
|
|
102
|
+
#
|
|
103
|
+
# If `decimal` is NaN, returns NaN.
|
|
104
|
+
#
|
|
105
|
+
# BigMath.atanh(BigDecimal('0.5'), 32).to_s
|
|
106
|
+
# #=> "0.54930614433405484569762261846126e0"
|
|
107
|
+
#
|
|
108
|
+
def self?.atanh: (BigDecimal, Numeric) -> BigDecimal
|
|
109
|
+
|
|
110
|
+
# Computes the cube root of `decimal` to the specified number of digits of
|
|
111
|
+
# precision, `numeric`.
|
|
112
|
+
#
|
|
113
|
+
# BigMath.cbrt(BigDecimal('2'), 32).to_s
|
|
114
|
+
# #=> "0.12599210498948731647672106072782e1"
|
|
115
|
+
#
|
|
116
|
+
def self?.cbrt: (BigDecimal, Numeric) -> BigDecimal
|
|
117
|
+
|
|
52
118
|
# <!--
|
|
53
119
|
# rdoc-file=ext/bigdecimal/lib/bigdecimal/math.rb
|
|
54
120
|
# - cos(decimal, numeric) -> BigDecimal
|
|
@@ -63,10 +129,36 @@ module BigMath
|
|
|
63
129
|
#
|
|
64
130
|
def self?.cos: (BigDecimal x, Numeric prec) -> BigDecimal
|
|
65
131
|
|
|
66
|
-
#
|
|
67
|
-
#
|
|
68
|
-
#
|
|
69
|
-
#
|
|
132
|
+
# Computes the hyperbolic cosine of `decimal` to the specified number of digits
|
|
133
|
+
# of precision, `numeric`.
|
|
134
|
+
#
|
|
135
|
+
# If `decimal` is NaN, returns NaN.
|
|
136
|
+
#
|
|
137
|
+
# BigMath.cosh(BigDecimal('1'), 32).to_s
|
|
138
|
+
# #=> "0.15430806348152437784779056207571e1"
|
|
139
|
+
#
|
|
140
|
+
def self?.cosh: (BigDecimal, Numeric) -> BigDecimal
|
|
141
|
+
|
|
142
|
+
# Computes the error function of +decimal+ to the specified number of digits of
|
|
143
|
+
# precision, +numeric+.
|
|
144
|
+
#
|
|
145
|
+
# If +decimal+ is NaN, returns NaN.
|
|
146
|
+
#
|
|
147
|
+
# BigMath.erf(BigDecimal('1'), 32).to_s
|
|
148
|
+
# #=> "0.84270079294971486934122063508261e0"
|
|
149
|
+
#
|
|
150
|
+
def self?.erf: (BigDecimal, Numeric) -> BigDecimal
|
|
151
|
+
|
|
152
|
+
# Computes the complementary error function of +decimal+ to the specified number of digits of
|
|
153
|
+
# precision, +numeric+.
|
|
154
|
+
#
|
|
155
|
+
# If +decimal+ is NaN, returns NaN.
|
|
156
|
+
#
|
|
157
|
+
# BigMath.erfc(BigDecimal('10'), 32).to_s
|
|
158
|
+
# #=> "0.20884875837625447570007862949578e-44"
|
|
159
|
+
#
|
|
160
|
+
def self?.erfc: (BigDecimal, Numeric) -> BigDecimal
|
|
161
|
+
|
|
70
162
|
# Computes the value of e (the base of natural logarithms) raised to the power
|
|
71
163
|
# of `decimal`, to the specified number of digits of precision.
|
|
72
164
|
#
|
|
@@ -76,10 +168,45 @@ module BigMath
|
|
|
76
168
|
#
|
|
77
169
|
def self?.exp: (BigDecimal, Numeric prec) -> BigDecimal
|
|
78
170
|
|
|
79
|
-
#
|
|
80
|
-
#
|
|
81
|
-
#
|
|
82
|
-
#
|
|
171
|
+
# Decomposes +x+ into a normalized fraction and an integral power of ten.
|
|
172
|
+
#
|
|
173
|
+
# BigMath.frexp(BigDecimal(123.456))
|
|
174
|
+
# #=> [0.123456e0, 3]
|
|
175
|
+
#
|
|
176
|
+
def self?.frexp: (BigDecimal) -> [ BigDecimal, Integer ]
|
|
177
|
+
|
|
178
|
+
# Computes the gamma function of +decimal+ to the specified number of
|
|
179
|
+
# digits of precision, +numeric+.
|
|
180
|
+
#
|
|
181
|
+
# BigMath.gamma(BigDecimal('0.5'), 32).to_s
|
|
182
|
+
# #=> "0.17724538509055160272981674833411e1"
|
|
183
|
+
#
|
|
184
|
+
def self?.gamma: (BigDecimal, Numeric) -> BigDecimal
|
|
185
|
+
|
|
186
|
+
# Returns sqrt(x**2 + y**2) to the specified number of digits of precision,
|
|
187
|
+
# `numeric`.
|
|
188
|
+
#
|
|
189
|
+
# BigMath.hypot(BigDecimal('1'), BigDecimal('2'), 32).to_s
|
|
190
|
+
# #=> "0.22360679774997896964091736687313e1"
|
|
191
|
+
#
|
|
192
|
+
def self?.hypot: (BigDecimal, BigDecimal, Numeric) -> BigDecimal
|
|
193
|
+
|
|
194
|
+
# Inverse of +frexp+.
|
|
195
|
+
# Returns the value of fraction * 10**exponent.
|
|
196
|
+
#
|
|
197
|
+
# BigMath.ldexp(BigDecimal("0.123456e0"), 3)
|
|
198
|
+
# #=> 0.123456e3
|
|
199
|
+
#
|
|
200
|
+
def self?.ldexp: (BigDecimal, Integer) -> BigDecimal
|
|
201
|
+
|
|
202
|
+
# Computes the natural logarithm of the absolute value of the gamma function
|
|
203
|
+
# of +decimal+ to the specified number of digits of precision, +numeric+ and its sign.
|
|
204
|
+
#
|
|
205
|
+
# BigMath.lgamma(BigDecimal('0.5'), 32)
|
|
206
|
+
# #=> [0.57236494292470008707171367567653e0, 1]
|
|
207
|
+
#
|
|
208
|
+
def self?.lgamma: (BigDecimal, Numeric) -> [BigDecimal, Integer]
|
|
209
|
+
|
|
83
210
|
# Computes the natural logarithm of `decimal` to the specified number of digits
|
|
84
211
|
# of precision, `numeric`.
|
|
85
212
|
#
|
|
@@ -91,6 +218,20 @@ module BigMath
|
|
|
91
218
|
#
|
|
92
219
|
def self?.log: (BigDecimal, Numeric prec) -> BigDecimal
|
|
93
220
|
|
|
221
|
+
# Computes the base 2 logarithm of `decimal` to the specified number of digits
|
|
222
|
+
# of precision, `numeric`.
|
|
223
|
+
#
|
|
224
|
+
# If `decimal` is zero or negative, raises Math::DomainError.
|
|
225
|
+
#
|
|
226
|
+
# If `decimal` is positive infinity, returns Infinity.
|
|
227
|
+
#
|
|
228
|
+
# If `decimal` is NaN, returns NaN.
|
|
229
|
+
#
|
|
230
|
+
# BigMath.log2(BigDecimal('3'), 32).to_s
|
|
231
|
+
# #=> "0.15849625007211561814537389439478e1"
|
|
232
|
+
#
|
|
233
|
+
def self?.log2: (BigDecimal, Numeric) -> BigDecimal
|
|
234
|
+
|
|
94
235
|
# <!--
|
|
95
236
|
# rdoc-file=ext/bigdecimal/lib/bigdecimal/math.rb
|
|
96
237
|
# - sin(decimal, numeric) -> BigDecimal
|
|
@@ -105,6 +246,16 @@ module BigMath
|
|
|
105
246
|
#
|
|
106
247
|
def self?.sin: (BigDecimal x, Numeric prec) -> BigDecimal
|
|
107
248
|
|
|
249
|
+
# Computes the hyperbolic sine of `decimal` to the specified number of digits of
|
|
250
|
+
# precision, `numeric`.
|
|
251
|
+
#
|
|
252
|
+
# If `decimal` is NaN, returns NaN.
|
|
253
|
+
#
|
|
254
|
+
# BigMath.sinh(BigDecimal('1'), 32).to_s
|
|
255
|
+
# #=> "0.11752011936438014568823818505956e1"
|
|
256
|
+
#
|
|
257
|
+
def self?.sinh: (BigDecimal, Numeric) -> BigDecimal
|
|
258
|
+
|
|
108
259
|
# <!--
|
|
109
260
|
# rdoc-file=ext/bigdecimal/lib/bigdecimal/math.rb
|
|
110
261
|
# - sqrt(decimal, numeric) -> BigDecimal
|
|
@@ -116,4 +267,14 @@ module BigMath
|
|
|
116
267
|
# #=> "0.1414213562373095048801688724e1"
|
|
117
268
|
#
|
|
118
269
|
def self?.sqrt: (BigDecimal x, Numeric prec) -> BigDecimal
|
|
270
|
+
|
|
271
|
+
# Computes the hyperbolic tangent of `decimal` to the specified number of digits
|
|
272
|
+
# of precision, `numeric`.
|
|
273
|
+
#
|
|
274
|
+
# If `decimal` is NaN, returns NaN.
|
|
275
|
+
#
|
|
276
|
+
# BigMath.tanh(BigDecimal('1'), 32).to_s
|
|
277
|
+
# #=> "0.76159415595576488811945828260479e0"
|
|
278
|
+
#
|
|
279
|
+
def self?.tanh: (BigDecimal, Numeric) -> BigDecimal
|
|
119
280
|
end
|
data/stdlib/cgi/0/core.rbs
CHANGED
|
@@ -1,274 +1,5 @@
|
|
|
1
|
-
# <!-- rdoc-file=lib/cgi.rb -->
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
# The Common Gateway Interface (CGI) is a simple protocol for passing an HTTP
|
|
5
|
-
# request from a web server to a standalone program, and returning the output to
|
|
6
|
-
# the web browser. Basically, a CGI program is called with the parameters of
|
|
7
|
-
# the request passed in either in the environment (GET) or via $stdin (POST),
|
|
8
|
-
# and everything it prints to $stdout is returned to the client.
|
|
9
|
-
#
|
|
10
|
-
# This file holds the CGI class. This class provides functionality for
|
|
11
|
-
# retrieving HTTP request parameters, managing cookies, and generating HTML
|
|
12
|
-
# output.
|
|
13
|
-
#
|
|
14
|
-
# The file CGI::Session provides session management functionality; see that
|
|
15
|
-
# class for more details.
|
|
16
|
-
#
|
|
17
|
-
# See http://www.w3.org/CGI/ for more information on the CGI protocol.
|
|
18
|
-
#
|
|
19
|
-
# ## Introduction
|
|
20
|
-
#
|
|
21
|
-
# CGI is a large class, providing several categories of methods, many of which
|
|
22
|
-
# are mixed in from other modules. Some of the documentation is in this class,
|
|
23
|
-
# some in the modules CGI::QueryExtension and CGI::HtmlExtension. See
|
|
24
|
-
# CGI::Cookie for specific information on handling cookies, and cgi/session.rb
|
|
25
|
-
# (CGI::Session) for information on sessions.
|
|
26
|
-
#
|
|
27
|
-
# For queries, CGI provides methods to get at environmental variables,
|
|
28
|
-
# parameters, cookies, and multipart request data. For responses, CGI provides
|
|
29
|
-
# methods for writing output and generating HTML.
|
|
30
|
-
#
|
|
31
|
-
# Read on for more details. Examples are provided at the bottom.
|
|
32
|
-
#
|
|
33
|
-
# ## Queries
|
|
34
|
-
#
|
|
35
|
-
# The CGI class dynamically mixes in parameter and cookie-parsing functionality,
|
|
36
|
-
# environmental variable access, and support for parsing multipart requests
|
|
37
|
-
# (including uploaded files) from the CGI::QueryExtension module.
|
|
38
|
-
#
|
|
39
|
-
# ### Environmental Variables
|
|
40
|
-
#
|
|
41
|
-
# The standard CGI environmental variables are available as read-only attributes
|
|
42
|
-
# of a CGI object. The following is a list of these variables:
|
|
43
|
-
#
|
|
44
|
-
# AUTH_TYPE HTTP_HOST REMOTE_IDENT
|
|
45
|
-
# CONTENT_LENGTH HTTP_NEGOTIATE REMOTE_USER
|
|
46
|
-
# CONTENT_TYPE HTTP_PRAGMA REQUEST_METHOD
|
|
47
|
-
# GATEWAY_INTERFACE HTTP_REFERER SCRIPT_NAME
|
|
48
|
-
# HTTP_ACCEPT HTTP_USER_AGENT SERVER_NAME
|
|
49
|
-
# HTTP_ACCEPT_CHARSET PATH_INFO SERVER_PORT
|
|
50
|
-
# HTTP_ACCEPT_ENCODING PATH_TRANSLATED SERVER_PROTOCOL
|
|
51
|
-
# HTTP_ACCEPT_LANGUAGE QUERY_STRING SERVER_SOFTWARE
|
|
52
|
-
# HTTP_CACHE_CONTROL REMOTE_ADDR
|
|
53
|
-
# HTTP_FROM REMOTE_HOST
|
|
54
|
-
#
|
|
55
|
-
# For each of these variables, there is a corresponding attribute with the same
|
|
56
|
-
# name, except all lower case and without a preceding HTTP_. `content_length`
|
|
57
|
-
# and `server_port` are integers; the rest are strings.
|
|
58
|
-
#
|
|
59
|
-
# ### Parameters
|
|
60
|
-
#
|
|
61
|
-
# The method #params() returns a hash of all parameters in the request as
|
|
62
|
-
# name/value-list pairs, where the value-list is an Array of one or more values.
|
|
63
|
-
# The CGI object itself also behaves as a hash of parameter names to values,
|
|
64
|
-
# but only returns a single value (as a String) for each parameter name.
|
|
65
|
-
#
|
|
66
|
-
# For instance, suppose the request contains the parameter "favourite_colours"
|
|
67
|
-
# with the multiple values "blue" and "green". The following behavior would
|
|
68
|
-
# occur:
|
|
69
|
-
#
|
|
70
|
-
# cgi.params["favourite_colours"] # => ["blue", "green"]
|
|
71
|
-
# cgi["favourite_colours"] # => "blue"
|
|
72
|
-
#
|
|
73
|
-
# If a parameter does not exist, the former method will return an empty array,
|
|
74
|
-
# the latter an empty string. The simplest way to test for existence of a
|
|
75
|
-
# parameter is by the #has_key? method.
|
|
76
|
-
#
|
|
77
|
-
# ### Cookies
|
|
78
|
-
#
|
|
79
|
-
# HTTP Cookies are automatically parsed from the request. They are available
|
|
80
|
-
# from the #cookies() accessor, which returns a hash from cookie name to
|
|
81
|
-
# CGI::Cookie object.
|
|
82
|
-
#
|
|
83
|
-
# ### Multipart requests
|
|
84
|
-
#
|
|
85
|
-
# If a request's method is POST and its content type is multipart/form-data,
|
|
86
|
-
# then it may contain uploaded files. These are stored by the QueryExtension
|
|
87
|
-
# module in the parameters of the request. The parameter name is the name
|
|
88
|
-
# attribute of the file input field, as usual. However, the value is not a
|
|
89
|
-
# string, but an IO object, either an IOString for small files, or a Tempfile
|
|
90
|
-
# for larger ones. This object also has the additional singleton methods:
|
|
91
|
-
#
|
|
92
|
-
# #local_path()
|
|
93
|
-
# : the path of the uploaded file on the local filesystem
|
|
94
|
-
#
|
|
95
|
-
# #original_filename()
|
|
96
|
-
# : the name of the file on the client computer
|
|
97
|
-
#
|
|
98
|
-
# #content_type()
|
|
99
|
-
# : the content type of the file
|
|
100
|
-
#
|
|
101
|
-
#
|
|
102
|
-
# ## Responses
|
|
103
|
-
#
|
|
104
|
-
# The CGI class provides methods for sending header and content output to the
|
|
105
|
-
# HTTP client, and mixes in methods for programmatic HTML generation from
|
|
106
|
-
# CGI::HtmlExtension and CGI::TagMaker modules. The precise version of HTML to
|
|
107
|
-
# use for HTML generation is specified at object creation time.
|
|
108
|
-
#
|
|
109
|
-
# ### Writing output
|
|
110
|
-
#
|
|
111
|
-
# The simplest way to send output to the HTTP client is using the #out() method.
|
|
112
|
-
# This takes the HTTP headers as a hash parameter, and the body content via a
|
|
113
|
-
# block. The headers can be generated as a string using the #http_header()
|
|
114
|
-
# method. The output stream can be written directly to using the #print()
|
|
115
|
-
# method.
|
|
116
|
-
#
|
|
117
|
-
# ### Generating HTML
|
|
118
|
-
#
|
|
119
|
-
# Each HTML element has a corresponding method for generating that element as a
|
|
120
|
-
# String. The name of this method is the same as that of the element, all
|
|
121
|
-
# lowercase. The attributes of the element are passed in as a hash, and the
|
|
122
|
-
# body as a no-argument block that evaluates to a String. The HTML generation
|
|
123
|
-
# module knows which elements are always empty, and silently drops any passed-in
|
|
124
|
-
# body. It also knows which elements require matching closing tags and which
|
|
125
|
-
# don't. However, it does not know what attributes are legal for which
|
|
126
|
-
# elements.
|
|
127
|
-
#
|
|
128
|
-
# There are also some additional HTML generation methods mixed in from the
|
|
129
|
-
# CGI::HtmlExtension module. These include individual methods for the different
|
|
130
|
-
# types of form inputs, and methods for elements that commonly take particular
|
|
131
|
-
# attributes where the attributes can be directly specified as arguments, rather
|
|
132
|
-
# than via a hash.
|
|
133
|
-
#
|
|
134
|
-
# ### Utility HTML escape and other methods like a function.
|
|
135
|
-
#
|
|
136
|
-
# There are some utility tool defined in cgi/util.rb . And when include, you can
|
|
137
|
-
# use utility methods like a function.
|
|
138
|
-
#
|
|
139
|
-
# ## Examples of use
|
|
140
|
-
#
|
|
141
|
-
# ### Get form values
|
|
142
|
-
#
|
|
143
|
-
# require "cgi"
|
|
144
|
-
# cgi = CGI.new
|
|
145
|
-
# value = cgi['field_name'] # <== value string for 'field_name'
|
|
146
|
-
# # if not 'field_name' included, then return "".
|
|
147
|
-
# fields = cgi.keys # <== array of field names
|
|
148
|
-
#
|
|
149
|
-
# # returns true if form has 'field_name'
|
|
150
|
-
# cgi.has_key?('field_name')
|
|
151
|
-
# cgi.has_key?('field_name')
|
|
152
|
-
# cgi.include?('field_name')
|
|
153
|
-
#
|
|
154
|
-
# CAUTION! `cgi['field_name']` returned an Array with the old cgi.rb(included in
|
|
155
|
-
# Ruby 1.6)
|
|
156
|
-
#
|
|
157
|
-
# ### Get form values as hash
|
|
158
|
-
#
|
|
159
|
-
# require "cgi"
|
|
160
|
-
# cgi = CGI.new
|
|
161
|
-
# params = cgi.params
|
|
162
|
-
#
|
|
163
|
-
# cgi.params is a hash.
|
|
164
|
-
#
|
|
165
|
-
# cgi.params['new_field_name'] = ["value"] # add new param
|
|
166
|
-
# cgi.params['field_name'] = ["new_value"] # change value
|
|
167
|
-
# cgi.params.delete('field_name') # delete param
|
|
168
|
-
# cgi.params.clear # delete all params
|
|
169
|
-
#
|
|
170
|
-
# ### Save form values to file
|
|
171
|
-
#
|
|
172
|
-
# require "pstore"
|
|
173
|
-
# db = PStore.new("query.db")
|
|
174
|
-
# db.transaction do
|
|
175
|
-
# db["params"] = cgi.params
|
|
176
|
-
# end
|
|
177
|
-
#
|
|
178
|
-
# ### Restore form values from file
|
|
179
|
-
#
|
|
180
|
-
# require "pstore"
|
|
181
|
-
# db = PStore.new("query.db")
|
|
182
|
-
# db.transaction do
|
|
183
|
-
# cgi.params = db["params"]
|
|
184
|
-
# end
|
|
185
|
-
#
|
|
186
|
-
# ### Get multipart form values
|
|
187
|
-
#
|
|
188
|
-
# require "cgi"
|
|
189
|
-
# cgi = CGI.new
|
|
190
|
-
# value = cgi['field_name'] # <== value string for 'field_name'
|
|
191
|
-
# value.read # <== body of value
|
|
192
|
-
# value.local_path # <== path to local file of value
|
|
193
|
-
# value.original_filename # <== original filename of value
|
|
194
|
-
# value.content_type # <== content_type of value
|
|
195
|
-
#
|
|
196
|
-
# and value has StringIO or Tempfile class methods.
|
|
197
|
-
#
|
|
198
|
-
# ### Get cookie values
|
|
199
|
-
#
|
|
200
|
-
# require "cgi"
|
|
201
|
-
# cgi = CGI.new
|
|
202
|
-
# values = cgi.cookies['name'] # <== array of 'name'
|
|
203
|
-
# # if not 'name' included, then return [].
|
|
204
|
-
# names = cgi.cookies.keys # <== array of cookie names
|
|
205
|
-
#
|
|
206
|
-
# and cgi.cookies is a hash.
|
|
207
|
-
#
|
|
208
|
-
# ### Get cookie objects
|
|
209
|
-
#
|
|
210
|
-
# require "cgi"
|
|
211
|
-
# cgi = CGI.new
|
|
212
|
-
# for name, cookie in cgi.cookies
|
|
213
|
-
# cookie.expires = Time.now + 30
|
|
214
|
-
# end
|
|
215
|
-
# cgi.out("cookie" => cgi.cookies) {"string"}
|
|
216
|
-
#
|
|
217
|
-
# cgi.cookies # { "name1" => cookie1, "name2" => cookie2, ... }
|
|
218
|
-
#
|
|
219
|
-
# require "cgi"
|
|
220
|
-
# cgi = CGI.new
|
|
221
|
-
# cgi.cookies['name'].expires = Time.now + 30
|
|
222
|
-
# cgi.out("cookie" => cgi.cookies['name']) {"string"}
|
|
223
|
-
#
|
|
224
|
-
# ### Print http header and html string to $DEFAULT_OUTPUT ($>)
|
|
225
|
-
#
|
|
226
|
-
# require "cgi"
|
|
227
|
-
# cgi = CGI.new("html4") # add HTML generation methods
|
|
228
|
-
# cgi.out do
|
|
229
|
-
# cgi.html do
|
|
230
|
-
# cgi.head do
|
|
231
|
-
# cgi.title { "TITLE" }
|
|
232
|
-
# end +
|
|
233
|
-
# cgi.body do
|
|
234
|
-
# cgi.form("ACTION" => "uri") do
|
|
235
|
-
# cgi.p do
|
|
236
|
-
# cgi.textarea("get_text") +
|
|
237
|
-
# cgi.br +
|
|
238
|
-
# cgi.submit
|
|
239
|
-
# end
|
|
240
|
-
# end +
|
|
241
|
-
# cgi.pre do
|
|
242
|
-
# CGI.escapeHTML(
|
|
243
|
-
# "params: #{cgi.params.inspect}\n" +
|
|
244
|
-
# "cookies: #{cgi.cookies.inspect}\n" +
|
|
245
|
-
# ENV.collect do |key, value|
|
|
246
|
-
# "#{key} --> #{value}\n"
|
|
247
|
-
# end.join("")
|
|
248
|
-
# )
|
|
249
|
-
# end
|
|
250
|
-
# end
|
|
251
|
-
# end
|
|
252
|
-
# end
|
|
253
|
-
#
|
|
254
|
-
# # add HTML generation methods
|
|
255
|
-
# CGI.new("html3") # html3.2
|
|
256
|
-
# CGI.new("html4") # html4.01 (Strict)
|
|
257
|
-
# CGI.new("html4Tr") # html4.01 Transitional
|
|
258
|
-
# CGI.new("html4Fr") # html4.01 Frameset
|
|
259
|
-
# CGI.new("html5") # html5
|
|
260
|
-
#
|
|
261
|
-
# ### Some utility methods
|
|
262
|
-
#
|
|
263
|
-
# require 'cgi/util'
|
|
264
|
-
# CGI.escapeHTML('Usage: foo "bar" <baz>')
|
|
265
|
-
#
|
|
266
|
-
# ### Some utility methods like a function
|
|
267
|
-
#
|
|
268
|
-
# require 'cgi/util'
|
|
269
|
-
# include CGI::Util
|
|
270
|
-
# escapeHTML('Usage: foo "bar" <baz>')
|
|
271
|
-
# h('Usage: foo "bar" <baz>') # alias
|
|
1
|
+
# <!-- rdoc-file=lib/cgi/escape.rb -->
|
|
2
|
+
# :stopdoc
|
|
272
3
|
#
|
|
273
4
|
class CGI
|
|
274
5
|
include CGI::Util
|
|
@@ -906,66 +637,6 @@ class CGI
|
|
|
906
637
|
| (Hash[String, untyped] options_hash) -> void
|
|
907
638
|
end
|
|
908
639
|
|
|
909
|
-
module Escape
|
|
910
|
-
# <!--
|
|
911
|
-
# rdoc-file=ext/cgi/escape/escape.c
|
|
912
|
-
# - CGI.escape(string) -> string
|
|
913
|
-
# -->
|
|
914
|
-
# Returns URL-escaped string (`application/x-www-form-urlencoded`).
|
|
915
|
-
#
|
|
916
|
-
def escape: (string str) -> String
|
|
917
|
-
|
|
918
|
-
# <!--
|
|
919
|
-
# rdoc-file=ext/cgi/escape/escape.c
|
|
920
|
-
# - CGI.escapeHTML(string) -> string
|
|
921
|
-
# -->
|
|
922
|
-
# Returns HTML-escaped string.
|
|
923
|
-
#
|
|
924
|
-
def escapeHTML: (string str) -> String
|
|
925
|
-
|
|
926
|
-
# <!--
|
|
927
|
-
# rdoc-file=ext/cgi/escape/escape.c
|
|
928
|
-
# - CGI.escapeURIComponent(string) -> string
|
|
929
|
-
# -->
|
|
930
|
-
# Returns URL-escaped string following RFC 3986.
|
|
931
|
-
#
|
|
932
|
-
def escapeURIComponent: (string) -> String
|
|
933
|
-
|
|
934
|
-
# <!-- rdoc-file=ext/cgi/escape/escape.c -->
|
|
935
|
-
# Returns URL-escaped string following RFC 3986.
|
|
936
|
-
#
|
|
937
|
-
alias escape_uri_component escapeURIComponent
|
|
938
|
-
|
|
939
|
-
# <!--
|
|
940
|
-
# rdoc-file=ext/cgi/escape/escape.c
|
|
941
|
-
# - CGI.unescape(string, encoding=@@accept_charset) -> string
|
|
942
|
-
# -->
|
|
943
|
-
# Returns URL-unescaped string (`application/x-www-form-urlencoded`).
|
|
944
|
-
#
|
|
945
|
-
def unescape: (string str, ?encoding encoding) -> String
|
|
946
|
-
|
|
947
|
-
# <!--
|
|
948
|
-
# rdoc-file=ext/cgi/escape/escape.c
|
|
949
|
-
# - CGI.unescapeHTML(string) -> string
|
|
950
|
-
# -->
|
|
951
|
-
# Returns HTML-unescaped string.
|
|
952
|
-
#
|
|
953
|
-
def unescapeHTML: (string str) -> String
|
|
954
|
-
|
|
955
|
-
# <!--
|
|
956
|
-
# rdoc-file=ext/cgi/escape/escape.c
|
|
957
|
-
# - CGI.unescapeURIComponent(string, encoding=@@accept_charset) -> string
|
|
958
|
-
# -->
|
|
959
|
-
# Returns URL-unescaped string following RFC 3986.
|
|
960
|
-
#
|
|
961
|
-
def unescapeURIComponent: (string) -> String
|
|
962
|
-
|
|
963
|
-
# <!-- rdoc-file=ext/cgi/escape/escape.c -->
|
|
964
|
-
# Returns URL-unescaped string following RFC 3986.
|
|
965
|
-
#
|
|
966
|
-
alias unescape_uri_component unescapeURIComponent
|
|
967
|
-
end
|
|
968
|
-
|
|
969
640
|
# <!-- rdoc-file=lib/cgi/core.rb -->
|
|
970
641
|
# Exception raised when there is an invalid encoding detected
|
|
971
642
|
#
|
|
@@ -1182,45 +853,6 @@ class CGI
|
|
|
1182
853
|
end
|
|
1183
854
|
|
|
1184
855
|
module Util
|
|
1185
|
-
include CGI::Escape
|
|
1186
|
-
|
|
1187
|
-
# <!--
|
|
1188
|
-
# rdoc-file=lib/cgi/util.rb
|
|
1189
|
-
# - escapeElement(string, *elements)
|
|
1190
|
-
# -->
|
|
1191
|
-
# Escape only the tags of certain HTML elements in `string`.
|
|
1192
|
-
#
|
|
1193
|
-
# Takes an element or elements or array of elements. Each element is specified
|
|
1194
|
-
# by the name of the element, without angle brackets. This matches both the
|
|
1195
|
-
# start and the end tag of that element. The attribute list of the open tag will
|
|
1196
|
-
# also be escaped (for instance, the double-quotes surrounding attribute
|
|
1197
|
-
# values).
|
|
1198
|
-
#
|
|
1199
|
-
# print CGI.escapeElement('<BR><A HREF="url"></A>', "A", "IMG")
|
|
1200
|
-
# # "<BR><A HREF="url"></A>"
|
|
1201
|
-
#
|
|
1202
|
-
# print CGI.escapeElement('<BR><A HREF="url"></A>', ["A", "IMG"])
|
|
1203
|
-
# # "<BR><A HREF="url"></A>"
|
|
1204
|
-
#
|
|
1205
|
-
def escapeElement: (string string, *String | Array[String] elements) -> String
|
|
1206
|
-
|
|
1207
|
-
# <!-- rdoc-file=lib/cgi/util.rb -->
|
|
1208
|
-
# Synonym for CGI.escapeElement(str)
|
|
1209
|
-
#
|
|
1210
|
-
alias escape_element escapeElement
|
|
1211
|
-
|
|
1212
|
-
# <!-- rdoc-file=lib/cgi/util.rb -->
|
|
1213
|
-
# Synonym for CGI.escapeHTML(str)
|
|
1214
|
-
#
|
|
1215
|
-
alias escape_html escapeHTML
|
|
1216
|
-
|
|
1217
|
-
# <!--
|
|
1218
|
-
# rdoc-file=lib/cgi/util.rb
|
|
1219
|
-
# - h(string)
|
|
1220
|
-
# -->
|
|
1221
|
-
#
|
|
1222
|
-
alias h escapeHTML
|
|
1223
|
-
|
|
1224
856
|
# <!--
|
|
1225
857
|
# rdoc-file=lib/cgi/util.rb
|
|
1226
858
|
# - pretty(string, shift = " ")
|
|
@@ -1255,32 +887,6 @@ class CGI
|
|
|
1255
887
|
#
|
|
1256
888
|
def rfc1123_date: (Time time) -> String
|
|
1257
889
|
|
|
1258
|
-
# <!--
|
|
1259
|
-
# rdoc-file=lib/cgi/util.rb
|
|
1260
|
-
# - unescapeElement(string, *elements)
|
|
1261
|
-
# -->
|
|
1262
|
-
# Undo escaping such as that done by CGI.escapeElement()
|
|
1263
|
-
#
|
|
1264
|
-
# print CGI.unescapeElement(
|
|
1265
|
-
# CGI.escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
|
|
1266
|
-
# # "<BR><A HREF="url"></A>"
|
|
1267
|
-
#
|
|
1268
|
-
# print CGI.unescapeElement(
|
|
1269
|
-
# CGI.escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
|
|
1270
|
-
# # "<BR><A HREF="url"></A>"
|
|
1271
|
-
#
|
|
1272
|
-
def unescapeElement: (string string, *String | Array[String] elements) -> String
|
|
1273
|
-
|
|
1274
|
-
# <!-- rdoc-file=lib/cgi/util.rb -->
|
|
1275
|
-
# Synonym for CGI.unescapeElement(str)
|
|
1276
|
-
#
|
|
1277
|
-
alias unescape_element unescapeElement
|
|
1278
|
-
|
|
1279
|
-
# <!-- rdoc-file=lib/cgi/util.rb -->
|
|
1280
|
-
# Synonym for CGI.unescapeHTML(str)
|
|
1281
|
-
#
|
|
1282
|
-
alias unescape_html unescapeHTML
|
|
1283
|
-
|
|
1284
890
|
# Abbreviated day-of-week names specified by RFC 822
|
|
1285
891
|
RFC822_DAYS: Array[String]
|
|
1286
892
|
|
data/stdlib/cgi/0/manifest.yaml
CHANGED