scout 5.7.1 → 5.7.2.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. data/CHANGELOG.markdown +5 -0
  2. data/lib/scout/command/run.rb +1 -1
  3. data/lib/scout/server.rb +2 -1
  4. data/lib/scout/streamer.rb +3 -2
  5. data/lib/scout/streamer_daemon.rb +4 -4
  6. data/lib/scout/version.rb +1 -1
  7. data/test/scout_test.rb +7 -8
  8. data/vendor/httpclient/README.txt +759 -0
  9. data/vendor/httpclient/bin/httpclient +65 -0
  10. data/vendor/httpclient/lib/hexdump.rb +50 -0
  11. data/vendor/httpclient/lib/http-access2.rb +55 -0
  12. data/vendor/httpclient/lib/http-access2/cookie.rb +1 -0
  13. data/vendor/httpclient/lib/http-access2/http.rb +1 -0
  14. data/vendor/httpclient/lib/httpclient.rb +1156 -0
  15. data/vendor/httpclient/lib/httpclient/auth.rb +899 -0
  16. data/vendor/httpclient/lib/httpclient/cacert.p7s +1912 -0
  17. data/vendor/httpclient/lib/httpclient/connection.rb +88 -0
  18. data/vendor/httpclient/lib/httpclient/cookie.rb +438 -0
  19. data/vendor/httpclient/lib/httpclient/http.rb +1046 -0
  20. data/vendor/httpclient/lib/httpclient/include_client.rb +83 -0
  21. data/vendor/httpclient/lib/httpclient/session.rb +1025 -0
  22. data/vendor/httpclient/lib/httpclient/ssl_config.rb +403 -0
  23. data/vendor/httpclient/lib/httpclient/timeout.rb +140 -0
  24. data/vendor/httpclient/lib/httpclient/util.rb +178 -0
  25. data/vendor/httpclient/lib/httpclient/version.rb +3 -0
  26. data/vendor/httpclient/lib/oauthclient.rb +110 -0
  27. data/vendor/httpclient/sample/async.rb +8 -0
  28. data/vendor/httpclient/sample/auth.rb +11 -0
  29. data/vendor/httpclient/sample/cookie.rb +18 -0
  30. data/vendor/httpclient/sample/dav.rb +103 -0
  31. data/vendor/httpclient/sample/howto.rb +49 -0
  32. data/vendor/httpclient/sample/oauth_buzz.rb +57 -0
  33. data/vendor/httpclient/sample/oauth_friendfeed.rb +59 -0
  34. data/vendor/httpclient/sample/oauth_salesforce_10.rb +63 -0
  35. data/vendor/httpclient/sample/oauth_twitter.rb +61 -0
  36. data/vendor/httpclient/sample/ssl/0cert.pem +22 -0
  37. data/vendor/httpclient/sample/ssl/0key.pem +30 -0
  38. data/vendor/httpclient/sample/ssl/1000cert.pem +19 -0
  39. data/vendor/httpclient/sample/ssl/1000key.pem +18 -0
  40. data/vendor/httpclient/sample/ssl/htdocs/index.html +10 -0
  41. data/vendor/httpclient/sample/ssl/ssl_client.rb +22 -0
  42. data/vendor/httpclient/sample/ssl/webrick_httpsd.rb +29 -0
  43. data/vendor/httpclient/sample/stream.rb +21 -0
  44. data/vendor/httpclient/sample/thread.rb +27 -0
  45. data/vendor/httpclient/sample/wcat.rb +21 -0
  46. data/vendor/httpclient/test/ca-chain.cert +44 -0
  47. data/vendor/httpclient/test/ca.cert +23 -0
  48. data/vendor/httpclient/test/client.cert +19 -0
  49. data/vendor/httpclient/test/client.key +15 -0
  50. data/vendor/httpclient/test/helper.rb +129 -0
  51. data/vendor/httpclient/test/htdigest +1 -0
  52. data/vendor/httpclient/test/htpasswd +2 -0
  53. data/vendor/httpclient/test/runner.rb +2 -0
  54. data/vendor/httpclient/test/server.cert +19 -0
  55. data/vendor/httpclient/test/server.key +15 -0
  56. data/vendor/httpclient/test/sslsvr.rb +65 -0
  57. data/vendor/httpclient/test/subca.cert +21 -0
  58. data/vendor/httpclient/test/test_auth.rb +321 -0
  59. data/vendor/httpclient/test/test_cookie.rb +391 -0
  60. data/vendor/httpclient/test/test_hexdump.rb +14 -0
  61. data/vendor/httpclient/test/test_http-access2.rb +507 -0
  62. data/vendor/httpclient/test/test_httpclient.rb +1783 -0
  63. data/vendor/httpclient/test/test_include_client.rb +52 -0
  64. data/vendor/httpclient/test/test_ssl.rb +235 -0
  65. data/vendor/multi_json/.document +5 -0
  66. data/vendor/multi_json/.rspec +3 -0
  67. data/vendor/multi_json/.travis.yml +11 -0
  68. data/vendor/multi_json/.yardopts +6 -0
  69. data/vendor/multi_json/CHANGELOG.md +169 -0
  70. data/vendor/multi_json/CONTRIBUTING.md +46 -0
  71. data/vendor/multi_json/Gemfile +31 -0
  72. data/vendor/multi_json/LICENSE.md +20 -0
  73. data/vendor/multi_json/README.md +109 -0
  74. data/vendor/multi_json/Rakefile +12 -0
  75. data/vendor/multi_json/lib/multi_json.rb +157 -0
  76. data/vendor/multi_json/lib/multi_json/adapter.rb +48 -0
  77. data/vendor/multi_json/lib/multi_json/adapters/gson.rb +19 -0
  78. data/vendor/multi_json/lib/multi_json/adapters/jr_jackson.rb +19 -0
  79. data/vendor/multi_json/lib/multi_json/adapters/json_common.rb +25 -0
  80. data/vendor/multi_json/lib/multi_json/adapters/json_gem.rb +11 -0
  81. data/vendor/multi_json/lib/multi_json/adapters/json_pure.rb +11 -0
  82. data/vendor/multi_json/lib/multi_json/adapters/nsjsonserialization.rb +34 -0
  83. data/vendor/multi_json/lib/multi_json/adapters/oj.rb +24 -0
  84. data/vendor/multi_json/lib/multi_json/adapters/ok_json.rb +22 -0
  85. data/vendor/multi_json/lib/multi_json/adapters/yajl.rb +19 -0
  86. data/vendor/multi_json/lib/multi_json/convertible_hash_keys.rb +43 -0
  87. data/vendor/multi_json/lib/multi_json/load_error.rb +11 -0
  88. data/vendor/multi_json/lib/multi_json/options.rb +48 -0
  89. data/vendor/multi_json/lib/multi_json/vendor/okjson.rb +606 -0
  90. data/vendor/multi_json/lib/multi_json/version.rb +20 -0
  91. data/vendor/multi_json/multi_json.gemspec +22 -0
  92. data/vendor/multi_json/spec/adapter_shared_example.rb +235 -0
  93. data/vendor/multi_json/spec/has_options.rb +119 -0
  94. data/vendor/multi_json/spec/helper.rb +35 -0
  95. data/vendor/multi_json/spec/json_common_shared_example.rb +30 -0
  96. data/vendor/multi_json/spec/multi_json_spec.rb +226 -0
  97. data/vendor/{signature → pusher}/.document +0 -0
  98. data/vendor/{json_pure/diagrams/.keep → pusher/.gemtest} +0 -0
  99. data/vendor/pusher/.gitignore +23 -0
  100. data/vendor/pusher/.travis.yml +15 -0
  101. data/vendor/pusher/Gemfile +2 -0
  102. data/vendor/{pusher-gem → pusher}/LICENSE +1 -1
  103. data/vendor/pusher/README.md +186 -0
  104. data/vendor/{pusher-gem → pusher}/Rakefile +0 -0
  105. data/vendor/{pusher-gem → pusher}/examples/async_message.rb +0 -0
  106. data/vendor/pusher/lib/pusher.rb +60 -0
  107. data/vendor/{pusher-gem → pusher}/lib/pusher/channel.rb +47 -54
  108. data/vendor/pusher/lib/pusher/client.rb +306 -0
  109. data/vendor/pusher/lib/pusher/request.rb +107 -0
  110. data/vendor/pusher/lib/pusher/resource.rb +36 -0
  111. data/vendor/pusher/lib/pusher/webhook.rb +110 -0
  112. data/vendor/{pusher-gem → pusher}/pusher.gemspec +6 -5
  113. data/vendor/pusher/spec/channel_spec.rb +127 -0
  114. data/vendor/pusher/spec/client_spec.rb +464 -0
  115. data/vendor/{pusher-gem → pusher}/spec/spec_helper.rb +12 -0
  116. data/vendor/pusher/spec/web_hook_spec.rb +117 -0
  117. data/vendor/signature/.travis.yml +15 -0
  118. data/vendor/signature/Gemfile +1 -1
  119. data/vendor/signature/README.md +38 -28
  120. data/vendor/signature/lib/signature.rb +97 -15
  121. data/vendor/signature/lib/signature/query_encoder.rb +47 -0
  122. data/vendor/signature/lib/signature/version.rb +1 -1
  123. data/vendor/signature/signature.gemspec +3 -2
  124. data/vendor/signature/spec/signature_spec.rb +164 -55
  125. data/vendor/signature/spec/spec_helper.rb +2 -3
  126. metadata +120 -145
  127. data/vendor/json_pure/.gitignore +0 -12
  128. data/vendor/json_pure/.travis.yml +0 -20
  129. data/vendor/json_pure/CHANGES +0 -282
  130. data/vendor/json_pure/COPYING +0 -58
  131. data/vendor/json_pure/COPYING-json-jruby +0 -57
  132. data/vendor/json_pure/GPL +0 -340
  133. data/vendor/json_pure/Gemfile +0 -11
  134. data/vendor/json_pure/README-json-jruby.markdown +0 -33
  135. data/vendor/json_pure/README.rdoc +0 -358
  136. data/vendor/json_pure/Rakefile +0 -412
  137. data/vendor/json_pure/TODO +0 -1
  138. data/vendor/json_pure/VERSION +0 -1
  139. data/vendor/json_pure/data/example.json +0 -1
  140. data/vendor/json_pure/data/index.html +0 -38
  141. data/vendor/json_pure/data/prototype.js +0 -4184
  142. data/vendor/json_pure/ext/json/ext/fbuffer/fbuffer.h +0 -181
  143. data/vendor/json_pure/ext/json/ext/generator/depend +0 -1
  144. data/vendor/json_pure/ext/json/ext/generator/extconf.rb +0 -14
  145. data/vendor/json_pure/ext/json/ext/generator/generator.c +0 -1435
  146. data/vendor/json_pure/ext/json/ext/generator/generator.h +0 -148
  147. data/vendor/json_pure/ext/json/ext/parser/depend +0 -1
  148. data/vendor/json_pure/ext/json/ext/parser/extconf.rb +0 -13
  149. data/vendor/json_pure/ext/json/ext/parser/parser.c +0 -2204
  150. data/vendor/json_pure/ext/json/ext/parser/parser.h +0 -77
  151. data/vendor/json_pure/ext/json/ext/parser/parser.rl +0 -927
  152. data/vendor/json_pure/install.rb +0 -23
  153. data/vendor/json_pure/java/src/json/ext/ByteListTranscoder.java +0 -167
  154. data/vendor/json_pure/java/src/json/ext/Generator.java +0 -444
  155. data/vendor/json_pure/java/src/json/ext/GeneratorMethods.java +0 -232
  156. data/vendor/json_pure/java/src/json/ext/GeneratorService.java +0 -43
  157. data/vendor/json_pure/java/src/json/ext/GeneratorState.java +0 -543
  158. data/vendor/json_pure/java/src/json/ext/OptionsReader.java +0 -114
  159. data/vendor/json_pure/java/src/json/ext/Parser.java +0 -2644
  160. data/vendor/json_pure/java/src/json/ext/Parser.rl +0 -968
  161. data/vendor/json_pure/java/src/json/ext/ParserService.java +0 -35
  162. data/vendor/json_pure/java/src/json/ext/RuntimeInfo.java +0 -121
  163. data/vendor/json_pure/java/src/json/ext/StringDecoder.java +0 -167
  164. data/vendor/json_pure/java/src/json/ext/StringEncoder.java +0 -106
  165. data/vendor/json_pure/java/src/json/ext/Utils.java +0 -89
  166. data/vendor/json_pure/json-java.gemspec +0 -23
  167. data/vendor/json_pure/json.gemspec +0 -37
  168. data/vendor/json_pure/json_pure.gemspec +0 -39
  169. data/vendor/json_pure/lib/json.rb +0 -62
  170. data/vendor/json_pure/lib/json/add/bigdecimal.rb +0 -28
  171. data/vendor/json_pure/lib/json/add/complex.rb +0 -22
  172. data/vendor/json_pure/lib/json/add/core.rb +0 -11
  173. data/vendor/json_pure/lib/json/add/date.rb +0 -34
  174. data/vendor/json_pure/lib/json/add/date_time.rb +0 -50
  175. data/vendor/json_pure/lib/json/add/exception.rb +0 -31
  176. data/vendor/json_pure/lib/json/add/ostruct.rb +0 -31
  177. data/vendor/json_pure/lib/json/add/range.rb +0 -29
  178. data/vendor/json_pure/lib/json/add/rational.rb +0 -22
  179. data/vendor/json_pure/lib/json/add/regexp.rb +0 -30
  180. data/vendor/json_pure/lib/json/add/struct.rb +0 -30
  181. data/vendor/json_pure/lib/json/add/symbol.rb +0 -25
  182. data/vendor/json_pure/lib/json/add/time.rb +0 -38
  183. data/vendor/json_pure/lib/json/common.rb +0 -487
  184. data/vendor/json_pure/lib/json/ext.rb +0 -21
  185. data/vendor/json_pure/lib/json/ext/.keep +0 -0
  186. data/vendor/json_pure/lib/json/generic_object.rb +0 -70
  187. data/vendor/json_pure/lib/json/pure.rb +0 -21
  188. data/vendor/json_pure/lib/json/pure/generator.rb +0 -522
  189. data/vendor/json_pure/lib/json/pure/parser.rb +0 -359
  190. data/vendor/json_pure/lib/json/version.rb +0 -8
  191. data/vendor/json_pure/tests/fixtures/fail1.json +0 -1
  192. data/vendor/json_pure/tests/fixtures/fail10.json +0 -1
  193. data/vendor/json_pure/tests/fixtures/fail11.json +0 -1
  194. data/vendor/json_pure/tests/fixtures/fail12.json +0 -1
  195. data/vendor/json_pure/tests/fixtures/fail13.json +0 -1
  196. data/vendor/json_pure/tests/fixtures/fail14.json +0 -1
  197. data/vendor/json_pure/tests/fixtures/fail18.json +0 -1
  198. data/vendor/json_pure/tests/fixtures/fail19.json +0 -1
  199. data/vendor/json_pure/tests/fixtures/fail2.json +0 -1
  200. data/vendor/json_pure/tests/fixtures/fail20.json +0 -1
  201. data/vendor/json_pure/tests/fixtures/fail21.json +0 -1
  202. data/vendor/json_pure/tests/fixtures/fail22.json +0 -1
  203. data/vendor/json_pure/tests/fixtures/fail23.json +0 -1
  204. data/vendor/json_pure/tests/fixtures/fail24.json +0 -1
  205. data/vendor/json_pure/tests/fixtures/fail25.json +0 -1
  206. data/vendor/json_pure/tests/fixtures/fail27.json +0 -2
  207. data/vendor/json_pure/tests/fixtures/fail28.json +0 -2
  208. data/vendor/json_pure/tests/fixtures/fail3.json +0 -1
  209. data/vendor/json_pure/tests/fixtures/fail4.json +0 -1
  210. data/vendor/json_pure/tests/fixtures/fail5.json +0 -1
  211. data/vendor/json_pure/tests/fixtures/fail6.json +0 -1
  212. data/vendor/json_pure/tests/fixtures/fail7.json +0 -1
  213. data/vendor/json_pure/tests/fixtures/fail8.json +0 -1
  214. data/vendor/json_pure/tests/fixtures/fail9.json +0 -1
  215. data/vendor/json_pure/tests/fixtures/pass1.json +0 -56
  216. data/vendor/json_pure/tests/fixtures/pass15.json +0 -1
  217. data/vendor/json_pure/tests/fixtures/pass16.json +0 -1
  218. data/vendor/json_pure/tests/fixtures/pass17.json +0 -1
  219. data/vendor/json_pure/tests/fixtures/pass2.json +0 -1
  220. data/vendor/json_pure/tests/fixtures/pass26.json +0 -1
  221. data/vendor/json_pure/tests/fixtures/pass3.json +0 -6
  222. data/vendor/json_pure/tests/setup_variant.rb +0 -11
  223. data/vendor/json_pure/tests/test_json.rb +0 -545
  224. data/vendor/json_pure/tests/test_json_addition.rb +0 -196
  225. data/vendor/json_pure/tests/test_json_encoding.rb +0 -65
  226. data/vendor/json_pure/tests/test_json_fixtures.rb +0 -35
  227. data/vendor/json_pure/tests/test_json_generate.rb +0 -322
  228. data/vendor/json_pure/tests/test_json_generic_object.rb +0 -75
  229. data/vendor/json_pure/tests/test_json_string_matching.rb +0 -39
  230. data/vendor/json_pure/tests/test_json_unicode.rb +0 -72
  231. data/vendor/json_pure/tools/fuzz.rb +0 -139
  232. data/vendor/json_pure/tools/server.rb +0 -62
  233. data/vendor/pusher-gem/Gemfile +0 -2
  234. data/vendor/pusher-gem/README.md +0 -80
  235. data/vendor/pusher-gem/lib/pusher.rb +0 -107
  236. data/vendor/pusher-gem/lib/pusher/request.rb +0 -107
  237. data/vendor/pusher-gem/spec/channel_spec.rb +0 -274
  238. data/vendor/pusher-gem/spec/pusher_spec.rb +0 -87
  239. data/vendor/ruby-hmac/History.txt +0 -15
  240. data/vendor/ruby-hmac/Manifest.txt +0 -11
  241. data/vendor/ruby-hmac/README.md +0 -41
  242. data/vendor/ruby-hmac/Rakefile +0 -23
  243. data/vendor/ruby-hmac/lib/hmac-md5.rb +0 -11
  244. data/vendor/ruby-hmac/lib/hmac-rmd160.rb +0 -11
  245. data/vendor/ruby-hmac/lib/hmac-sha1.rb +0 -11
  246. data/vendor/ruby-hmac/lib/hmac-sha2.rb +0 -25
  247. data/vendor/ruby-hmac/lib/hmac.rb +0 -118
  248. data/vendor/ruby-hmac/lib/ruby_hmac.rb +0 -2
  249. data/vendor/ruby-hmac/ruby-hmac.gemspec +0 -33
  250. data/vendor/ruby-hmac/test/test_hmac.rb +0 -89
  251. data/vendor/signature/VERSION +0 -1
