CFPropertyList 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0365c5873a771aa9b3f29a9c40ff915c23839a25
4
+ data.tar.gz: 4cc982239b806c7857b844deebbcca016deea87d
5
+ SHA512:
6
+ metadata.gz: a4ec6d399c5823c687ac7800ec9b72d9b0e69f1eb9774cf9467f84d3d1555e903c53d6dc23312e0cfeed9349a5fb044406b2d0750ed3799bdb4ef40ce855dd7d
7
+ data.tar.gz: d1043959eac257f061eef8279cebdcfe1de2fe0f1ecacdab816805f95e8a105446b40089c477b66ff2f5f2994163569bc41292feb5e01c9a38f597178c8822ed
data/README CHANGED
File without changes
File without changes
@@ -38,10 +38,13 @@ module CFPropertyList
38
38
  @count_objects = number_of_objects
39
39
 
40
40
  # decode offset table
41
- formats = ["","C*","n*","(H6)*","N*"]
42
- @offsets = coded_offset_table.unpack(formats[offset_size])
43
- if(offset_size == 3)
44
- 0.upto(@offsets.size-1) { |i| @offsets[i] = @offsets[i].to_i(16) }
41
+ if(offset_size != 3)
42
+ formats = ["","C*","n*","","N*"]
43
+ @offsets = coded_offset_table.unpack(formats[offset_size])
44
+ else
45
+ @offsets = coded_offset_table.unpack("C*").each_slice(3).map {
46
+ |x,y,z| (x << 16) | (y << 8) | z
47
+ }
45
48
  end
46
49
 
47
50
  @object_ref_size = object_ref_size
File without changes
@@ -222,10 +222,12 @@ module CFPropertyList
222
222
 
223
223
  # Path of PropertyList
224
224
  attr_accessor :filename
225
- # Path of PropertyList
225
+ # the original format of the PropertyList
226
226
  attr_accessor :format
227
227
  # the root value in the plist file
228
228
  attr_accessor :value
229
+ # default value for XML generation; if true generate formatted XML
230
+ attr_accessor :formatted
229
231
 
230
232
  # initialize a new CFPropertyList, arguments are:
231
233
  #
@@ -238,11 +240,22 @@ module CFPropertyList
238
240
  @filename = opts[:file]
239
241
  @format = opts[:format] || FORMAT_AUTO
240
242
  @data = opts[:data]
243
+ @formatted = opts[:formatted]
241
244
 
242
245
  load(@filename) unless @filename.nil?
243
246
  load_str(@data) unless @data.nil?
244
247
  end
245
248
 
249
+ # returns a list of registered parsers
250
+ def self.parsers
251
+ @@parsers
252
+ end
253
+
254
+ # set a list of parsers
255
+ def self.parsers=(val)
256
+ @@parsers = val
257
+ end
258
+
246
259
  # Load an XML PropertyList
247
260
  # filename = nil:: The filename to read from; if nil, read from the file defined by instance variable +filename+
248
261
  def load_xml(filename=nil)
@@ -288,8 +301,10 @@ module CFPropertyList
288
301
  if filetype == "bplist" then
289
302
  raise CFFormatError.new("Wrong file version #{version}") unless version == "00"
290
303
  prsr = Binary.new
304
+ @format = List::FORMAT_BINARY
291
305
  else
292
306
  prsr = CFPropertyList.xml_parser_interface.new
307
+ @format = List::FORMAT_XML
293
308
  end
294
309
 
295
310
  @value = prsr.load({:data => str})
@@ -321,12 +336,16 @@ module CFPropertyList
321
336
  if filetype == "bplist" then
322
337
  raise CFFormatError.new("Wong file version #{version}") unless version == "00"
323
338
  prsr = Binary.new
339
+ @format = List::FORMAT_BINARY
324
340
  else
325
341
  prsr = CFPropertyList.xml_parser_interface.new
342
+ @format = List::FORMAT_XML
326
343
  end
327
344
 
328
345
  @value = prsr.load({:file => file})
329
346
  end
347
+
348
+ raise CFFormatError.new("Invalid format or parser error!") if @value.nil?
330
349
  end
331
350
 
332
351
  # Serialize CFPropertyList object to specified format and write it to file
@@ -345,7 +364,10 @@ module CFPropertyList
345
364
  end
346
365
 
347
366
  opts[:root] = @value
367
+ opts[:formatted] = @formatted unless opts.has_key?(:formatted)
368
+
348
369
  prsr = @@parsers[format-1].new
370
+
349
371
  content = prsr.to_str(opts)
350
372
 
