puppet-parse 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/puppet-parse/version.rb
CHANGED
@@ -321,6 +321,21 @@ module PSON
|
|
321
321
|
rescue PSON::NestingError
|
322
322
|
raise ArgumentError, "exceed depth limit"
|
323
323
|
end
|
324
|
+
|
325
|
+
|
326
|
+
# Provide a smarter wrapper for changing string encoding that works with
|
327
|
+
# both Ruby 1.8 (iconv) and 1.9 (String#encode). Thankfully they seem to
|
328
|
+
# have compatible input syntax, at least for the encodings we touch.
|
329
|
+
if String.method_defined?("encode")
|
330
|
+
def encode(to, from, string)
|
331
|
+
string.encode(to, from)
|
332
|
+
end
|
333
|
+
else
|
334
|
+
require 'iconv'
|
335
|
+
def encode(to, from, string)
|
336
|
+
Iconv.conv(to, from, string)
|
337
|
+
end
|
338
|
+
end
|
324
339
|
end
|
325
340
|
|
326
341
|
module ::Kernel
|
@@ -141,7 +141,7 @@ module PSON
|
|
141
141
|
bytes << c[6 * i + 2, 2].to_i(16) << c[6 * i + 4, 2].to_i(16)
|
142
142
|
i += 1
|
143
143
|
end
|
144
|
-
PSON
|
144
|
+
PSON.encode('utf-8', 'utf-16be', bytes)
|
145
145
|
end
|
146
146
|
end
|
147
147
|
string.force_encoding(Encoding::UTF_8) if string.respond_to?(:force_encoding)
|
@@ -149,7 +149,7 @@ module PSON
|
|
149
149
|
else
|
150
150
|
UNPARSED
|
151
151
|
end
|
152
|
-
rescue
|
152
|
+
rescue => e
|
153
153
|
raise GeneratorError, "Caught #{e.class}: #{e}"
|
154
154
|
end
|
155
155
|
|
@@ -3,68 +3,6 @@ require 'puppet/external/pson/pure/parser'
|
|
3
3
|
require 'puppet/external/pson/pure/generator'
|
4
4
|
|
5
5
|
module PSON
|
6
|
-
begin
|
7
|
-
require 'iconv'
|
8
|
-
# An iconv instance to convert from UTF8 to UTF16 Big Endian.
|
9
|
-
UTF16toUTF8 = Iconv.new('utf-8', 'utf-16be') # :nodoc:
|
10
|
-
# An iconv instance to convert from UTF16 Big Endian to UTF8.
|
11
|
-
UTF8toUTF16 = Iconv.new('utf-16be', 'utf-8') # :nodoc:
|
12
|
-
UTF8toUTF16.iconv('no bom')
|
13
|
-
rescue LoadError
|
14
|
-
# We actually don't care
|
15
|
-
Puppet.warning "iconv couldn't be loaded, which is required for UTF-8/UTF-16 conversions"
|
16
|
-
rescue Errno::EINVAL, Iconv::InvalidEncoding
|
17
|
-
# Iconv doesn't support big endian utf-16. Let's try to hack this manually
|
18
|
-
# into the converters.
|
19
|
-
begin
|
20
|
-
old_verbose, $VERBSOSE = $VERBOSE, nil
|
21
|
-
# An iconv instance to convert from UTF8 to UTF16 Big Endian.
|
22
|
-
UTF16toUTF8 = Iconv.new('utf-8', 'utf-16') # :nodoc:
|
23
|
-
# An iconv instance to convert from UTF16 Big Endian to UTF8.
|
24
|
-
UTF8toUTF16 = Iconv.new('utf-16', 'utf-8') # :nodoc:
|
25
|
-
UTF8toUTF16.iconv('no bom')
|
26
|
-
if UTF8toUTF16.iconv("\xe2\x82\xac") == "\xac\x20"
|
27
|
-
swapper = Class.new do
|
28
|
-
def initialize(iconv) # :nodoc:
|
29
|
-
@iconv = iconv
|
30
|
-
end
|
31
|
-
|
32
|
-
def iconv(string) # :nodoc:
|
33
|
-
result = @iconv.iconv(string)
|
34
|
-
PSON.swap!(result)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
UTF8toUTF16 = swapper.new(UTF8toUTF16) # :nodoc:
|
38
|
-
end
|
39
|
-
if UTF16toUTF8.iconv("\xac\x20") == "\xe2\x82\xac"
|
40
|
-
swapper = Class.new do
|
41
|
-
def initialize(iconv) # :nodoc:
|
42
|
-
@iconv = iconv
|
43
|
-
end
|
44
|
-
|
45
|
-
def iconv(string) # :nodoc:
|
46
|
-
string = PSON.swap!(string.dup)
|
47
|
-
@iconv.iconv(string)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
UTF16toUTF8 = swapper.new(UTF16toUTF8) # :nodoc:
|
51
|
-
end
|
52
|
-
rescue Errno::EINVAL, Iconv::InvalidEncoding
|
53
|
-
Puppet.warning "iconv doesn't seem to support UTF-8/UTF-16 conversions"
|
54
|
-
ensure
|
55
|
-
$VERBOSE = old_verbose
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# Swap consecutive bytes of _string_ in place.
|
60
|
-
def self.swap!(string) # :nodoc:
|
61
|
-
0.upto(string.size / 2) do |i|
|
62
|
-
break unless string[2 * i + 1]
|
63
|
-
string[2 * i], string[2 * i + 1] = string[2 * i + 1], string[2 * i]
|
64
|
-
end
|
65
|
-
string
|
66
|
-
end
|
67
|
-
|
68
6
|
# This module holds all the modules/classes that implement PSON's
|
69
7
|
# functionality in pure ruby.
|
70
8
|
module Pure
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-parse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|