From bca3b70437666a8b840af032cab20fc1ea4f18a2 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Fri, 9 Oct 2009 15:23:19 -0700 Subject: Bundling of pure ruby json lib as "pson" Bundeling and renaming the pure ruby json library to addresses a number of cross version serliaization bugs (#2615, et al). This patch adds a subset of the files from the json_pure gem to lib/puppet/external/pson (renamed to avoid conflicts with rails) so that we will always have a known-good erialization format available. The pure ruby json gem as distibuted defers to the compiled version if it is installed. This is problematic in some circumstances so the files that have been brought over have been modified to always and only use the bundled version. It's a large patch, so here's a breakdown of the change categories: The majority of the lines are only marginally interesting: * The json lib itself (in lib/puppet/external/pson) make up the bulk of the lines. * Renaming of json to pson make up the second largest group. Somewhat more interesting are the following, which can be located by searching the diffs for the indicated strings: * Adjusting tests to reflect the changes * Changing the encoding/decoding behavior so that nested structures (e.g. resources) don't serialize as escaped strings. This should make it much easier to process the results with external tools, if needed. Search for "to_pson" and "to_pson_data_hash" * Cleaning up the envelope/metadata * Now provides a document_type (as opposed to a ruby class name) by using a symple registration scheme instead of constant lookup (search for "document_type") * Added an api_version (search for "api_version") * Added a hash for document metadata (search for "metadata") * Removing the yaml monkeypatch and instead disabling yaml serialization on ruby 1.8.1 in favor of pson (search for "yaml") * Cleaning up the json/rails feature interaction (they're now totally independent) (search for "feature") --- lib/puppet/network/formats.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'lib/puppet/network') diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb index 3a19b0bba..df6ef399c 100644 --- a/lib/puppet/network/formats.rb +++ b/lib/puppet/network/formats.rb @@ -26,9 +26,9 @@ Puppet::Network::FormatHandler.create(:yaml, :mime => "text/yaml") do yaml end - # Everything's supported + # Everything's supported unless you're on 1.8.1 def supported?(klass) - true + RUBY_VERSION != '1.8.1' end # fixup invalid yaml as per: @@ -89,22 +89,22 @@ Puppet::Network::FormatHandler.create(:raw, :mime => "application/x-raw", :weigh end end -Puppet::Network::FormatHandler.create(:json, :mime => "text/json", :weight => 10, :required_methods => [:render_method, :intern_method]) do - confine :true => Puppet.features.json? +Puppet::Network::FormatHandler.create(:pson, :mime => "text/pson", :weight => 10, :required_methods => [:render_method, :intern_method]) do + confine :true => Puppet.features.pson? def intern(klass, text) - data_to_instance(klass, JSON.parse(text)) + data_to_instance(klass, PSON.parse(text)) end def intern_multiple(klass, text) - JSON.parse(text).collect do |data| + PSON.parse(text).collect do |data| data_to_instance(klass, data) end end - # JSON monkey-patches Array, so this works. + # PSON monkey-patches Array, so this works. def render_multiple(instances) - instances.to_json + instances.to_pson end # If they pass class information, we want to ignore it. By default, @@ -118,6 +118,6 @@ Puppet::Network::FormatHandler.create(:json, :mime => "text/json", :weight => 10 if data.is_a?(klass) return data end - klass.from_json(data) + klass.from_pson(data) end end -- cgit