scout 5.6.7 → 5.6.8.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +4 -0
- data/lib/scout/version.rb +1 -1
- data/vendor/json_pure/.gitignore +12 -0
- data/vendor/json_pure/.travis.yml +20 -0
- data/vendor/json_pure/CHANGES +120 -0
- data/vendor/json_pure/COPYING-json-jruby +57 -0
- data/vendor/json_pure/Gemfile +11 -0
- data/vendor/json_pure/README-json-jruby.markdown +33 -0
- data/vendor/json_pure/{README → README.rdoc} +7 -7
- data/vendor/json_pure/Rakefile +305 -185
- data/vendor/json_pure/VERSION +1 -1
- data/vendor/json_pure/diagrams/.keep +0 -0
- data/vendor/json_pure/ext/json/ext/fbuffer/fbuffer.h +181 -0
- data/vendor/json_pure/ext/json/ext/generator/depend +1 -0
- data/vendor/json_pure/ext/json/ext/generator/extconf.rb +4 -6
- data/vendor/json_pure/ext/json/ext/generator/generator.c +463 -369
- data/vendor/json_pure/ext/json/ext/generator/generator.h +44 -66
- data/vendor/json_pure/ext/json/ext/parser/depend +1 -0
- data/vendor/json_pure/ext/json/ext/parser/extconf.rb +3 -5
- data/vendor/json_pure/ext/json/ext/parser/parser.c +580 -311
- data/vendor/json_pure/ext/json/ext/parser/parser.h +14 -8
- data/vendor/json_pure/ext/json/ext/parser/parser.rl +242 -107
- data/vendor/json_pure/install.rb +8 -11
- data/vendor/json_pure/java/src/json/ext/ByteListTranscoder.java +167 -0
- data/vendor/json_pure/java/src/json/ext/Generator.java +444 -0
- data/vendor/json_pure/java/src/json/ext/GeneratorMethods.java +232 -0
- data/vendor/json_pure/java/src/json/ext/GeneratorService.java +43 -0
- data/vendor/json_pure/java/src/json/ext/GeneratorState.java +543 -0
- data/vendor/json_pure/java/src/json/ext/OptionsReader.java +114 -0
- data/vendor/json_pure/java/src/json/ext/Parser.java +2644 -0
- data/vendor/json_pure/java/src/json/ext/Parser.rl +968 -0
- data/vendor/json_pure/java/src/json/ext/ParserService.java +35 -0
- data/vendor/json_pure/java/src/json/ext/RuntimeInfo.java +121 -0
- data/vendor/json_pure/java/src/json/ext/StringDecoder.java +167 -0
- data/vendor/json_pure/java/src/json/ext/StringEncoder.java +106 -0
- data/vendor/json_pure/java/src/json/ext/Utils.java +89 -0
- data/vendor/json_pure/json-java.gemspec +23 -0
- data/vendor/json_pure/json.gemspec +37 -0
- data/vendor/json_pure/json_pure.gemspec +39 -0
- data/vendor/json_pure/lib/json.rb +52 -0
- data/vendor/json_pure/lib/json/add/bigdecimal.rb +28 -0
- data/vendor/json_pure/lib/json/add/complex.rb +22 -0
- data/vendor/json_pure/lib/json/add/core.rb +9 -146
- data/vendor/json_pure/lib/json/add/date.rb +34 -0
- data/vendor/json_pure/lib/json/add/date_time.rb +50 -0
- data/vendor/json_pure/lib/json/add/exception.rb +31 -0
- data/vendor/json_pure/lib/json/add/ostruct.rb +31 -0
- data/vendor/json_pure/lib/json/add/range.rb +29 -0
- data/vendor/json_pure/lib/json/add/rational.rb +22 -0
- data/vendor/json_pure/lib/json/add/regexp.rb +30 -0
- data/vendor/json_pure/lib/json/add/struct.rb +30 -0
- data/vendor/json_pure/lib/json/add/symbol.rb +25 -0
- data/vendor/json_pure/lib/json/add/time.rb +38 -0
- data/vendor/json_pure/lib/json/common.rb +157 -67
- data/vendor/json_pure/lib/json/ext.rb +8 -2
- data/vendor/json_pure/lib/json/ext/.keep +0 -0
- data/vendor/json_pure/lib/json/generic_object.rb +70 -0
- data/vendor/json_pure/lib/json/pure.rb +8 -64
- data/vendor/json_pure/lib/json/pure/generator.rb +183 -113
- data/vendor/json_pure/lib/json/pure/parser.rb +118 -66
- data/vendor/json_pure/lib/json/version.rb +1 -1
- data/vendor/json_pure/tests/fixtures/fail18.json +1 -1
- data/vendor/json_pure/tests/setup_variant.rb +11 -0
- data/vendor/json_pure/tests/test_json.rb +233 -28
- data/vendor/json_pure/tests/test_json_addition.rb +68 -34
- data/vendor/json_pure/tests/test_json_encoding.rb +11 -14
- data/vendor/json_pure/tests/test_json_fixtures.rb +11 -10
- data/vendor/json_pure/tests/test_json_generate.rb +207 -7
- data/vendor/json_pure/tests/test_json_generic_object.rb +75 -0
- data/vendor/json_pure/tests/test_json_string_matching.rb +39 -0
- data/vendor/json_pure/tests/test_json_unicode.rb +3 -7
- data/vendor/json_pure/tools/fuzz.rb +1 -1
- data/vendor/json_pure/tools/server.rb +1 -0
- metadata +87 -94
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log +0 -52
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat +0 -1000
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat +0 -1001
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat +0 -900
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat +0 -901
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat +0 -1000
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat +0 -1001
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log +0 -261
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat +0 -1000
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat +0 -1001
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat +0 -1000
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat +0 -1001
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat +0 -1000
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat +0 -1001
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log +0 -262
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat +0 -1000
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat +0 -1001
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log +0 -82
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log +0 -34
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat +0 -900
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat +0 -901
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log +0 -81
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat +0 -1000
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat +0 -1001
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log +0 -82
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat +0 -1000
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat +0 -1001
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log +0 -82
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat +0 -1000
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat +0 -1001
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log +0 -82
- data/vendor/json_pure/benchmarks/generator2_benchmark.rb +0 -222
- data/vendor/json_pure/benchmarks/generator_benchmark.rb +0 -224
- data/vendor/json_pure/benchmarks/ohai.json +0 -1216
- data/vendor/json_pure/benchmarks/ohai.ruby +0 -1
- data/vendor/json_pure/benchmarks/parser2_benchmark.rb +0 -251
- data/vendor/json_pure/benchmarks/parser_benchmark.rb +0 -259
- data/vendor/json_pure/bin/edit_json.rb +0 -9
- data/vendor/json_pure/bin/prettify_json.rb +0 -75
- data/vendor/json_pure/lib/json/Array.xpm +0 -21
- data/vendor/json_pure/lib/json/FalseClass.xpm +0 -21
- data/vendor/json_pure/lib/json/Hash.xpm +0 -21
- data/vendor/json_pure/lib/json/Key.xpm +0 -73
- data/vendor/json_pure/lib/json/NilClass.xpm +0 -21
- data/vendor/json_pure/lib/json/Numeric.xpm +0 -28
- data/vendor/json_pure/lib/json/String.xpm +0 -96
- data/vendor/json_pure/lib/json/TrueClass.xpm +0 -21
- data/vendor/json_pure/lib/json/add/rails.rb +0 -58
- data/vendor/json_pure/lib/json/editor.rb +0 -1371
- data/vendor/json_pure/lib/json/json.xpm +0 -1499
- data/vendor/json_pure/tests/test_json_rails.rb +0 -144
@@ -0,0 +1,31 @@
|
|
1
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
|
+
require 'json'
|
3
|
+
end
|
4
|
+
|
5
|
+
# Exception serialization/deserialization
|
6
|
+
class Exception
|
7
|
+
|
8
|
+
# Deserializes JSON string by constructing new Exception object with message
|
9
|
+
# <tt>m</tt> and backtrace <tt>b</tt> serialized with <tt>to_json</tt>
|
10
|
+
def self.json_create(object)
|
11
|
+
result = new(object['m'])
|
12
|
+
result.set_backtrace object['b']
|
13
|
+
result
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
17
|
+
# object.
|
18
|
+
def as_json(*)
|
19
|
+
{
|
20
|
+
JSON.create_id => self.class.name,
|
21
|
+
'm' => message,
|
22
|
+
'b' => backtrace,
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
# Stores class name (Exception) with message <tt>m</tt> and backtrace array
|
27
|
+
# <tt>b</tt> as JSON string
|
28
|
+
def to_json(*args)
|
29
|
+
as_json.to_json(*args)
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
|
+
require 'json'
|
3
|
+
end
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
# OpenStruct serialization/deserialization
|
7
|
+
class OpenStruct
|
8
|
+
|
9
|
+
# Deserializes JSON string by constructing new Struct object with values
|
10
|
+
# <tt>v</tt> serialized by <tt>to_json</tt>.
|
11
|
+
def self.json_create(object)
|
12
|
+
new(object['t'] || object[:t])
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
16
|
+
# object.
|
17
|
+
def as_json(*)
|
18
|
+
klass = self.class.name
|
19
|
+
klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!"
|
20
|
+
{
|
21
|
+
JSON.create_id => klass,
|
22
|
+
't' => table,
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
# Stores class name (OpenStruct) with this struct's values <tt>v</tt> as a
|
27
|
+
# JSON string.
|
28
|
+
def to_json(*args)
|
29
|
+
as_json.to_json(*args)
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
|
+
require 'json'
|
3
|
+
end
|
4
|
+
|
5
|
+
# Range serialization/deserialization
|
6
|
+
class Range
|
7
|
+
|
8
|
+
# Deserializes JSON string by constructing new Range object with arguments
|
9
|
+
# <tt>a</tt> serialized by <tt>to_json</tt>.
|
10
|
+
def self.json_create(object)
|
11
|
+
new(*object['a'])
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
15
|
+
# object.
|
16
|
+
def as_json(*)
|
17
|
+
{
|
18
|
+
JSON.create_id => self.class.name,
|
19
|
+
'a' => [ first, last, exclude_end? ]
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
# Stores class name (Range) with JSON array of arguments <tt>a</tt> which
|
24
|
+
# include <tt>first</tt> (integer), <tt>last</tt> (integer), and
|
25
|
+
# <tt>exclude_end?</tt> (boolean) as JSON string.
|
26
|
+
def to_json(*args)
|
27
|
+
as_json.to_json(*args)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
|
+
require 'json'
|
3
|
+
end
|
4
|
+
defined?(::Rational) or require 'rational'
|
5
|
+
|
6
|
+
class Rational
|
7
|
+
def self.json_create(object)
|
8
|
+
Rational(object['n'], object['d'])
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_json(*)
|
12
|
+
{
|
13
|
+
JSON.create_id => self.class.name,
|
14
|
+
'n' => numerator,
|
15
|
+
'd' => denominator,
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_json(*)
|
20
|
+
as_json.to_json
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
|
+
require 'json'
|
3
|
+
end
|
4
|
+
|
5
|
+
# Regexp serialization/deserialization
|
6
|
+
class Regexp
|
7
|
+
|
8
|
+
# Deserializes JSON string by constructing new Regexp object with source
|
9
|
+
# <tt>s</tt> (Regexp or String) and options <tt>o</tt> serialized by
|
10
|
+
# <tt>to_json</tt>
|
11
|
+
def self.json_create(object)
|
12
|
+
new(object['s'], object['o'])
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
16
|
+
# object.
|
17
|
+
def as_json(*)
|
18
|
+
{
|
19
|
+
JSON.create_id => self.class.name,
|
20
|
+
'o' => options,
|
21
|
+
's' => source,
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Stores class name (Regexp) with options <tt>o</tt> and source <tt>s</tt>
|
26
|
+
# (Regexp or String) as JSON string
|
27
|
+
def to_json(*)
|
28
|
+
as_json.to_json
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
|
+
require 'json'
|
3
|
+
end
|
4
|
+
|
5
|
+
# Struct serialization/deserialization
|
6
|
+
class Struct
|
7
|
+
|
8
|
+
# Deserializes JSON string by constructing new Struct object with values
|
9
|
+
# <tt>v</tt> serialized by <tt>to_json</tt>.
|
10
|
+
def self.json_create(object)
|
11
|
+
new(*object['v'])
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
15
|
+
# object.
|
16
|
+
def as_json(*)
|
17
|
+
klass = self.class.name
|
18
|
+
klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!"
|
19
|
+
{
|
20
|
+
JSON.create_id => klass,
|
21
|
+
'v' => values,
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Stores class name (Struct) with Struct values <tt>v</tt> as a JSON string.
|
26
|
+
# Only named structs are supported.
|
27
|
+
def to_json(*args)
|
28
|
+
as_json.to_json(*args)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
|
+
require 'json'
|
3
|
+
end
|
4
|
+
|
5
|
+
# Symbol serialization/deserialization
|
6
|
+
class Symbol
|
7
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
8
|
+
# object.
|
9
|
+
def as_json(*)
|
10
|
+
{
|
11
|
+
JSON.create_id => self.class.name,
|
12
|
+
's' => to_s,
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
# Stores class name (Symbol) with String representation of Symbol as a JSON string.
|
17
|
+
def to_json(*a)
|
18
|
+
as_json.to_json(*a)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Deserializes JSON string by converting the <tt>string</tt> value stored in the object to a Symbol
|
22
|
+
def self.json_create(o)
|
23
|
+
o['s'].to_sym
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
|
+
require 'json'
|
3
|
+
end
|
4
|
+
|
5
|
+
# Time serialization/deserialization
|
6
|
+
class Time
|
7
|
+
|
8
|
+
# Deserializes JSON string by converting time since epoch to Time
|
9
|
+
def self.json_create(object)
|
10
|
+
if usec = object.delete('u') # used to be tv_usec -> tv_nsec
|
11
|
+
object['n'] = usec * 1000
|
12
|
+
end
|
13
|
+
if instance_methods.include?(:tv_nsec)
|
14
|
+
at(object['s'], Rational(object['n'], 1000))
|
15
|
+
else
|
16
|
+
at(object['s'], object['n'] / 1000)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
21
|
+
# object.
|
22
|
+
def as_json(*)
|
23
|
+
nanoseconds = [ tv_usec * 1000 ]
|
24
|
+
respond_to?(:tv_nsec) and nanoseconds << tv_nsec
|
25
|
+
nanoseconds = nanoseconds.max
|
26
|
+
{
|
27
|
+
JSON.create_id => self.class.name,
|
28
|
+
's' => tv_sec,
|
29
|
+
'n' => nanoseconds,
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
# Stores class name (Time) with number of seconds since epoch and number of
|
34
|
+
# microseconds for Time as JSON string
|
35
|
+
def to_json(*args)
|
36
|
+
as_json.to_json(*args)
|
37
|
+
end
|
38
|
+
end
|
@@ -1,47 +1,47 @@
|
|
1
1
|
require 'json/version'
|
2
|
-
require '
|
2
|
+
require 'json/generic_object'
|
3
3
|
|
4
4
|
module JSON
|
5
5
|
class << self
|
6
|
-
# If _object_ is string-like parse the string and return the parsed result
|
6
|
+
# If _object_ is string-like, parse the string and return the parsed result
|
7
7
|
# as a Ruby data structure. Otherwise generate a JSON text from the Ruby
|
8
8
|
# data structure object and return it.
|
9
9
|
#
|
10
|
-
# The _opts_ argument is passed through to generate/parse respectively
|
10
|
+
# The _opts_ argument is passed through to generate/parse respectively. See
|
11
11
|
# generate and parse for their documentation.
|
12
12
|
def [](object, opts = {})
|
13
13
|
if object.respond_to? :to_str
|
14
|
-
JSON.parse(object.to_str, opts
|
14
|
+
JSON.parse(object.to_str, opts)
|
15
15
|
else
|
16
|
-
JSON.generate(object, opts
|
16
|
+
JSON.generate(object, opts)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
# Returns the JSON parser class
|
20
|
+
# Returns the JSON parser class that is used by JSON. This is either
|
21
21
|
# JSON::Ext::Parser or JSON::Pure::Parser.
|
22
22
|
attr_reader :parser
|
23
23
|
|
24
24
|
# Set the JSON parser class _parser_ to be used by JSON.
|
25
25
|
def parser=(parser) # :nodoc:
|
26
26
|
@parser = parser
|
27
|
-
remove_const :Parser if
|
27
|
+
remove_const :Parser if JSON.const_defined_in?(self, :Parser)
|
28
28
|
const_set :Parser, parser
|
29
29
|
end
|
30
30
|
|
31
31
|
# Return the constant located at _path_. The format of _path_ has to be
|
32
|
-
# either ::A::B::C or A::B::C. In any case A has to be located at the top
|
32
|
+
# either ::A::B::C or A::B::C. In any case, A has to be located at the top
|
33
33
|
# level (absolute namespace path?). If there doesn't exist a constant at
|
34
34
|
# the given path, an ArgumentError is raised.
|
35
35
|
def deep_const_get(path) # :nodoc:
|
36
36
|
path.to_s.split(/::/).inject(Object) do |p, c|
|
37
37
|
case
|
38
|
-
when c.empty?
|
39
|
-
when
|
38
|
+
when c.empty? then p
|
39
|
+
when JSON.const_defined_in?(p, c) then p.const_get(c)
|
40
40
|
else
|
41
41
|
begin
|
42
42
|
p.const_missing(c)
|
43
|
-
rescue NameError
|
44
|
-
raise ArgumentError, "can't
|
43
|
+
rescue NameError => e
|
44
|
+
raise ArgumentError, "can't get const #{path}: #{e}"
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -49,6 +49,7 @@ module JSON
|
|
49
49
|
|
50
50
|
# Set the module _generator_ to be used by JSON.
|
51
51
|
def generator=(generator) # :nodoc:
|
52
|
+
old, $VERBOSE = $VERBOSE, nil
|
52
53
|
@generator = generator
|
53
54
|
generator_methods = generator::GeneratorMethods
|
54
55
|
for const in generator_methods.constants
|
@@ -63,31 +64,33 @@ module JSON
|
|
63
64
|
end
|
64
65
|
self.state = generator::State
|
65
66
|
const_set :State, self.state
|
66
|
-
const_set :SAFE_STATE_PROTOTYPE, State.new
|
67
|
+
const_set :SAFE_STATE_PROTOTYPE, State.new
|
67
68
|
const_set :FAST_STATE_PROTOTYPE, State.new(
|
68
69
|
:indent => '',
|
69
70
|
:space => '',
|
70
71
|
:object_nl => "",
|
71
72
|
:array_nl => "",
|
72
73
|
:max_nesting => false
|
73
|
-
)
|
74
|
+
)
|
74
75
|
const_set :PRETTY_STATE_PROTOTYPE, State.new(
|
75
76
|
:indent => ' ',
|
76
77
|
:space => ' ',
|
77
78
|
:object_nl => "\n",
|
78
79
|
:array_nl => "\n"
|
79
|
-
)
|
80
|
+
)
|
81
|
+
ensure
|
82
|
+
$VERBOSE = old
|
80
83
|
end
|
81
84
|
|
82
|
-
# Returns the JSON generator
|
85
|
+
# Returns the JSON generator module that is used by JSON. This is
|
83
86
|
# either JSON::Ext::Generator or JSON::Pure::Generator.
|
84
87
|
attr_reader :generator
|
85
88
|
|
86
|
-
# Returns the JSON generator state class
|
87
|
-
#
|
89
|
+
# Returns the JSON generator state class that is used by JSON. This is
|
90
|
+
# either JSON::Ext::Generator::State or JSON::Pure::Generator::State.
|
88
91
|
attr_accessor :state
|
89
92
|
|
90
|
-
# This is create identifier,
|
93
|
+
# This is create identifier, which is used to decide if the _json_create_
|
91
94
|
# hook of a class should be called. It defaults to 'json_class'.
|
92
95
|
attr_accessor :create_id
|
93
96
|
end
|
@@ -100,12 +103,18 @@ module JSON
|
|
100
103
|
MinusInfinity = -Infinity
|
101
104
|
|
102
105
|
# The base exception for JSON errors.
|
103
|
-
class JSONError < StandardError
|
106
|
+
class JSONError < StandardError
|
107
|
+
def self.wrap(exception)
|
108
|
+
obj = new("Wrapped(#{exception.class}): #{exception.message.inspect}")
|
109
|
+
obj.set_backtrace exception.backtrace
|
110
|
+
obj
|
111
|
+
end
|
112
|
+
end
|
104
113
|
|
105
|
-
# This exception is raised
|
114
|
+
# This exception is raised if a parser error occurs.
|
106
115
|
class ParserError < JSONError; end
|
107
116
|
|
108
|
-
# This exception is raised
|
117
|
+
# This exception is raised if the nesting of parsed data structures is too
|
109
118
|
# deep.
|
110
119
|
class NestingError < ParserError; end
|
111
120
|
|
@@ -113,13 +122,13 @@ module JSON
|
|
113
122
|
class CircularDatastructure < NestingError; end
|
114
123
|
# :startdoc:
|
115
124
|
|
116
|
-
# This exception is raised
|
125
|
+
# This exception is raised if a generator or unparser error occurs.
|
117
126
|
class GeneratorError < JSONError; end
|
118
127
|
# For backwards compatibility
|
119
128
|
UnparserError = GeneratorError
|
120
129
|
|
121
|
-
# This exception is raised
|
122
|
-
# system. Usually this means
|
130
|
+
# This exception is raised if the required unicode support is missing on the
|
131
|
+
# system. Usually this means that the iconv library is not installed.
|
123
132
|
class MissingUnicodeSupport < JSONError; end
|
124
133
|
|
125
134
|
module_function
|
@@ -129,16 +138,16 @@ module JSON
|
|
129
138
|
# _opts_ can have the following
|
130
139
|
# keys:
|
131
140
|
# * *max_nesting*: The maximum depth of nesting allowed in the parsed data
|
132
|
-
# structures. Disable depth checking with :max_nesting => false
|
133
|
-
# to
|
141
|
+
# structures. Disable depth checking with :max_nesting => false. It defaults
|
142
|
+
# to 100.
|
134
143
|
# * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
|
135
144
|
# defiance of RFC 4627 to be parsed by the Parser. This option defaults
|
136
145
|
# to false.
|
137
146
|
# * *symbolize_names*: If set to true, returns symbols for the names
|
138
|
-
# (keys) in a JSON object. Otherwise strings are returned
|
147
|
+
# (keys) in a JSON object. Otherwise strings are returned. Strings are
|
139
148
|
# the default.
|
140
149
|
# * *create_additions*: If set to false, the Parser doesn't create
|
141
|
-
# additions even if a
|
150
|
+
# additions even if a matching class and create_id was found. This option
|
142
151
|
# defaults to true.
|
143
152
|
# * *object_class*: Defaults to Hash
|
144
153
|
# * *array_class*: Defaults to Array
|
@@ -147,19 +156,19 @@ module JSON
|
|
147
156
|
end
|
148
157
|
|
149
158
|
# Parse the JSON document _source_ into a Ruby data structure and return it.
|
150
|
-
# The bang version of the parse method
|
159
|
+
# The bang version of the parse method defaults to the more dangerous values
|
151
160
|
# for the _opts_ hash, so be sure only to parse trusted _source_ documents.
|
152
161
|
#
|
153
162
|
# _opts_ can have the following keys:
|
154
163
|
# * *max_nesting*: The maximum depth of nesting allowed in the parsed data
|
155
164
|
# structures. Enable depth checking with :max_nesting => anInteger. The parse!
|
156
|
-
# methods defaults to not doing max depth checking: This can be dangerous
|
165
|
+
# methods defaults to not doing max depth checking: This can be dangerous
|
157
166
|
# if someone wants to fill up your stack.
|
158
167
|
# * *allow_nan*: If set to true, allow NaN, Infinity, and -Infinity in
|
159
168
|
# defiance of RFC 4627 to be parsed by the Parser. This option defaults
|
160
169
|
# to true.
|
161
170
|
# * *create_additions*: If set to false, the Parser doesn't create
|
162
|
-
# additions even if a
|
171
|
+
# additions even if a matching class and create_id was found. This option
|
163
172
|
# defaults to true.
|
164
173
|
def parse!(source, opts = {})
|
165
174
|
opts = {
|
@@ -183,19 +192,24 @@ module JSON
|
|
183
192
|
# * *indent*: a string used to indent levels (default: ''),
|
184
193
|
# * *space*: a string that is put after, a : or , delimiter (default: ''),
|
185
194
|
# * *space_before*: a string that is put before a : pair delimiter (default: ''),
|
186
|
-
# * *object_nl*: a string that is put at the end of a JSON object (default: ''),
|
195
|
+
# * *object_nl*: a string that is put at the end of a JSON object (default: ''),
|
187
196
|
# * *array_nl*: a string that is put at the end of a JSON array (default: ''),
|
188
197
|
# * *allow_nan*: true if NaN, Infinity, and -Infinity should be
|
189
|
-
# generated, otherwise an exception is thrown
|
198
|
+
# generated, otherwise an exception is thrown if these values are
|
190
199
|
# encountered. This options defaults to false.
|
191
200
|
# * *max_nesting*: The maximum depth of nesting allowed in the data
|
192
201
|
# structures from which JSON is to be generated. Disable depth checking
|
193
|
-
# with :max_nesting => false, it defaults to
|
202
|
+
# with :max_nesting => false, it defaults to 100.
|
194
203
|
#
|
195
204
|
# See also the fast_generate for the fastest creation method with the least
|
196
205
|
# amount of sanity checks, and the pretty_generate method for some
|
197
|
-
# defaults for
|
206
|
+
# defaults for pretty output.
|
198
207
|
def generate(obj, opts = nil)
|
208
|
+
if State === opts
|
209
|
+
state, opts = opts, nil
|
210
|
+
else
|
211
|
+
state = SAFE_STATE_PROTOTYPE.dup
|
212
|
+
end
|
199
213
|
if opts
|
200
214
|
if opts.respond_to? :to_hash
|
201
215
|
opts = opts.to_hash
|
@@ -204,10 +218,7 @@ module JSON
|
|
204
218
|
else
|
205
219
|
raise TypeError, "can't convert #{opts.class} into Hash"
|
206
220
|
end
|
207
|
-
state = SAFE_STATE_PROTOTYPE.dup
|
208
221
|
state = state.configure(opts)
|
209
|
-
else
|
210
|
-
state = SAFE_STATE_PROTOTYPE
|
211
222
|
end
|
212
223
|
state.generate(obj)
|
213
224
|
end
|
@@ -223,8 +234,13 @@ module JSON
|
|
223
234
|
# This method disables the checks for circles in Ruby objects.
|
224
235
|
#
|
225
236
|
# *WARNING*: Be careful not to pass any Ruby data structures with circles as
|
226
|
-
# _obj_ argument
|
237
|
+
# _obj_ argument because this will cause JSON to go into an infinite loop.
|
227
238
|
def fast_generate(obj, opts = nil)
|
239
|
+
if State === opts
|
240
|
+
state, opts = opts, nil
|
241
|
+
else
|
242
|
+
state = FAST_STATE_PROTOTYPE.dup
|
243
|
+
end
|
228
244
|
if opts
|
229
245
|
if opts.respond_to? :to_hash
|
230
246
|
opts = opts.to_hash
|
@@ -233,10 +249,7 @@ module JSON
|
|
233
249
|
else
|
234
250
|
raise TypeError, "can't convert #{opts.class} into Hash"
|
235
251
|
end
|
236
|
-
state = FAST_STATE_PROTOTYPE.dup
|
237
252
|
state.configure(opts)
|
238
|
-
else
|
239
|
-
state = FAST_STATE_PROTOTYPE
|
240
253
|
end
|
241
254
|
state.generate(obj)
|
242
255
|
end
|
@@ -251,9 +264,14 @@ module JSON
|
|
251
264
|
# The returned document is a prettier form of the document returned by
|
252
265
|
# #unparse.
|
253
266
|
#
|
254
|
-
# The _opts_ argument can be used to configure the generator
|
267
|
+
# The _opts_ argument can be used to configure the generator. See the
|
255
268
|
# generate method for a more detailed explanation.
|
256
269
|
def pretty_generate(obj, opts = nil)
|
270
|
+
if State === opts
|
271
|
+
state, opts = opts, nil
|
272
|
+
else
|
273
|
+
state = PRETTY_STATE_PROTOTYPE.dup
|
274
|
+
end
|
257
275
|
if opts
|
258
276
|
if opts.respond_to? :to_hash
|
259
277
|
opts = opts.to_hash
|
@@ -262,10 +280,7 @@ module JSON
|
|
262
280
|
else
|
263
281
|
raise TypeError, "can't convert #{opts.class} into Hash"
|
264
282
|
end
|
265
|
-
state = PRETTY_STATE_PROTOTYPE.dup
|
266
283
|
state.configure(opts)
|
267
|
-
else
|
268
|
-
state = PRETTY_STATE_PROTOTYPE
|
269
284
|
end
|
270
285
|
state.generate(obj)
|
271
286
|
end
|
@@ -276,26 +291,52 @@ module JSON
|
|
276
291
|
module_function :pretty_unparse
|
277
292
|
# :startdoc:
|
278
293
|
|
294
|
+
class << self
|
295
|
+
# The global default options for the JSON.load method:
|
296
|
+
# :max_nesting: false
|
297
|
+
# :allow_nan: true
|
298
|
+
# :quirks_mode: true
|
299
|
+
attr_accessor :load_default_options
|
300
|
+
end
|
301
|
+
self.load_default_options = {
|
302
|
+
:max_nesting => false,
|
303
|
+
:allow_nan => true,
|
304
|
+
:quirks_mode => true,
|
305
|
+
:create_additions => true,
|
306
|
+
}
|
307
|
+
|
279
308
|
# Load a ruby data structure from a JSON _source_ and return it. A source can
|
280
|
-
# either be a string-like object, an IO
|
309
|
+
# either be a string-like object, an IO-like object, or an object responding
|
281
310
|
# to the read method. If _proc_ was given, it will be called with any nested
|
282
|
-
# Ruby object as an argument recursively in depth first order.
|
311
|
+
# Ruby object as an argument recursively in depth first order. To modify the
|
312
|
+
# default options pass in the optional _options_ argument as well.
|
313
|
+
#
|
314
|
+
# BEWARE: This method is meant to serialise data from trusted user input,
|
315
|
+
# like from your own database server or clients under your control, it could
|
316
|
+
# be dangerous to allow untrusted users to pass JSON sources into it. The
|
317
|
+
# default options for the parser can be changed via the load_default_options
|
318
|
+
# method.
|
283
319
|
#
|
284
320
|
# This method is part of the implementation of the load/dump interface of
|
285
321
|
# Marshal and YAML.
|
286
|
-
def load(source, proc = nil)
|
322
|
+
def load(source, proc = nil, options = {})
|
323
|
+
opts = load_default_options.merge options
|
287
324
|
if source.respond_to? :to_str
|
288
325
|
source = source.to_str
|
289
326
|
elsif source.respond_to? :to_io
|
290
327
|
source = source.to_io.read
|
291
|
-
|
328
|
+
elsif source.respond_to?(:read)
|
292
329
|
source = source.read
|
293
330
|
end
|
294
|
-
|
331
|
+
if opts[:quirks_mode] && (source.nil? || source.empty?)
|
332
|
+
source = 'null'
|
333
|
+
end
|
334
|
+
result = parse(source, opts)
|
295
335
|
recurse_proc(result, &proc) if proc
|
296
336
|
result
|
297
337
|
end
|
298
338
|
|
339
|
+
# Recursively calls passed _Proc_ if the parsed data structure is an _Array_ or _Hash_
|
299
340
|
def recurse_proc(result, &proc)
|
300
341
|
case result
|
301
342
|
when Array
|
@@ -312,16 +353,32 @@ module JSON
|
|
312
353
|
alias restore load
|
313
354
|
module_function :restore
|
314
355
|
|
356
|
+
class << self
|
357
|
+
# The global default options for the JSON.dump method:
|
358
|
+
# :max_nesting: false
|
359
|
+
# :allow_nan: true
|
360
|
+
# :quirks_mode: true
|
361
|
+
attr_accessor :dump_default_options
|
362
|
+
end
|
363
|
+
self.dump_default_options = {
|
364
|
+
:max_nesting => false,
|
365
|
+
:allow_nan => true,
|
366
|
+
:quirks_mode => true,
|
367
|
+
}
|
368
|
+
|
315
369
|
# Dumps _obj_ as a JSON string, i.e. calls generate on the object and returns
|
316
370
|
# the result.
|
317
371
|
#
|
318
|
-
# If anIO (an IO
|
372
|
+
# If anIO (an IO-like object or an object that responds to the write method)
|
319
373
|
# was given, the resulting JSON is written to it.
|
320
374
|
#
|
321
|
-
# If the number of nested arrays or objects exceeds _limit_ an ArgumentError
|
375
|
+
# If the number of nested arrays or objects exceeds _limit_, an ArgumentError
|
322
376
|
# exception is raised. This argument is similar (but not exactly the
|
323
377
|
# same!) to the _limit_ argument in Marshal.dump.
|
324
378
|
#
|
379
|
+
# The default options for the generator can be changed via the
|
380
|
+
# dump_default_options method.
|
381
|
+
#
|
325
382
|
# This method is part of the implementation of the load/dump interface of
|
326
383
|
# Marshal and YAML.
|
327
384
|
def dump(obj, anIO = nil, limit = nil)
|
@@ -332,8 +389,9 @@ module JSON
|
|
332
389
|
anIO = nil
|
333
390
|
end
|
334
391
|
end
|
335
|
-
|
336
|
-
|
392
|
+
opts = JSON.dump_default_options
|
393
|
+
limit and opts.update(:max_nesting => limit)
|
394
|
+
result = generate(obj, opts)
|
337
395
|
if anIO
|
338
396
|
anIO.write result
|
339
397
|
anIO
|
@@ -344,9 +402,40 @@ module JSON
|
|
344
402
|
raise ArgumentError, "exceed depth limit"
|
345
403
|
end
|
346
404
|
|
405
|
+
# Swap consecutive bytes of _string_ in place.
|
406
|
+
def self.swap!(string) # :nodoc:
|
407
|
+
0.upto(string.size / 2) do |i|
|
408
|
+
break unless string[2 * i + 1]
|
409
|
+
string[2 * i], string[2 * i + 1] = string[2 * i + 1], string[2 * i]
|
410
|
+
end
|
411
|
+
string
|
412
|
+
end
|
413
|
+
|
347
414
|
# Shortuct for iconv.
|
348
|
-
|
349
|
-
|
415
|
+
if ::String.method_defined?(:encode) &&
|
416
|
+
# XXX Rubinius doesn't support ruby 1.9 encoding yet
|
417
|
+
defined?(RUBY_ENGINE) && RUBY_ENGINE != 'rbx'
|
418
|
+
then
|
419
|
+
# Encodes string using Ruby's _String.encode_
|
420
|
+
def self.iconv(to, from, string)
|
421
|
+
string.encode(to, from)
|
422
|
+
end
|
423
|
+
else
|
424
|
+
require 'iconv'
|
425
|
+
# Encodes string using _iconv_ library
|
426
|
+
def self.iconv(to, from, string)
|
427
|
+
Iconv.conv(to, from, string)
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
if ::Object.method(:const_defined?).arity == 1
|
432
|
+
def self.const_defined_in?(modul, constant)
|
433
|
+
modul.const_defined?(constant)
|
434
|
+
end
|
435
|
+
else
|
436
|
+
def self.const_defined_in?(modul, constant)
|
437
|
+
modul.const_defined?(constant, false)
|
438
|
+
end
|
350
439
|
end
|
351
440
|
end
|
352
441
|
|
@@ -371,26 +460,27 @@ module ::Kernel
|
|
371
460
|
nil
|
372
461
|
end
|
373
462
|
|
374
|
-
# If _object_ is string-like parse the string and return the parsed result as
|
375
|
-
# a Ruby data structure. Otherwise generate a JSON text from the Ruby data
|
463
|
+
# If _object_ is string-like, parse the string and return the parsed result as
|
464
|
+
# a Ruby data structure. Otherwise, generate a JSON text from the Ruby data
|
376
465
|
# structure object and return it.
|
377
466
|
#
|
378
|
-
# The _opts_ argument is passed through to generate/parse respectively
|
467
|
+
# The _opts_ argument is passed through to generate/parse respectively. See
|
379
468
|
# generate and parse for their documentation.
|
380
|
-
def JSON(object,
|
469
|
+
def JSON(object, *args)
|
381
470
|
if object.respond_to? :to_str
|
382
|
-
JSON.parse(object.to_str,
|
471
|
+
JSON.parse(object.to_str, args.first)
|
383
472
|
else
|
384
|
-
JSON.generate(object,
|
473
|
+
JSON.generate(object, args.first)
|
385
474
|
end
|
386
475
|
end
|
387
476
|
end
|
388
477
|
|
478
|
+
# Extends any Class to include _json_creatable?_ method.
|
389
479
|
class ::Class
|
390
|
-
# Returns true
|
480
|
+
# Returns true if this class can be used to create an instance
|
391
481
|
# from a serialised JSON string. The class has to implement a class
|
392
|
-
# method _json_create_ that expects a hash as first parameter
|
393
|
-
# the required data.
|
482
|
+
# method _json_create_ that expects a hash as first parameter. The hash
|
483
|
+
# should include the required data.
|
394
484
|
def json_creatable?
|
395
485
|
respond_to?(:json_create)
|
396
486
|
end
|