Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update library and removing working tags

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4114 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit 467bc1b0b432c6f10f8bce04f31352f772eb2ec9 1 parent 0581a0e
Thibault Martin-Lagardette authored
Showing with 7,492 additions and 6,194 deletions.
  1. +5 −5 lib/English.rb
  2. +42 −41 lib/cgi.rb
  3. +51 −41 lib/cgi/cookie.rb
  4. +39 −34 lib/cgi/core.rb
  5. +59 −59 lib/cgi/html.rb
  6. +27 −27 lib/cgi/session.rb
  7. +3 −3 lib/cgi/session/pstore.rb
  8. +16 −9 lib/cgi/util.rb
  9. +42 −21 lib/cmath.rb
  10. +4 −0 lib/complex.rb
  11. +595 −582 lib/csv.rb
  12. +17 −5 lib/date.rb
  13. +3 −3 lib/date/format.rb
  14. +94 −99 lib/drb/drb.rb
  15. +0 −2  lib/drb/eq.rb
  16. +1 −1  lib/drb/extserv.rb
  17. +4 −8 lib/drb/extservm.rb
  18. +1 −1  lib/drb/invokemethod.rb
  19. +10 −10 lib/drb/observer.rb
  20. +11 −11 lib/drb/ssl.rb
  21. +4 −4 lib/drb/timeridconv.rb
  22. +2 −2 lib/drb/unix.rb
  23. +7 −7 lib/e2mmap.rb
  24. +273 −273 lib/erb.rb
  25. +116 −113 lib/fileutils.rb
  26. +18 −22 lib/find.rb
  27. +119 −26 lib/forwardable.rb
  28. +26 −24 lib/getoptlong.rb
  29. +5 −5 lib/gserver.rb
  30. +50 −13 lib/ipaddr.rb
  31. +62 −44 lib/logger.rb
  32. +21 −17 lib/mathn.rb
  33. +685 −528 lib/matrix.rb
  34. +2 −0  lib/minitest/autorun.rb
  35. +1 −0  lib/minitest/mock.rb
  36. +221 −18 lib/minitest/spec.rb
  37. +352 −73 lib/minitest/unit.rb
  38. +221 −105 lib/mkmf.rb
  39. +44 −32 lib/monitor.rb
  40. +11 −11 lib/mutex_m.rb
  41. +98 −94 lib/net/ftp.rb
  42. +2 −2 lib/net/http.rb
  43. +3 −47 lib/net/https.rb
  44. +367 −207 lib/net/imap.rb
  45. +54 −54 lib/net/pop.rb
  46. +20 −6 lib/net/protocol.rb
  47. +76 −64 lib/net/smtp.rb
  48. +109 −109 lib/net/telnet.rb
  49. +7 −7 lib/observer.rb
  50. +9 −5 lib/open-uri.rb
  51. +671 −40 lib/open3.rb
  52. +58 −45 lib/optparse.rb
  53. +105 −132 lib/pathname.rb
  54. +23 −199 lib/pp.rb
  55. +0 −519 lib/prettyprint.rb
  56. +69 −68 lib/pstore.rb
  57. +120 −99 lib/rake.rb
  58. +2 −4 lib/rake/clean.rb
  59. +4 −6 lib/rake/gempackagetask.rb
  60. +15 −12 lib/rake/loaders/makefile.rb
  61. +11 −14 lib/rake/packagetask.rb
  62. +84 −23 lib/rake/rdoctask.rb
  63. +0 −2  lib/rake/runtest.rb
  64. +0 −2  lib/rake/tasklib.rb
  65. +4 −15 lib/rake/testtask.rb
  66. +15 −3 lib/rake/win32.rb
  67. +6 −2 lib/rational.rb
  68. +136 −58 lib/resolv.rb
  69. +1 −1  lib/rexml/attlistdecl.rb
  70. +8 −8 lib/rexml/attribute.rb
  71. +1 −1  lib/rexml/cdata.rb
  72. +3 −3 lib/rexml/child.rb
  73. +3 −3 lib/rexml/comment.rb
  74. +17 −17 lib/rexml/doctype.rb
  75. +16 −14 lib/rexml/document.rb
  76. +1 −1  lib/rexml/dtd/entitydecl.rb
  77. +1 −1  lib/rexml/dtd/notationdecl.rb
  78. +71 −71 lib/rexml/element.rb
  79. +1 −1  lib/rexml/encoding.rb
  80. +1 −1  lib/rexml/encodings/CP-1252.rb
  81. +1 −1  lib/rexml/encodings/ISO-8859-15.rb
  82. +1 −1  lib/rexml/encodings/UNILE.rb
  83. +2 −1  lib/rexml/encodings/UTF-16.rb
  84. +3 −3 lib/rexml/entity.rb
  85. +5 −3 lib/rexml/formatters/default.rb
  86. +1 −1  lib/rexml/formatters/pretty.rb
  87. +1 −1  lib/rexml/formatters/transitive.rb
  88. +17 −17 lib/rexml/functions.rb
  89. +2 −2 lib/rexml/instruction.rb
  90. +1 −1  lib/rexml/namespace.rb
  91. +1 −1  lib/rexml/node.rb
  92. +1 −1  lib/rexml/output.rb
  93. +26 −25 lib/rexml/parent.rb
  94. +3 −3 lib/rexml/parseexception.rb
  95. +20 −27 lib/rexml/parsers/baseparser.rb
  96. +1 −1  lib/rexml/parsers/pullparser.rb
  97. +16 −16 lib/rexml/parsers/sax2parser.rb
  98. +2 −2 lib/rexml/parsers/streamparser.rb
  99. +2 −2 lib/rexml/parsers/treeparser.rb
  100. +11 −11 lib/rexml/parsers/xpathparser.rb
  101. +12 −9 lib/rexml/quickpath.rb
  102. +5 −5 lib/rexml/rexml.rb
  103. +4 −4 lib/rexml/sax2listener.rb
  104. +29 −18 lib/rexml/source.rb
  105. +3 −3 lib/rexml/streamlistener.rb
  106. +31 −31 lib/rexml/text.rb
  107. +17 −17 lib/rexml/validation/relaxng.rb
  108. +3 −3 lib/rexml/validation/validation.rb
  109. +2 −2 lib/rexml/xmltokens.rb
  110. +1 −1  lib/rexml/xpath.rb
  111. +21 −21 lib/rexml/xpath_parser.rb
  112. +9 −9 lib/rinda/rinda.rb
  113. +4 −4 lib/rinda/ring.rb
  114. +9 −9 lib/rinda/tuplespace.rb
  115. +20 −20 lib/rss/0.9.rb
  116. +24 −24 lib/rss/1.0.rb
  117. +3 −3 lib/rss/2.0.rb
  118. +2 −2 lib/rss/atom.rb
  119. +0 −1  lib/rss/content/1.0.rb
  120. +0 −1  lib/rss/content/2.0.rb
  121. +13 −13 lib/rss/converter.rb
  122. +8 −8 lib/rss/dublincore.rb
  123. +0 −1  lib/rss/dublincore/1.0.rb
  124. +0 −1  lib/rss/dublincore/2.0.rb
  125. +0 −1  lib/rss/dublincore/atom.rb
  126. +9 −9 lib/rss/image.rb
  127. +15 −5 lib/rss/maker.rb
  128. +62 −21 lib/rss/maker/0.9.rb
  129. +6 −5 lib/rss/maker/1.0.rb
  130. +11 −11 lib/rss/maker/2.0.rb
  131. +84 −20 lib/rss/maker/base.rb
  132. +1 −1  lib/rss/maker/dublincore.rb
  133. +1 −1  lib/rss/maker/entry.rb
  134. +3 −6 lib/rss/maker/feed.rb
  135. +1 −1  lib/rss/maker/image.rb
  136. +4 −4 lib/rss/maker/taxonomy.rb
  137. +1 −1  lib/rss/maker/trackback.rb
  138. +33 −16 lib/rss/parser.rb
  139. +5 −5 lib/rss/rexmlparser.rb
  140. +9 −9 lib/rss/rss.rb
  141. +3 −3 lib/rss/syndication.rb
  142. +9 −9 lib/rss/taxonomy.rb
  143. +18 −18 lib/rss/trackback.rb
  144. +3 −5 lib/rss/utils.rb
  145. +2 −2 lib/rss/xml-stylesheet.rb
  146. +7 −7 lib/rss/xmlparser.rb
  147. +5 −5 lib/rss/xmlscanner.rb
  148. +77 −2 lib/securerandom.rb
  149. +24 −11 lib/set.rb
  150. +2 −2 lib/shell.rb
  151. +6 −6 lib/shell/builtin-command.rb
  152. +25 −25 lib/shell/command-processor.rb
  153. +3 −3 lib/shell/error.rb
  154. +4 −4 lib/shell/filter.rb
  155. +13 −13 lib/shell/process-controller.rb
  156. +6 −6 lib/shell/system-command.rb
  157. +2 −2 lib/shell/version.rb
  158. +26 −26 lib/sync.rb
  159. +238 −107 lib/tempfile.rb
  160. +9 −9 lib/test/unit.rb
  161. +35 −3 lib/test/unit/assertions.rb
  162. +3 −0  lib/test/unit/testcase.rb
  163. +29 −35 lib/thread.rb
  164. +22 −47 lib/thwait.rb
  165. +48 −384 lib/time.rb
  166. +8 −24 lib/timeout.rb
  167. +62 −56 lib/tmpdir.rb
  168. +65 −36 lib/tracer.rb
  169. +0 −48 lib/tsort.rb
  170. +43 −5 lib/un.rb
  171. +3 −3 lib/uri.rb
  172. +152 −32 lib/uri/common.rb
  173. +30 −19 lib/uri/ftp.rb
  174. +77 −64 lib/uri/generic.rb
  175. +14 −14 lib/uri/http.rb
  176. +1 −1  lib/uri/https.rb
  177. +4 −4 lib/uri/ldap.rb
  178. +18 −18 lib/uri/mailto.rb
  179. +12 −12 lib/xmlrpc/base64.rb
  180. +72 −72 lib/xmlrpc/client.rb
  181. +5 −5 lib/xmlrpc/config.rb
  182. +36 −36 lib/xmlrpc/create.rb
  183. +10 −10 lib/xmlrpc/datetime.rb
  184. +23 −23 lib/xmlrpc/httpserver.rb
  185. +4 −4 lib/xmlrpc/marshal.rb
  186. +68 −68 lib/xmlrpc/parser.rb
  187. +97 −101 lib/xmlrpc/server.rb
  188. +15 −15 lib/xmlrpc/utils.rb
  189. +15 −0 numeric.c
  190. +0 −1  rakelib/builder/builder.rb
  191. +0 −3  spec/frozen/tags/macruby/library/cgi/cookie/value_tags.txt
  192. +0 −2  spec/frozen/tags/macruby/library/cgi/initialize_tags.txt
  193. +1 −0  spec/frozen/tags/macruby/library/cgi/unescape_tags.txt
  194. +0 −7 spec/frozen/tags/macruby/library/csv/parse_tags.txt
  195. +0 −1  spec/frozen/tags/macruby/library/date/strptime_tags.txt
  196. +0 −1  spec/frozen/tags/macruby/library/getoptlong/set_options_tags.txt
  197. +0 −1  spec/frozen/tags/macruby/library/logger/device/close_tags.txt
  198. +0 −1  spec/frozen/tags/macruby/library/logger/device/write_tags.txt
  199. +0 −1  spec/frozen/tags/macruby/library/logger/logger/close_tags.txt
  200. +0 −9 spec/frozen/tags/macruby/library/matrix/build_tags.txt
  201. +0 −1  spec/frozen/tags/macruby/library/matrix/collect_tags.txt
  202. +0 −1  spec/frozen/tags/macruby/library/matrix/column_size_tags.txt
  203. +0 −3  spec/frozen/tags/macruby/library/matrix/column_tags.txt
  204. +0 −1  spec/frozen/tags/macruby/library/matrix/column_vector_tags.txt
  205. +0 −1  spec/frozen/tags/macruby/library/matrix/columns_tags.txt
  206. +0 −2  spec/frozen/tags/macruby/library/matrix/conj_tags.txt
  207. +0 −2  spec/frozen/tags/macruby/library/matrix/conjugate_tags.txt
  208. +0 −5 spec/frozen/tags/macruby/library/matrix/constructor_tags.txt
  209. +0 −3  spec/frozen/tags/macruby/library/matrix/det_tags.txt
  210. +0 −3  spec/frozen/tags/macruby/library/matrix/determinant_tags.txt
  211. +0 −1  spec/frozen/tags/macruby/library/matrix/divide_tags.txt
  212. +0 −3  spec/frozen/tags/macruby/library/matrix/each_tags.txt
  213. +0 −3  spec/frozen/tags/macruby/library/matrix/each_with_index_tags.txt
  214. +0 −1  spec/frozen/tags/macruby/library/matrix/element_reference_tags.txt
  215. +0 −8 spec/frozen/tags/macruby/library/matrix/empty_tags.txt
  216. +0 −1  spec/frozen/tags/macruby/library/matrix/exponent_tags.txt
  217. +0 −2  spec/frozen/tags/macruby/library/matrix/imag_tags.txt
  218. +0 −2  spec/frozen/tags/macruby/library/matrix/imaginary_tags.txt
  219. +0 −1  spec/frozen/tags/macruby/library/matrix/inspect_tags.txt
  220. +0 −1  spec/frozen/tags/macruby/library/matrix/map_tags.txt
  221. +0 −4 spec/frozen/tags/macruby/library/matrix/minor_tags.txt
  222. +0 −1  spec/frozen/tags/macruby/library/matrix/minus_tags.txt
  223. +0 −4 spec/frozen/tags/macruby/library/matrix/multiply_tags.txt
  224. +0 −1  spec/frozen/tags/macruby/library/matrix/plus_tags.txt
  225. +0 −1  spec/frozen/tags/macruby/library/matrix/rank_tags.txt
  226. +0 −5 spec/frozen/tags/macruby/library/matrix/real_tags.txt
  227. +0 −1  spec/frozen/tags/macruby/library/matrix/rect_tags.txt
  228. +0 −1  spec/frozen/tags/macruby/library/matrix/rectangular_tags.txt
  229. +0 −2  spec/frozen/tags/macruby/library/matrix/regular_tags.txt
  230. +0 −3  spec/frozen/tags/macruby/library/matrix/row_tags.txt
  231. +0 −2  spec/frozen/tags/macruby/library/matrix/singular_tags.txt
  232. +0 −1  spec/frozen/tags/macruby/library/matrix/square_tags.txt
  233. +0 −1  spec/frozen/tags/macruby/library/matrix/t_tags.txt
  234. +0 −1  spec/frozen/tags/macruby/library/matrix/tr_tags.txt
  235. +0 −1  spec/frozen/tags/macruby/library/matrix/trace_tags.txt
  236. +0 −1  spec/frozen/tags/macruby/library/matrix/transpose_tags.txt
  237. +0 −2  spec/frozen/tags/macruby/library/matrix/vector/each2_tags.txt
  238. +0 −1  spec/frozen/tags/macruby/library/uri/eql_tags.txt
