CFPropertyList 2.3.5 → 3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 74e0407ecce8171dfa845b93f5f55e1cd7d386a3
4
- data.tar.gz: d3d8e956ad24476ee83293c9f4d25fa23b7f2947
2
+ SHA256:
3
+ metadata.gz: 8c0a5cbb9e2df1216733df683ea384fc16c6bc4cf391ba5d5a211d503fa81b39
4
+ data.tar.gz: ccb49926da5d6c487cf60b55824fdc1f1c58d58dff1f6a2ef0bc68420899efa2
5
5
  SHA512:
6
- metadata.gz: 96bc102584b4a4745bcfaa403667644fff60e8be9b2ad9224c454f6b977b236f16156863cc48d20b8aa4cffc0f9f0e4bbea5c05fc7f06450afb49cb37f4aaede
7
- data.tar.gz: 9f36e44475f5b7a48d957e54b35ed99a821c3df6ead60598c4fd8a7637bbbb1b9bfa8d5a7a438456ae814696ed52a438dbf94151cf2b29974995716c78a7189a
6
+ metadata.gz: d44a547b9efb6e3dc36cb3c78a1c4735c62ec242c12ea01158a85ee10033ae391f325663253ae8e0df90347a40ac92ca626df39308b150a327581ffd1aef842c
7
+ data.tar.gz: c95903238e74197c99628fc7bfd9263a09a93c33184da8b39a03e49adeaf77ba693d64c5fca62a5bdb305933b1edbaec4fb19075a54b5bd47a6633a26e868dda
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ CFPropertyList implementation
2
+ class to read, manipulate and write both XML and binary property list
3
+ files (plist(5)) as defined by Apple. Have a look at CFPropertyList::List
4
+ for more documentation.
5
+
6
+ # Caution!
7
+
8
+ In version 3.0.0 we dropped Ruby 1.8 compatibility. If you are using
9
+ Ruby 1.8 consider to update Ruby; if you can't upgrade, don't upgrade
10
+ CFPropertyList.
11
+
12
+ # Installation
13
+
14
+ You could either use ruby gems and install it via
15
+
16
+ ```bash
17
+ gem install CFPropertyList
18
+ ```
19
+
20
+ or you could clone this repository and place it somewhere in your load path.
21
+
22
+ Example:
23
+ ```ruby
24
+ require 'cfpropertylist'
25
+ ```
26
+
27
+ If you're using Rails, you can add it into your Gemfile
28
+
29
+ ```ruby
30
+ gem 'CFPropertyList'
31
+ ```
32
+
33
+ # Usage
34
+
35
+ ## create a arbitrary data structure of basic data types
36
+
37
+ ```ruby
38
+ data = {
39
+ 'name' => 'John Doe',
40
+ 'missing' => true,
41
+ 'last_seen' => Time.now,
42
+ 'friends' => ['Jane Doe','Julian Doe'],
43
+ 'likes' => {
44
+ 'me' => false
45
+ }
46
+ }
47
+ ```
48
+
49
+ ## create CFPropertyList::List object
50
+
51
+ ```ruby
52
+ plist = CFPropertyList::List.new
53
+ ```
54
+
55
+ ## call CFPropertyList.guess() to create corresponding CFType values
56
+
57
+ ```ruby
58
+ plist.value = CFPropertyList.guess(data)
59
+ ```
60
+
61
+ ## write plist to file
62
+ ```ruby
63
+ plist.save("example.plist", CFPropertyList::List::FORMAT_BINARY)
64
+ ```
65
+
66
+ ## … later, read it again
67
+ ```ruby
68
+ plist = CFPropertyList::List.new(:file => "example.plist")
69
+ data = CFPropertyList.native_types(plist.value)
70
+ ```
71
+
72
+ # Author and license
73
+
74
+ **Author:** Christian Kruse (mailto:cjk@wwwtech.de)
75
+
76
+ **Copyright:** Copyright (c) 2010
77
+
78
+ **License:** MIT License
79
+
@@ -41,4 +41,3 @@ or you could clone this repository and place it somewhere in your load path.
41
41
  Author:: Christian Kruse (mailto:cjk@wwwtech.de)
42
42
  Copyright:: Copyright (c) 2010
43
43
  License:: MIT License
44
-
@@ -123,8 +123,8 @@ module CFPropertyList
123
123
 
124
124
  # read a binary int value
125
125
  def read_binary_int(fname,fd,length)
126
- if length > 3
127
- raise CFFormatError.new("Integer greater than 8 bytes: #{length}")
126
+ if length > 4
127
+ raise CFFormatError.new("Integer greater than 16 bytes: #{length}")
128
128
  end
129
129
 
