psych 2.2.1 → 5.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CONTRIBUTING.md +24 -0
- data/{ext/psych/yaml/LICENSE → LICENSE} +9 -7
- data/README.md +13 -13
- data/ext/psych/depend +14 -0
- data/ext/psych/extconf.rb +43 -29
- data/ext/psych/psych.c +6 -3
- data/ext/psych/psych_emitter.c +10 -9
- data/ext/psych/psych_parser.c +69 -72
- data/ext/psych/psych_yaml_tree.c +0 -12
- data/lib/psych/class_loader.rb +11 -9
- data/lib/psych/coder.rb +1 -1
- data/lib/psych/core_ext.rb +3 -20
- data/lib/psych/exception.rb +17 -3
- data/lib/psych/handler.rb +8 -3
- data/lib/psych/handlers/document_stream.rb +2 -2
- data/lib/psych/handlers/recorder.rb +2 -2
- data/lib/psych/json/ruby_events.rb +1 -1
- data/lib/psych/json/stream.rb +3 -3
- data/lib/psych/json/tree_builder.rb +2 -2
- data/lib/psych/json/yaml_events.rb +1 -1
- data/lib/psych/nodes/alias.rb +3 -1
- data/lib/psych/nodes/document.rb +3 -1
- data/lib/psych/nodes/mapping.rb +3 -1
- data/lib/psych/nodes/node.rb +24 -5
- data/lib/psych/nodes/scalar.rb +4 -2
- data/lib/psych/nodes/sequence.rb +3 -1
- data/lib/psych/nodes/stream.rb +3 -1
- data/lib/psych/nodes.rb +8 -8
- data/lib/psych/omap.rb +1 -1
- data/lib/psych/parser.rb +14 -1
- data/lib/psych/scalar_scanner.rb +39 -47
- data/lib/psych/set.rb +1 -1
- data/lib/psych/stream.rb +1 -1
- data/lib/psych/streaming.rb +1 -1
- data/lib/psych/syntax_error.rb +2 -2
- data/lib/psych/tree_builder.rb +48 -8
- data/lib/psych/versions.rb +5 -4
- data/lib/psych/visitors/depth_first.rb +1 -1
- data/lib/psych/visitors/emitter.rb +1 -1
- data/lib/psych/visitors/json_tree.rb +2 -2
- data/lib/psych/visitors/to_ruby.rb +61 -31
- data/lib/psych/visitors/visitor.rb +18 -4
- data/lib/psych/visitors/yaml_tree.rb +111 -123
- data/lib/psych/visitors.rb +7 -7
- data/lib/psych/y.rb +1 -1
- data/lib/psych.rb +333 -96
- metadata +16 -52
- data/.gitignore +0 -14
- data/.travis.yml +0 -18
- data/CHANGELOG.rdoc +0 -576
- data/Gemfile +0 -3
- data/Mavenfile +0 -7
- data/Rakefile +0 -33
- data/bin/console +0 -7
- data/bin/setup +0 -6
- data/ext/psych/.gitignore +0 -11
- data/ext/psych/yaml/api.c +0 -1392
- data/ext/psych/yaml/config.h +0 -10
- data/ext/psych/yaml/dumper.c +0 -394
- data/ext/psych/yaml/emitter.c +0 -2329
- data/ext/psych/yaml/loader.c +0 -444
- data/ext/psych/yaml/parser.c +0 -1374
- data/ext/psych/yaml/reader.c +0 -469
- data/ext/psych/yaml/scanner.c +0 -3576
- data/ext/psych/yaml/writer.c +0 -141
- data/ext/psych/yaml/yaml.h +0 -1971
- data/ext/psych/yaml/yaml_private.h +0 -662
- data/lib/psych/deprecated.rb +0 -86
- data/psych.gemspec +0 -43
data/lib/psych/class_loader.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# frozen_string_literal:
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'omap'
|
3
|
+
require_relative 'set'
|
4
4
|
|
5
5
|
module Psych
|
6
6
|
class ClassLoader # :nodoc:
|
@@ -35,9 +35,11 @@ module Psych
|
|
35
35
|
|
36
36
|
constants.each do |const|
|
37
37
|
konst = const_get const
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
39
|
+
def #{const.to_s.downcase}
|
40
|
+
load #{konst.inspect}
|
41
|
+
end
|
42
|
+
RUBY
|
41
43
|
end
|
42
44
|
|
43
45
|
private
|
@@ -69,7 +71,7 @@ module Psych
|
|
69
71
|
rescue
|
70
72
|
nil
|
71
73
|
end
|
72
|
-
}.compact]
|
74
|
+
}.compact].freeze
|
73
75
|
|
74
76
|
class Restricted < ClassLoader
|
75
77
|
def initialize classes, symbols
|
@@ -84,7 +86,7 @@ module Psych
|
|
84
86
|
if @symbols.include? sym
|
85
87
|
super
|
86
88
|
else
|
87
|
-
raise DisallowedClass, 'Symbol'
|
89
|
+
raise DisallowedClass.new('load', 'Symbol')
|
88
90
|
end
|
89
91
|
end
|
90
92
|
|
@@ -94,7 +96,7 @@ module Psych
|
|
94
96
|
if @classes.include? klassname
|
95
97
|
super
|
96
98
|
else
|
97
|
-
raise DisallowedClass, klassname
|
99
|
+
raise DisallowedClass.new('load', klassname)
|
98
100
|
end
|
99
101
|
end
|
100
102
|
end
|
data/lib/psych/coder.rb
CHANGED
data/lib/psych/core_ext.rb
CHANGED
@@ -1,36 +1,19 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
class Object
|
3
3
|
def self.yaml_tag url
|
4
4
|
Psych.add_tag(url, self)
|
5
5
|
end
|
6
6
|
|
7
|
-
# FIXME: rename this to "to_yaml" when syck is removed
|
8
|
-
|
9
7
|
###
|
10
8
|
# call-seq: to_yaml(options = {})
|
11
9
|
#
|
12
10
|
# Convert an object to YAML. See Psych.dump for more information on the
|
13
11
|
# available +options+.
|
14
|
-
def
|
12
|
+
def to_yaml options = {}
|
15
13
|
Psych.dump self, options
|
16
14
|
end
|
17
|
-
remove_method :to_yaml rescue nil
|
18
|
-
alias :to_yaml :psych_to_yaml
|
19
|
-
end
|
20
|
-
|
21
|
-
class Module
|
22
|
-
def psych_yaml_as url
|
23
|
-
return if caller[0].end_with?('rubytypes.rb')
|
24
|
-
if $VERBOSE
|
25
|
-
warn "#{caller[0]}: yaml_as is deprecated, please use yaml_tag"
|
26
|
-
end
|
27
|
-
Psych.add_tag(url, self)
|
28
|
-
end
|
29
|
-
|
30
|
-
remove_method :yaml_as rescue nil
|
31
|
-
alias :yaml_as :psych_yaml_as
|
32
15
|
end
|
33
16
|
|
34
17
|
if defined?(::IRB)
|
35
|
-
|
18
|
+
require_relative 'y'
|
36
19
|
end
|
data/lib/psych/exception.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
module Psych
|
3
3
|
class Exception < RuntimeError
|
4
4
|
end
|
@@ -6,9 +6,23 @@ module Psych
|
|
6
6
|
class BadAlias < Exception
|
7
7
|
end
|
8
8
|
|
9
|
+
# Subclasses `BadAlias` for backwards compatibility
|
10
|
+
class AliasesNotEnabled < BadAlias
|
11
|
+
def initialize
|
12
|
+
super "Alias parsing was not enabled. To enable it, pass `aliases: true` to `Psych::load` or `Psych::safe_load`."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Subclasses `BadAlias` for backwards compatibility
|
17
|
+
class AnchorNotDefined < BadAlias
|
18
|
+
def initialize anchor_name
|
19
|
+
super "An alias referenced an unknown anchor: #{anchor_name}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
9
23
|
class DisallowedClass < Exception
|
10
|
-
def initialize klass_name
|
11
|
-
super "Tried to
|
24
|
+
def initialize action, klass_name
|
25
|
+
super "Tried to #{action} unspecified class: #{klass_name}"
|
12
26
|
end
|
13
27
|
end
|
14
28
|
end
|
data/lib/psych/handler.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
module Psych
|
3
3
|
###
|
4
4
|
# Psych::Handler is an abstract base class that defines the events used
|
@@ -105,7 +105,7 @@ module Psych
|
|
105
105
|
# - first element
|
106
106
|
# - *ponies
|
107
107
|
#
|
108
|
-
# &ponies is the
|
108
|
+
# &ponies is the anchor, *ponies is the alias. In this case, alias is
|
109
109
|
# called with "ponies".
|
110
110
|
def alias anchor
|
111
111
|
end
|
@@ -119,7 +119,7 @@ module Psych
|
|
119
119
|
# +tag+ is an associated tag or nil
|
120
120
|
# +plain+ is a boolean value
|
121
121
|
# +quoted+ is a boolean value
|
122
|
-
# +style+ is an integer
|
122
|
+
# +style+ is an integer indicating the string style
|
123
123
|
#
|
124
124
|
# See the constants in Psych::Nodes::Scalar for the possible values of
|
125
125
|
# +style+
|
@@ -241,6 +241,11 @@ module Psych
|
|
241
241
|
def end_stream
|
242
242
|
end
|
243
243
|
|
244
|
+
###
|
245
|
+
# Called before each event with line/column information.
|
246
|
+
def event_location(start_line, start_column, end_line, end_column)
|
247
|
+
end
|
248
|
+
|
244
249
|
###
|
245
250
|
# Is this handler a streaming handler?
|
246
251
|
def streaming?
|
data/lib/psych/json/stream.rb
CHANGED
data/lib/psych/nodes/alias.rb
CHANGED
data/lib/psych/nodes/document.rb
CHANGED
data/lib/psych/nodes/mapping.rb
CHANGED
data/lib/psych/nodes/node.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
require 'stringio'
|
3
|
-
|
4
|
-
|
3
|
+
require_relative '../class_loader'
|
4
|
+
require_relative '../scalar_scanner'
|
5
5
|
|
6
6
|
module Psych
|
7
7
|
module Nodes
|
@@ -17,6 +17,18 @@ module Psych
|
|
17
17
|
# An associated tag
|
18
18
|
attr_reader :tag
|
19
19
|
|
20
|
+
# The line number where this node start
|
21
|
+
attr_accessor :start_line
|
22
|
+
|
23
|
+
# The column number where this node start
|
24
|
+
attr_accessor :start_column
|
25
|
+
|
26
|
+
# The line number where this node ends
|
27
|
+
attr_accessor :end_line
|
28
|
+
|
29
|
+
# The column number where this node ends
|
30
|
+
attr_accessor :end_column
|
31
|
+
|
20
32
|
# Create a new Psych::Nodes::Node
|
21
33
|
def initialize
|
22
34
|
@children = []
|
@@ -34,8 +46,8 @@ module Psych
|
|
34
46
|
# Convert this node to Ruby.
|
35
47
|
#
|
36
48
|
# See also Psych::Visitors::ToRuby
|
37
|
-
def to_ruby
|
38
|
-
Visitors::ToRuby.create.accept(self)
|
49
|
+
def to_ruby(symbolize_names: false, freeze: false, strict_integer: false)
|
50
|
+
Visitors::ToRuby.create(symbolize_names: symbolize_names, freeze: freeze, strict_integer: strict_integer).accept(self)
|
39
51
|
end
|
40
52
|
alias :transform :to_ruby
|
41
53
|
|
@@ -51,6 +63,13 @@ module Psych
|
|
51
63
|
io
|
52
64
|
end
|
53
65
|
alias :to_yaml :yaml
|
66
|
+
|
67
|
+
def alias?; false; end
|
68
|
+
def document?; false; end
|
69
|
+
def mapping?; false; end
|
70
|
+
def scalar?; false; end
|
71
|
+
def sequence?; false; end
|
72
|
+
def stream?; false; end
|
54
73
|
end
|
55
74
|
end
|
56
75
|
end
|
data/lib/psych/nodes/scalar.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
module Psych
|
3
3
|
module Nodes
|
4
4
|
###
|
@@ -50,7 +50,7 @@ module Psych
|
|
50
50
|
# +tag+ is an associated tag or nil
|
51
51
|
# +plain+ is a boolean value
|
52
52
|
# +quoted+ is a boolean value
|
53
|
-
# +style+ is an integer
|
53
|
+
# +style+ is an integer indicating the string style
|
54
54
|
#
|
55
55
|
# == See Also
|
56
56
|
#
|
@@ -63,6 +63,8 @@ module Psych
|
|
63
63
|
@quoted = quoted
|
64
64
|
@style = style
|
65
65
|
end
|
66
|
+
|
67
|
+
def scalar?; true; end
|
66
68
|
end
|
67
69
|
end
|
68
70
|
end
|
data/lib/psych/nodes/sequence.rb
CHANGED
data/lib/psych/nodes/stream.rb
CHANGED
data/lib/psych/nodes.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
# frozen_string_literal:
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'nodes/node'
|
3
|
+
require_relative 'nodes/stream'
|
4
|
+
require_relative 'nodes/document'
|
5
|
+
require_relative 'nodes/sequence'
|
6
|
+
require_relative 'nodes/scalar'
|
7
|
+
require_relative 'nodes/mapping'
|
8
|
+
require_relative 'nodes/alias'
|
9
9
|
|
10
10
|
module Psych
|
11
11
|
###
|
data/lib/psych/omap.rb
CHANGED
data/lib/psych/parser.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
module Psych
|
3
3
|
###
|
4
4
|
# YAML event parser class. This class parses a YAML document and calls
|
@@ -48,5 +48,18 @@ module Psych
|
|
48
48
|
@handler = handler
|
49
49
|
@external_encoding = ANY
|
50
50
|
end
|
51
|
+
|
52
|
+
###
|
53
|
+
# call-seq:
|
54
|
+
# parser.parse(yaml)
|
55
|
+
#
|
56
|
+
# Parse the YAML document contained in +yaml+. Events will be called on
|
57
|
+
# the handler set on the parser instance.
|
58
|
+
#
|
59
|
+
# See Psych::Parser and Psych::Parser#handler
|
60
|
+
|
61
|
+
def parse yaml, path = yaml.respond_to?(:path) ? yaml.path : "<unknown>"
|
62
|
+
_native_parse @handler, yaml, path
|
63
|
+
end
|
51
64
|
end
|
52
65
|
end
|
data/lib/psych/scalar_scanner.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
2
|
-
require 'strscan'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module Psych
|
5
4
|
###
|
@@ -9,104 +8,98 @@ module Psych
|
|
9
8
|
TIME = /^-?\d{4}-\d{1,2}-\d{1,2}(?:[Tt]|\s+)\d{1,2}:\d\d:\d\d(?:\.\d*)?(?:\s*(?:Z|[-+]\d{1,2}:?(?:\d\d)?))?$/
|
10
9
|
|
11
10
|
# Taken from http://yaml.org/type/float.html
|
12
|
-
|
13
|
-
|
14
|
-
|[-+]?\.(inf|Inf|INF)(?# infinity)
|
15
|
-
|\.(nan|NaN|NAN)(?# not a number))$/x
|
11
|
+
# Base 60, [-+]inf and NaN are handled separately
|
12
|
+
FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9]*([eE][-+][0-9]+)?(?# base 10))$/x
|
16
13
|
|
17
14
|
# Taken from http://yaml.org/type/int.html
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
INTEGER_STRICT = /^(?:[-+]?0b[0-1_]+ (?# base 2)
|
16
|
+
|[-+]?0[0-7_]+ (?# base 8)
|
17
|
+
|[-+]?(0|[1-9][0-9_]*) (?# base 10)
|
18
|
+
|[-+]?0x[0-9a-fA-F_]+ (?# base 16))$/x
|
19
|
+
|
20
|
+
# Same as above, but allows commas.
|
21
|
+
# Not to YML spec, but kept for backwards compatibility
|
22
|
+
INTEGER_LEGACY = /^(?:[-+]?0b[0-1_,]+ (?# base 2)
|
23
|
+
|[-+]?0[0-7_,]+ (?# base 8)
|
24
|
+
|[-+]?(?:0|[1-9](?:[0-9]|,[0-9]|_[0-9])*) (?# base 10)
|
25
|
+
|[-+]?0x[0-9a-fA-F_,]+ (?# base 16))$/x
|
22
26
|
|
23
27
|
attr_reader :class_loader
|
24
28
|
|
25
29
|
# Create a new scanner
|
26
|
-
def initialize class_loader
|
27
|
-
@string_cache = {}
|
30
|
+
def initialize class_loader, strict_integer: false
|
28
31
|
@symbol_cache = {}
|
29
32
|
@class_loader = class_loader
|
33
|
+
@strict_integer = strict_integer
|
30
34
|
end
|
31
35
|
|
32
36
|
# Tokenize +string+ returning the Ruby object
|
33
37
|
def tokenize string
|
34
38
|
return nil if string.empty?
|
35
|
-
return string if @string_cache.key?(string)
|
36
39
|
return @symbol_cache[string] if @symbol_cache.key?(string)
|
37
|
-
|
38
|
-
case string
|
40
|
+
integer_regex = @strict_integer ? INTEGER_STRICT : INTEGER_LEGACY
|
39
41
|
# Check for a String type, being careful not to get caught by hash keys, hex values, and
|
40
42
|
# special floats (e.g., -.inf).
|
41
|
-
|
42
|
-
if string.length > 5
|
43
|
-
@string_cache[string] = true
|
44
|
-
return string
|
45
|
-
end
|
43
|
+
if string.match?(%r{^[^\d.:-]?[[:alpha:]_\s!@#$%\^&*(){}<>|/\\~;=]+}) || string.match?(/\n/)
|
44
|
+
return string if string.length > 5
|
46
45
|
|
47
|
-
|
48
|
-
when /^[^ytonf~]/i
|
49
|
-
@string_cache[string] = true
|
46
|
+
if string.match?(/^[^ytonf~]/i)
|
50
47
|
string
|
51
|
-
|
48
|
+
elsif string == '~' || string.match?(/^null$/i)
|
52
49
|
nil
|
53
|
-
|
50
|
+
elsif string.match?(/^(yes|true|on)$/i)
|
54
51
|
true
|
55
|
-
|
52
|
+
elsif string.match?(/^(no|false|off)$/i)
|
56
53
|
false
|
57
54
|
else
|
58
|
-
@string_cache[string] = true
|
59
55
|
string
|
60
56
|
end
|
61
|
-
|
57
|
+
elsif string.match?(TIME)
|
62
58
|
begin
|
63
59
|
parse_time string
|
64
60
|
rescue ArgumentError
|
65
61
|
string
|
66
62
|
end
|
67
|
-
|
63
|
+
elsif string.match?(/^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/)
|
68
64
|
require 'date'
|
69
65
|
begin
|
70
|
-
class_loader.date.strptime(string, '%
|
66
|
+
class_loader.date.strptime(string, '%F', Date::GREGORIAN)
|
71
67
|
rescue ArgumentError
|
72
68
|
string
|
73
69
|
end
|
74
|
-
|
70
|
+
elsif string.match?(/^\+?\.inf$/i)
|
75
71
|
Float::INFINITY
|
76
|
-
|
72
|
+
elsif string.match?(/^-\.inf$/i)
|
77
73
|
-Float::INFINITY
|
78
|
-
|
74
|
+
elsif string.match?(/^\.nan$/i)
|
79
75
|
Float::NAN
|
80
|
-
|
76
|
+
elsif string.match?(/^:./)
|
81
77
|
if string =~ /^:(["'])(.*)\1/
|
82
78
|
@symbol_cache[string] = class_loader.symbolize($2.sub(/^:/, ''))
|
83
79
|
else
|
84
80
|
@symbol_cache[string] = class_loader.symbolize(string.sub(/^:/, ''))
|
85
81
|
end
|
86
|
-
|
82
|
+
elsif string.match?(/^[-+]?[0-9][0-9_]*(:[0-5]?[0-9]){1,2}$/)
|
87
83
|
i = 0
|
88
84
|
string.split(':').each_with_index do |n,e|
|
89
85
|
i += (n.to_i * 60 ** (e - 2).abs)
|
90
86
|
end
|
91
87
|
i
|
92
|
-
|
88
|
+
elsif string.match?(/^[-+]?[0-9][0-9_]*(:[0-5]?[0-9]){1,2}\.[0-9_]*$/)
|
93
89
|
i = 0
|
94
90
|
string.split(':').each_with_index do |n,e|
|
95
91
|
i += (n.to_f * 60 ** (e - 2).abs)
|
96
92
|
end
|
97
93
|
i
|
98
|
-
|
99
|
-
if string
|
100
|
-
@string_cache[string] = true
|
94
|
+
elsif string.match?(FLOAT)
|
95
|
+
if string.match?(/\A[-+]?\.\Z/)
|
101
96
|
string
|
102
97
|
else
|
103
|
-
Float(string.
|
98
|
+
Float(string.delete(',_').gsub(/\.([Ee]|$)/, '\1'))
|
104
99
|
end
|
100
|
+
elsif string.match?(integer_regex)
|
101
|
+
parse_int string
|
105
102
|
else
|
106
|
-
int = parse_int string.gsub(/[,_]/, '')
|
107
|
-
return int if int
|
108
|
-
|
109
|
-
@string_cache[string] = true
|
110
103
|
string
|
111
104
|
end
|
112
105
|
end
|
@@ -114,8 +107,7 @@ module Psych
|
|
114
107
|
###
|
115
108
|
# Parse and return an int from +string+
|
116
109
|
def parse_int string
|
117
|
-
|
118
|
-
Integer(string)
|
110
|
+
Integer(string.delete(',_'))
|
119
111
|
end
|
120
112
|
|
121
113
|
###
|
@@ -144,7 +136,7 @@ module Psych
|
|
144
136
|
offset += ((tz[1] || 0) * 60)
|
145
137
|
end
|
146
138
|
|
147
|
-
klass.
|
139
|
+
klass.new(yy, m, dd, hh, mm, ss+us/(1_000_000r), offset)
|
148
140
|
end
|
149
141
|
end
|
150
142
|
end
|
data/lib/psych/set.rb
CHANGED
data/lib/psych/stream.rb
CHANGED
data/lib/psych/streaming.rb
CHANGED
data/lib/psych/syntax_error.rb
CHANGED