From 631086b7843601b06d6eecba842320dce99d0994 Mon Sep 17 00:00:00 2001 From: hsbt Date: Tue, 4 Dec 2018 12:24:12 +0000 Subject: Merge upstream from ruby/psych * https://github.com/ruby/psych/pull/379 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/psych/lib/psych.rb | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/ext/psych/lib/psych.rb b/ext/psych/lib/psych.rb index 5b24ebf091..2a2ec2af43 100644 --- a/ext/psych/lib/psych.rb +++ b/ext/psych/lib/psych.rb @@ -270,7 +270,7 @@ module Psych # def self.load yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: false, symbolize_names: false if legacy_filename != NOT_GIVEN - warn 'warning: Passing filename with the 2nd argument of Psych.load is deprecated. Use keyword argument like Psych.load(yaml, filename: ...) instead.' + 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 filename = legacy_filename end @@ -327,22 +327,22 @@ module Psych # 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 if legacy_permitted_classes != NOT_GIVEN - warn 'warning: Passing permitted_classes with the 2nd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, permitted_classes: ...) instead.' + 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 permitted_classes = legacy_permitted_classes end if legacy_permitted_symbols != NOT_GIVEN - warn 'warning: Passing permitted_symbols with the 3rd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, permitted_symbols: ...) instead.' + 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 permitted_symbols = legacy_permitted_symbols end if legacy_aliases != NOT_GIVEN - warn 'warning: Passing aliases with the 4th argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, aliases: ...) instead.' + 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 aliases = legacy_aliases end if legacy_filename != NOT_GIVEN - warn 'warning: Passing filename with the 5th argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, filename: ...) instead.' + 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 filename = legacy_filename end @@ -383,7 +383,7 @@ module Psych # See Psych::Nodes for more information about YAML AST. def self.parse yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: NOT_GIVEN if legacy_filename != NOT_GIVEN - warn 'warning: Passing filename with the 2nd argument of Psych.parse is deprecated. Use keyword argument like Psych.parse(yaml, filename: ...) instead.' + 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 filename = legacy_filename end @@ -392,7 +392,7 @@ module Psych end if fallback != NOT_GIVEN - warn 'warning: Passing the `fallback` keyword argument of Psych.parse is deprecated.' + warn_with_uplevel 'Passing the `fallback` keyword argument of Psych.parse is deprecated.', uplevel: 1 if $VERBOSE fallback else false @@ -447,7 +447,7 @@ module Psych # See Psych::Nodes for more information about YAML AST. def self.parse_stream yaml, legacy_filename = NOT_GIVEN, filename: nil, &block if legacy_filename != NOT_GIVEN - warn 'warning: Passing filename with the 2nd argument of Psych.parse_stream is deprecated. Use keyword argument like Psych.parse_stream(yaml, filename: ...) instead.' + 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 filename = legacy_filename end @@ -553,7 +553,7 @@ module Psych # def self.load_stream yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: [] if legacy_filename != NOT_GIVEN - warn 'warning: Passing filename with the 2nd argument of Psych.load_stream is deprecated. Use keyword argument like Psych.load_stream(yaml, filename: ...) instead.' + 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 filename = legacy_filename end @@ -617,6 +617,21 @@ module Psych end private_class_method :symbolize_names! + # Workaround for emulating `warn '...', uplevel: 1` in Ruby 2.4 or lower. + def self.warn_with_uplevel(message, uplevel: 1) + at = parse_caller(caller[uplevel]).join(':') + warn "#{at}: #{message}" + end + + def self.parse_caller(at) + if /^(.+?):(\d+)(?::in `.*')?/ =~ at + file = $1 + line = $2.to_i + [file, line] + end + end + private_class_method :warn_with_uplevel, :parse_caller + class << self attr_accessor :load_tags attr_accessor :dump_tags -- cgit v1.2.3