130
130
  nbytes = 1 << length
@@ -136,17 +136,12 @@ module CFPropertyList
136
136
  when 0 then buff.unpack("C")[0]
137
137
  when 1 then buff.unpack("n")[0]
138
138
  when 2 then buff.unpack("N")[0]
139
- when 3
140
- hiword,loword = buff.unpack("NN")
141
- if (hiword & 0x80000000) != 0
142
- # 8 byte integers are always signed, and are negative when bit 63 is
143
- # set. Decoding into either a Fixnum or Bignum is tricky, however,
144
- # because the size of a Fixnum varies among systems, and Ruby
145
- # doesn't consider the number to be negative, and won't sign extend.
146
- -(2**63 - ((hiword & 0x7fffffff) << 32 | loword))
147
- else
148
- hiword << 32 | loword
149
- end
139
+ # 8 byte integers are always signed
140
+ when 3 then buff.unpack("q>")[0]
141
+ # 16 byte integers are used to represent unsigned 8 byte integers
142
+ # where the unsigned value is stored in the lower 8 bytes and the
143
+ # upper 8 bytes are unused.
144
+ when 4 then buff.unpack("Q>Q>")[1]
150
145
  end
151
146
  )
152
147
  end
@@ -474,25 +469,19 @@ module CFPropertyList
474
469
 
475
470
  # Codes an integer to binary format
476
471
  def int_to_binary(value)
472
+ # Note: nbytes is actually an exponent. number of bytes = 2**nbytes.
477
473
  nbytes = 0
478
- nbytes = 1 if value > 0xFF # 1 byte integer
479
- nbytes += 1 if value > 0xFFFF # 4 byte integer
480
- nbytes += 1 if value > 0xFFFFFFFF # 8 byte integer
481
- nbytes = 3 if value < 0 # 8 byte integer, since signed
474
+ nbytes = 1 if value > 0xFF # 1 byte unsigned integer
475
+ nbytes += 1 if value > 0xFFFF # 4 byte unsigned integer
476
+ nbytes += 1 if value > 0xFFFFFFFF # 8 byte unsigned integer
477
+ nbytes += 1 if value > 0x7FFFFFFFFFFFFFFF # 8 byte unsigned integer, stored in lower half of 16 bytes
478
+ nbytes = 3 if value < 0 # signed integers always stored in 8 bytes
482
479
 
483
480
  Binary.type_bytes(0b0001, nbytes) <<
484
- if nbytes < 3
485
- [value].pack(
486
- if nbytes == 0 then "C"
487
- elsif nbytes == 1 then "n"
488
- else "N"
489
- end
490
- )
491
- else
492
- # 64 bit signed integer; we need the higher and the lower 32 bit of the value
493
- high_word = value >> 32
494
- low_word = value & 0xFFFFFFFF
495
- [high_word,low_word].pack("NN")
481
+ if nbytes < 4
482
+ [value].pack(["C", "n", "N", "q>"][nbytes])
483
+ else # nbytes == 4
484
+ [0,value].pack("Q>Q>")
496
485
  end
497
486
  end
498
487
 
@@ -72,28 +72,12 @@ module CFPropertyList
72
72
  end
73
73
  end
74
74
 
75
- class String
76
- unless("".respond_to?(:bytesize)) then
77
- def bytesize
78
- self.length
79
- end
80
- end
81
- end
82
-
83
75
  dirname = File.dirname(__FILE__)
84
76
  require dirname + '/rbCFPlistError.rb'
85
77
  require dirname + '/rbCFTypes.rb'
86
78
  require dirname + '/rbBinaryCFPropertyList.rb'
87
79
  require dirname + '/rbPlainCFPropertyList.rb'
88
80
 
89
- require 'iconv' unless "".respond_to?("encode")
90
-
91
- # ensure that the module and class exist
92
- module Enumerable
93
- class Enumerator
94
- end
95
- end
96
-
97
81
  begin
98
82
  require dirname + '/rbLibXMLParser.rb'
99
83
  temp = LibXML::XML::Parser::Options::NOBLANKS # check if we have a version with parser options
@@ -144,7 +128,7 @@ module CFPropertyList
144
128
  when Time, DateTime, Date
145
129
  CFDate.new(object)
146
130
 
147
- when Array, Enumerator, Enumerable::Enumerator
131
+ when Array, Enumerator
148
132
  ary = Array.new
149
133
  object.each do |o|
150
134
  ary.push CFPropertyList.guess(o, options)
@@ -213,7 +197,7 @@ module CFPropertyList
213
197
 
214
198
  module_function :guess, :native_types
215
199
 
216
- # Class representing a CFPropertyList. Instanciate with #new
200
+ # Class representing a CFPropertyList. Instantiate with #new
217
201
  class List
