psych 3.3.4 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1614b04a5a806644859542b1db0eecd24fa9b8fe9c8af6bd670ba8fd558298fe
4
- data.tar.gz: c14e82662ae31ae97b79cf32eb1d4f331c65b555297b94af2e3f653759642169
3
+ metadata.gz: d17b99168b9a2274379d31e2e75b667e8cbe0d4b56cf9bc7dace2e8af07d8c3d
4
+ data.tar.gz: cf0e77e91cd7f3b9dc4390f1fac70734daad2d747336cf5a4e5e9062035c1f84
5
5
  SHA512:
6
- metadata.gz: 975cd8b825d358d91ada09f9909b11c92c639dc2e1950f1fe95fb4c217c30b2e8dd8cf1215bb38588d56033f483a938fa32c409408e7ae70b0ef9c9d9fae3573
7
- data.tar.gz: 7c4d25c3b16fc5f5439258d6513281eb29e9aad566e78ee4916f0108944cd6201b59fab1321f3074258a9e7f50083e6d695a9995790f9dacc1ae6d9749138b31
6
+ metadata.gz: 92813d4ba7e393f2d1800ee7fe77b65cc9f56c6d0cc324440c367a71ef087d9d1a0ce2c3cbddaec238c05f50a205e62b8bd95a2bb88564ba03d729b473a31fcf
7
+ data.tar.gz: ee68420c75330f9a0671b1e595962fb971940e55b6693d17b41b7b06b8d75c6aa5541625371f3f81e8505c6b7f2d84426dd4fd610b5968e1b17581ca7f5d4bfb
@@ -34,7 +34,7 @@ module Psych
34
34
 
35
35
  # Check for a String type, being careful not to get caught by hash keys, hex values, and
36
36
  # special floats (e.g., -.inf).
