lib/puppet/network/formats.rb in puppet-3.2.1 vs lib/puppet/network/formats.rb in puppet-3.2.2
- old
+ new
@@ -1,16 +1,24 @@
require 'puppet/network/format_handler'
Puppet::Network::FormatHandler.create_serialized_formats(:yaml) do
# Yaml doesn't need the class name; it's serialized.
def intern(klass, text)
- YAML.safely_load(text)
+ data = YAML.load(text, :safe => true, :deserialize_symbols => true)
+ return data if data.is_a?(klass)
+ klass.from_pson(data)
end
# Yaml doesn't need the class name; it's serialized.
def intern_multiple(klass, text)
- YAML.safely_load(text)
+ YAML.load(text, :safe => true, :deserialize_symbols => true).collect do |data|
+ if data.is_a?(klass)
+ data
+ else
+ klass.from_pson(data)
+ end
+ end
end
def render(instance)
instance.to_yaml
end
@@ -43,15 +51,19 @@
raise Puppet::Error, "the zlib library is not installed or is disabled."
end
end
def intern(klass, text)
- decode(text)
+ requiring_zlib do
+ Puppet::Network::FormatHandler.format(:yaml).intern(klass, decode(text))
+ end
end
def intern_multiple(klass, text)
- decode(text)
+ requiring_zlib do
+ Puppet::Network::FormatHandler.format(:yaml).intern_multiple(klass, decode(text))
+ end
end
def render(instance)
encode(instance.to_yaml)
end
@@ -62,18 +74,16 @@
def supported?(klass)
true
end
- def encode(text)
- requiring_zlib do
- Base64.encode64(Zlib::Deflate.deflate(text, Zlib::BEST_COMPRESSION))
- end
+ def decode(data)
+ Zlib::Inflate.inflate(Base64.decode64(data))
end
- def decode(yaml)
+ def encode(text)
requiring_zlib do
- YAML.safely_load(Zlib::Inflate.inflate(Base64.decode64(yaml)))
+ Base64.encode64(Zlib::Deflate.deflate(text, Zlib::BEST_COMPRESSION))
end
end
end
Puppet::Network::FormatHandler.create(:s, :mime => "text/plain", :extension => "txt")