eric6/Utilities/binplistlib.py

Sun, 21 Jun 2020 18:26:12 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 21 Jun 2020 18:26:12 +0200
changeset 7635
0cdead130a81
parent 7360
9190402e4505
child 7639
422fd05e9c91
permissions
-rw-r--r--

Removed support for Python2 and removed support for Qt4 (PyQt4 and pyside).

1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
3 # Copyright (c) 2012 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
7 Module implementing a library for reading and writing binary property list
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
8 files.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 Binary Property List (plist) files provide a faster and smaller serialization
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 format for property lists on OS X. This is a library for generating binary
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 plists which can be read by OS X, iOS, or other clients.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 The API models the plistlib API, and will call through to plistlib when
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 XML serialization or deserialization is required.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 To generate plists with UID values, wrap the values with the Uid object. The
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 value must be an int.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 To generate plists with NSData/CFData values, wrap the values with the
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 Data object. The value must be a bytes object.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Date values can only be datetime.datetime objects.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
25 The exceptions InvalidPlistException and NotBinaryPlistException may be
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 thrown to indicate that the data cannot be serialized or deserialized as
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 a binary plist.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 Plist generation example:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 <pre>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 from binplistlib import *
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 from datetime import datetime
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 plist = {'aKey':'aValue',
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 '0':1.322,
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 'now':datetime.now(),
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 'list':[1,2,3],
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 'tuple':('a','b','c')
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 }
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 try:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 writePlist(plist, "example.plist")
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 except (InvalidPlistException, NotBinaryPlistException) as e:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 print("Something bad happened:", e)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 </pre>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 Plist parsing example:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 <pre>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 from binplistlib import *
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 try:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 plist = readPlist("example.plist")
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 print(plist)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 except (InvalidPlistException, NotBinaryPlistException) as e:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 print("Not a plist:", e)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 </pre>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
55
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 #
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 # Ported from the Python 2 biplist.py script.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 #
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 # Original License:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 #
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 # Copyright (c) 2010, Andrew Wooster
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 # All rights reserved.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 #
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 # Redistribution and use in source and binary forms, with or without
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 # modification, are permitted provided that the following conditions are met:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 #
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 # * Redistributions of source code must retain the above copyright notice,
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 # this list of conditions and the following disclaimer.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 # * Redistributions in binary form must reproduce the above copyright
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 # notice, this list of conditions and the following disclaimer in the
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 # documentation and/or other materials provided with the distribution.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 # * Neither the name of biplist nor the names of its contributors may be
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
73 # used to endorse or promote products derived from this software without
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 # specific prior written permission.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 #
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
78 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
79 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
80 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
81 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
82 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
83 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
84 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
85 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
86 # POSSIBILITY OF SUCH DAMAGE.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 #
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 from collections import namedtuple
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 from io import BytesIO
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 import calendar
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 import datetime
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 import math
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 import plistlib
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 from struct import pack, unpack
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 __all__ = [
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 'Uid', 'Data', 'readPlist', 'writePlist', 'readPlistFromBytes',
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 'writePlistToBytes', 'InvalidPlistException', 'NotBinaryPlistException'
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 ]
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 apple_reference_date_offset = 978307200
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 class Uid(int):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 Class implementing a wrapper around integers for representing UID values.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 This is used in keyed archiving.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 def __repr__(self):
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
112 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
113 Special method to return an object representation.
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
114
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
115 @return object representation (string)
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
116 """
4544
5145cf800bb0 Fixed usage of some old style string formattings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4436
diff changeset
117 return "Uid({0:d})".format(self)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 class Data(bytes):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 """
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
122 Class implementing a wrapper around bytes types for representing Data
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
123 values.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 pass
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 class InvalidPlistException(Exception):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 Exception raised when the plist is incorrectly formatted.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 pass
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 class NotBinaryPlistException(Exception):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 Exception raised when a binary plist was expected but not encountered.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 pass
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 def readPlist(pathOrFile):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 Module function to read a plist file.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
146 @param pathOrFile name of the plist file (string) or an open file
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
147 (file object)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 @return reference to the read object
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 @exception InvalidPlistException raised to signal an invalid plist file
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 didOpen = False
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 result = None
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 if isinstance(pathOrFile, str):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 pathOrFile = open(pathOrFile, 'rb')
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 didOpen = True
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 try:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 reader = PlistReader(pathOrFile)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 result = reader.parse()
6360
73033fa6a99c Fixed some pyflakes warnings detected by the upgraded version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
159 except NotBinaryPlistException:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 try:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 pathOrFile.seek(0)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 result = plistlib.readPlist(pathOrFile)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 except Exception as e:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 raise InvalidPlistException(e)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 if didOpen:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 pathOrFile.close()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 return result
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
169
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 def writePlist(rootObject, pathOrFile, binary=True):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 Module function to write a plist file.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 @param rootObject reference to the object to be written
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
175 @param pathOrFile name of the plist file (string) or an open file
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
176 (file object)
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
177 @param binary flag indicating the generation of a binary plist file
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
178 (boolean)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 if not binary:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 plistlib.writePlist(rootObject, pathOrFile)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 return
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 else:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 didOpen = False
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 if isinstance(pathOrFile, str):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 pathOrFile = open(pathOrFile, 'wb')
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 didOpen = True
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 writer = PlistWriter(pathOrFile)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 writer.writeRoot(rootObject)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 if didOpen:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 pathOrFile.close()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 return
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
194
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 def readPlistFromBytes(data):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 Module function to read from a plist bytes object.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 @param data plist data (bytes)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 @return reference to the read object
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 return readPlist(BytesIO(data))
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
204
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 def writePlistToBytes(rootObject, binary=True):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 Module function to write a plist bytes object.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 @param rootObject reference to the object to be written
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
210 @param binary flag indicating the generation of a binary plist bytes
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
211 object (boolean)
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
212 @return bytes object containing the plist data
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 if not binary:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 return plistlib.writePlistToBytes(rootObject)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 else:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 io = BytesIO()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 writer = PlistWriter(io)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 writer.writeRoot(rootObject)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 return io.getvalue()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
222
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 def is_stream_binary_plist(stream):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 Module function to check, if the stream is a binary plist.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 @param stream plist stream (file object)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 @return flag indicating a binary plist (boolean)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 stream.seek(0)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 header = stream.read(7)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 if header == b'bplist0':
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 return True
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 else:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 return False
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236
3030
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2997
diff changeset
237 PlistTrailer = namedtuple(
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2997
diff changeset
238 'PlistTrailer',
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
239 'offsetSize, objectRefSize, offsetCount, topLevelObjectNumber,'
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
240 ' offsetTableOffset')
3030
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2997
diff changeset
241 PlistByteCounts = namedtuple(
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2997
diff changeset
242 'PlistByteCounts',
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
243 'nullBytes, boolBytes, intBytes, realBytes, dateBytes, dataBytes,'
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
244 ' stringBytes, uidBytes, arrayBytes, setBytes, dictBytes')
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
246
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 class PlistReader(object):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 Class implementing the plist reader.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 file = None
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 contents = b''
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 offsets = None
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 trailer = None
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 currentOffset = 0
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 def __init__(self, fileOrStream):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 Constructor
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 @param fileOrStream open file containing the plist data (file object)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 self.reset()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 self.file = fileOrStream
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 def parse(self):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 Public method to parse the plist data.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 @return unpickled object
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 return self.readRoot()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 def reset(self):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
276 Public method to reset the instance object.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 self.trailer = None
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 self.contents = b''
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 self.offsets = []
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 self.currentOffset = 0
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 def readRoot(self):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
285 Public method to read the root object.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 @return unpickled object
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
288 @exception InvalidPlistException raised to indicate an invalid
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
289 plist file
5726
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
290 @exception NotBinaryPlistException raised to indicate, that the
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
291 plist file is not a binary file
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 result = None
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 self.reset()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 # Get the header, make sure it's a valid file.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 if not is_stream_binary_plist(self.file):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 raise NotBinaryPlistException()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 self.file.seek(0)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 self.contents = self.file.read()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 if len(self.contents) < 32:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 raise InvalidPlistException("File is too short.")
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 trailerContents = self.contents[-32:]
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 try:
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
304 self.trailer = PlistTrailer._make(
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
305 unpack("!xxxxxxBBQQQ", trailerContents))
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 offset_size = self.trailer.offsetSize * self.trailer.offsetCount
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 offset = self.trailer.offsetTableOffset
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
308 offset_contents = self.contents[offset:offset + offset_size]
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 offset_i = 0
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 while offset_i < self.trailer.offsetCount:
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
311 begin = self.trailer.offsetSize * offset_i
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
312 tmp_contents = offset_contents[
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
313 begin:begin + self.trailer.offsetSize]
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
314 tmp_sized = self.getSizedInteger(
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
315 tmp_contents, self.trailer.offsetSize)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 self.offsets.append(tmp_sized)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 offset_i += 1
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
318 self.setCurrentOffsetToObjectNumber(
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
319 self.trailer.topLevelObjectNumber)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 result = self.readObject()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 except TypeError as e:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 raise InvalidPlistException(e)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 return result
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 def setCurrentOffsetToObjectNumber(self, objectNumber):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
327 Public method to set the current offset.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 @param objectNumber number of the object (integer)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 self.currentOffset = self.offsets[objectNumber]
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 def readObject(self):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
335 Public method to read the object data.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 @return unpickled object
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
338 @exception InvalidPlistException raised to indicate an invalid
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
339 plist file
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 result = None
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
342 tmp_byte = self.contents[self.currentOffset:self.currentOffset + 1]
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 marker_byte = unpack("!B", tmp_byte)[0]
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
344 formatNibble = (marker_byte >> 4) & 0x0f
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 extra = marker_byte & 0x0f
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 self.currentOffset += 1
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 def proc_extra(extra):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 if extra == 0b1111:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 extra = self.readObject()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 return extra
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 # bool, null, or fill byte
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
354 if formatNibble == 0b0000:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 if extra == 0b0000:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 result = None
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 elif extra == 0b1000:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 result = False
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 elif extra == 0b1001:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 result = True
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 elif extra == 0b1111:
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
362 pass # fill byte
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 else:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 raise InvalidPlistException(
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
365 "Invalid object found at offset: {0}".format(
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
366 self.currentOffset - 1))
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 # int
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
368 elif formatNibble == 0b0001:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 extra = proc_extra(extra)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 result = self.readInteger(pow(2, extra))
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 # real
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
372 elif formatNibble == 0b0010:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 extra = proc_extra(extra)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 result = self.readReal(extra)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 # date
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
376 elif formatNibble == 0b0011 and extra == 0b0011:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 result = self.readDate()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 # data
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
379 elif formatNibble == 0b0100:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 extra = proc_extra(extra)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 result = self.readData(extra)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 # ascii string
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
383 elif formatNibble == 0b0101:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 extra = proc_extra(extra)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 result = self.readAsciiString(extra)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 # Unicode string
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
387 elif formatNibble == 0b0110:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 extra = proc_extra(extra)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 result = self.readUnicode(extra)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 # uid
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
391 elif formatNibble == 0b1000:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 result = self.readUid(extra)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 # array
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
394 elif formatNibble == 0b1010:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 extra = proc_extra(extra)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 result = self.readArray(extra)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 # set
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
398 elif formatNibble == 0b1100:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 extra = proc_extra(extra)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 result = set(self.readArray(extra))
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 # dict
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
402 elif formatNibble == 0b1101:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 extra = proc_extra(extra)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 result = self.readDict(extra)
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
405 else:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 raise InvalidPlistException(
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 "Invalid object found: {{format: {0}, extra: {1}}}".format(
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
408 bin(formatNibble), bin(extra)))
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409 return result
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
411 def readInteger(self, length):
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
413 Public method to read an Integer object.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
415 @param length length of the object (integer)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416 @return integer object
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418 result = 0
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
419 original_offset = self.currentOffset
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
420 data = self.contents[self.currentOffset:self.currentOffset + length]
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
421 result = self.getSizedInteger(data, length)
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
422 self.currentOffset = original_offset + length
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
423 return result
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425 def readReal(self, length):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
427 Public method to read a Real object.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
429 @param length length of the object (integer)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430 @return float object
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
431 @exception InvalidPlistException raised to indicate an invalid
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
432 plist file
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434 result = 0.0
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435 to_read = pow(2, length)
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
436 data = self.contents[self.currentOffset:self.currentOffset + to_read]
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
437 if length == 2: # 4 bytes
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
438 result = unpack('>f', data)[0]
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
439 elif length == 3: # 8 bytes
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 result = unpack('>d', data)[0]
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 else:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 raise InvalidPlistException(
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443 "Unknown real of length {0} bytes".format(to_read))
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
444 return result
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
446 def readRefs(self, count):
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
447 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
448 Public method to read References.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
449
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450 @param count amount of the references (integer)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
451 @return list of references (list of integers)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
452 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
453 refs = []
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
454 i = 0
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
455 while i < count:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
456 fragment = self.contents[
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
457 self.currentOffset:
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
458 self.currentOffset + self.trailer.objectRefSize]
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
459 ref = self.getSizedInteger(fragment, len(fragment))
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
460 refs.append(ref)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
461 self.currentOffset += self.trailer.objectRefSize
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
462 i += 1
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
463 return refs
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
464
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
465 def readArray(self, count):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
466 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
467 Public method to read an Array object.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
468
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
469 @param count number of array elements (integer)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
470 @return list of unpickled objects
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
471 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
472 result = []
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
473 values = self.readRefs(count)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
474 i = 0
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
475 while i < len(values):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
476 self.setCurrentOffsetToObjectNumber(values[i])
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
477 value = self.readObject()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
478 result.append(value)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
479 i += 1
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
480 return result
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
481
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
482 def readDict(self, count):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
483 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
484 Public method to read a Dictionary object.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
485
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
486 @param count number of dictionary elements (integer)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
487 @return dictionary of unpickled objects
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
488 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
489 result = {}
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
490 keys = self.readRefs(count)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
491 values = self.readRefs(count)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
492 i = 0
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
493 while i < len(keys):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
494 self.setCurrentOffsetToObjectNumber(keys[i])
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
495 key = self.readObject()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
496 self.setCurrentOffsetToObjectNumber(values[i])
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
497 value = self.readObject()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
498 result[key] = value
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
499 i += 1
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
500 return result
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
501
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
502 def readAsciiString(self, length):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
503 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
504 Public method to read an ASCII encoded string.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
505
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
506 @param length length of the string (integer)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
507 @return ASCII encoded string
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
508 """
3030
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2997
diff changeset
509 result = str(unpack(
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2997
diff changeset
510 "!{0}s".format(length),
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
511 self.contents[self.currentOffset:self.currentOffset + length])[0],
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
512 encoding="ascii")
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
513 self.currentOffset += length
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
514 return result
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
515
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
516 def readUnicode(self, length):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
517 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
518 Public method to read an Unicode encoded string.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
519
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
520 @param length length of the string (integer)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
521 @return unicode encoded string
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
522 """
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
523 actual_length = length * 2
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
524 data = self.contents[
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
525 self.currentOffset:self.currentOffset + actual_length]
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
526 self.currentOffset += actual_length
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
527 return data.decode('utf_16_be')
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
528
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
529 def readDate(self):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
530 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
531 Public method to read a date.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
532
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
533 @return date object (datetime.datetime)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
534 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
535 global apple_reference_date_offset
3030
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2997
diff changeset
536 result = unpack(
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2997
diff changeset
537 ">d",
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
538 self.contents[self.currentOffset:self.currentOffset + 8])[0]
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
539 result = datetime.datetime.utcfromtimestamp(
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
540 result + apple_reference_date_offset)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
541 self.currentOffset += 8
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
542 return result
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
543
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
544 def readData(self, length):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
545 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
546 Public method to read some bytes.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
547
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
548 @param length number of bytes to read (integer)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
549 @return Data object
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
550 """
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
551 result = self.contents[self.currentOffset:self.currentOffset + length]
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
552 self.currentOffset += length
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
553 return Data(result)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
554
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
555 def readUid(self, length):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
556 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
557 Public method to read a UID.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
558
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
559 @param length length of the UID (integer)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
560 @return Uid object
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
561 """
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
562 return Uid(self.readInteger(length + 1))
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
563
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
564 def getSizedInteger(self, data, length):
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
565 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
566 Public method to read an integer of a specific size.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
567
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
568 @param data data to extract the integer from (bytes)
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
569 @param length length of the integer (integer)
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
570 @return read integer (integer)
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
571 @exception InvalidPlistException raised to indicate an invalid
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
572 plist file
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
573 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
574 result = 0
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
575 # 1, 2, and 4 byte integers are unsigned
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
576 if length == 1:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
577 result = unpack('>B', data)[0]
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
578 elif length == 2:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
579 result = unpack('>H', data)[0]
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
580 elif length == 4:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
581 result = unpack('>L', data)[0]
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
582 elif length == 8:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
583 result = unpack('>q', data)[0]
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
584 else:
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
585 raise InvalidPlistException(
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
586 "Encountered integer longer than 8 bytes.")
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
587 return result
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
588
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
589
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
590 class HashableWrapper(object):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
591 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
592 Class wrapping a hashable value.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
593 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
594 def __init__(self, value):
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
595 """
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
596 Constructor
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
597
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
598 @param value object value
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
599 """
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
600 self.value = value
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
601
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
602 def __repr__(self):
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
603 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
604 Special method to generate a representation of the object.
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
605
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
606 @return object representation (string)
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
607 """
4544
5145cf800bb0 Fixed usage of some old style string formattings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4436
diff changeset
608 return "<HashableWrapper: {0}>".format([self.value])
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
609
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
610
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
611 class BoolWrapper(object):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
612 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
613 Class wrapping a boolean value.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
614 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
615 def __init__(self, value):
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
616 """
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
617 Constructor
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
618
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
619 @param value object value (boolean)
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
620 """
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
621 self.value = value
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
622
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
623 def __repr__(self):
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
624 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
625 Special method to generate a representation of the object.
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
626
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
627 @return object representation (string)
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
628 """
4544
5145cf800bb0 Fixed usage of some old style string formattings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4436
diff changeset
629 return "<BoolWrapper: {0}>".format(self.value)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
630
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
631
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
632 class PlistWriter(object):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
633 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
634 Class implementing the plist writer.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
635 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
636 header = b'bplist00bybiplist1.0'
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
637 file = None
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
638 byteCounts = None
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
639 trailer = None
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
640 computedUniques = None
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
641 writtenReferences = None
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
642 referencePositions = None
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
643 wrappedTrue = None
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
644 wrappedFalse = None
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
645
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
646 def __init__(self, file):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
647 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
648 Constructor
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
649
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
650 @param file file to write the plist data to (file object)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
651 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
652 self.reset()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
653 self.file = file
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
654 self.wrappedTrue = BoolWrapper(True)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
655 self.wrappedFalse = BoolWrapper(False)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
656
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
657 def reset(self):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
658 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
659 Public method to reset the instance object.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
660 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
661 self.byteCounts = PlistByteCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
662 self.trailer = PlistTrailer(0, 0, 0, 0, 0)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
663
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
664 # A set of all the uniques which have been computed.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
665 self.computedUniques = set()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
666 # A list of all the uniques which have been written.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
667 self.writtenReferences = {}
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
668 # A dict of the positions of the written uniques.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
669 self.referencePositions = {}
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
670
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
671 def positionOfObjectReference(self, obj):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
672 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
673 Public method to get the position of an object.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
674
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
675 If the given object has been written already, return its
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
676 position in the offset table. Otherwise, return None.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
677
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
678 @param obj object
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
679 @return position of the object (integer)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
680 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
681 return self.writtenReferences.get(obj)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
682
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
683 def writeRoot(self, root):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
684 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
685 Public method to write an object to a plist file.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
686
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
687 Strategy is:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
688 <ul>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
689 <li>write header</li>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
690 <li>wrap root object so everything is hashable</li>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
691 <li>compute size of objects which will be written
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
692 <ul>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
693 <li>need to do this in order to know how large the object refs
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
694 will be in the list/dict/set reference lists</li>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
695 </ul></li>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
696 <li>write objects
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
697 <ul>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
698 <li>keep objects in writtenReferences</li>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
699 <li>keep positions of object references in referencePositions</li>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
700 <li>write object references with the length computed previously</li>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
701 </ul></li>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
702 <li>computer object reference length</li>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
703 <li>write object reference positions</li>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
704 <li>write trailer</li>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
705 </ul>
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
706
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
707 @param root reference to the object to be written
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
708 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
709 output = self.header
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
710 wrapped_root = self.wrapRoot(root)
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
711 should_reference_root = True
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
712 self.computeOffsets(
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
713 wrapped_root, asReference=should_reference_root, isRoot=True)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
714 self.trailer = self.trailer._replace(
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
715 **{'objectRefSize': self.intSize(len(self.computedUniques))})
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
716 (_, output) = self.writeObjectReference(wrapped_root, output)
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
717 output = self.writeObject(
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
718 wrapped_root, output, setReferencePosition=True)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
719
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
720 # output size at this point is an upper bound on how big the
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
721 # object reference offsets need to be.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
722 self.trailer = self.trailer._replace(**{
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
723 'offsetSize': self.intSize(len(output)),
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
724 'offsetCount': len(self.computedUniques),
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
725 'offsetTableOffset': len(output),
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
726 'topLevelObjectNumber': 0
3039
8dd0165d805d Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
727 })
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
728
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
729 output = self.writeOffsetTable(output)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
730 output += pack('!xxxxxxBBQQQ', *self.trailer)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
731 self.file.write(output)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
732
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
733 def wrapRoot(self, root):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
734 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
735 Public method to generate object wrappers.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
736
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
737 @param root object to be wrapped
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
738 @return wrapped object
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
739 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
740 if isinstance(root, bool):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
741 if root is True:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
742 return self.wrappedTrue
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
743 else:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
744 return self.wrappedFalse
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
745 elif isinstance(root, set):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
746 n = set()
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
747 for value in root:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
748 n.add(self.wrapRoot(value))
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
749 return HashableWrapper(n)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
750 elif isinstance(root, dict):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
751 n = {}
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
752 for key, value in root.items():
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
753 n[self.wrapRoot(key)] = self.wrapRoot(value)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
754 return HashableWrapper(n)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
755 elif isinstance(root, list):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
756 n = []
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
757 for value in root:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
758 n.append(self.wrapRoot(value))
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
759 return HashableWrapper(n)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
760 elif isinstance(root, tuple):
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
761 n = tuple(self.wrapRoot(value) for value in root)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
762 return HashableWrapper(n)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
763 else:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
764 return root
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
765
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
766 def incrementByteCount(self, field, incr=1):
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
767 """
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
768 Public method to increment the byte count.
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
769
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
770 @param field field to evaluate
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
771 @param incr byte count increment (integer)
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
772 """
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
773 self.byteCounts = self.byteCounts._replace(
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
774 **{field: self.byteCounts.__getattribute__(field) + incr})
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
775
4436
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
776 def __checkKey(self, key):
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
777 """
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
778 Private method to check the validity of a key.
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
779
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
780 @param key key to be checked
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
781 @exception InvalidPlistException raised to indicate an invalid
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
782 plist file
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
783 """
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
784 if key is None:
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
785 raise InvalidPlistException(
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
786 'Dictionary keys cannot be null in plists.')
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
787 elif isinstance(key, Data):
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
788 raise InvalidPlistException(
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
789 'Data cannot be dictionary keys in plists.')
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
790 elif not isinstance(key, str):
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
791 raise InvalidPlistException('Keys must be strings.')
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
792
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
793 def __processSize(self, size):
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
794 """
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
795 Private method to process a size.
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
796
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
797 @param size size value to be processed (int)
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
798 @return processed size (int)
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
799 """
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
800 if size > 0b1110:
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
801 size += self.intSize(size)
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
802 return size
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
803
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
804 def computeOffsets(self, obj, asReference=False, isRoot=False):
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
805 """
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
806 Public method to compute offsets of an object.
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
807
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
808 @param obj plist object
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
809 @param asReference flag indicating offsets as references (boolean)
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
810 @param isRoot flag indicating a root object (boolean)
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
811 @exception InvalidPlistException raised to indicate an invalid
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
812 plist file
4436
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
813 """
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
814 # If this should be a reference, then we keep a record of it in the
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
815 # uniques table.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
816 if asReference:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
817 if obj in self.computedUniques:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
818 return
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
819 else:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
820 self.computedUniques.add(obj)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
821
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
822 if obj is None:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
823 self.incrementByteCount('nullBytes')
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
824 elif isinstance(obj, BoolWrapper):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
825 self.incrementByteCount('boolBytes')
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
826 elif isinstance(obj, Uid):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
827 size = self.intSize(obj)
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
828 self.incrementByteCount('uidBytes', incr=1 + size)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
829 elif isinstance(obj, int):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
830 size = self.intSize(obj)
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
831 self.incrementByteCount('intBytes', incr=1 + size)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
832 elif isinstance(obj, (float)):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
833 size = self.realSize(obj)
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
834 self.incrementByteCount('realBytes', incr=1 + size)
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
835 elif isinstance(obj, datetime.datetime):
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
836 self.incrementByteCount('dateBytes', incr=2)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
837 elif isinstance(obj, Data):
4436
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
838 size = self.__processSize(len(obj))
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
839 self.incrementByteCount('dataBytes', incr=1 + size)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
840 elif isinstance(obj, str):
4436
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
841 size = self.__processSize(len(obj))
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
842 self.incrementByteCount('stringBytes', incr=1 + size)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
843 elif isinstance(obj, HashableWrapper):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
844 obj = obj.value
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
845 if isinstance(obj, set):
4436
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
846 size = self.__processSize(len(obj))
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
847 self.incrementByteCount('setBytes', incr=1 + size)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
848 for value in obj:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
849 self.computeOffsets(value, asReference=True)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
850 elif isinstance(obj, (list, tuple)):
4436
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
851 size = self.__processSize(len(obj))
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
852 self.incrementByteCount('arrayBytes', incr=1 + size)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
853 for value in obj:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
854 self.computeOffsets(value, asReference=True)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
855 elif isinstance(obj, dict):
4436
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
856 size = self.__processSize(len(obj))
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
857 self.incrementByteCount('dictBytes', incr=1 + size)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
858 for key, value in obj.items():
4436
52ec6b6b3432 Refactored the binplistlib.py module to get rid of some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
859 self.__checkKey(key)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
860 self.computeOffsets(key, asReference=True)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
861 self.computeOffsets(value, asReference=True)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
862 else:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
863 raise InvalidPlistException("Unknown object type.")
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
864
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
865 def writeObjectReference(self, obj, output):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
866 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
867 Public method to write an object reference.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
868
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
869 Tries to write an object reference, adding it to the references
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
870 table. Does not write the actual object bytes or set the reference
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
871 position. Returns a tuple of whether the object was a new reference
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
872 (True if it was, False if it already was in the reference table)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
873 and the new output.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
874
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
875 @param obj object to be written
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
876 @param output output stream to append the object to
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
877 @return flag indicating a new reference and the new output
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
878 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
879 position = self.positionOfObjectReference(obj)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
880 if position is None:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
881 self.writtenReferences[obj] = len(self.writtenReferences)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
882 output += self.binaryInt(len(self.writtenReferences) - 1,
3039
8dd0165d805d Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
883 bytes=self.trailer.objectRefSize)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
884 return (True, output)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
885 else:
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
886 output += self.binaryInt(
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
887 position, bytes=self.trailer.objectRefSize)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
888 return (False, output)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
889
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
890 def writeObject(self, obj, output, setReferencePosition=False):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
891 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
892 Public method to serialize the given object to the output.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
893
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
894 @param obj object to be serialized
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
895 @param output output to be serialized to (bytes)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
896 @param setReferencePosition flag indicating, that the reference
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
897 position the object was written to shall be recorded (boolean)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
898 @return new output
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
899 """
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
900 def proc_variable_length(formatNibble, length):
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
901 result = ''
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
902 if length > 0b1110:
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
903 result += pack('!B', (formatNibble << 4) | 0b1111)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
904 result = self.writeObject(length, result)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
905 else:
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
906 result += pack('!B', (formatNibble << 4) | length)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
907 return result
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
908
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
909 if setReferencePosition:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
910 self.referencePositions[obj] = len(output)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
911
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
912 if obj is None:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
913 output += pack('!B', 0b00000000)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
914 elif isinstance(obj, BoolWrapper):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
915 if obj.value is False:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
916 output += pack('!B', 0b00001000)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
917 else:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
918 output += pack('!B', 0b00001001)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
919 elif isinstance(obj, Uid):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
920 size = self.intSize(obj)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
921 output += pack('!B', (0b1000 << 4) | size - 1)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
922 output += self.binaryInt(obj)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
923 elif isinstance(obj, int):
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
924 length = self.intSize(obj)
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
925 root = math.log(length, 2)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
926 output += pack('!B', (0b0001 << 4) | int(root))
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
927 output += self.binaryInt(obj)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
928 elif isinstance(obj, float):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
929 # just use doubles
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
930 output += pack('!B', (0b0010 << 4) | 3)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
931 output += self.binaryReal(obj)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
932 elif isinstance(obj, datetime.datetime):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
933 timestamp = calendar.timegm(obj.utctimetuple())
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
934 timestamp -= apple_reference_date_offset
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
935 output += pack('!B', 0b00110011)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
936 output += pack('!d', float(timestamp))
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
937 elif isinstance(obj, Data):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
938 output += proc_variable_length(0b0100, len(obj))
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
939 output += obj
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
940 elif isinstance(obj, str):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
941 # Python 3 uses unicode strings only
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
942 length = obj.encode('utf_16_be')
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
943 output += proc_variable_length(0b0110, len(length) / 2)
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
944 output += length
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
945 elif isinstance(obj, HashableWrapper):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
946 obj = obj.value
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
947 if isinstance(obj, (set, list, tuple)):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
948 if isinstance(obj, set):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
949 output += proc_variable_length(0b1100, len(obj))
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
950 else:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
951 output += proc_variable_length(0b1010, len(obj))
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
952
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
953 objectsToWrite = []
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
954 for objRef in obj:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
955 (isNew, output) = self.writeObjectReference(objRef, output)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
956 if isNew:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
957 objectsToWrite.append(objRef)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
958 for objRef in objectsToWrite:
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
959 output = self.writeObject(
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
960 objRef, output, setReferencePosition=True)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
961 elif isinstance(obj, dict):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
962 output += proc_variable_length(0b1101, len(obj))
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
963 keys = []
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
964 values = []
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
965 objectsToWrite = []
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
966 for key, value in obj.items():
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
967 keys.append(key)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
968 values.append(value)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
969 for key in keys:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
970 (isNew, output) = self.writeObjectReference(key, output)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
971 if isNew:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
972 objectsToWrite.append(key)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
973 for value in values:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
974 (isNew, output) = self.writeObjectReference(value, output)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
975 if isNew:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
976 objectsToWrite.append(value)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
977 for objRef in objectsToWrite:
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
978 output = self.writeObject(
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
979 objRef, output, setReferencePosition=True)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
980 return output
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
981
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
982 def writeOffsetTable(self, output):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
983 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
984 Public method to write all of the object reference offsets.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
985
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
986 @param output current output (bytes)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
987 @return new output (bytes)
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
988 @exception InvalidPlistException raised to indicate an invalid
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
989 plist file
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
990 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
991 all_positions = []
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
992 writtenReferences = list(self.writtenReferences.items())
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
993 writtenReferences.sort(key=lambda x: x[1])
6188
5a6ae3be31e6 Fixed some loop related coding issues detected by the extended code style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
994 for obj, _order in writtenReferences:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
995 position = self.referencePositions.get(obj)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
996 if position is None:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
997 raise InvalidPlistException(
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
998 "Error while writing offsets table. Object not found. {0}"
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
999 .format(obj))
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1000 output += self.binaryInt(position, self.trailer.offsetSize)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1001 all_positions.append(position)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1002 return output
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1003
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1004 def binaryReal(self, obj):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1005 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
1006 Public method to pack a real object.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1007
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1008 @param obj real to be packed
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1009 @return serialized object (bytes)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1010 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1011 # just use doubles
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1012 result = pack('>d', obj)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1013 return result
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1014
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
1015 def binaryInt(self, obj, length=None):
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1016 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
1017 Public method to pack an integer object.
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1018
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1019 @param obj integer to be packed
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
1020 @param length length the integer should be packed into (integer)
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1021 @return serialized object (bytes)
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
1022 @exception InvalidPlistException raised to indicate an invalid
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
1023 plist file
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1024 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1025 result = ''
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
1026 if length is None:
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
1027 length = self.intSize(obj)
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
1028 if length == 1:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1029 result += pack('>B', obj)
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
1030 elif length == 2:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1031 result += pack('>H', obj)
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
1032 elif length == 4:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1033 result += pack('>L', obj)
5604
b047181a4a33 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
1034 elif length == 8:
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1035 result += pack('>q', obj)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1036 else:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1037 raise InvalidPlistException(
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
1038 "Core Foundation can't handle integers with size greater"
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
1039 " than 8 bytes.")
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1040 return result
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1041
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1042 def intSize(self, obj):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1043 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
1044 Public method to determine the number of bytes necessary to store the
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1045 given integer.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1046
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1047 @param obj integer object
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1048 @return number of bytes required (integer)
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
1049 @exception InvalidPlistException raised to indicate an invalid
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
1050 plist file
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1051 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1052 # SIGNED
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
1053 if obj < 0: # Signed integer, always 8 bytes
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1054 return 8
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1055 # UNSIGNED
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
1056 elif obj <= 0xFF: # 1 byte
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1057 return 1
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
1058 elif obj <= 0xFFFF: # 2 bytes
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1059 return 2
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
1060 elif obj <= 0xFFFFFFFF: # 4 bytes
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1061 return 4
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1062 # SIGNED
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1063 # 0x7FFFFFFFFFFFFFFF is the max.
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1720
diff changeset
1064 elif obj <= 0x7FFFFFFFFFFFFFFF: # 8 bytes
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1065 return 8
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1066 else:
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1067 raise InvalidPlistException(
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
1068 "Core Foundation can't handle integers with size greater"
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2969
diff changeset
1069 " than 8 bytes.")
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1070
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1071 def realSize(self, obj):
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1072 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
1073 Public method to determine the number of bytes necessary to store the
1720
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1074 given real.
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1075
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1076 @param obj real object
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1077 @return number of bytes required (integer)
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1078 """
201622cf8a01 Added a bookmarks importer for Apple Safari.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1079 return 8

eric ide

mercurial