351
373
  File.open(file, 'wb') {
@@ -10,14 +10,20 @@ module CFPropertyList
10
10
  # * :file - The filename of the file to load
11
11
  # * :data - The data to parse
12
12
  def load(opts)
13
+ doc = nil
14
+
13
15
  if(opts.has_key?(:file)) then
14
16
  doc = LibXML::XML::Document.file(opts[:file],:options => LibXML::XML::Parser::Options::NOBLANKS|LibXML::XML::Parser::Options::NOENT)
15
17
  else
16
18
  doc = LibXML::XML::Document.string(opts[:data],:options => LibXML::XML::Parser::Options::NOBLANKS|LibXML::XML::Parser::Options::NOENT)
17
19
  end
18
20
 
19
- root = doc.root.first
20
- return import_xml(root)
21
+ if doc
22
+ root = doc.root.first
23
+ return import_xml(root)
24
+ end
25
+ rescue LibXML::XML::Error => e
26
+ raise CFFormatError.new('invalid XML: ' + e.message)
21
27
  end
22
28
 
23
29
  # serialize CFPropertyList object to XML
@@ -105,6 +111,8 @@ module CFPropertyList
105
111
 
106
112
  if node.children? then
107
113
  node.children.each do |n|
114
+ next if n.text? # avoid a bug of libxml
115
+ next if n.comment?
108
116
  ary.push import_xml(n)
109
117
  end
110
118
  end
@@ -10,7 +10,6 @@ module CFPropertyList
10
10
  # * :file - The filename of the file to load
11
11
  # * :data - The data to parse
12
12
  def load(opts)
13
-
14
13
  doc = nil
15
14
  if(opts.has_key?(:file)) then
16
15
  File.open(opts[:file], "rb") { |fd| doc = Nokogiri::XML::Document.parse(fd, nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS|Nokogiri::XML::ParseOptions::NOENT) }
@@ -18,8 +17,12 @@ module CFPropertyList
18
17
  doc = Nokogiri::XML::Document.parse(opts[:data], nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS|Nokogiri::XML::ParseOptions::NOENT)
19
18
  end
20
19
 
21
- root = doc.root.children.first
22
- return import_xml(root)
20
+ if doc
21
+ root = doc.root.children.first
22
+ return import_xml(root)
23
+ end
24
+ rescue Nokogiri::XML::SyntaxError => e
25
+ raise CFFormatError.new('invalid XML: ' + e.message)
23
26
  end
24
27
 
25
28
  # serialize CFPropertyList object to XML
@@ -112,6 +115,8 @@ module CFPropertyList
112
115
 
113
116
  unless children.empty? then
114
117
  children.each do |n|
118
+ next if n.text? # avoid a bug of libxml
119
+ next if n.comment?
115
120
  ary.push import_xml(n)
116
121
  end
117
122
  end
@@ -18,8 +18,12 @@ module CFPropertyList
18
18
  doc = REXML::Document.new(opts[:data])
19
19
  end
20
20
 
21
- root = doc.root.elements[1]
22
- return import_xml(root)
21
+ if doc
22
+ root = doc.root.elements[1]
23
+ return import_xml(root)
24
+ end
25
+ rescue REXML::ParseException => e
26
+ raise CFFormatError.new('invalid XML: ' + e.message)
23
27
  end
24
28
 
25
29
  # serialize CFPropertyList object to XML
@@ -108,6 +112,7 @@ module CFPropertyList
108
112
 
109
113
  if node.has_elements? then
110
114
  node.elements.each do |n|
115
+ next if n.name == '#text' # avoid a bug of libxml
111
116
  ary.push import_xml(n)
112
117
  end
113
118
  end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: CFPropertyList
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
5
- prerelease:
4
+ version: 2.2.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Christian Kruse
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-14 00:00:00.000000000 Z
11
+ date: 2013-08-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 0.7.0
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 0.7.0
30
27
  description: This is a module to read, write and manipulate both binary and XML property
@@ -46,27 +43,26 @@ files:
46
43
  - README
47
44
  homepage: http://github.com/ckruse/CFPropertyList
48
45
  licenses: []
46
+ metadata: {}
49
47
  post_install_message:
50
48
  rdoc_options: []
51
49
  require_paths:
52
50
  - lib
53
51
  required_ruby_version: !ruby/object:Gem::Requirement
54
- none: false
55
52
  requirements:
56
- - - ! '>='
53
+ - - '>='
57
54
  - !ruby/object:Gem::Version
58
55
  version: '0'
59
56
  required_rubygems_version: !ruby/object:Gem::Requirement
60
- none: false
61
57
  requirements:
62
- - - ! '>='
58
+ - - '>='
63
59
  - !ruby/object:Gem::Version
64
60
  version: '0'
65
61
  requirements: []
66
62
  rubyforge_project:
67
- rubygems_version: 1.8.23
63
+ rubygems_version: 2.0.3
68
64
  signing_key:
69
- specification_version: 3
65
+ specification_version: 4
70
66
  summary: Read, write and manipulate both binary and XML property lists as defined
71
67
  by apple
72
68
  test_files: []