2014-03-15 17:59:15 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2014-03-15
|
2015-01-03 21:30:57 +00:00
|
|
|
# Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
|
2020-01-01 02:16:27 +00:00
|
|
|
#
|
|
|
|
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
|
|
|
# which should be included with this package. The terms are also available at
|
2015-01-03 21:33:16 +00:00
|
|
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
2014-03-15 17:59:15 +00:00
|
|
|
|
|
|
|
import plistlib
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2014-05-03 19:12:13 +00:00
|
|
|
class IPhotoPlistParser(plistlib._PlistParser):
|
2014-03-15 17:59:15 +00:00
|
|
|
"""A parser for iPhoto plists.
|
|
|
|
|
|
|
|
iPhoto plists tend to be malformed, so we have to subclass the built-in parser to be a bit more
|
|
|
|
lenient.
|
|
|
|
"""
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2014-03-15 17:59:15 +00:00
|
|
|
def __init__(self):
|
2014-05-03 19:12:13 +00:00
|
|
|
plistlib._PlistParser.__init__(self, use_builtin_types=True, dict_type=dict)
|
2014-03-15 17:59:15 +00:00
|
|
|
# For debugging purposes, we remember the last bit of data to be analyzed so that we can
|
|
|
|
# log it in case of an exception
|
2020-01-01 02:16:27 +00:00
|
|
|
self.lastdata = ""
|
2014-03-15 17:59:15 +00:00
|
|
|
|
2014-05-03 19:12:13 +00:00
|
|
|
def get_data(self):
|
|
|
|
self.lastdata = plistlib._PlistParser.get_data(self)
|
2014-03-15 17:59:15 +00:00
|
|
|
return self.lastdata
|
2014-03-15 18:06:20 +00:00
|
|
|
|
|
|
|
def end_integer(self):
|
|
|
|
try:
|
2014-05-03 19:12:13 +00:00
|
|
|
self.add_object(int(self.get_data()))
|
2014-03-15 18:06:20 +00:00
|
|
|
except ValueError:
|
2014-05-03 19:12:13 +00:00
|
|
|
self.add_object(0)
|