@@ -1,21 +0,0 @@
1
- if ENV['SIMPLECOV_COVERAGE'].to_i == 1
2
- require 'simplecov'
3
- SimpleCov.start do
4
- add_filter "/tests/"
5
- end
6
- end
7
- require 'json/common'
8
-
9
- module JSON
10
- # This module holds all the modules/classes that implement JSON's
11
- # functionality as C extensions.
12
- module Ext
13
- require 'json/ext/parser'
14
- require 'json/ext/generator'
15
- $DEBUG and warn "Using Ext extension for JSON."
16
- JSON.parser = Parser
17
- JSON.generator = Generator
18
- end
19
-
20
- JSON_LOADED = true unless defined?(::JSON::JSON_LOADED)
21
- end
File without changes
@@ -1,70 +0,0 @@
1
- require 'ostruct'
2
-
3
- module JSON
4
- class GenericObject < OpenStruct
5
- class << self
6
- alias [] new
7
-
8
- def json_creatable?
9
- @json_creatable
10
- end
11
-
12
- attr_writer :json_creatable
13
-
14
- def json_create(data)
15
- data = data.dup
16
- data.delete JSON.create_id
17
- self[data]
18
- end
19
-
20
- def from_hash(object)
21
- case
22
- when object.respond_to?(:to_hash)
23
- result = new
24
- object.to_hash.each do |key, value|
25
- result[key] = from_hash(value)
26
- end
27
- result
28
- when object.respond_to?(:to_ary)
29
- object.to_ary.map { |a| from_hash(a) }
30
- else
31
- object
32
- end
33
- end
34
-
35
- def load(source, proc = nil, opts = {})
36
- result = ::JSON.load(source, proc, opts.merge(:object_class => self))
37
- result.nil? ? new : result
38
- end
39
-
40
- def dump(obj, *args)
41
- ::JSON.dump(obj, *args)
42
- end
43
- end
44
- self.json_creatable = false
45
-
46
- def to_hash
47
- table
48
- end
49
-
50
- def [](name)
51
- table[name.to_sym]
52
- end
53
-
54
- def []=(name, value)
55
- __send__ "#{name}=", value
56
- end
57
-
58
- def |(other)
59
- self.class[other.to_hash.merge(to_hash)]
60
- end
61
-
62
- def as_json(*)
63
- { JSON.create_id => self.class.name }.merge to_hash
64
- end
65
-
66
- def to_json(*a)
67
- as_json.to_json(*a)
68
- end
69
- end
70
- end
@@ -1,21 +0,0 @@
1
- if ENV['SIMPLECOV_COVERAGE'].to_i == 1
2
- require 'simplecov'
3
- SimpleCov.start do
4
- add_filter "/tests/"
5
- end
6
- end
7
- require 'json/common'
8
- require 'json/pure/parser'
9
- require 'json/pure/generator'
10
-
11
- module JSON
12
- # This module holds all the modules/classes that implement JSON's
13
- # functionality in pure ruby.
14
- module Pure
15
- $DEBUG and warn "Using Pure library for JSON."
16
- JSON.parser = Parser
17
- JSON.generator = Generator
18
- end
19
-
20
- JSON_LOADED = true unless defined?(::JSON::JSON_LOADED)
21
- end
@@ -1,522 +0,0 @@
1
- module JSON
2
- MAP = {
3
- "\x0" => '\u0000',
4
- "\x1" => '\u0001',
5
- "\x2" => '\u0002',
6
- "\x3" => '\u0003',
7
- "\x4" => '\u0004',
8
- "\x5" => '\u0005',
9
- "\x6" => '\u0006',
10
- "\x7" => '\u0007',
11
- "\b" => '\b',
12
- "\t" => '\t',
13
- "\n" => '\n',
14
- "\xb" => '\u000b',
15
- "\f" => '\f',
16
- "\r" => '\r',
17
- "\xe" => '\u000e',
18
- "\xf" => '\u000f',
19
- "\x10" => '\u0010',
20
- "\x11" => '\u0011',
21
- "\x12" => '\u0012',
22
- "\x13" => '\u0013',
23
- "\x14" => '\u0014',
24
- "\x15" => '\u0015',
25
- "\x16" => '\u0016',
26
- "\x17" => '\u0017',
27
- "\x18" => '\u0018',
28
- "\x19" => '\u0019',
29
- "\x1a" => '\u001a',
30
- "\x1b" => '\u001b',
31
- "\x1c" => '\u001c',
32
- "\x1d" => '\u001d',
33
- "\x1e" => '\u001e',
34
- "\x1f" => '\u001f',
35
- '"' => '\"',
36
- '\\' => '\\\\',
37
- } # :nodoc:
38
-
39
- # Convert a UTF8 encoded Ruby string _string_ to a JSON string, encoded with
40
- # UTF16 big endian characters as \u????, and return it.
41
- if defined?(::Encoding)
42
- def utf8_to_json(string) # :nodoc:
43
- string = string.dup
44
- string.force_encoding(::Encoding::ASCII_8BIT)
45
- string.gsub!(/["\\\x0-\x1f]/) { MAP[$&] }
46
- string.force_encoding(::Encoding::UTF_8)
47
- string
48
- end
49
-
50
- def utf8_to_json_ascii(string) # :nodoc:
51
- string = string.dup
52
- string.force_encoding(::Encoding::ASCII_8BIT)
53
- string.gsub!(/["\\\x0-\x1f]/n) { MAP[$&] }
54
- string.gsub!(/(
55
- (?:
56
- [\xc2-\xdf][\x80-\xbf] |
57
- [\xe0-\xef][\x80-\xbf]{2} |
58
- [\xf0-\xf4][\x80-\xbf]{3}
59
- )+ |
60
- [\x80-\xc1\xf5-\xff] # invalid
61
- )/nx) { |c|
62
- c.size == 1 and raise GeneratorError, "invalid utf8 byte: '#{c}'"
63
- s = JSON.iconv('utf-16be', 'utf-8', c).unpack('H*')[0]
64
- s.force_encoding(::Encoding::ASCII_8BIT)
65
- s.gsub!(/.{4}/n, '\\\\u\&')
66
- s.force_encoding(::Encoding::UTF_8)
67
- }
68
- string.force_encoding(::Encoding::UTF_8)
69
- string
70
- rescue => e
71
- raise GeneratorError.wrap(e)
72
- end
73
-
74
- def valid_utf8?(string)
75
- encoding = string.encoding
76
- (encoding == Encoding::UTF_8 || encoding == Encoding::ASCII) &&
77
- string.valid_encoding?
78
- end
79
- module_function :valid_utf8?
80
- else
81
- def utf8_to_json(string) # :nodoc:
82
- string.gsub(/["\\\x0-\x1f]/n) { MAP[$&] }
83
- end
84
-
85
- def utf8_to_json_ascii(string) # :nodoc:
86
- string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] }
87
- string.gsub!(/(
88
- (?:
89
- [\xc2-\xdf][\x80-\xbf] |
90
- [\xe0-\xef][\x80-\xbf]{2} |
91
- [\xf0-\xf4][\x80-\xbf]{3}
92
- )+ |
93
- [\x80-\xc1\xf5-\xff] # invalid
94
- )/nx) { |c|
95
- c.size == 1 and raise GeneratorError, "invalid utf8 byte: '#{c}'"
96
- s = JSON.iconv('utf-16be', 'utf-8', c).unpack('H*')[0]
97
- s.gsub!(/.{4}/n, '\\\\u\&')
98
- }
99
- string
100
- rescue => e
101
- raise GeneratorError.wrap(e)
102
- end
103
-
104
- def valid_utf8?(string)
105
- string =~
106
- /\A( [\x09\x0a\x0d\x20-\x7e] # ASCII
107
- | [\xc2-\xdf][\x80-\xbf] # non-overlong 2-byte
108
- | \xe0[\xa0-\xbf][\x80-\xbf] # excluding overlongs
109
- | [\xe1-\xec\xee\xef][\x80-\xbf]{2} # straight 3-byte
110
- | \xed[\x80-\x9f][\x80-\xbf] # excluding surrogates
111
- | \xf0[\x90-\xbf][\x80-\xbf]{2} # planes 1-3
112
- | [\xf1-\xf3][\x80-\xbf]{3} # planes 4-15
113
- | \xf4[\x80-\x8f][\x80-\xbf]{2} # plane 16
114
- )*\z/nx
115
- end
116
- end
117
- module_function :utf8_to_json, :utf8_to_json_ascii, :valid_utf8?
118
-
119
-
120
- module Pure
121
- module Generator
122
- # This class is used to create State instances, that are use to hold data
123
- # while generating a JSON text from a Ruby data structure.
124
- class State
125
- # Creates a State object from _opts_, which ought to be Hash to create
126
- # a new State instance configured by _opts_, something else to create
127
- # an unconfigured instance. If _opts_ is a State object, it is just
128
- # returned.
129
- def self.from_state(opts)
130
- case
131
- when self === opts
132
- opts
133
- when opts.respond_to?(:to_hash)
134
- new(opts.to_hash)
135
- when opts.respond_to?(:to_h)
136
- new(opts.to_h)
137
- else
138
- SAFE_STATE_PROTOTYPE.dup
139
- end
140
- end
141
-
142
- # Instantiates a new State object, configured by _opts_.
143
- #
144
- # _opts_ can have the following keys:
145
- #
146
- # * *indent*: a string used to indent levels (default: ''),
147
- # * *space*: a string that is put after, a : or , delimiter (default: ''),
148
- # * *space_before*: a string that is put before a : pair delimiter (default: ''),
149
- # * *object_nl*: a string that is put at the end of a JSON object (default: ''),
150
- # * *array_nl*: a string that is put at the end of a JSON array (default: ''),
151
- # * *check_circular*: is deprecated now, use the :max_nesting option instead,
152
- # * *max_nesting*: sets the maximum level of data structure nesting in
153
- # the generated JSON, max_nesting = 0 if no maximum should be checked.
154
- # * *allow_nan*: true if NaN, Infinity, and -Infinity should be
155
- # generated, otherwise an exception is thrown, if these values are
156
- # encountered. This options defaults to false.
157
- # * *quirks_mode*: Enables quirks_mode for parser, that is for example
158
- # generating single JSON values instead of documents is possible.
159
- def initialize(opts = {})
160
- @indent = ''
161
- @space = ''
162
- @space_before = ''
163
- @object_nl = ''
164
- @array_nl = ''
165
- @allow_nan = false
166
- @ascii_only = false
167
- @quirks_mode = false
168
- @buffer_initial_length = 1024
169
- configure opts
170
- end
171
-
172
- # This string is used to indent levels in the JSON text.
173
- attr_accessor :indent
174
-
175
- # This string is used to insert a space between the tokens in a JSON
176
- # string.
177
- attr_accessor :space
178
-
179
- # This string is used to insert a space before the ':' in JSON objects.
180
- attr_accessor :space_before
181
-
182
- # This string is put at the end of a line that holds a JSON object (or
183
- # Hash).
184
- attr_accessor :object_nl
185
-
186
- # This string is put at the end of a line that holds a JSON array.
187
- attr_accessor :array_nl
188
-
189
- # This integer returns the maximum level of data structure nesting in
190
- # the generated JSON, max_nesting = 0 if no maximum is checked.
191
- attr_accessor :max_nesting
192
-
193
- # If this attribute is set to true, quirks mode is enabled, otherwise
194
- # it's disabled.
195
- attr_accessor :quirks_mode
196
-
197
- # :stopdoc:
198
- attr_reader :buffer_initial_length
199
-
200
- def buffer_initial_length=(length)
201
- if length > 0
202
- @buffer_initial_length = length
203
- end
204
- end
205
- # :startdoc:
206
-
207
- # This integer returns the current depth data structure nesting in the
208
- # generated JSON.
209
- attr_accessor :depth
210
-
211
- def check_max_nesting # :nodoc:
212
- return if @max_nesting.zero?
213
- current_nesting = depth + 1
214
- current_nesting > @max_nesting and
215
- raise NestingError, "nesting of #{current_nesting} is too deep"
216
- end
217
-
218
- # Returns true, if circular data structures are checked,
219
- # otherwise returns false.
220
- def check_circular?
221
- !@max_nesting.zero?
222
- end
223
-
224
- # Returns true if NaN, Infinity, and -Infinity should be considered as
225
- # valid JSON and output.
226
- def allow_nan?
227
- @allow_nan
228
- end
229
-
230
- # Returns true, if only ASCII characters should be generated. Otherwise
231
- # returns false.
232
- def ascii_only?
233
- @ascii_only
234
- end
235
-
236
- # Returns true, if quirks mode is enabled. Otherwise returns false.
237
- def quirks_mode?
238
- @quirks_mode
239
- end
240
-
241
- # Configure this State instance with the Hash _opts_, and return
242
- # itself.
243
- def configure(opts)
244
- if opts.respond_to?(:to_hash)
245
- opts = opts.to_hash
246
- elsif opts.respond_to?(:to_h)
247
- opts = opts.to_h
248
- else
249
- raise TypeError, "can't convert #{opts.class} into Hash"
250
- end
251
- for key, value in opts
252
- instance_variable_set "@#{key}", value
253
- end
254
- @indent = opts[:indent] if opts.key?(:indent)
255
- @space = opts[:space] if opts.key?(:space)
256
- @space_before = opts[:space_before] if opts.key?(:space_before)
257
- @object_nl = opts[:object_nl] if opts.key?(:object_nl)
258
- @array_nl = opts[:array_nl] if opts.key?(:array_nl)
259
- @allow_nan = !!opts[:allow_nan] if opts.key?(:allow_nan)
260
- @ascii_only = opts[:ascii_only] if opts.key?(:ascii_only)
261
- @depth = opts[:depth] || 0
262
- @quirks_mode = opts[:quirks_mode] if opts.key?(:quirks_mode)
263
- @buffer_initial_length ||= opts[:buffer_initial_length]
264
-
265
- if !opts.key?(:max_nesting) # defaults to 100
266
- @max_nesting = 100
267
- elsif opts[:max_nesting]
268
- @max_nesting = opts[:max_nesting]
269
- else
270
- @max_nesting = 0
271
- end
272
- self
273
- end
274
- alias merge configure
275
-
276
- # Returns the configuration instance variables as a hash, that can be
277
- # passed to the configure method.
278
- def to_h
279
- result = {}
280
- for iv in instance_variables
281
- iv = iv.to_s[1..-1]
282
- result[iv.to_sym] = self[iv]
283
- end
284
- result
285
- end
286
-
287
- alias to_hash to_h
288
-
289
- # Generates a valid JSON document from object +obj+ and returns the
290
- # result. If no valid JSON document can be created this method raises a
291
- # GeneratorError exception.
292
- def generate(obj)
293
- result = obj.to_json(self)
294
- JSON.valid_utf8?(result) or raise GeneratorError,
295
- "source sequence #{result.inspect} is illegal/malformed utf-8"
296
- unless @quirks_mode
297
- unless result =~ /\A\s*\[/ && result =~ /\]\s*\Z/ ||
298
- result =~ /\A\s*\{/ && result =~ /\}\s*\Z/
299
- then
300
- raise GeneratorError, "only generation of JSON objects or arrays allowed"
301
- end
302
- end
303
- result
304
- end
305
-
306
- # Return the value returned by method +name+.
307
- def [](name)
308
- if respond_to?(name)
309
- __send__(name)
310
- else
311
- instance_variable_get("@#{name}")
312
- end
313
- end
314
-
315
- def []=(name, value)
316
- if respond_to?(name_writer = "#{name}=")
317
- __send__ name_writer, value
318
- else
319
- instance_variable_set "@#{name}", value
320
- end
321
- end
322
- end
323
-
324
- module GeneratorMethods
325
- module Object
326
- # Converts this object to a string (calling #to_s), converts
327
- # it to a JSON string, and returns the result. This is a fallback, if no
328
- # special method #to_json was defined for some object.
329
- def to_json(*) to_s.to_json end
330
- end
331
-
332
- module Hash
333
- # Returns a JSON string containing a JSON object, that is unparsed from
334
- # this Hash instance.
335
- # _state_ is a JSON::State object, that can also be used to configure the
336
- # produced JSON string output further.
337
- # _depth_ is used to find out nesting depth, to indent accordingly.
338
- def to_json(state = nil, *)
339
- state = State.from_state(state)
340
- state.check_max_nesting
341
- json_transform(state)
342
- end
343
-
344
- private
345
-
346
- def json_shift(state)
347
- state.object_nl.empty? or return ''
348
- state.indent * state.depth
349
- end
350
-
351
- def json_transform(state)
352
- delim = ','
353
- delim << state.object_nl
354
- result = '{'
355
- result << state.object_nl
356
- depth = state.depth += 1
357
- first = true
358
- indent = !state.object_nl.empty?
359
- each { |key,value|
360
- result << delim unless first
361
- result << state.indent * depth if indent
362
- result << key.to_s.to_json(state)
363
- result << state.space_before
364
- result << ':'
365
- result << state.space
366
- result << value.to_json(state)
367
- first = false
368
- }
369
- depth = state.depth -= 1
370
- result << state.object_nl
371
- result << state.indent * depth if indent
372
- result << '}'
373
- result
374
- end
375
- end
376
-
377
- module Array
378
- # Returns a JSON string containing a JSON array, that is unparsed from
379
- # this Array instance.
380
- # _state_ is a JSON::State object, that can also be used to configure the
381
- # produced JSON string output further.
382
- def to_json(state = nil, *)
383
- state = State.from_state(state)
384
- state.check_max_nesting
385
- json_transform(state)
386
- end
387
-
388
- private
389
-
390
- def json_transform(state)
391
- delim = ','
392
- delim << state.array_nl
393
- result = '['
394
- result << state.array_nl
395
- depth = state.depth += 1
396
- first = true
397
- indent = !state.array_nl.empty?
398
- each { |value|
399
- result << delim unless first
400
- result << state.indent * depth if indent
401
- result << value.to_json(state)
402
- first = false
403
- }
404
- depth = state.depth -= 1
405
- result << state.array_nl
406
- result << state.indent * depth if indent
407
- result << ']'
408
- end
409
- end
410
-
411
- module Integer
412
- # Returns a JSON string representation for this Integer number.
413
- def to_json(*) to_s end
414
- end
415
-
416
- module Float
417
- # Returns a JSON string representation for this Float number.
418
- def to_json(state = nil, *)
419
- state = State.from_state(state)
420
- case
421
- when infinite?
422
- if state.allow_nan?
423
- to_s
424
- else
425
- raise GeneratorError, "#{self} not allowed in JSON"
426
- end
427
- when nan?
428
- if state.allow_nan?
429
- to_s
430
- else
431
- raise GeneratorError, "#{self} not allowed in JSON"
432
- end
433
- else
434
- to_s
435
- end
436
- end
437
- end
438
-
439
- module String
440
- if defined?(::Encoding)
441
- # This string should be encoded with UTF-8 A call to this method
442
- # returns a JSON string encoded with UTF16 big endian characters as
443
- # \u????.
444
- def to_json(state = nil, *args)
445
- state = State.from_state(state)
446
- if encoding == ::Encoding::UTF_8
447
- string = self
448
- else
449
- string = encode(::Encoding::UTF_8)
450
- end
451
- if state.ascii_only?
452
- '"' << JSON.utf8_to_json_ascii(string) << '"'
453
- else
454
- '"' << JSON.utf8_to_json(string) << '"'
455
- end
456
- end
457
- else
458
- # This string should be encoded with UTF-8 A call to this method
459
- # returns a JSON string encoded with UTF16 big endian characters as
460
- # \u????.
461
- def to_json(state = nil, *args)
462
- state = State.from_state(state)
463
- if state.ascii_only?
464
- '"' << JSON.utf8_to_json_ascii(self) << '"'
465
- else
466
- '"' << JSON.utf8_to_json(self) << '"'
467
- end
468
- end
469
- end
470
-
471
- # Module that holds the extinding methods if, the String module is
472
- # included.
473
- module Extend
474
- # Raw Strings are JSON Objects (the raw bytes are stored in an
475
- # array for the key "raw"). The Ruby String can be created by this
476
- # module method.
477
- def json_create(o)
478
- o['raw'].pack('C*')
479
- end
480
- end
481
-
482
- # Extends _modul_ with the String::Extend module.
483
- def self.included(modul)
484
- modul.extend Extend
485
- end
486
-
487
- # This method creates a raw object hash, that can be nested into
488
- # other data structures and will be unparsed as a raw string. This
489
- # method should be used, if you want to convert raw strings to JSON
490
- # instead of UTF-8 strings, e. g. binary data.
491
- def to_json_raw_object
492
- {
493
- JSON.create_id => self.class.name,
494
- 'raw' => self.unpack('C*'),
495
- }
496
- end
497
-
498
- # This method creates a JSON text from the result of
499
- # a call to to_json_raw_object of this String.
500
- def to_json_raw(*args)
501
- to_json_raw_object.to_json(*args)
502
- end
503
- end
504
-
505
- module TrueClass
506
- # Returns a JSON string for true: 'true'.
507
- def to_json(*) 'true' end
508
- end
509
-
510
- module FalseClass
511
- # Returns a JSON string for false: 'false'.
512
- def to_json(*) 'false' end
513
- end
514
-
515
- module NilClass
516
- # Returns a JSON string for nil: 'null'.
517
- def to_json(*) 'null' end
518
- end
519
- end
520
- end
521
- end
522
- end