This project is closed and read-only.
Backport #6815 ยป backport.patch
| ChangeLog | ||
|---|---|---|
|
Tue Jul 31 10:36:12 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
||
|
* ext/psych/lib/psych.rb: updated to released version.
|
||
|
* ext/psych/psych.gemspec: ditto
|
||
|
Thu Jul 19 09:33:46 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
||
|
* ext/psych/emitter.c (initialize): allow a configuration object to be
|
||
|
passed to the constructor so that mutation isn't required after
|
||
|
instantiation.
|
||
|
* ext/psych/lib/psych/handler.rb: add configuration object
|
||
|
* ext/psych/lib/psych/visitors/emitter.rb: use configuration object if
|
||
|
extra configuration is present.
|
||
|
Tue Jul 17 03:56:34 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
||
|
* ext/psych/lib/psych/visitors/to_ruby.rb: strings with YAML anchors
|
||
|
are properly referenced. Patched by Joe Rafaniello via Github:
|
||
|
https://github.com/tenderlove/psych/pull/69
|
||
|
* ext/psych/lib/psych/visitors/yaml_tree.rb: ditto
|
||
|
* test/psych/test_alias_and_anchor.rb: test for change
|
||
|
Sat Jun 16 01:27:14 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
||
|
* ext/psych/lib/psych.rb: bumping psych to 1.3.3
|
||
|
* ext/psych/psych.gemspec: ditto
|
||
|
Fri May 18 15:53:05 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||
|
* ext/psych/extconf.rb: Use an exception instaed of bare abort.
|
||
|
Fri May 18 01:28:21 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
||
|
* ext/psych/parser.c (transcode_string): fix encoding index names.
|
||
|
Thanks markizko for reporting.
|
||
|
Wed May 16 05:11:29 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
||
|
* ext/psych/lib/psych/visitors/to_ruby.rb: fix a bug with string
|
||
|
subclass dumping and loading.
|
||
|
* test/psych/test_array.rb: pertinent tests
|
||
|
* test/psych/test_string.rb: ditto
|
||
|
Wed May 16 01:31:21 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
||
|
* ext/psych/lib/psych/visitors/to_ruby.rb: convert omap tagged maps to
|
||
|
Psych::Omap objects rather than hashes. [Bug #6425]
|
||
|
* test/psych/test_omap.rb: pertinent test.
|
||
|
Wed May 16 01:15:45 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
||
|
* ext/psych/lib/psych/visitors/yaml_tree.rb: keep a reference to
|
||
|
custom coders so that GC does not impact dumped yaml reference ids.
|
||
|
Mon Apr 30 04:43:53 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
||
|
* ext/psych/lib/psych/json/yaml_events.rb: implicit styles should not
|
||
|
be changeable for JSON events.
|
||
|
Sun Jul 29 04:32:31 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||
|
* configure.in (ruby_pc): make configurable. [Bug #6051]
|
||
| ext/psych/emitter.c | ||
|---|---|---|
|
VALUE cPsychEmitter;
|
||
|
static ID id_write;
|
||
|
static ID id_line_width;
|
||
|
static ID id_indentation;
|
||
|
static ID id_canonical;
|
||
|
static void emit(yaml_emitter_t * emitter, yaml_event_t * event)
|
||
|
{
|
||
| ... | ... | |
|
return Data_Wrap_Struct(klass, 0, dealloc, emitter);
|
||
|
}
|
||
|
/* call-seq: Psych::Emitter.new(io)
|
||
|
/* call-seq: Psych::Emitter.new(io, options = Psych::Emitter::OPTIONS)
|
||
|
*
|
||
|
* Create a new Psych::Emitter that writes to +io+.
|
||
|
*/
|
||
|
static VALUE initialize(VALUE self, VALUE io)
|
||
|
static VALUE initialize(int argc, VALUE *argv, VALUE self)
|
||
|
{
|
||
|
yaml_emitter_t * emitter;
|
||
|
VALUE io, options;
|
||
|
VALUE line_width;
|
||
|
VALUE indent;
|
||
|
VALUE canonical;
|
||
|
Data_Get_Struct(self, yaml_emitter_t, emitter);
|
||
|
if (rb_scan_args(argc, argv, "11", &io, &options) == 2) {
|
||
|
line_width = rb_funcall(options, id_line_width, 0);
|
||
|
indent = rb_funcall(options, id_indentation, 0);
|
||
|
canonical = rb_funcall(options, id_canonical, 0);
|
||
|
yaml_emitter_set_width(emitter, NUM2INT(line_width));
|
||
|
yaml_emitter_set_indent(emitter, NUM2INT(indent));
|
||
|
yaml_emitter_set_canonical(emitter, Qtrue == canonical ? 1 : 0);
|
||
|
}
|
||
|
yaml_emitter_set_output(emitter, writer, (void *)io);
|
||
|
return self;
|
||
| ... | ... | |
|
rb_define_alloc_func(cPsychEmitter, allocate);
|
||
|
rb_define_method(cPsychEmitter, "initialize", initialize, 1);
|
||
|
rb_define_method(cPsychEmitter, "initialize", initialize, -1);
|
||
|
rb_define_method(cPsychEmitter, "start_stream", start_stream, 1);
|
||
|
rb_define_method(cPsychEmitter, "end_stream", end_stream, 0);
|
||
|
rb_define_method(cPsychEmitter, "start_document", start_document, 3);
|
||
| ... | ... | |
|
rb_define_method(cPsychEmitter, "line_width", line_width, 0);
|
||
|
rb_define_method(cPsychEmitter, "line_width=", set_line_width, 1);
|
||
|
id_write = rb_intern("write");
|
||
|
id_write = rb_intern("write");
|
||
|
id_line_width = rb_intern("line_width");
|
||
|
id_indentation = rb_intern("indentation");
|
||
|
id_canonical = rb_intern("canonical");
|
||
|
}
|
||
|
/* vim: set noet sws=4 sw=4: */
|
||
| ext/psych/extconf.rb | ||
|---|---|---|
|
dir_config 'libyaml'
|
||
|
def asplode missing
|
||
|
abort "#{missing} is missing. Please install libyaml."
|
||
|
raise "#{missing} is missing. Please install libyaml."
|
||
|
end
|
||
|
asplode('yaml.h') unless find_header 'yaml.h'
|
||
| ext/psych/lib/psych.rb | ||
|---|---|---|
|
module Psych
|
||
|
# The version is Psych you're using
|
||
|
VERSION = '1.3.2'
|
||
|
VERSION = '1.3.4'
|
||
|
# The version of libyaml Psych is using
|
||
|
LIBYAML_VERSION = Psych.libyaml_version.join '.'
|
||
| ext/psych/lib/psych/handler.rb | ||
|---|---|---|
|
# See Psych::Parser for more details
|
||
|
class Handler
|
||
|
###
|
||
|
# Configuration options for dumping YAML.
|
||
|
class DumperOptions
|
||
|
attr_accessor :line_width, :indentation, :canonical
|
||
|
def initialize
|
||
|
@line_width = 0
|
||
|
@indentation = 2
|
||
|
@canonical = false
|
||
|
end
|
||
|
end
|
||
|
# Default dumping options
|
||
|
OPTIONS = DumperOptions.new
|
||
|
###
|
||
|
# Called with +encoding+ when the YAML stream starts. This method is
|
||
|
# called once per stream. A stream may contain multiple documents.
|
||
|
#
|
||
| ext/psych/lib/psych/json/yaml_events.rb | ||
|---|---|---|
|
end
|
||
|
def start_mapping anchor, tag, implicit, style
|
||
|
super(anchor, nil, implicit, Nodes::Mapping::FLOW)
|
||
|
super(anchor, nil, true, Nodes::Mapping::FLOW)
|
||
|
end
|
||
|
def start_sequence anchor, tag, implicit, style
|
||
|
super(anchor, nil, implicit, Nodes::Sequence::FLOW)
|
||
|
super(anchor, nil, true, Nodes::Sequence::FLOW)
|
||
|
end
|
||
|
def scalar value, anchor, tag, plain, quoted, style
|
||
| ext/psych/lib/psych/visitors/emitter.rb | ||
|---|---|---|
|
module Visitors
|
||
|
class Emitter < Psych::Visitors::Visitor
|
||
|
def initialize io, options = {}
|
||
|
@handler = Psych::Emitter.new io
|
||
|
@handler.indentation = options[:indentation] if options[:indentation]
|
||
|
@handler.canonical = options[:canonical] if options[:canonical]
|
||
|
@handler.line_width = options[:line_width] if options[:line_width]
|
||
|
opts = [:indentation, :canonical, :line_width].find_all { |opt|
|
||
|
options.key?(opt)
|
||
|
}
|
||
|
if opts.empty?
|
||
|
@handler = Psych::Emitter.new io
|
||
|
else
|
||
|
du = Handler::DumperOptions.new
|
||
|
opts.each { |option| du.send :"#{option}=", options[option] }
|
||
|
@handler = Psych::Emitter.new io, du
|
||
|
end
|
||
|
end
|
||
|
def visit_Psych_Nodes_Stream o
|
||
| ext/psych/lib/psych/visitors/to_ruby.rb | ||
|---|---|---|
|
string = members.delete 'str'
|
||
|
if klass
|
||
|
string = klass.allocate
|
||
|
string.replace string
|
||
|
string = klass.allocate.replace string
|
||
|
register(o, string)
|
||
|
end
|
||
|
init_with(string, members.map { |k,v| [k.to_s.sub(/^@/, ''),v] }, o)
|
||
| ... | ... | |
|
when /^!map:(.*)$/, /^!ruby\/hash:(.*)$/
|
||
|
revive_hash resolve_class($1).new, o
|
||
|
when '!omap', 'tag:yaml.org,2002:omap'
|
||
|
map = register(o, Psych::Omap.new)
|
||
|
o.children.each_slice(2) do |l,r|
|
||
|
map[accept(l)] = accept r
|
||
|
end
|
||
|
map
|
||
|
else
|
||
|
revive_hash({}, o)
|
||
|
end
|
||
| ext/psych/lib/psych/visitors/yaml_tree.rb | ||
|---|---|---|
|
@st = {}
|
||
|
@ss = ss
|
||
|
@options = options
|
||
|
@coders = []
|
||
|
@dispatch_cache = Hash.new do |h,klass|
|
||
|
method = "visit_#{(klass.name || '').split('::').join('_')}"
|
||
| ... | ... | |
|
maptag = '!ruby/string'
|
||
|
maptag << ":#{o.class}" unless o.class == ::String
|
||
|
@emitter.start_mapping nil, maptag, false, Nodes::Mapping::BLOCK
|
||
|
register o, @emitter.start_mapping(nil, maptag, false, Nodes::Mapping::BLOCK)
|
||
|
@emitter.scalar 'str', nil, nil, true, false, Nodes::Scalar::ANY
|
||
|
@emitter.scalar str, nil, tag, plain, quote, style
|
||
| ... | ... | |
|
end
|
||
|
def dump_coder o
|
||
|
@coders << o
|
||
|
tag = Psych.dump_tags[o.class]
|
||
|
unless tag
|
||
|
klass = o.class == Object ? nil : o.class.name
|
||
| ext/psych/parser.c | ||
|---|---|---|
|
static VALUE transcode_string(VALUE src, int * parser_encoding)
|
||
|
{
|
||
|
int utf8 = rb_utf8_encindex();
|
||
|
int utf16le = rb_enc_find_index("UTF16_LE");
|
||
|
int utf16be = rb_enc_find_index("UTF16_BE");
|
||
|
int utf16le = rb_enc_find_index("UTF-16LE");
|
||
|
int utf16be = rb_enc_find_index("UTF-16BE");
|
||
|
int source_encoding = rb_enc_get_index(src);
|
||
|
if (source_encoding == utf8) {
|
||
| test/psych/test_alias_and_anchor.rb | ||
|---|---|---|
|
require 'psych/helper'
|
||
|
class ObjectWithInstanceVariables
|
||
|
attr_accessor :var1, :var2
|
||
|
end
|
||
|
class SubStringWithInstanceVariables < String
|
||
|
attr_accessor :var1
|
||
|
end
|
||
|
module Psych
|
||
|
class TestAliasAndAnchor < TestCase
|
||
|
def test_mri_compatibility
|
||
| ... | ... | |
|
result.each {|el| assert_same(result[0], el) }
|
||
|
end
|
||
|
def test_mri_compatibility_object_with_ivars
|
||
|
yaml = <<EOYAML
|
||
|
---
|
||
|
- &id001 !ruby/object:ObjectWithInstanceVariables
|
||
|
var1: test1
|
||
|
var2: test2
|
||
|
- *id001
|
||
|
- *id001
|
||
|
EOYAML
|
||
|
result = Psych.load yaml
|
||
|
result.each do |el|
|
||
|
assert_same(result[0], el)
|
||
|
assert_equal('test1', el.var1)
|
||
|
assert_equal('test2', el.var2)
|
||
|
end
|
||
|
end
|
||
|
def test_mri_compatibility_substring_with_ivars
|
||
|
yaml = <<EOYAML
|
||
|
---
|
||
|
- &id001 !str:SubStringWithInstanceVariables
|
||
|
str: test
|
||
|
"@var1": test
|
||
|
- *id001
|
||
|
- *id001
|
||
|
EOYAML
|
||
|
result = Psych.load yaml
|
||
|
result.each do |el|
|
||
|
assert_same(result[0], el)
|
||
|
assert_equal('test', el.var1)
|
||
|
end
|
||
|
end
|
||
|
def test_anchor_alias_round_trip
|
||
|
o = Object.new
|
||
|
original = [o,o,o]
|
||
| ... | ... | |
|
result = Psych.load yaml
|
||
|
result.each {|el| assert_same(result[0], el) }
|
||
|
end
|
||
|
def test_anchor_alias_round_trip_object_with_ivars
|
||
|
o = ObjectWithInstanceVariables.new
|
||
|
o.var1 = 'test1'
|
||
|
o.var2 = 'test2'
|
||
|
original = [o,o,o]
|
||
|
yaml = Psych.dump original
|
||
|
result = Psych.load yaml
|
||
|
result.each do |el|
|
||
|
assert_same(result[0], el)
|
||
|
assert_equal('test1', el.var1)
|
||
|
assert_equal('test2', el.var2)
|
||
|
end
|
||
|
end
|
||
|
def test_anchor_alias_round_trip_substring_with_ivars
|
||
|
o = SubStringWithInstanceVariables.new
|
||
|
o.var1 = 'test'
|
||
|
original = [o,o,o]
|
||
|
yaml = Psych.dump original
|
||
|
result = Psych.load yaml
|
||
|
result.each do |el|
|
||
|
assert_same(result[0], el)
|
||
|
assert_equal('test', el.var1)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| test/psych/test_array.rb | ||
|---|---|---|
|
@list = [{ :a => 'b' }, 'foo']
|
||
|
end
|
||
|
def test_another_subclass_with_attributes
|
||
|
y = Y.new.tap {|y| y.val = 1}
|
||
|
y << "foo" << "bar"
|
||
|
y = Psych.load Psych.dump y
|
||
|
assert_equal %w{foo bar}, y
|
||
|
assert_equal Y, y.class
|
||
|
assert_equal 1, y.val
|
||
|
end
|
||
|
def test_subclass
|
||
|
yaml = Psych.dump X.new
|
||
|
assert_match X.name, yaml
|
||
| test/psych/test_omap.rb | ||
|---|---|---|
|
module Psych
|
||
|
class TestOmap < TestCase
|
||
|
def test_parse_as_map
|
||
|
o = Psych.load "--- !!omap\na: 1\nb: 2"
|
||
|
assert_kind_of Psych::Omap, o
|
||
|
assert_equal 1, o['a']
|
||
|
assert_equal 2, o['b']
|
||
|
end
|
||
|
def test_self_referential
|
||
|
map = Psych::Omap.new
|
||
|
map['foo'] = 'bar'
|
||
| test/psych/test_string.rb | ||
|---|---|---|
|
attr_accessor :val
|
||
|
end
|
||
|
def test_another_subclass_with_attributes
|
||
|
y = Psych.load Psych.dump Y.new("foo").tap {|y| y.val = 1}
|
||
|
assert_equal "foo", y
|
||
|
assert_equal Y, y.class
|
||
|
assert_equal 1, y.val
|
||
|
end
|
||
|
def test_backwards_with_syck
|
||
|
x = Psych.load "--- !str:#{X.name} foo\n\n"
|
||
|
assert_equal X, x.class
|
||