37
- if string.match?(%r{^[^\d.:-]?[[:alpha:]_\s!@#$%\^&*(){}<>|/\\~;=]+}) || string.match?(/\n/)
37
+ if string.match?(/^[^\d\.:-]?[A-Za-z_\s!@#\$%\^&\*\(\)\{\}\<\>\|\/\\~;=]+/) || string.match?(/\n/)
38
38
  return string if string.length > 5
39
39
 
40
40
  if string.match?(/^[^ytonf~]/i)
@@ -57,7 +57,7 @@ module Psych
57
57
  elsif string.match?(/^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/)
58
58
  require 'date'
59
59
  begin
60
- class_loader.date.strptime(string, '%F', Date::GREGORIAN)
60
+ class_loader.date.strptime(string, '%Y-%m-%d')
61
61
  rescue ArgumentError
62
62
  string
63
63
  end
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Psych
4
4
  # The version of Psych you are using
5
- VERSION = '3.3.4'
5
+ VERSION = '4.0.0'
6
6
 
7
7
  if RUBY_ENGINE == 'jruby'
8
- DEFAULT_SNAKEYAML_VERSION = '1.33'.freeze
8
+ DEFAULT_SNAKEYAML_VERSION = '1.28'.freeze
9
9
  end
10
10
  end
@@ -80,9 +80,7 @@ module Psych
80
80
  when "!ruby/object:DateTime"
81
81
  class_loader.date_time
82
82
  require 'date' unless defined? DateTime
83
- t = @ss.parse_time(o.value)
84
- DateTime.civil(*t.to_a[0, 6].reverse, Rational(t.utc_offset, 86400)) +
85
- (t.subsec/86400)
83
+ @ss.parse_time(o.value).to_datetime
86
84
  when '!ruby/encoding'
87
85
  ::Encoding.find o.value
88
86
  when "!ruby/object:Complex"
@@ -192,13 +192,12 @@ module Psych
192
192
  register o, @emitter.scalar(o.inspect, nil, '!ruby/regexp', false, false, Nodes::Scalar::ANY)
193
193
  end
194
194
 
195
- def visit_Date o
196
- register o, visit_Integer(o.gregorian)
197
- end
198
-
199
195
  def visit_DateTime o
200
- t = o.italy
201
- formatted = format_time t, t.offset.zero?
196
+ formatted = if o.offset.zero?
197
+ o.strftime("%Y-%m-%d %H:%M:%S.%9N Z".freeze)
198
+ else
199
+ o.strftime("%Y-%m-%d %H:%M:%S.%9N %:z".freeze)
200
+ end
202
201
  tag = '!ruby/object:DateTime'
203
202
  register o, @emitter.scalar(formatted, nil, tag, false, false, Nodes::Scalar::ANY)
204
203
  end
@@ -236,6 +235,7 @@ module Psych
236
235
  end
237
236
  alias :visit_TrueClass :visit_Integer
238
237
  alias :visit_FalseClass :visit_Integer
238
+ alias :visit_Date :visit_Integer
239
239
 
240
240
  def visit_Float o
241
241
  if o.nan?
@@ -480,8 +480,8 @@ module Psych
480
480
  @emitter.end_mapping
481
481
  end
482
482
 
483
- def format_time time, utc = time.utc?
484
- if utc
483
+ def format_time time
484
+ if time.utc?
485
485
  time.strftime("%Y-%m-%d %H:%M:%S.%9N Z")
486
486
  else
487
487
  time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")
data/lib/psych.rb CHANGED
@@ -234,9 +234,6 @@ require 'psych/class_loader'
234
234
  module Psych
235
235
  # The version of libyaml Psych is using
236
236
  LIBYAML_VERSION = Psych.libyaml_version.join('.').freeze
237
- # Deprecation guard
238
- NOT_GIVEN = Object.new.freeze
239
- private_constant :NOT_GIVEN
240
237
 
241
238
  ###
242
239
  # Load +yaml+ in to a Ruby data structure. If multiple documents are
@@ -249,11 +246,11 @@ module Psych
249
246
  #
250
247
  # Example:
251
248
  #
252
- # Psych.load("--- a") # => 'a'
253
- # Psych.load("---\n - a\n - b") # => ['a', 'b']
249
+ # Psych.unsafe_load("--- a") # => 'a'
250
+ # Psych.unsafe_load("---\n - a\n - b") # => ['a', 'b']
254
251
  #
255
252
  # begin
256
- # Psych.load("--- `", filename: "file.txt")
253
+ # Psych.unsafe_load("--- `", filename: "file.txt")
257
254
  # rescue Psych::SyntaxError => ex
258
255
  # ex.file # => 'file.txt'
259
256
  # ex.message # => "(file.txt): found character that cannot start any token"
@@ -262,21 +259,16 @@ module Psych
262
259
  # When the optional +symbolize_names+ keyword argument is set to a
263
260
  # true value, returns symbols for keys in Hash objects (default: strings).
264
261
  #
265
- # Psych.load("---\n foo: bar") # => {"foo"=>"bar"}
266
- # Psych.load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
262
+ # Psych.unsafe_load("---\n foo: bar") # => {"foo"=>"bar"}
263
+ # Psych.unsafe_load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
267
264
  #
268
265
  # Raises a TypeError when `yaml` parameter is NilClass
269
266
  #
270
267
  # NOTE: This method *should not* be used to parse untrusted documents, such as
271
268
  # YAML documents that are supplied via user input. Instead, please use the
272
- # safe_load method.
269
+ # load method or the safe_load method.
273
270
  #
274
- def self.unsafe_load yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: false, symbolize_names: false, freeze: false
275
- if legacy_filename != NOT_GIVEN
276
- warn_with_uplevel 'Passing filename with the 2nd argument of Psych.load is deprecated. Use keyword argument like Psych.load(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
277
- filename = legacy_filename
278
- end
279
-
271
+ def self.unsafe_load yaml, filename: nil, fallback: false, symbolize_names: false, freeze: false
280
272
  result = parse(yaml, filename: filename)
281
273
  return fallback unless result
282
274
  result.to_ruby(symbolize_names: symbolize_names, freeze: freeze)
@@ -327,27 +319,7 @@ module Psych
327
319
  # Psych.safe_load("---\n foo: bar") # => {"foo"=>"bar"}
328
320
  # Psych.safe_load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
329
321
  #
330
- def self.safe_load yaml, legacy_permitted_classes = NOT_GIVEN, legacy_permitted_symbols = NOT_GIVEN, legacy_aliases = NOT_GIVEN, legacy_filename = NOT_GIVEN, permitted_classes: [], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false
331
- if legacy_permitted_classes != NOT_GIVEN
332
- warn_with_uplevel 'Passing permitted_classes with the 2nd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, permitted_classes: ...) instead.', uplevel: 1 if $VERBOSE
333
- permitted_classes = legacy_permitted_classes
334
- end
335
-
336
- if legacy_permitted_symbols != NOT_GIVEN
337
- warn_with_uplevel 'Passing permitted_symbols with the 3rd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, permitted_symbols: ...) instead.', uplevel: 1 if $VERBOSE
338
- permitted_symbols = legacy_permitted_symbols
339
- end
340
-
341
- if legacy_aliases != NOT_GIVEN
342
- warn_with_uplevel 'Passing aliases with the 4th argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, aliases: ...) instead.', uplevel: 1 if $VERBOSE
343
- aliases = legacy_aliases
344
- end
345
-
346
- if legacy_filename != NOT_GIVEN
347
- warn_with_uplevel 'Passing filename with the 5th argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
348
- filename = legacy_filename
349
- end
350
-
322
+ def self.safe_load yaml, permitted_classes: [], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false
351
323
  result = parse(yaml, filename: filename)
352
324
  return fallback unless result
353
325
 
@@ -363,6 +335,46 @@ module Psych
363
335
  result
364
336
  end
365
337
 
338
+ ###
339
+ # Load +yaml+ in to a Ruby data structure. If multiple documents are
340
+ # provided, the object contained in the first document will be returned.
341
+ # +filename+ will be used in the exception message if any exception
342
+ # is raised while parsing. If +yaml+ is empty, it returns
343
+ # the specified +fallback+ return value, which defaults to +false+.
344
+ #
345
+ # Raises a Psych::SyntaxError when a YAML syntax error is detected.
346
+ #
347
+ # Example:
348
+ #
349
+ # Psych.load("--- a") # => 'a'
350
+ # Psych.load("---\n - a\n - b") # => ['a', 'b']
351
+ #
352
+ # begin
353
+ # Psych.load("--- `", filename: "file.txt")
354
+ # rescue Psych::SyntaxError => ex
355
+ # ex.file # => 'file.txt'
356
+ # ex.message # => "(file.txt): found character that cannot start any token"
357
+ # end
358
+ #
359
+ # When the optional +symbolize_names+ keyword argument is set to a
360
+ # true value, returns symbols for keys in Hash objects (default: strings).
361
+ #
362
+ # Psych.load("---\n foo: bar") # => {"foo"=>"bar"}
363
+ # Psych.load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
364
+ #
365
+ # Raises a TypeError when `yaml` parameter is NilClass. This method is
366
+ # similar to `safe_load` except that `Symbol` objects are allowed by default.
367
+ #
368
+ def self.load yaml, permitted_classes: [Symbol], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false
369
+ safe_load yaml, permitted_classes: permitted_classes,
370
+ permitted_symbols: permitted_symbols,
371
+ aliases: aliases,
372
+ filename: filename,
373
+ fallback: fallback,
374
+ symbolize_names: symbolize_names,
375
+ freeze: freeze
376
+ end
377
+
366
378
  ###
367
379
  # Parse a YAML string in +yaml+. Returns the Psych::Nodes::Document.
368
380
  # +filename+ is used in the exception message if a Psych::SyntaxError is
@@ -382,22 +394,12 @@ module Psych
382
394
  # end
383
395
  #
384
396
  # See Psych::Nodes for more information about YAML AST.
385
- def self.parse yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: NOT_GIVEN
386
- if legacy_filename != NOT_GIVEN
387
- warn_with_uplevel 'Passing filename with the 2nd argument of Psych.parse is deprecated. Use keyword argument like Psych.parse(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
388
- filename = legacy_filename
389
- end
390
-
397
+ def self.parse yaml, filename: nil
391
398
  parse_stream(yaml, filename: filename) do |node|
392
399
  return node
393
400
  end
394
401
 
395
- if fallback != NOT_GIVEN
396
- warn_with_uplevel 'Passing the `fallback` keyword argument of Psych.parse is deprecated.', uplevel: 1 if $VERBOSE
397
- fallback
398
- else
399
- false
400
- end
402
+ false
401
403
  end
402
404
 
403
405
  ###
@@ -446,12 +448,7 @@ module Psych
446
448
  # Raises a TypeError when NilClass is passed.
447
449
  #
448
450
  # See Psych::Nodes for more information about YAML AST.
449
- def self.parse_stream yaml, legacy_filename = NOT_GIVEN, filename: nil, &block
450
- if legacy_filename != NOT_GIVEN
451
- warn_with_uplevel 'Passing filename with the 2nd argument of Psych.parse_stream is deprecated. Use keyword argument like Psych.parse_stream(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
452
- filename = legacy_filename
453
- end
454
-
451
+ def self.parse_stream yaml, filename: nil, &block
455
452
  if block_given?
456
453
  parser = Psych::Parser.new(Handlers::DocumentStream.new(&block))
457
454
  parser.parse yaml, filename
@@ -552,12 +549,7 @@ module Psych
552
549
  # end
553
550
  # list # => ['foo', 'bar']
554
551
  #
555
- def self.load_stream yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: [], **kwargs
556
- if legacy_filename != NOT_GIVEN
557
- warn_with_uplevel 'Passing filename with the 2nd argument of Psych.load_stream is deprecated. Use keyword argument like Psych.load_stream(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
558
- filename = legacy_filename
559
- end
560
-
552
+ def self.load_stream yaml, filename: nil, fallback: [], **kwargs
561
553
  result = if block_given?
562
554
  parse_stream(yaml, filename: filename) do |node|
563
555
  yield node.to_ruby(**kwargs)
@@ -595,6 +587,7 @@ module Psych
595
587
  self.safe_load f, filename: filename, **kwargs
596
588
  }
597
589
  end
590
+ class << self; alias load_file safe_load_file end
598
591
 
599
592
  # :stopdoc:
600
593
  def self.add_domain_type domain, type_tag, &block
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: psych
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.4
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-09-28 00:00:00.000000000 Z
13
+ date: 2021-05-13 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: |
16
16
  Psych is a YAML parser and emitter. Psych leverages libyaml[https://pyyaml.org/wiki/LibYAML]
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.4.0.dev
120
+ rubygems_version: 3.3.0.dev
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Psych is a YAML parser and emitter