View
10 lib/English.rb
@@ -11,7 +11,7 @@
# With English:
#
# require "English"
-#
+#
# $OUTPUT_FIELD_SEPARATOR = ' -- '
# "waterbuffalo" =~ /buff/
# print $LOADED_FEATURES, $POSTMATCH, $PID, "\n"
@@ -83,7 +83,7 @@
# of the contents of all the files
# given as command-line arguments, or <tt>$stdin</tt>
# (in the case where there are no
-# arguments). <tt>$<</tt> supports methods similar to a
+# arguments). <tt>$<</tt> supports methods similar to a
# +File+ object:
# +inmode+, +close+,
# <tt>closed?</tt>, +each+,
@@ -91,7 +91,7 @@
# +eof+, <tt>eof?</tt>, +file+,
# +filename+, +fileno+,
# +getc+, +gets+, +lineno+,
-# <tt>lineno=</tt>, +path+,
+# <tt>lineno=</tt>, +path+,
# +pos+, <tt>pos=</tt>,
# +read+, +readchar+,
# +readline+, +readlines+,
@@ -139,12 +139,12 @@
alias $MATCH $&
# The string preceding the match in the last
-# successful pattern match. This variable is local to
+# successful pattern match. This variable is local to
# the current scope. Read only. Thread local.
alias $PREMATCH $`
# The string following the match in the last
-# successful pattern match. This variable is local to
+# successful pattern match. This variable is local to
# the current scope. Read only. Thread local.
alias $POSTMATCH $'
View
83 lib/cgi.rb
@@ -1,14 +1,14 @@
-#
+#
# cgi.rb - cgi support library
-#
+#
# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
-#
+#
# Copyright (C) 2000 Information-technology Promotion Agency, Japan
#
# Author: Wakou Aoyama <wakou@ruby-lang.org>
#
-# Documentation: Wakou Aoyama (RDoc'd and embellished by William Webber)
-#
+# Documentation: Wakou Aoyama (RDoc'd and embellished by William Webber)
+#
# == Overview
#
# The Common Gateway Interface (CGI) is a simple protocol
@@ -18,7 +18,7 @@
# parameters of the request passed in either in the
# environment (GET) or via $stdin (POST), and everything
# it prints to $stdout is returned to the client.
-#
+#
# This file holds the +CGI+ class. This class provides
# functionality for retrieving HTTP request parameters,
# managing cookies, and generating HTML output. See the
@@ -75,18 +75,18 @@
#
#
# For each of these variables, there is a corresponding attribute with the
-# same name, except all lower case and without a preceding HTTP_.
+# same name, except all lower case and without a preceding HTTP_.
# +content_length+ and +server_port+ are integers; the rest are strings.
#
# === Parameters
#
# The method #params() returns a hash of all parameters in the request as
# name/value-list pairs, where the value-list is an Array of one or more
-# values. The CGI object itself also behaves as a hash of parameter names
-# to values, but only returns a single value (as a String) for each
+# values. The CGI object itself also behaves as a hash of parameter names
+# to values, but only returns a single value (as a String) for each
# parameter name.
#
-# For instance, suppose the request contains the parameter
+# For instance, suppose the request contains the parameter
# "favourite_colours" with the multiple values "blue" and "green". The
# following behaviour would occur:
#
@@ -105,7 +105,7 @@
#
# === Multipart requests
#
-# If a request's method is POST and its content type is multipart/form-data,
+# If a request's method is POST and its content type is multipart/form-data,
# then it may contain uploaded files. These are stored by the QueryExtension
# module in the parameters of the request. The parameter name is the name
# attribute of the file input field, as usual. However, the value is not
@@ -136,7 +136,7 @@
#
# Each HTML element has a corresponding method for generating that
# element as a String. The name of this method is the same as that
-# of the element, all lowercase. The attributes of the element are
+# of the element, all lowercase. The attributes of the element are
# passed in as a hash, and the body as a no-argument block that evaluates
# to a String. The HTML generation module knows which elements are
# always empty, and silently drops any passed-in body. It also knows
@@ -150,57 +150,57 @@
# as arguments, rather than via a hash.
#
# == Examples of use
-#
+#
# === Get form values
-#
+#
# require "cgi"
# cgi = CGI.new
# value = cgi['field_name'] # <== value string for 'field_name'
# # if not 'field_name' included, then return "".
# fields = cgi.keys # <== array of field names
-#
+#
# # returns true if form has 'field_name'
# cgi.has_key?('field_name')
# cgi.has_key?('field_name')
# cgi.include?('field_name')
-#
-# CAUTION! cgi['field_name'] returned an Array with the old
+#
+# CAUTION! cgi['field_name'] returned an Array with the old
# cgi.rb(included in ruby 1.6)
-#
+#
# === Get form values as hash
-#
+#
# require "cgi"
# cgi = CGI.new
# params = cgi.params
-#
+#
# cgi.params is a hash.
-#
+#
# cgi.params['new_field_name'] = ["value"] # add new param
# cgi.params['field_name'] = ["new_value"] # change value
# cgi.params.delete('field_name') # delete param
# cgi.params.clear # delete all params
-#
-#
+#
+#
# === Save form values to file
-#
+#
# require "pstore"
# db = PStore.new("query.db")
# db.transaction do
# db["params"] = cgi.params
# end
-#
-#
+#
+#
# === Restore form values from file
-#
+#
# require "pstore"
# db = PStore.new("query.db")
# db.transaction do
# cgi.params = db["params"]
# end
-#
-#
+#
+#
# === Get multipart form values
-#
+#
# require "cgi"
# cgi = CGI.new
# value = cgi['field_name'] # <== value string for 'field_name'
@@ -208,37 +208,37 @@
# value.local_path # <== path to local file of value
# value.original_filename # <== original filename of value
# value.content_type # <== content_type of value
-#
+#
# and value has StringIO or Tempfile class methods.
-#
+#
# === Get cookie values
-#
+#
# require "cgi"
# cgi = CGI.new
# values = cgi.cookies['name'] # <== array of 'name'
# # if not 'name' included, then return [].
# names = cgi.cookies.keys # <== array of cookie names
-#
+#
# and cgi.cookies is a hash.
-#
+#
# === Get cookie objects
-#
+#
# require "cgi"
# cgi = CGI.new
# for name, cookie in cgi.cookies
# cookie.expires = Time.now + 30
# end
# cgi.out("cookie" => cgi.cookies) {"string"}
-#
+#
# cgi.cookies # { "name1" => cookie1, "name2" => cookie2, ... }
-#
+#
# require "cgi"
# cgi = CGI.new
# cgi.cookies['name'].expires = Time.now + 30
# cgi.out("cookie" => cgi.cookies['name']) {"string"}
-#
+#
# === Print http header and html string to $DEFAULT_OUTPUT ($>)
-#
+#
# require "cgi"
# cgi = CGI.new("html3") # add HTML generation methods
# cgi.out() do
@@ -262,7 +262,7 @@
# end
# end
# end
-#
+#
# # add HTML generation methods
# CGI.new("html3") # html3.2
# CGI.new("html4") # html4.01 (Strict)
@@ -272,3 +272,4 @@
require 'cgi/core'
require 'cgi/cookie'
require 'cgi/util'
+CGI.autoload(:HtmlExtension, 'cgi/html')
View
92 lib/cgi/cookie.rb
@@ -1,37 +1,38 @@
- # Class representing an HTTP cookie.
- #
- # In addition to its specific fields and methods, a Cookie instance
- # is a delegator to the array of its values.
- #
- # See RFC 2965.
- #
- # == Examples of use
- # cookie1 = CGI::Cookie::new("name", "value1", "value2", ...)
- # cookie1 = CGI::Cookie::new("name" => "name", "value" => "value")
- # cookie1 = CGI::Cookie::new('name' => 'name',
- # 'value' => ['value1', 'value2', ...],
- # 'path' => 'path', # optional
- # 'domain' => 'domain', # optional
- # 'expires' => Time.now, # optional
- # 'secure' => true # optional
- # )
- #
- # cgi.out("cookie" => [cookie1, cookie2]) { "string" }
- #
- # name = cookie1.name
- # values = cookie1.value
- # path = cookie1.path
- # domain = cookie1.domain
- # expires = cookie1.expires
- # secure = cookie1.secure
- #
- # cookie1.name = 'name'
- # cookie1.value = ['value1', 'value2', ...]
- # cookie1.path = 'path'
- # cookie1.domain = 'domain'
- # cookie1.expires = Time.now + 30
- # cookie1.secure = true
+# Class representing an HTTP cookie.
+#
+# In addition to its specific fields and methods, a Cookie instance
+# is a delegator to the array of its values.
+#
+# See RFC 2965.
+#
+# == Examples of use
+# cookie1 = CGI::Cookie::new("name", "value1", "value2", ...)
+# cookie1 = CGI::Cookie::new("name" => "name", "value" => "value")
+# cookie1 = CGI::Cookie::new('name' => 'name',
+# 'value' => ['value1', 'value2', ...],
+# 'path' => 'path', # optional
+# 'domain' => 'domain', # optional
+# 'expires' => Time.now, # optional
+# 'secure' => true # optional
+# )
+#
+# cgi.out("cookie" => [cookie1, cookie2]) { "string" }
+#
+# name = cookie1.name
+# values = cookie1.value
+# path = cookie1.path
+# domain = cookie1.domain
+# expires = cookie1.expires
+# secure = cookie1.secure
+#
+# cookie1.name = 'name'
+# cookie1.value = ['value1', 'value2', ...]
+# cookie1.path = 'path'
+# cookie1.domain = 'domain'
+# cookie1.expires = Time.now + 30
+# cookie1.secure = true
class CGI
+ @@accept_charset="UTF-8" unless defined?(@@accept_charset)
class Cookie < Array
# Create a new CGI::Cookie object.
@@ -48,18 +49,19 @@ class Cookie < Array
# domain:: the domain for which this cookie applies.
# expires:: the time at which this cookie expires, as a +Time+ object.
# secure:: whether this cookie is a secure cookie or not (default to
- # false). Secure cookies are only transmitted to HTTPS
+ # false). Secure cookies are only transmitted to HTTPS
# servers.
#
# These keywords correspond to attributes of the cookie object.
def initialize(name = "", *value)
+ @domain = nil
+ @expires = nil
if name.kind_of?(String)
@name = name
- @value = value
%r|^(.*/)|.match(ENV["SCRIPT_NAME"])
@path = ($1 or "")
@secure = false
- return super(@value)
+ return super(value)
end
options = name
@@ -68,7 +70,7 @@ def initialize(name = "", *value)
end
@name = options["name"]
- @value = Array(options["value"])
+ value = Array(options["value"])
# simple support for IE
if options["path"]
@path = options["path"]
@@ -80,12 +82,20 @@ def initialize(name = "", *value)
@expires = options["expires"]
@secure = options["secure"] == true ? true : false
- super(@value)
+ super(value)
end
- attr_accessor("name", "value", "path", "domain", "expires")
+ attr_accessor("name", "path", "domain", "expires")
attr_reader("secure")
+ def value
+ self
+ end
+
+ def value=(val)
+ replace(Array(val))
+ end
+
# Set whether the Cookie is a secure cookie or not.
#
# +val+ must be a boolean.
@@ -96,7 +106,7 @@ def secure=(val)
# Convert the Cookie to its string representation.
def to_s
- val = @value.kind_of?(String) ? CGI::escape(@value) : @value.collect{|v| CGI::escape(v) }.join("&")
+ val = collect{|v| CGI::escape(v) }.join("&")
buf = "#{@name}=#{val}"
buf << "; domain=#{@domain}" if @domain
buf << "; path=#{@path}" if @path
@@ -123,7 +133,7 @@ def Cookie::parse(raw_cookie)
next unless name and values
name = CGI::unescape(name)
values ||= ""
- values = values.split('&').collect{|v| CGI::unescape(v) }
+ values = values.split('&').collect{|v| CGI::unescape(v,@@accept_charset) }
if cookies.has_key?(name)
values = cookies[name].value + values
end
View
73 lib/cgi/core.rb
@@ -11,9 +11,9 @@ class CGI
# Standard internet newline sequence
EOL = CR + LF
- REVISION = '$Id: core.rb 21825 2009-01-28 09:21:49Z yugui $' #:nodoc:
+ REVISION = '$Id: core.rb 27581 2010-05-01 23:54:39Z nobu $' #:nodoc:
- NEEDS_BINMODE = true if /WIN/i.match(RUBY_PLATFORM)
+ NEEDS_BINMODE = File::BINARY != 0
# Path separators in different environments.
PATH_SEPARATOR = {'UNIX'=>'/', 'WINDOWS'=>'\\', 'MACINTOSH'=>':'}
@@ -33,22 +33,16 @@ class CGI
"METHOD_NOT_ALLOWED" => "405 Method Not Allowed",
"NOT_ACCEPTABLE" => "406 Not Acceptable",
"LENGTH_REQUIRED" => "411 Length Required",
- "PRECONDITION_FAILED" => "412 Rrecondition Failed",
+ "PRECONDITION_FAILED" => "412 Precondition Failed",
"SERVER_ERROR" => "500 Internal Server Error",
"NOT_IMPLEMENTED" => "501 Method Not Implemented",
"BAD_GATEWAY" => "502 Bad Gateway",
"VARIANT_ALSO_VARIES" => "506 Variant Also Negotiates"
}
- # Abbreviated day-of-week names specified by RFC 822
- RFC822_DAYS = %w[ Sun Mon Tue Wed Thu Fri Sat ]
-
- # Abbreviated month names specified by RFC 822
- RFC822_MONTHS = %w[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ]
-
# :startdoc:
- def env_table
+ def env_table
ENV
end
@@ -79,7 +73,7 @@ def stdoutput
# status:: the HTTP status code, returned as the Status header. See the
# list of available status codes below.
# server:: the server software, returned as the Server header.
- # connection:: the connection type, returned as the Connection header (for
+ # connection:: the connection type, returned as the Connection header (for
# instance, "close".
# length:: the length of the content that will be sent, returned as the
# Content-Length header.
@@ -89,19 +83,19 @@ def stdoutput
# object, returned as the Expires header.
# cookie:: a cookie or cookies, returned as one or more Set-Cookie headers.
# The value can be the literal string of the cookie; a CGI::Cookie
- # object; an Array of literal cookie strings or Cookie objects; or a
+ # object; an Array of literal cookie strings or Cookie objects; or a
# hash all of whose values are literal cookie strings or Cookie objects.
# These cookies are in addition to the cookies held in the
# @output_cookies field.
#
# Other header lines can also be set; they are appended as key: value.
- #
+ #
# header
# # Content-Type: text/html
- #
+ #
# header("text/plain")
# # Content-Type: text/plain
- #
+ #
# header("nph" => true,
# "status" => "OK", # == "200 OK"
# # "status" => "200 GOOD",
@@ -116,9 +110,9 @@ def stdoutput
# "cookie" => [cookie1, cookie2],
# "my_header1" => "my_value"
# "my_header2" => "my_value")
- #
+ #
# The status codes are:
- #
+ #
# "OK" --> "200 OK"
# "PARTIAL_CONTENT" --> "206 Partial Content"
# "MULTIPLE_CHOICES" --> "300 Multiple Choices"
@@ -137,8 +131,8 @@ def stdoutput
# "NOT_IMPLEMENTED" --> "501 Method Not Implemented"
# "BAD_GATEWAY" --> "502 Bad Gateway"
# "VARIANT_ALSO_VARIES" --> "506 Variant Also Negotiates"
- #
- # This method does not perform charset conversion.
+ #
+ # This method does not perform charset conversion.
def header(options='text/html')
if options.is_a?(String)
content_type = options
@@ -277,13 +271,13 @@ def _header_for_modruby(buf) #:nodoc:
# # Content-Length: 6
# #
# # string
- #
+ #
# cgi.out("text/plain") { "string" }
# # Content-Type: text/plain
# # Content-Length: 6
# #
# # string
- #
+ #
# cgi.out("nph" => true,
# "status" => "OK", # == "200 OK"
# "server" => ENV['SERVER_SOFTWARE'],
@@ -296,16 +290,16 @@ def _header_for_modruby(buf) #:nodoc:
# "cookie" => [cookie1, cookie2],
# "my_header1" => "my_value",
# "my_header2" => "my_value") { "string" }
- #
+ #
# Content-Length is automatically calculated from the size of
# the String returned by the content block.
#
# If ENV['REQUEST_METHOD'] == "HEAD", then only the header
# is outputted (the content block is still required, but it
# is ignored).
- #
+ #
# If the charset is "iso-2022-jp" or "euc-jp" or "shift_jis" then
- # the content is converted to this charset, and the language is set
+ # the content is converted to this charset, and the language is set
# to "ja".
def out(options = "text/html") # :yield:
@@ -358,7 +352,7 @@ def CGI::parse(query)
# Mixin module. It provides the follow functionality groups:
#
- # 1. Access to CGI environment variables as methods. See
+ # 1. Access to CGI environment variables as methods. See
# documentation to the CGI class for a list of these variables.
#
# 2. Access to cookies, including the cookies attribute.
@@ -408,7 +402,7 @@ def raw_cookie2
# values is an Array.
attr_reader :params
- # Get the uploaed files as a hash of name=>values pairs
+ # Get the uploaded files as a hash of name=>values pairs
attr_reader :files
# Set all the parameters.
@@ -440,7 +434,13 @@ def read_multipart(boundary, content_length)
## create body (StringIO or Tempfile)
body = create_body(bufsize < content_length)
class << body
- alias local_path path
+ if method_defined?(:path)
+ alias local_path path
+ else
+ def local_path
+ nil
+ end
+ end
attr_reader :original_filename, :content_type
end
## find head and boundary
@@ -549,12 +549,17 @@ def read_from_cmdline
%|(offline mode: enter name=value pairs on standard input)\n|
)
end
- readlines.join(' ').gsub(/\n/, '')
- end.gsub(/\\=/, '%3D').gsub(/\\&/, '%26')
+ array = readlines rescue nil
+ if not array.nil?
+ array.join(' ').gsub(/\n/n, '')
+ else
+ ""
+ end
+ end.gsub(/\\=/n, '%3D').gsub(/\\&/n, '%26')
words = Shellwords.shellwords(string)
- if words.find{|x| /=/.match(x) }
+ if words.find{|x| /=/n.match(x) }
words.join('&')
else
words.join('+')
@@ -617,7 +622,7 @@ def multipart?
# Get the value for the parameter with a given key.
#
- # If the parameter has multiple values, only the first will be
+ # If the parameter has multiple values, only the first will be
# retrieved; use #params() to get the array of values.
def [](key)
params = @params[key]
@@ -658,7 +663,7 @@ class InvalidEncoding < Exception; end
# This default value default is "UTF-8"
# If you want to change the default accept character set
# when create a new CGI instance, set this:
- #
+ #
# CGI.accept_charset = "EUC-JP"
#
@@ -700,11 +705,11 @@ def self.accept_charset=(accept_charset)
#
# == block
#
- # When you use a block, you can write a process
+ # When you use a block, you can write a process
# that query encoding is invalid. Example:
#
# encoding_error={}
- # cgi=CGI.new(:accept_charset=>"EUC-JP") do |name,value|
+ # cgi=CGI.new(:accept_charset=>"EUC-JP") do |name,value|
# encoding_error[key] = value
# end
#
View
118 lib/cgi/html.rb
@@ -66,7 +66,7 @@ def nO_element_def(element)
# Modules Http3, Http4, etc., contain more basic HTML-generation methods
# (:title, :center, etc.).
#
- # See class CGI for a detailed example.
+ # See class CGI for a detailed example.
#
module HtmlExtension
@@ -99,7 +99,7 @@ def a(href = "") # :yield:
end
end
- # Generate a Document Base URI element as a String.
+ # Generate a Document Base URI element as a String.
#
# +href+ can either by a string, giving the base URL for the HREF
# attribute, or it can be a has of the element's attributes.
@@ -179,10 +179,10 @@ def caption(align = {}) # :yield:
#
# checkbox("name")
# # = checkbox("NAME" => "name")
- #
+ #
# checkbox("name", "value")
# # = checkbox("NAME" => "name", "VALUE" => "value")
- #
+ #
# checkbox("name", "value", true)
# # = checkbox("NAME" => "name", "VALUE" => "value", "CHECKED" => true)
def checkbox(name = "", value = nil, checked = nil)
@@ -220,23 +220,23 @@ def checkbox(name = "", value = nil, checked = nil)
# # <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo
# # <INPUT TYPE="checkbox" NAME="name" VALUE="bar">bar
# # <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz
- #
+ #
# checkbox_group("name", ["foo"], ["bar", true], "baz")
# # <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo
# # <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="bar">bar
# # <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz
- #
+ #
# checkbox_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
# # <INPUT TYPE="checkbox" NAME="name" VALUE="1">Foo
# # <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="2">Bar
# # <INPUT TYPE="checkbox" NAME="name" VALUE="Baz">Baz
- #
+ #
# checkbox_group("NAME" => "name",
# "VALUES" => ["foo", "bar", "baz"])
- #
+ #
# checkbox_group("NAME" => "name",
# "VALUES" => [["foo"], ["bar", true], "baz"])
- #
+ #
# checkbox_group("NAME" => "name",
# "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
def checkbox_group(name = "", *values)
@@ -272,13 +272,13 @@ def checkbox_group(name = "", *values)
#
# file_field("name")
# # <INPUT TYPE="file" NAME="name" SIZE="20">
- #
+ #
# file_field("name", 40)
# # <INPUT TYPE="file" NAME="name" SIZE="40">
- #
+ #
# file_field("name", 40, 100)
# # <INPUT TYPE="file" NAME="name" SIZE="40" MAXLENGTH="100">
- #
+ #
# file_field("NAME" => "name", "SIZE" => 40)
# # <INPUT TYPE="file" NAME="name" SIZE="40">
def file_field(name = "", size = 20, maxlength = nil)
@@ -298,7 +298,7 @@ def file_field(name = "", size = 20, maxlength = nil)
#
# +method+ should be either "get" or "post", and defaults to the latter.
# +action+ defaults to the current CGI script name. +enctype+
- # defaults to "application/x-www-form-urlencoded".
+ # defaults to "application/x-www-form-urlencoded".
#
# Alternatively, the attributes can be specified as a hash.
#
@@ -306,19 +306,19 @@ def file_field(name = "", size = 20, maxlength = nil)
#
# form{ "string" }
# # <FORM METHOD="post" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
- #
+ #
# form("get") { "string" }
# # <FORM METHOD="get" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
- #
+ #
# form("get", "url") { "string" }
# # <FORM METHOD="get" ACTION="url" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
- #
+ #
# form("METHOD" => "post", "ENCTYPE" => "enctype") { "string" }
# # <FORM METHOD="post" ENCTYPE="enctype">string</FORM>
def form(method = "post", action = script_name, enctype = "application/x-www-form-urlencoded")
attributes = if method.kind_of?(String)
{ "METHOD" => method, "ACTION" => action,
- "ENCTYPE" => enctype }
+ "ENCTYPE" => enctype }
else
unless method.has_key?("METHOD")
method["METHOD"] = "post"
@@ -350,10 +350,10 @@ def form(method = "post", action = script_name, enctype = "application/x-www-for
#
# hidden("name")
# # <INPUT TYPE="hidden" NAME="name">
- #
+ #
# hidden("name", "value")
# # <INPUT TYPE="hidden" NAME="name" VALUE="value">
- #
+ #
# hidden("NAME" => "name", "VALUE" => "reset", "ID" => "foo")
# # <INPUT TYPE="hidden" NAME="name" VALUE="value" ID="foo">
def hidden(name = "", value = nil)
@@ -376,36 +376,36 @@ def hidden(name = "", value = nil)
# should include the entire text of this tag, including angle brackets.
#
# The body of the html element is supplied as a block.
- #
+ #
# html{ "string" }
# # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML>string</HTML>
- #
+ #
# html("LANG" => "ja") { "string" }
# # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML LANG="ja">string</HTML>
- #
+ #
# html("DOCTYPE" => false) { "string" }
# # <HTML>string</HTML>
- #
+ #
# html("DOCTYPE" => '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">') { "string" }
# # <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML>string</HTML>
- #
+ #
# html("PRETTY" => " ") { "<BODY></BODY>" }
# # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
# # <HTML>
# # <BODY>
# # </BODY>
# # </HTML>
- #
+ #
# html("PRETTY" => "\t") { "<BODY></BODY>" }
# # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
# # <HTML>
# # <BODY>
# # </BODY>
# # </HTML>
- #
+ #
# html("PRETTY") { "<BODY></BODY>" }
# # = html("PRETTY" => " ") { "<BODY></BODY>" }
- #
+ #
# html(if $VERBOSE then "PRETTY" end) { "HTML string" }
#
def html(attributes = {}) # :yield:
@@ -444,18 +444,18 @@ def html(attributes = {}) # :yield:
# Generate an Image Button Input element as a string.
#
- # +src+ is the URL of the image to use for the button. +name+
+ # +src+ is the URL of the image to use for the button. +name+
# is the input name. +alt+ is the alternative text for the image.
#
# Alternatively, the attributes can be specified as a hash.
- #
+ #
# image_button("url")
# # <INPUT TYPE="image" SRC="url">
- #
+ #
# image_button("url", "name", "string")
# # <INPUT TYPE="image" SRC="url" NAME="name" ALT="string">
- #
- # image_button("SRC" => "url", "ATL" => "strng")
+ #
+ # image_button("SRC" => "url", "ALT" => "string")
# # <INPUT TYPE="image" SRC="url" ALT="string">
def image_button(src = "", name = nil, alt = nil)
attributes = if src.kind_of?(String)
@@ -480,7 +480,7 @@ def image_button(src = "", name = nil, alt = nil)
#
# img("src", "alt", 100, 50)
# # <IMG SRC="src" ALT="alt" WIDTH="100" HEIGHT="50">
- #
+ #
# img("SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50)
# # <IMG SRC="src" ALT="alt" WIDTH="100" HEIGHT="50">
def img(src = "", alt = "", width = nil, height = nil)
@@ -506,15 +506,15 @@ def img(src = "", alt = "", width = nil, height = nil)
#
# multipart_form{ "string" }
# # <FORM METHOD="post" ENCTYPE="multipart/form-data">string</FORM>
- #
+ #
# multipart_form("url") { "string" }
# # <FORM METHOD="post" ACTION="url" ENCTYPE="multipart/form-data">string</FORM>
def multipart_form(action = nil, enctype = "multipart/form-data")
attributes = if action == nil
- { "METHOD" => "post", "ENCTYPE" => enctype }
+ { "METHOD" => "post", "ENCTYPE" => enctype }
elsif action.kind_of?(String)
{ "METHOD" => "post", "ACTION" => action,
- "ENCTYPE" => enctype }
+ "ENCTYPE" => enctype }
else
unless action.has_key?("METHOD")
action["METHOD"] = "post"
@@ -542,13 +542,13 @@ def multipart_form(action = nil, enctype = "multipart/form-data")
#
# password_field("name")
# # <INPUT TYPE="password" NAME="name" SIZE="40">
- #
+ #
# password_field("name", "value")
# # <INPUT TYPE="password" NAME="name" VALUE="value" SIZE="40">
- #
+ #
# password_field("password", "value", 80, 200)
# # <INPUT TYPE="password" NAME="name" VALUE="value" SIZE="80" MAXLENGTH="200">
- #
+ #
# password_field("NAME" => "name", "VALUE" => "value")
# # <INPUT TYPE="password" NAME="name" VALUE="value">
def password_field(name = "", value = nil, size = 40, maxlength = nil)
@@ -584,21 +584,21 @@ def password_field(name = "", value = nil, size = 40, maxlength = nil)
# # <OPTION VALUE="bar">bar</OPTION>
# # <OPTION VALUE="baz">baz</OPTION>
# # </SELECT>
- #
+ #
# popup_menu("name", ["foo"], ["bar", true], "baz")
# # <SELECT NAME="name">
# # <OPTION VALUE="foo">foo</OPTION>
# # <OPTION VALUE="bar" SELECTED>bar</OPTION>
# # <OPTION VALUE="baz">baz</OPTION>
# # </SELECT>
- #
+ #
# popup_menu("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
# # <SELECT NAME="name">
# # <OPTION VALUE="1">Foo</OPTION>
# # <OPTION SELECTED VALUE="2">Bar</OPTION>
# # <OPTION VALUE="Baz">Baz</OPTION>
# # </SELECT>
- #
+ #
# popup_menu("NAME" => "name", "SIZE" => 2, "MULTIPLE" => true,
# "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
# # <SELECT NAME="name" MULTIPLE SIZE="2">
@@ -649,10 +649,10 @@ def popup_menu(name = "", *values)
#
# radio_button("name", "value")
# # <INPUT TYPE="radio" NAME="name" VALUE="value">
- #
+ #
# radio_button("name", "value", true)
# # <INPUT TYPE="radio" NAME="name" VALUE="value" CHECKED>
- #
+ #
# radio_button("NAME" => "name", "VALUE" => "value", "ID" => "foo")
# # <INPUT TYPE="radio" NAME="name" VALUE="value" ID="foo">
def radio_button(name = "", value = nil, checked = nil)
@@ -670,28 +670,28 @@ def radio_button(name = "", value = nil, checked = nil)
#
# This works the same as #checkbox_group(). However, it is not valid
# to have more than one radiobutton in a group checked.
- #
+ #
# radio_group("name", "foo", "bar", "baz")
# # <INPUT TYPE="radio" NAME="name" VALUE="foo">foo
# # <INPUT TYPE="radio" NAME="name" VALUE="bar">bar
# # <INPUT TYPE="radio" NAME="name" VALUE="baz">baz
- #
+ #
# radio_group("name", ["foo"], ["bar", true], "baz")
# # <INPUT TYPE="radio" NAME="name" VALUE="foo">foo
# # <INPUT TYPE="radio" CHECKED NAME="name" VALUE="bar">bar
# # <INPUT TYPE="radio" NAME="name" VALUE="baz">baz
- #
+ #
# radio_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
# # <INPUT TYPE="radio" NAME="name" VALUE="1">Foo
# # <INPUT TYPE="radio" CHECKED NAME="name" VALUE="2">Bar
# # <INPUT TYPE="radio" NAME="name" VALUE="Baz">Baz
- #
+ #
# radio_group("NAME" => "name",
# "VALUES" => ["foo", "bar", "baz"])
- #
+ #
# radio_group("NAME" => "name",
# "VALUES" => [["foo"], ["bar", true], "baz"])
- #
+ #
# radio_group("NAME" => "name",
# "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
def radio_group(name = "", *values)
@@ -723,10 +723,10 @@ def radio_group(name = "", *values)
#
# reset
# # <INPUT TYPE="reset">
- #
+ #
# reset("reset")
# # <INPUT TYPE="reset" VALUE="reset">
- #
+ #
# reset("VALUE" => "reset", "ID" => "foo")
# # <INPUT TYPE="reset" VALUE="reset" ID="foo">
def reset(value = nil, name = nil)
@@ -750,13 +750,13 @@ def reset(value = nil, name = nil)
#
# submit
# # <INPUT TYPE="submit">
- #
+ #
# submit("ok")
# # <INPUT TYPE="submit" VALUE="ok">
- #
+ #
# submit("ok", "button1")
# # <INPUT TYPE="submit" VALUE="ok" NAME="button1">
- #
+ #
# submit("VALUE" => "ok", "NAME" => "button1", "ID" => "foo")
# # <INPUT TYPE="submit" VALUE="ok" NAME="button1" ID="foo">
def submit(value = nil, name = nil)
@@ -779,16 +779,16 @@ def submit(value = nil, name = nil)
#
# text_field("name")
# # <INPUT TYPE="text" NAME="name" SIZE="40">
- #
+ #
# text_field("name", "value")
# # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="40">
- #
+ #
# text_field("name", "value", 80)
# # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="80">
- #
+ #
# text_field("name", "value", 80, 200)
# # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="80" MAXLENGTH="200">
- #
+ #
# text_field("NAME" => "name", "VALUE" => "value")
# # <INPUT TYPE="text" NAME="name" VALUE="value">
def text_field(name = "", value = nil, size = 40, maxlength = nil)
View
54 lib/cgi/session.rb
@@ -13,7 +13,7 @@
#
# This file provides the +CGI::Session+ class, which provides session
# support for CGI scripts. A session is a sequence of HTTP requests
-# and responses linked together and associated with a single client.
+# and responses linked together and associated with a single client.
# Information associated with the session is stored
# on the server between requests. A session id is passed between client
# and server with every request and response, transparently
@@ -28,7 +28,7 @@
class CGI
- # Class representing an HTTP session. See documentation for the file
+ # Class representing an HTTP session. See documentation for the file
# cgi/session.rb for an introduction to HTTP sessions.
#
# == Lifecycle
@@ -47,7 +47,7 @@ class CGI
# == Setting and retrieving session data.
#
# The Session class associates data with a session as key-value pairs.
- # This data can be set and retrieved by indexing the Session instance
+ # This data can be set and retrieved by indexing the Session instance
# using '[]', much the same as hashes (although other hash methods
# are not supported).
#
@@ -60,21 +60,21 @@ class CGI
#
# == Storing session state
#
- # The caller can specify what form of storage to use for the session's
+ # The caller can specify what form of storage to use for the session's
# data with the +database_manager+ option to CGI::Session::new. The
# following storage classes are provided as part of the standard library:
#
- # CGI::Session::FileStore:: stores data as plain text in a flat file. Only
- # works with String data. This is the default
+ # CGI::Session::FileStore:: stores data as plain text in a flat file. Only
+ # works with String data. This is the default
# storage type.
- # CGI::Session::MemoryStore:: stores data in an in-memory hash. The data
- # only persists for as long as the current ruby
+ # CGI::Session::MemoryStore:: stores data in an in-memory hash. The data
+ # only persists for as long as the current ruby
# interpreter instance does.
# CGI::Session::PStore:: stores data in Marshalled format. Provided by
- # cgi/session/pstore.rb. Supports data of any type,
+ # cgi/session/pstore.rb. Supports data of any type,
# and provides file-locking and transaction support.
#
- # Custom storage types can also be created by defining a class with
+ # Custom storage types can also be created by defining a class with
# the following methods:
#
# new(session, options)
@@ -99,14 +99,14 @@ class CGI
# The simplest way to do this is via cookies. The CGI::Session class
# provides transparent support for session id communication via cookies
# if the client has cookies enabled.
- #
+ #
# If the client has cookies disabled, the session id must be included
# as a parameter of all requests sent by the client to the server. The
# CGI::Session class in conjunction with the CGI class will transparently
# add the session id as a hidden input field to all forms generated
# using the CGI#form() HTML generation method. No built-in support is
# provided for other mechanisms, such as URL re-writing. The caller is
- # responsible for extracting the session id from the session_id
+ # responsible for extracting the session id from the session_id
# attribute and manually encoding it in URLs and adding it as a hidden
# input to HTML forms created by other mechanisms. Also, session expiry
# is not automatically handled.
@@ -124,10 +124,10 @@ class CGI
# session = CGI::Session.new(cgi,
# 'database_manager' => CGI::Session::PStore, # use PStore
# 'session_key' => '_rb_sess_id', # custom session key
- # 'session_expires' => Time.now + 30 * 60, # 30 minute timeout
+ # 'session_expires' => Time.now + 30 * 60, # 30 minute timeout
# 'prefix' => 'pstore_sid_') # PStore option
# if cgi.has_key?('user_name') and cgi['user_name'] != ''
- # # coerce to String: cgi[] returns the
+ # # coerce to String: cgi[] returns the
# # string-like CGI::QueryExtension::Value
# session['user_name'] = cgi['user_name'].to_s
# elsif !session['user_name']
@@ -143,11 +143,11 @@ class CGI
# cgi = CGI.new("html4")
#
# # We make sure to delete an old session if one exists,
- # # not just to free resources, but to prevent the session
+ # # not just to free resources, but to prevent the session
# # from being maliciously hijacked later on.
# begin
- # session = CGI::Session.new(cgi, 'new_session' => false)
- # session.delete
+ # session = CGI::Session.new(cgi, 'new_session' => false)
+ # session.delete
# rescue ArgumentError # if no old session
# end
# session = CGI::Session.new(cgi, 'new_session' => true)
@@ -172,7 +172,7 @@ def Session::callback(dbman) #:nodoc:
# The session id is an MD5 hash based upon the time,
# a random number, and a constant string. This routine
# is used internally for automatically generated
- # session ids.
+ # session ids.
def create_new_id
require 'securerandom'
begin
@@ -205,7 +205,7 @@ def create_new_id
# it is retrieved from the +session_key+ parameter
# of the request, or automatically generated for
# a new session.
- # new_session:: if true, force creation of a new session. If not set,
+ # new_session:: if true, force creation of a new session. If not set,
# a new session is only created if none currently
# exists. If false, a new session is never created,
# and if none currently exists and the +session_id+
@@ -220,7 +220,7 @@ def create_new_id
# The following options are also recognised, but only apply if the
# session id is stored in a cookie.
#
- # session_expires:: the time the current session expires, as a
+ # session_expires:: the time the current session expires, as a
# +Time+ object. If not set, the session will terminate
# when the user's browser is closed.
# session_domain:: the hostname domain for which this session is valid.
@@ -232,10 +232,10 @@ def create_new_id
# +option+ is also passed on to the session storage class initializer; see
# the documentation for each session storage class for the options
# they support.
- #
+ #
# The retrieved or created session is automatically added to +request+
# as a cookie, and also to its +output_hidden+ table, which is used
- # to add hidden input elements to forms.
+ # to add hidden input elements to forms.
#
# *WARNING* the +output_hidden+
# fields are surrounded by a <fieldset> tag in HTML 4 generation, which
@@ -294,7 +294,7 @@ def initialize(request, option={})
"expires" => option['session_expires'],
"domain" => option['session_domain'],
"secure" => option['session_secure'],
- "path" =>
+ "path" =>
if option['session_path']
option['session_path']
elsif ENV["SCRIPT_NAME"]
@@ -323,11 +323,11 @@ def []=(key, val)
# Store session data on the server. For some session storage types,
# this is a no-op.
- def update
+ def update
@dbman.update
end
- # Store session data on the server and close the session storage.
+ # Store session data on the server and close the session storage.
# For some session storage types, this is a no-op.
def close
@dbman.close
@@ -359,7 +359,7 @@ class FileStore
# created. The session id must only contain alphanumeric
# characters; automatically generated session ids observe
# this requirement.
- #
+ #
# +option+ is a hash of options for the initializer. The
# following options are recognised:
#
@@ -450,7 +450,7 @@ def delete
# In-memory session storage class.
#
# Implements session storage as a global in-memory hash. Session
- # data will only persist for as long as the ruby interpreter
+ # data will only persist for as long as the ruby interpreter
# instance does.
class MemoryStore
GLOBAL_HASH_TABLE = {} #:nodoc:
View
6 lib/cgi/session/pstore.rb
@@ -2,7 +2,7 @@
# cgi/session/pstore.rb - persistent storage of marshalled session data
#
# Documentation: William Webber (william@williamwebber.com)
-#
+#
# == Overview
#
# This file provides the CGI::Session::PStore class, which builds
@@ -29,7 +29,7 @@ class PStore
# created. The session id must only contain alphanumeric
# characters; automatically generated session ids observe
# this requirement.
- #
+ #
# +option+ is a hash of options for the initializer. The
# following options are recognised:
#
@@ -77,7 +77,7 @@ def restore
end
# Save session state to the session's PStore file.
- def update
+ def update
@p.transaction do
@p['hash'] = @hash
end
View
25 lib/cgi/util.rb
@@ -1,4 +1,5 @@
class CGI
+ @@accept_charset="UTF-8" unless defined?(@@accept_charset)
# URL-encode a string.
# url_encoded_string = CGI::escape("'Stop!' said Fred")
# # => "%27Stop%21%27+said+Fred"
@@ -9,14 +10,14 @@ def CGI::escape(string)
end
- # URL-decode a string.
+ # URL-decode a string with encoding(optional).
# string = CGI::unescape("%27Stop%21%27+said+Fred")
# # => "'Stop!' said Fred"
- def CGI::unescape(string)
- enc = string.encoding
- string.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/) do
- [$1.delete('%')].pack('H*').force_encoding(enc)
- end
+ def CGI::unescape(string,encoding=@@accept_charset)
+ str=string.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/) do
+ [$1.delete('%')].pack('H*')
+ end.force_encoding(encoding)
+ str.valid_encoding? ? str : str.force_encoding(string.encoding)
end
TABLE_FOR_ESCAPE_HTML__ = {
@@ -119,7 +120,7 @@ def CGI::escapeElement(string, *elements)
# print CGI::unescapeElement(
# CGI::escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
# # "&lt;BR&gt;<A HREF="url"></A>"
- #
+ #
# print CGI::unescapeElement(
# CGI::escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
# # "&lt;BR&gt;<A HREF="url"></A>"
@@ -140,6 +141,12 @@ def CGI::unescape_element(str)
unescapeElement(str)
end
+ # Abbreviated day-of-week names specified by RFC 822
+ RFC822_DAYS = %w[ Sun Mon Tue Wed Thu Fri Sat ]
+
+ # Abbreviated month names specified by RFC 822
+ RFC822_MONTHS = %w[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ]
+
# Format a +Time+ object as a String using the format specified by RFC 1123.
#
# CGI::rfc1123_date(Time.now)
@@ -161,7 +168,7 @@ def CGI::rfc1123_date(time)
# # <BODY>
# # </BODY>
# # </HTML>
- #
+ #
# print CGI::pretty("<HTML><BODY></BODY></HTML>", "\t")
# # <HTML>
# # <BODY>
@@ -169,7 +176,7 @@ def CGI::rfc1123_date(time)
# # </HTML>
#
def CGI::pretty(string, shift = " ")
- lines = string.gsub(/(?!\A)<(?:.|\n)*?>/, "\n\\0").gsub(/<(?:.|\n)*?>(?!\n)/, "\\0\n")
+ lines = string.gsub(/(?!\A)<.*?>/m, "\n\\0").gsub(/<.*?>(?!\n)/m, "\\0\n")
end_pos = 0
while end_pos = lines.index(/^<\/(\w+)/, end_pos)
element = $1.dup
View
63 lib/cmath.rb
@@ -4,8 +4,10 @@ module CMath
alias exp! exp
alias log! log
+ alias log2! log2
alias log10! log10
alias sqrt! sqrt
+ alias cbrt! cbrt
alias sin! sin
alias cos! cos
@@ -28,8 +30,9 @@ def exp(z)
if z.real?
exp!(z)
else
- Complex(exp!(z.real) * cos!(z.imag),
- exp!(z.real) * sin!(z.imag))
+ ere = exp!(z.real)
+ Complex(ere * cos!(z.imag),
+ ere * sin!(z.imag))
end
end
@@ -38,8 +41,7 @@ def log(*args)
if z.real? and z >= 0 and (b.nil? or b >= 0)
log!(*args)
else
- r, theta = z.polar
- a = Complex(log!(r.abs), theta)
+ a = Complex(log!(z.abs), z.arg)
if b
a /= log(b)
end
@@ -47,8 +49,16 @@ def log(*args)
end
end
+ def log2(z)
+ if z.real? and z >= 0
+ log2!(z)
+ else
+ log(z) / log!(2)
+ end
+ end
+
def log10(z)
- if z.real?
+ if z.real? and z >= 0
log10!(z)
else
log(z) / log!(10)
@@ -63,7 +73,8 @@ def sqrt(z)
sqrt!(z)
end
else
- if z.imag < 0
+ if z.imag < 0 ||
+ (z.imag == 0 && z.imag.to_s[0] == '-')
sqrt(z.conjugate).conjugate
else
r = z.abs
@@ -73,6 +84,14 @@ def sqrt(z)
end
end
+ def cbrt(z)
+ if z.real? and z >= 0
+ cbrt!(z)
+ else
+ Complex(z) ** (1.0/3)
+ end
+ end
+
def sin(z)
if z.real?
sin!(z)
@@ -95,7 +114,7 @@ def tan(z)
if z.real?
tan!(z)
else
- sin(z)/cos(z)
+ sin(z) / cos(z)
end
end
@@ -129,7 +148,7 @@ def asin(z)
if z.real? and z >= -1 and z <= 1
asin!(z)
else
- Complex(0, -1.0) * log(Complex(0, 1.0) * z + sqrt(1.0 - z * z))
+ (-1.0).i * log(1.0.i * z + sqrt(1.0 - z * z))
end
end
@@ -137,7 +156,7 @@ def acos(z)
if z.real? and z >= -1 and z <= 1
acos!(z)
else
- Complex(0, -1.0) * log(z + Complex(0, 1.0) * sqrt(1.0 - z * z))
+ (-1.0).i * log(z + 1.0.i * sqrt(1.0 - z * z))
end
end
@@ -145,7 +164,7 @@ def atan(z)
if z.real?
atan!(z)
else
- Complex(0, 1.0) * log((Complex(0, 1.0) + z) / (Complex(0, 1.0) - z)) / 2.0
+ 1.0.i * log((1.0.i + z) / (1.0.i - z)) / 2.0
end
end
@@ -153,15 +172,7 @@ def atan2(y,x)
if y.real? and x.real?
atan2!(y,x)
else
- Complex(0, -1.0) * log((x + Complex(0, 1.0) * y) / sqrt(x * x + y * y))
- end
- end
-
- def acosh(z)
- if z.real? and z >= 1
- acosh!(z)
- else
- log(z + sqrt(z * z - 1.0))
+ (-1.0).i * log((x + 1.0.i * y) / sqrt(x * x + y * y))
end
end
@@ -173,6 +184,14 @@ def asinh(z)
end
end
+ def acosh(z)
+ if z.real? and z >= 1
+ acosh!(z)
+ else
+ log(z + sqrt(z * z - 1.0))
+ end
+ end
+
def atanh(z)
if z.real? and z >= -1 and z <= 1
atanh!(z)
@@ -185,10 +204,14 @@ def atanh(z)
module_function :exp
module_function :log!
module_function :log
+ module_function :log2!
+ module_function :log2
module_function :log10!
module_function :log10
module_function :sqrt!
module_function :sqrt
+ module_function :cbrt!
+ module_function :cbrt
module_function :sin!
module_function :sin
@@ -220,8 +243,6 @@ def atanh(z)
module_function :atanh!
module_function :atanh
- module_function :log2
- module_function :cbrt
module_function :frexp
module_function :ldexp
module_function :hypot
View
4 lib/complex.rb
@@ -1,3 +1,7 @@
+# :enddoc:
+
+warn('lib/complex.rb is deprecated') if $VERBOSE
+
require 'cmath'
unless defined?(Math.exp!)
View
1,177 lib/csv.rb
@@ -1,42 +1,41 @@
-#!/usr/bin/env ruby -w
-# encoding: UTF-8
+# encoding: US-ASCII
# = csv.rb -- CSV Reading and Writing
#
# Created by James Edward Gray II on 2005-10-31.
# Copyright 2005 James Edward Gray II. You can redistribute or modify this code
# under the terms of Ruby's license.
-#
+#
# See CSV for documentation.
-#
+#
# == Description
-#
+#
# Welcome to the new and improved CSV.
-#
+#
# This version of the CSV library began its life as FasterCSV. FasterCSV was
# intended as a replacement to Ruby's then standard CSV library. It was
# designed to address concerns users of that library had and it had three
# primary goals:
-#
+#
# 1. Be significantly faster than CSV while remaining a pure Ruby library.
# 2. Use a smaller and easier to maintain code base. (FasterCSV eventually
# grew larger, was also but considerably richer in features. The parsing
# core remains quite small.)
# 3. Improve on the CSV interface.
-#
+#
# Obviously, the last one is subjective. I did try to defer to the original
# interface whenever I didn't have a compelling reason to change it though, so
# hopefully this won't be too radically different.
-#
+#
# We must have met our goals because FasterCSV was renamed to CSV and replaced
# the original library.
-#
+#
# == What's Different From the Old CSV?
-#
+#
# I'm sure I'll miss something, but I'll try to mention most of the major
# differences I am aware of, to help others quickly get up to speed:
-#
+#
# === CSV Parsing
-#
+#
# * This parser is m17n aware. See CSV for full details.
# * This library has a stricter parser and will throw MalformedCSVErrors on
# problematic data.
@@ -46,9 +45,9 @@
# * The old library returned empty lines as <tt>[nil]</tt>. This library calls
# them <tt>[]</tt>.
# * This library has a much faster parser.
-#
+#
# === Interface
-#
+#
# * CSV now uses Hash-style parameters to set options.
# * CSV no longer has generate_row() or parse_row().
# * The old CSV's Reader and Writer classes have been dropped.
@@ -60,33 +59,33 @@
# * CSV no longer supports partial reads. It works line-by-line.
# * CSV no longer allows the instance methods to override the separators for
# performance reasons. They must be set in the constructor.
-#
+#
# If you use this library and find yourself missing any functionality I have
# trimmed, please {let me know}[mailto:james@grayproductions.net].
-#
+#
# == Documentation
-#
+#
# See CSV for documentation.
-#
+#
# == What is CSV, really?
-#
+#
# CSV maintains a pretty strict definition of CSV taken directly from
# {the RFC}[http://www.ietf.org/rfc/rfc4180.txt]. I relax the rules in only one
# place and that is to make using this library easier. CSV will parse all valid
# CSV.
-#
+#
# What you don't want to do is feed CSV invalid data. Because of the way the
# CSV format works, it's common for a parser to need to read until the end of
# the file to be sure a field is invalid. This eats a lot of time and memory.
-#
+#
# Luckily, when working with invalid CSV, Ruby's built-in methods will almost
# always be superior in every way. For example, parsing non-quoted fields is as
# easy as:
-#
+#
# data.split(",")
-#
+#
# == Questions and/or Comments
-#
+#
# Feel free to email {James Edward Gray II}[mailto:james@grayproductions.net]
# with any questions.
@@ -95,139 +94,139 @@
require "date"
require "stringio"
-#
+#
# This class provides a complete interface to CSV files and data. It offers
# tools to enable you to read and write to and from Strings or IO objects, as
# needed.
-#
+#
# == Reading
-#
+#
# === From a File
-#
+#
# ==== A Line at a Time
-#
+#
# CSV.foreach("path/to/file.csv") do |row|
# # use row here...
# end
-#
+#
# ==== All at Once
-#
+#
# arr_of_arrs = CSV.read("path/to/file.csv")
-#
+#
# === From a String
-#
+#
# ==== A Line at a Time
-#
+#
# CSV.parse("CSV,data,String") do |row|
# # use row here...
# end
-#
+#
# ==== All at Once
-#
+#
# arr_of_arrs = CSV.parse("CSV,data,String")
-#
+#
# == Writing
-#
+#
# === To a File
-#
+#
# CSV.open("path/to/file.csv", "wb") do |csv|
# csv << ["row", "of", "CSV", "data"]
# csv << ["another", "row"]
# # ...
# end
-#
+#
# === To a String
-#
+#
# csv_string = CSV.generate do |csv|
# csv << ["row", "of", "CSV", "data"]
# csv << ["another", "row"]
# # ...
# end
-#
+#
# == Convert a Single Line
-#
+#
# csv_string = ["CSV", "data"].to_csv # to CSV
# csv_array = "CSV,String".parse_csv # from CSV
-#
+#
# == Shortcut Interface
-#
+#
# CSV { |csv_out| csv_out << %w{my data here} } # to $stdout
# CSV(csv = "") { |csv_str| csv_str << %w{my data here} } # to a String
# CSV($stderr) { |csv_err| csv_err << %w{my data here} } # to $stderr
-#
+#
# == CSV and Character Encodings (M17n or Multilingualization)
-#
+#
# This new CSV parser is m17n savvy. The parser works in the Encoding of the IO
# or String object being read from or written to. Your data is never transcoded
# (unless you ask Ruby to transcode it for you) and will literally be parsed in
# the Encoding it is in. Thus CSV will return Arrays or Rows of Strings in the
# Encoding of your data. This is accomplished by transcoding the parser itself
# into your Encoding.
-#
+#
# Some transcoding must take place, of course, to accomplish this multiencoding
# support. For example, <tt>:col_sep</tt>, <tt>:row_sep</tt>, and
# <tt>:quote_char</tt> must be transcoded to match your data. Hopefully this
# makes the entire process feel transparent, since CSV's defaults should just
# magically work for you data. However, you can set these values manually in
# the target Encoding to avoid the translation.
-#
+#
# It's also important to note that while all of CSV's core parser is now
# Encoding agnostic, some features are not. For example, the built-in
# converters will try to transcode data to UTF-8 before making conversions.
# Again, you can provide custom converters that are aware of your Encodings to
# avoid this translation. It's just too hard for me to support native
# conversions in all of Ruby's Encodings.
-#
+#
# Anyway, the practical side of this is simple: make sure IO and String objects
# passed into CSV have the proper Encoding set and everything should just work.
# CSV methods that allow you to open IO objects (CSV::foreach(), CSV::open(),
# CSV::read(), and CSV::readlines()) do allow you to specify the Encoding.
-#
+#
# One minor exception comes when generating CSV into a String with an Encoding
# that is not ASCII compatible. There's no existing data for CSV to use to
# prepare itself and thus you will probably need to manually specify the desired
# Encoding for most of those cases. It will try to guess using the fields in a
# row of output though, when using CSV::generate_line() or Array#to_csv().
-#
+#
# I try to point out any other Encoding issues in the documentation of methods
# as they come up.
-#
+#
# This has been tested to the best of my ability with all non-"dummy" Encodings
# Ruby ships with. However, it is brave new code and may have some bugs.
# Please feel free to {report}[mailto:james@grayproductions.net] any issues you
# find with it.
-#
+#
class CSV
# The version of the installed library.
- VERSION = "2.4.5".freeze
-
- #
+ VERSION = "2.4.6".freeze
+
+ #
# A CSV::Row is part Array and part Hash. It retains an order for the fields
# and allows duplicates just as an Array would, but also allows you to access
# fields by name just as you could if they were in a Hash.
- #
+ #
# All rows returned by CSV will be constructed from this class, if header row
# processing is activated.
- #
+ #
class Row
- #
+ #
# Construct a new CSV::Row from +headers+ and +fields+, which are expected
# to be Arrays. If one Array is shorter than the other, it will be padded
# with +nil+ objects.
- #
+ #
# The optional +header_row+ parameter can be set to +true+ to indicate, via
# CSV::Row.header_row?() and CSV::Row.field_row?(), that this is a header
# row. Otherwise, the row is assumes to be a field row.
- #
+ #
# A CSV::Row object supports the following Array methods through delegation:
- #