218
202
  # Format constant for binary format
219
203
  FORMAT_BINARY = 1
@@ -5,6 +5,8 @@ require 'libxml'
5
5
  module CFPropertyList
6
6
  # XML parser
7
7
  class LibXMLParser < XMLParserInterface
8
+ LibXML::XML::Error.set_handler(&LibXML::XML::Error::QUIET_HANDLER)
9
+ PARSER_OPTIONS = LibXML::XML::Parser::Options::NOBLANKS|LibXML::XML::Parser::Options::NONET
8
10
  # read a XML file
9
11
  # opts::
10
12
  # * :file - The filename of the file to load
@@ -13,9 +15,9 @@ module CFPropertyList
13
15
  doc = nil
14
16
 
15
17
  if(opts.has_key?(:file)) then
16
- doc = LibXML::XML::Document.file(opts[:file],:options => LibXML::XML::Parser::Options::NOBLANKS|LibXML::XML::Parser::Options::NOENT)
18
+ doc = LibXML::XML::Document.file(opts[:file],:options => PARSER_OPTIONS)
17
19
  else
18
- doc = LibXML::XML::Document.string(opts[:data],:options => LibXML::XML::Parser::Options::NOBLANKS|LibXML::XML::Parser::Options::NOENT)
20
+ doc = LibXML::XML::Document.string(opts[:data],:options => PARSER_OPTIONS)
19
21
  end
20
22
 
21
23
  if doc
@@ -5,6 +5,7 @@ require 'nokogiri'
5
5
  module CFPropertyList
6
6
  # XML parser
7
7
  class NokogiriXMLParser < ParserInterface
8
+ PARSER_OPTIONS = Nokogiri::XML::ParseOptions::NOBLANKS|Nokogiri::XML::ParseOptions::NONET
8
9
  # read a XML file
9
10
  # opts::
10
11
  # * :file - The filename of the file to load
@@ -12,9 +13,9 @@ module CFPropertyList
12
13
  def load(opts)
13
14
  doc = nil
14
15
  if(opts.has_key?(:file)) then
15
- File.open(opts[:file], "rb") { |fd| doc = Nokogiri::XML::Document.parse(fd, nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS|Nokogiri::XML::ParseOptions::NOENT) }
16
+ File.open(opts[:file], "rb") { |fd| doc = Nokogiri::XML::Document.parse(fd, nil, nil, PARSER_OPTIONS) }
16
17
  else
17
- doc = Nokogiri::XML::Document.parse(opts[:data], nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS|Nokogiri::XML::ParseOptions::NOENT)
18
+ doc = Nokogiri::XML::Document.parse(opts[:data], nil, nil, PARSER_OPTIONS)
18
19
  end
19
20
 
20
21
  if doc
metadata CHANGED
@@ -1,15 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: CFPropertyList
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.5
4
+ version: 3.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Kruse
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-27 00:00:00.000000000 Z
11
+ date: 2021-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rexml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: libxml-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
13
69
  - !ruby/object:Gem::Dependency
14
70
  name: rake
15
71
  requirement: !ruby/object:Gem::Requirement
@@ -30,10 +86,11 @@ email: cjk@defunct.ch
30
86
  executables: []
31
87
  extensions: []
32
88
  extra_rdoc_files:
33
- - README
89
+ - README.rdoc
34
90
  files:
35
91
  - LICENSE
36
- - README
92
+ - README.md
93
+ - README.rdoc
37
94
  - THANKS
38
95
  - lib/cfpropertylist.rb
39
96
  - lib/cfpropertylist/rbBinaryCFPropertyList.rb
@@ -44,11 +101,11 @@ files:
44
101
  - lib/cfpropertylist/rbNokogiriParser.rb
45
102
  - lib/cfpropertylist/rbPlainCFPropertyList.rb
46
103
  - lib/cfpropertylist/rbREXMLParser.rb
47
- homepage: http://github.com/ckruse/CFPropertyList
104
+ homepage: https://github.com/ckruse/CFPropertyList
48
105
  licenses:
49
106
  - MIT
50
107
  metadata: {}
51
- post_install_message:
108
+ post_install_message:
52
109
  rdoc_options: []
53
110
  require_paths:
54
111
  - lib
@@ -63,9 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
120
  - !ruby/object:Gem::Version
64
121
  version: '0'
65
122
  requirements: []
66
- rubyforge_project:
67
- rubygems_version: 2.5.1
68
- signing_key:
123
+ rubygems_version: 3.2.22
124
+ signing_key:
69
125
  specification_version: 4
70
126
  summary: Read, write and manipulate both binary and XML property lists as defined
71
127
  by apple