plist.utf8 3.1.1

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.
@@ -0,0 +1,225 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # = plist
4
+ #
5
+ # Copyright 2006-2010 Ben Bleything and Patrick May
6
+ # Distributed under the MIT License
7
+ #
8
+
9
+ # Plist parses Mac OS X xml property list files into ruby data structures.
10
+ #
11
+ # === Load a plist file
12
+ # This is the main point of the library:
13
+ #
14
+ # r = Plist::parse_xml( filename_or_xml )
15
+ module Plist
16
+ # Note that I don't use these two elements much:
17
+ #
18
+ # + Date elements are returned as DateTime objects.
19
+ # + Data elements are implemented as Tempfiles
20
+ #
21
+ # Plist::parse_xml will blow up if it encounters a Date element.
22
+ # If you encounter such an error, or if you have a Date element which
23
+ # can't be parsed into a Time object, please send your plist file to
24
+ # plist@hexane.org so that I can implement the proper support.
25
+ def Plist::parse_xml( filename_or_xml )
26
+ listener = Listener.new
27
+ #parser = REXML::Parsers::StreamParser.new(File.new(filename), listener)
28
+ parser = StreamParser.new(filename_or_xml, listener)
29
+ parser.parse
30
+ listener.result
31
+ end
32
+
33
+ class Listener
34
+ #include REXML::StreamListener
35
+
36
+ attr_accessor :result, :open
37
+
38
+ def initialize
39
+ @result = nil
40
+ @open = Array.new
41
+ end
42
+
43
+
44
+ def tag_start(name, attributes)
45
+ @open.push PTag::mappings[name].new
46
+ end
47
+
48
+ def text( contents )
49
+ @open.last.text = contents if @open.last
50
+ end
51
+
52
+ def tag_end(name)
53
+ last = @open.pop
54
+ if @open.empty?
55
+ @result = last.to_ruby
56
+ else
57
+ @open.last.children.push last
58
+ end
59
+ end
60
+ end
61
+
62
+ class StreamParser
63
+ def initialize( plist_data_or_file, listener )
64
+ if plist_data_or_file.respond_to? :read
65
+ @xml = plist_data_or_file.read
66
+ elsif File.exists? plist_data_or_file
67
+ @xml = File.read( plist_data_or_file )
68
+ else
69
+ @xml = plist_data_or_file
70
+ end
71
+
72
+ @listener = listener
73
+ end
74
+
75
+ TEXT = /([^<]+)/
76
+ XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/um
77
+ DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um
78
+ COMMENT_START = /\A<!--/u
79
+ COMMENT_END = /.*?-->/um
80
+
81
+
82
+ def parse
83
+ plist_tags = PTag::mappings.keys.join('|')
84
+ start_tag = /<(#{plist_tags})([^>]*)>/i
85
+ end_tag = /<\/(#{plist_tags})[^>]*>/i
86
+
87
+ require 'strscan'
88
+
89
+ @scanner = StringScanner.new( @xml ).force_encoding("gb2312")
90
+ until @scanner.eos?
91
+ if @scanner.scan(COMMENT_START)
92
+ @scanner.scan(COMMENT_END)
93
+ elsif @scanner.scan(XMLDECL_PATTERN)
94
+ elsif @scanner.scan(DOCTYPE_PATTERN)
95
+ elsif @scanner.scan(start_tag)
96
+ @listener.tag_start(@scanner[1], nil)
97
+ if (@scanner[2] =~ /\/$/)
98
+ @listener.tag_end(@scanner[1])
99
+ end
100
+ elsif @scanner.scan(TEXT)
101
+ @listener.text(@scanner[1])
102
+ elsif @scanner.scan(end_tag)
103
+ @listener.tag_end(@scanner[1])
104
+ else
105
+ raise "Unimplemented element"
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ class PTag
112
+ @@mappings = { }
113
+ def PTag::mappings
114
+ @@mappings
115
+ end
116
+
117
+ def PTag::inherited( sub_class )
118
+ key = sub_class.to_s.downcase
119
+ key.gsub!(/^plist::/, '' )
120
+ key.gsub!(/^p/, '') unless key == "plist"
121
+
122
+ @@mappings[key] = sub_class
123
+ end
124
+
125
+ attr_accessor :text, :children
126
+ def initialize
127
+ @children = Array.new
128
+ end
129
+
130
+ def to_ruby
131
+ raise "Unimplemented: " + self.class.to_s + "#to_ruby on #{self.inspect}"
132
+ end
133
+ end
134
+
135
+ class PList < PTag
136
+ def to_ruby
137
+ children.first.to_ruby if children.first
138
+ end
139
+ end
140
+
141
+ class PDict < PTag
142
+ def to_ruby
143
+ dict = Hash.new
144
+ key = nil
145
+
146
+ children.each do |c|
147
+ if key.nil?
148
+ key = c.to_ruby
149
+ else
150
+ dict[key] = c.to_ruby
151
+ key = nil
152
+ end
153
+ end
154
+
155
+ dict
156
+ end
157
+ end
158
+
159
+ class PKey < PTag
160
+ def to_ruby
161
+ CGI::unescapeHTML(text || '')
162
+ end
163
+ end
164
+
165
+ class PString < PTag
166
+ def to_ruby
167
+ CGI::unescapeHTML(text || '')
168
+ end
169
+ end
170
+
171
+ class PArray < PTag
172
+ def to_ruby
173
+ children.collect do |c|
174
+ c.to_ruby
175
+ end
176
+ end
177
+ end
178
+
179
+ class PInteger < PTag
180
+ def to_ruby
181
+ text.to_i
182
+ end
183
+ end
184
+
185
+ class PTrue < PTag
186
+ def to_ruby
187
+ true
188
+ end
189
+ end
190
+
191
+ class PFalse < PTag
192
+ def to_ruby
193
+ false
194
+ end
195
+ end
196
+
197
+ class PReal < PTag
198
+ def to_ruby
199
+ text.to_f
200
+ end
201
+ end
202
+
203
+ require 'date'
204
+ class PDate < PTag
205
+ def to_ruby
206
+ DateTime.parse(text)
207
+ end
208
+ end
209
+
210
+ require 'base64'
211
+ class PData < PTag
212
+ def to_ruby
213
+ data = Base64.decode64(text.gsub(/\s+/, ''))
214
+
215
+ begin
216
+ return Marshal.load(data)
217
+ rescue Exception => e
218
+ io = StringIO.new
219
+ io.write data
220
+ io.rewind
221
+ return io
222
+ end
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,3 @@
1
+ module Plist
2
+ VERSION = '3.1.1'
3
+ end
data/lib/plist.rb ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # = plist
4
+ #
5
+ # This is the main file for plist. Everything interesting happens in
6
+ # Plist and Plist::Emit.
7
+ #
8
+ # Copyright 2006-2010 Ben Bleything and Patrick May
9
+ # Distributed under the MIT License
10
+ #
11
+
12
+ require 'base64'
13
+ require 'cgi'
14
+ require 'stringio'
15
+
16
+ require 'plist/generator'
17
+ require 'plist/parser'
18
+
data/plist.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'plist/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "plist.utf8"
8
+ spec.version = Plist::VERSION
9
+ spec.authors = ["shiren1118"]
10
+ spec.email = ["shiren1118@126.com"]
11
+ spec.summary = "plist"
12
+ spec.description = "plist"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,203 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>Application Version</key>
6
+ <string>5.0.4 (263)</string>
7
+ <key>Archive Path</key>
8
+ <string>/Users/username/Pictures/iPhoto Library</string>
9
+ <key>List of Albums</key>
10
+ <array>
11
+ <dict>
12
+ <key>AlbumId</key>
13
+ <integer>999000</integer>
14
+ <key>AlbumName</key>
15
+ <string>哇哈哈哈哈</string>
16
+ <key>KeyList</key>
17
+ <array>
18
+ <string>7</string>
19
+ </array>
20
+ <key>Master</key>
21
+ <true/>
22
+ <key>PhotoCount</key>
23
+ <integer>1</integer>
24
+ <key>PlayMusic</key>
25
+ <string>YES</string>
26
+ <key>RepeatSlideShow</key>
27
+ <string>YES</string>
28
+ <key>SecondsPerSlide</key>
29
+ <integer>3</integer>
30
+ <key>SlideShowUseTitles</key>
31
+ <false/>
32
+ <key>SongPath</key>
33
+ <string></string>
34
+ <key>TransitionDirection</key>
35
+ <integer>0</integer>
36
+ <key>TransitionName</key>
37
+ <string>Dissolve</string>
38
+ <key>TransitionSpeed</key>
39
+ <real>1</real>
40
+ </dict>
41
+ <dict>
42
+ <key>Album Type</key>
43
+ <string>Special Roll</string>
44
+ <key>AlbumId</key>
45
+ <integer>999001</integer>
46
+ <key>AlbumName</key>
47
+ <string>Last Roll</string>
48
+ <key>Filter Mode</key>
49
+ <string>All</string>
50
+ <key>Filters</key>
51
+ <array>
52
+ <dict>
53
+ <key>Count</key>
54
+ <integer>1</integer>
55
+ <key>Operation</key>
56
+ <string>In Last</string>
57
+ <key>Type</key>
58
+ <string>Roll</string>
59
+ </dict>
60
+ </array>
61
+ <key>KeyList</key>
62
+ <array>
63
+ <string>7</string>
64
+ </array>
65
+ <key>PhotoCount</key>
66
+ <integer>1</integer>
67
+ <key>PlayMusic</key>
68
+ <string>YES</string>
69
+ <key>RepeatSlideShow</key>
70
+ <string>YES</string>
71
+ <key>SecondsPerSlide</key>
72
+ <integer>3</integer>
73
+ <key>SlideShowUseTitles</key>
74
+ <false/>
75
+ <key>SongPath</key>
76
+ <string></string>
77
+ <key>TransitionDirection</key>
78
+ <integer>0</integer>
79
+ <key>TransitionName</key>
80
+ <string>Dissolve</string>
81
+ <key>TransitionSpeed</key>
82
+ <real>1</real>
83
+ </dict>
84
+ <dict>
85
+ <key>Album Type</key>
86
+ <string>Special Month</string>
87
+ <key>AlbumId</key>
88
+ <integer>999002</integer>
89
+ <key>AlbumName</key>
90
+ <string>Last 12 Months</string>
91
+ <key>Filter Mode</key>
92
+ <string>All</string>
93
+ <key>Filters</key>
94
+ <array/>
95
+ <key>KeyList</key>
96
+ <array>
97
+ <string>7</string>
98
+ </array>
99
+ <key>PhotoCount</key>
100
+ <integer>1</integer>
101
+ <key>PlayMusic</key>
102
+ <string>YES</string>
103
+ <key>RepeatSlideShow</key>
104
+ <string>YES</string>
105
+ <key>SecondsPerSlide</key>
106
+ <integer>3</integer>
107
+ <key>SlideShowUseTitles</key>
108
+ <false/>
109
+ <key>SongPath</key>
110
+ <string></string>
111
+ <key>TransitionDirection</key>
112
+ <integer>0</integer>
113
+ <key>TransitionName</key>
114
+ <string>Dissolve</string>
115
+ <key>TransitionSpeed</key>
116
+ <real>1</real>
117
+ </dict>
118
+ <dict>
119
+ <key>Album Type</key>
120
+ <string>Regular</string>
121
+ <key>AlbumId</key>
122
+ <integer>9</integer>
123
+ <key>AlbumName</key>
124
+ <string>An Album</string>
125
+ <key>KeyList</key>
126
+ <array>
127
+ <string>7</string>
128
+ </array>
129
+ <key>PhotoCount</key>
130
+ <integer>1</integer>
131
+ <key>PlayMusic</key>
132
+ <string>YES</string>
133
+ <key>RepeatSlideShow</key>
134
+ <string>YES</string>
135
+ <key>SecondsPerSlide</key>
136
+ <integer>3</integer>
137
+ <key>SlideShowUseTitles</key>
138
+ <false/>
139
+ <key>SongPath</key>
140
+ <string></string>
141
+ <key>TransitionDirection</key>
142
+ <integer>0</integer>
143
+ <key>TransitionName</key>
144
+ <string>Dissolve</string>
145
+ <key>TransitionSpeed</key>
146
+ <real>1</real>
147
+ </dict>
148
+ </array>
149
+ <key>List of Keywords</key>
150
+ <dict/>
151
+ <key>List of Rolls</key>
152
+ <array>
153
+ <dict>
154
+ <key>Album Type</key>
155
+ <string>Regular</string>
156
+ <key>AlbumId</key>
157
+ <integer>6</integer>
158
+ <key>AlbumName</key>
159
+ <string>Roll 1</string>
160
+ <key>KeyList</key>
161
+ <array>
162
+ <string>7</string>
163
+ </array>
164
+ <key>Parent</key>
165
+ <integer>999000</integer>
166
+ <key>PhotoCount</key>
167
+ <integer>1</integer>
168
+ </dict>
169
+ </array>
170
+ <key>Major Version</key>
171
+ <integer>2</integer>
172
+ <key>Master Image List</key>
173
+ <dict>
174
+ <key>7</key>
175
+ <dict>
176
+ <key>Aspect Ratio</key>
177
+ <real>1</real>
178
+ <key>Caption</key>
179
+ <string>fallow_keep.png.450x450.2005-12-04</string>
180
+ <key>Comment</key>
181
+ <string>a comment</string>
182
+ <key>DateAsTimerInterval</key>
183
+ <real>158341389</real>
184
+ <key>ImagePath</key>
185
+ <string>/Users/username/Pictures/iPhoto Library/2006/01/07/fallow_keep.png.450x450.2005-12-04.jpg</string>
186
+ <key>MediaType</key>
187
+ <string>Image</string>
188
+ <key>MetaModDateAsTimerInterval</key>
189
+ <real>158341439.728129</real>
190
+ <key>ModDateAsTimerInterval</key>
191
+ <real>158341389</real>
192
+ <key>Rating</key>
193
+ <integer>0</integer>
194
+ <key>Roll</key>
195
+ <integer>6</integer>
196
+ <key>ThumbPath</key>
197
+ <string>/Users/username/Pictures/iPhoto Library/2006/01/07/Thumbs/7.jpg</string>
198
+ </dict>
199
+ </dict>
200
+ <key>Minor Version</key>
201
+ <integer>0</integer>
202
+ </dict>
203
+ </plist>
@@ -0,0 +1,104 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <array>
5
+ <dict>
6
+ <key>Created</key>
7
+ <real>151936595.697543</real>
8
+ <key>Domain</key>
9
+ <string>.cleveland.com</string>
10
+ <key>Expires</key>
11
+ <date>2007-10-25T12:36:35Z</date>
12
+ <key>Name</key>
13
+ <string>CTC</string>
14
+ <key>Path</key>
15
+ <string>/</string>
16
+ <key>Value</key>
17
+ <string>:broadband:</string>
18
+ </dict>
19
+ <dict>
20
+ <key>Created</key>
21
+ <real>151778895.063041</real>
22
+ <key>Domain</key>
23
+ <string>.gamefaqs.com</string>
24
+ <key>Expires</key>
25
+ <date>2006-04-21T16:47:58Z</date>
26
+ <key>Name</key>
27
+ <string>ctk</string>
28
+ <key>Path</key>
29
+ <string>/</string>
30
+ <key>Value</key>
31
+ <string>NDM1YmJlYmU0NjZiOGYxZjc1NjgxODg0YmRkMA%3D%3D</string>
32
+ </dict>
33
+ <dict>
34
+ <key>Created</key>
35
+ <real>183530456</real>
36
+ <key>Domain</key>
37
+ <string>arstechnica.com</string>
38
+ <key>Expires</key>
39
+ <date>2006-10-26T13:56:36Z</date>
40
+ <key>Name</key>
41
+ <string>fontFace</string>
42
+ <key>Path</key>
43
+ <string>/</string>
44
+ <key>Value</key>
45
+ <string>1</string>
46
+ </dict>
47
+ <dict>
48
+ <key>Created</key>
49
+ <real>183004526</real>
50
+ <key>Domain</key>
51
+ <string>.sourceforge.net</string>
52
+ <key>Expires</key>
53
+ <date>2006-10-20T02:35:26Z</date>
54
+ <key>Name</key>
55
+ <string>FRQSTR</string>
56
+ <key>Path</key>
57
+ <string>/</string>
58
+ <key>Value</key>
59
+ <string>18829595x86799:1:1440x87033:1:1440x86799:1:1440x87248:1:1440|18829595|18829595|18829595|18829595</string>
60
+ </dict>
61
+ <dict>
62
+ <key>Created</key>
63
+ <real>151053128.640531</real>
64
+ <key>Domain</key>
65
+ <string>.tvguide.com</string>
66
+ <key>Expires</key>
67
+ <date>2025-10-10T07:12:17Z</date>
68
+ <key>Name</key>
69
+ <string>DMSEG</string>
70
+ <key>Path</key>
71
+ <string>/</string>
72
+ <key>Value</key>
73
+ <string>1BDF3D1CC07FC70F&amp;D04451&amp;434EC763&amp;4351FD51&amp;0&amp;</string>
74
+ </dict>
75
+ <dict>
76
+ <key>Created</key>
77
+ <real>151304125.760261</real>
78
+ <key>Domain</key>
79
+ <string>.code.blogspot.com</string>
80
+ <key>Expires</key>
81
+ <date>2038-01-18T00:00:00Z</date>
82
+ <key>Name</key>
83
+ <string>__utma</string>
84
+ <key>Path</key>
85
+ <string>/</string>
86
+ <key>Value</key>
87
+ <string>11680422.1172819419.1129611326.1129611326.1129611326.1</string>
88
+ </dict>
89
+ <dict>
90
+ <key>Created</key>
91
+ <real>599529600</real>
92
+ <key>Domain</key>
93
+ <string>.tvguide.com</string>
94
+ <key>Expires</key>
95
+ <date>2020-01-01T00:00:00Z</date>
96
+ <key>Name</key>
97
+ <string>gfm</string>
98
+ <key>Path</key>
99
+ <string>/</string>
100
+ <key>Value</key>
101
+ <string>0</string>
102
+ </dict>
103
+ </array>
104
+ </plist>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <!-- I am a comment! -->
5
+ <!--
6
+ I am a multi-line comment!
7
+ hooray!
8
+ -->
9
+ </plist>
Binary file
Binary file