psych 3.0.0.beta2-x64-mingw32

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.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +20 -0
  4. data/CHANGELOG.rdoc +576 -0
  5. data/Gemfile +3 -0
  6. data/Mavenfile +7 -0
  7. data/README.md +73 -0
  8. data/Rakefile +46 -0
  9. data/bin/console +7 -0
  10. data/bin/setup +6 -0
  11. data/ext/psych/.gitignore +11 -0
  12. data/ext/psych/depend +3 -0
  13. data/ext/psych/extconf.rb +39 -0
  14. data/ext/psych/psych.c +34 -0
  15. data/ext/psych/psych.h +17 -0
  16. data/ext/psych/psych_emitter.c +554 -0
  17. data/ext/psych/psych_emitter.h +8 -0
  18. data/ext/psych/psych_parser.c +568 -0
  19. data/ext/psych/psych_parser.h +6 -0
  20. data/ext/psych/psych_to_ruby.c +39 -0
  21. data/ext/psych/psych_to_ruby.h +8 -0
  22. data/ext/psych/psych_yaml_tree.c +24 -0
  23. data/ext/psych/psych_yaml_tree.h +8 -0
  24. data/ext/psych/yaml/LICENSE +19 -0
  25. data/ext/psych/yaml/api.c +1392 -0
  26. data/ext/psych/yaml/config.h +10 -0
  27. data/ext/psych/yaml/dumper.c +394 -0
  28. data/ext/psych/yaml/emitter.c +2329 -0
  29. data/ext/psych/yaml/loader.c +444 -0
  30. data/ext/psych/yaml/parser.c +1374 -0
  31. data/ext/psych/yaml/reader.c +469 -0
  32. data/ext/psych/yaml/scanner.c +3576 -0
  33. data/ext/psych/yaml/writer.c +141 -0
  34. data/ext/psych/yaml/yaml.h +1971 -0
  35. data/ext/psych/yaml/yaml_private.h +662 -0
  36. data/lib/psych.rb +511 -0
  37. data/lib/psych/class_loader.rb +102 -0
  38. data/lib/psych/coder.rb +95 -0
  39. data/lib/psych/core_ext.rb +19 -0
  40. data/lib/psych/exception.rb +14 -0
  41. data/lib/psych/handler.rb +250 -0
  42. data/lib/psych/handlers/document_stream.rb +23 -0
  43. data/lib/psych/handlers/recorder.rb +40 -0
  44. data/lib/psych/json/ruby_events.rb +20 -0
  45. data/lib/psych/json/stream.rb +17 -0
  46. data/lib/psych/json/tree_builder.rb +13 -0
  47. data/lib/psych/json/yaml_events.rb +30 -0
  48. data/lib/psych/nodes.rb +78 -0
  49. data/lib/psych/nodes/alias.rb +19 -0
  50. data/lib/psych/nodes/document.rb +61 -0
  51. data/lib/psych/nodes/mapping.rb +57 -0
  52. data/lib/psych/nodes/node.rb +56 -0
  53. data/lib/psych/nodes/scalar.rb +68 -0
  54. data/lib/psych/nodes/sequence.rb +82 -0
  55. data/lib/psych/nodes/stream.rb +38 -0
  56. data/lib/psych/omap.rb +5 -0
  57. data/lib/psych/parser.rb +52 -0
  58. data/lib/psych/scalar_scanner.rb +149 -0
  59. data/lib/psych/set.rb +5 -0
  60. data/lib/psych/stream.rb +38 -0
  61. data/lib/psych/streaming.rb +28 -0
  62. data/lib/psych/syntax_error.rb +22 -0
  63. data/lib/psych/tree_builder.rb +97 -0
  64. data/lib/psych/versions.rb +9 -0
  65. data/lib/psych/visitors.rb +7 -0
  66. data/lib/psych/visitors/depth_first.rb +27 -0
  67. data/lib/psych/visitors/emitter.rb +52 -0
  68. data/lib/psych/visitors/json_tree.rb +25 -0
  69. data/lib/psych/visitors/to_ruby.rb +401 -0
  70. data/lib/psych/visitors/visitor.rb +20 -0
  71. data/lib/psych/visitors/yaml_tree.rb +551 -0
  72. data/lib/psych/y.rb +10 -0
  73. data/psych.gemspec +64 -0
  74. metadata +175 -0
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+ require 'psych/omap'
3
+ require 'psych/set'
4
+
5
+ module Psych
6
+ class ClassLoader # :nodoc:
7
+ BIG_DECIMAL = 'BigDecimal'
8
+ COMPLEX = 'Complex'
9
+ DATE = 'Date'
10
+ DATE_TIME = 'DateTime'
11
+ EXCEPTION = 'Exception'
12
+ OBJECT = 'Object'
13
+ PSYCH_OMAP = 'Psych::Omap'
14
+ PSYCH_SET = 'Psych::Set'
15
+ RANGE = 'Range'
16
+ RATIONAL = 'Rational'
17
+ REGEXP = 'Regexp'
18
+ STRUCT = 'Struct'
19
+ SYMBOL = 'Symbol'
20
+
21
+ def initialize
22
+ @cache = CACHE.dup
23
+ end
24
+
25
+ def load klassname
26
+ return nil if !klassname || klassname.empty?
27
+
28
+ find klassname
29
+ end
30
+
31
+ def symbolize sym
32
+ symbol
33
+ sym.to_sym
34
+ end
35
+
36
+ constants.each do |const|
37
+ konst = const_get const
38
+ define_method(const.to_s.downcase) do
39
+ load konst
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def find klassname
46
+ @cache[klassname] ||= resolve(klassname)
47
+ end
48
+
49
+ def resolve klassname
50
+ name = klassname
51
+ retried = false
52
+
53
+ begin
54
+ path2class(name)
55
+ rescue ArgumentError, NameError => ex
56
+ unless retried
57
+ name = "Struct::#{name}"
58
+ retried = ex
59
+ retry
60
+ end
61
+ raise retried
62
+ end
63
+ end
64
+
65
+ CACHE = Hash[constants.map { |const|
66
+ val = const_get const
67
+ begin
68
+ [val, ::Object.const_get(val)]
69
+ rescue
70
+ nil
71
+ end
72
+ }.compact]
73
+
74
+ class Restricted < ClassLoader
75
+ def initialize classes, symbols
76
+ @classes = classes
77
+ @symbols = symbols
78
+ super()
79
+ end
80
+
81
+ def symbolize sym
82
+ return super if @symbols.empty?
83
+
84
+ if @symbols.include? sym
85
+ super
86
+ else
87
+ raise DisallowedClass, 'Symbol'
88
+ end
89
+ end
90
+
91
+ private
92
+
93
+ def find klassname
94
+ if @classes.include? klassname
95
+ super
96
+ else
97
+ raise DisallowedClass, klassname
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+ module Psych
3
+ ###
4
+ # If an object defines +encode_with+, then an instance of Psych::Coder will
5
+ # be passed to the method when the object is being serialized. The Coder
6
+ # automatically assumes a Psych::Nodes::Mapping is being emitted. Other
7
+ # objects like Sequence and Scalar may be emitted if +seq=+ or +scalar=+ are
8
+ # called, respectively.
9
+ class Coder
10
+ attr_accessor :tag, :style, :implicit, :object
11
+ attr_reader :type, :seq
12
+
13
+ def initialize tag
14
+ @map = {}
15
+ @seq = []
16
+ @implicit = false
17
+ @type = :map
18
+ @tag = tag
19
+ @style = Psych::Nodes::Mapping::BLOCK
20
+ @scalar = nil
21
+ @object = nil
22
+ end
23
+
24
+ def scalar *args
25
+ if args.length > 0
26
+ warn "#{caller[0]}: Coder#scalar(a,b,c) is deprecated" if $VERBOSE
27
+ @tag, @scalar, _ = args
28
+ @type = :scalar
29
+ end
30
+ @scalar
31
+ end
32
+
33
+ # Emit a map. The coder will be yielded to the block.
34
+ def map tag = @tag, style = @style
35
+ @tag = tag
36
+ @style = style
37
+ yield self if block_given?
38
+ @map
39
+ end
40
+
41
+ # Emit a scalar with +value+ and +tag+
42
+ def represent_scalar tag, value
43
+ self.tag = tag
44
+ self.scalar = value
45
+ end
46
+
47
+ # Emit a sequence with +list+ and +tag+
48
+ def represent_seq tag, list
49
+ @tag = tag
50
+ self.seq = list
51
+ end
52
+
53
+ # Emit a sequence with +map+ and +tag+
54
+ def represent_map tag, map
55
+ @tag = tag
56
+ self.map = map
57
+ end
58
+
59
+ # Emit an arbitrary object +obj+ and +tag+
60
+ def represent_object tag, obj
61
+ @tag = tag
62
+ @type = :object
63
+ @object = obj
64
+ end
65
+
66
+ # Emit a scalar with +value+
67
+ def scalar= value
68
+ @type = :scalar
69
+ @scalar = value
70
+ end
71
+
72
+ # Emit a map with +value+
73
+ def map= map
74
+ @type = :map
75
+ @map = map
76
+ end
77
+
78
+ def []= k, v
79
+ @type = :map
80
+ @map[k] = v
81
+ end
82
+ alias :add :[]=
83
+
84
+ def [] k
85
+ @type = :map
86
+ @map[k]
87
+ end
88
+
89
+ # Emit a sequence of +list+
90
+ def seq= list
91
+ @type = :seq
92
+ @seq = list
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ class Object
3
+ def self.yaml_tag url
4
+ Psych.add_tag(url, self)
5
+ end
6
+
7
+ ###
8
+ # call-seq: to_yaml(options = {})
9
+ #
10
+ # Convert an object to YAML. See Psych.dump for more information on the
11
+ # available +options+.
12
+ def to_yaml options = {}
13
+ Psych.dump self, options
14
+ end
15
+ end
16
+
17
+ if defined?(::IRB)
18
+ require 'psych/y'
19
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module Psych
3
+ class Exception < RuntimeError
4
+ end
5
+
6
+ class BadAlias < Exception
7
+ end
8
+
9
+ class DisallowedClass < Exception
10
+ def initialize klass_name
11
+ super "Tried to load unspecified class: #{klass_name}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,250 @@
1
+ # frozen_string_literal: true
2
+ module Psych
3
+ ###
4
+ # Psych::Handler is an abstract base class that defines the events used
5
+ # when dealing with Psych::Parser. Clients who want to use Psych::Parser
6
+ # should implement a class that inherits from Psych::Handler and define
7
+ # events that they can handle.
8
+ #
9
+ # Psych::Handler defines all events that Psych::Parser can possibly send to
10
+ # event handlers.
11
+ #
12
+ # See Psych::Parser for more details
13
+ class Handler
14
+ ###
15
+ # Configuration options for dumping YAML.
16
+ class DumperOptions
17
+ attr_accessor :line_width, :indentation, :canonical
18
+
19
+ def initialize
20
+ @line_width = 0
21
+ @indentation = 2
22
+ @canonical = false
23
+ end
24
+ end
25
+
26
+ # Default dumping options
27
+ OPTIONS = DumperOptions.new
28
+
29
+ # Events that a Handler should respond to.
30
+ EVENTS = [ :alias,
31
+ :empty,
32
+ :end_document,
33
+ :end_mapping,
34
+ :end_sequence,
35
+ :end_stream,
36
+ :scalar,
37
+ :start_document,
38
+ :start_mapping,
39
+ :start_sequence,
40
+ :start_stream ]
41
+
42
+ ###
43
+ # Called with +encoding+ when the YAML stream starts. This method is
44
+ # called once per stream. A stream may contain multiple documents.
45
+ #
46
+ # See the constants in Psych::Parser for the possible values of +encoding+.
47
+ def start_stream encoding
48
+ end
49
+
50
+ ###
51
+ # Called when the document starts with the declared +version+,
52
+ # +tag_directives+, if the document is +implicit+.
53
+ #
54
+ # +version+ will be an array of integers indicating the YAML version being
55
+ # dealt with, +tag_directives+ is a list of tuples indicating the prefix
56
+ # and suffix of each tag, and +implicit+ is a boolean indicating whether
57
+ # the document is started implicitly.
58
+ #
59
+ # === Example
60
+ #
61
+ # Given the following YAML:
62
+ #
63
+ # %YAML 1.1
64
+ # %TAG ! tag:tenderlovemaking.com,2009:
65
+ # --- !squee
66
+ #
67
+ # The parameters for start_document must be this:
68
+ #
69
+ # version # => [1, 1]
70
+ # tag_directives # => [["!", "tag:tenderlovemaking.com,2009:"]]
71
+ # implicit # => false
72
+ def start_document version, tag_directives, implicit
73
+ end
74
+
75
+ ###
76
+ # Called with the document ends. +implicit+ is a boolean value indicating
77
+ # whether or not the document has an implicit ending.
78
+ #
79
+ # === Example
80
+ #
81
+ # Given the following YAML:
82
+ #
83
+ # ---
84
+ # hello world
85
+ #
86
+ # +implicit+ will be true. Given this YAML:
87
+ #
88
+ # ---
89
+ # hello world
90
+ # ...
91
+ #
92
+ # +implicit+ will be false.
93
+ def end_document implicit
94
+ end
95
+
96
+ ###
97
+ # Called when an alias is found to +anchor+. +anchor+ will be the name
98
+ # of the anchor found.
99
+ #
100
+ # === Example
101
+ #
102
+ # Here we have an example of an array that references itself in YAML:
103
+ #
104
+ # --- &ponies
105
+ # - first element
106
+ # - *ponies
107
+ #
108
+ # &ponies is the achor, *ponies is the alias. In this case, alias is
109
+ # called with "ponies".
110
+ def alias anchor
111
+ end
112
+
113
+ ###
114
+ # Called when a scalar +value+ is found. The scalar may have an
115
+ # +anchor+, a +tag+, be implicitly +plain+ or implicitly +quoted+
116
+ #
117
+ # +value+ is the string value of the scalar
118
+ # +anchor+ is an associated anchor or nil
119
+ # +tag+ is an associated tag or nil
120
+ # +plain+ is a boolean value
121
+ # +quoted+ is a boolean value
122
+ # +style+ is an integer idicating the string style
123
+ #
124
+ # See the constants in Psych::Nodes::Scalar for the possible values of
125
+ # +style+
126
+ #
127
+ # === Example
128
+ #
129
+ # Here is a YAML document that exercises most of the possible ways this
130
+ # method can be called:
131
+ #
132
+ # ---
133
+ # - !str "foo"
134
+ # - &anchor fun
135
+ # - many
136
+ # lines
137
+ # - |
138
+ # many
139
+ # newlines
140
+ #
141
+ # The above YAML document contains a list with four strings. Here are
142
+ # the parameters sent to this method in the same order:
143
+ #
144
+ # # value anchor tag plain quoted style
145
+ # ["foo", nil, "!str", false, false, 3 ]
146
+ # ["fun", "anchor", nil, true, false, 1 ]
147
+ # ["many lines", nil, nil, true, false, 1 ]
148
+ # ["many\nnewlines\n", nil, nil, false, true, 4 ]
149
+ #
150
+ def scalar value, anchor, tag, plain, quoted, style
151
+ end
152
+
153
+ ###
154
+ # Called when a sequence is started.
155
+ #
156
+ # +anchor+ is the anchor associated with the sequence or nil.
157
+ # +tag+ is the tag associated with the sequence or nil.
158
+ # +implicit+ a boolean indicating whether or not the sequence was implicitly
159
+ # started.
160
+ # +style+ is an integer indicating the list style.
161
+ #
162
+ # See the constants in Psych::Nodes::Sequence for the possible values of
163
+ # +style+.
164
+ #
165
+ # === Example
166
+ #
167
+ # Here is a YAML document that exercises most of the possible ways this
168
+ # method can be called:
169
+ #
170
+ # ---
171
+ # - !!seq [
172
+ # a
173
+ # ]
174
+ # - &pewpew
175
+ # - b
176
+ #
177
+ # The above YAML document consists of three lists, an outer list that
178
+ # contains two inner lists. Here is a matrix of the parameters sent
179
+ # to represent these lists:
180
+ #
181
+ # # anchor tag implicit style
182
+ # [nil, nil, true, 1 ]
183
+ # [nil, "tag:yaml.org,2002:seq", false, 2 ]
184
+ # ["pewpew", nil, true, 1 ]
185
+
186
+ def start_sequence anchor, tag, implicit, style
187
+ end
188
+
189
+ ###
190
+ # Called when a sequence ends.
191
+ def end_sequence
192
+ end
193
+
194
+ ###
195
+ # Called when a map starts.
196
+ #
197
+ # +anchor+ is the anchor associated with the map or +nil+.
198
+ # +tag+ is the tag associated with the map or +nil+.
199
+ # +implicit+ is a boolean indicating whether or not the map was implicitly
200
+ # started.
201
+ # +style+ is an integer indicating the mapping style.
202
+ #
203
+ # See the constants in Psych::Nodes::Mapping for the possible values of
204
+ # +style+.
205
+ #
206
+ # === Example
207
+ #
208
+ # Here is a YAML document that exercises most of the possible ways this
209
+ # method can be called:
210
+ #
211
+ # ---
212
+ # k: !!map { hello: world }
213
+ # v: &pewpew
214
+ # hello: world
215
+ #
216
+ # The above YAML document consists of three maps, an outer map that contains
217
+ # two inner maps. Below is a matrix of the parameters sent in order to
218
+ # represent these three maps:
219
+ #
220
+ # # anchor tag implicit style
221
+ # [nil, nil, true, 1 ]
222
+ # [nil, "tag:yaml.org,2002:map", false, 2 ]
223
+ # ["pewpew", nil, true, 1 ]
224
+
225
+ def start_mapping anchor, tag, implicit, style
226
+ end
227
+
228
+ ###
229
+ # Called when a map ends
230
+ def end_mapping
231
+ end
232
+
233
+ ###
234
+ # Called when an empty event happens. (Which, as far as I can tell, is
235
+ # never).
236
+ def empty
237
+ end
238
+
239
+ ###
240
+ # Called when the YAML stream ends
241
+ def end_stream
242
+ end
243
+
244
+ ###
245
+ # Is this handler a streaming handler?
246
+ def streaming?
247
+ false
248
+ end
249
+ end
250
+ end