diff --git a/lnt/formats/PlistFormat.py b/lnt/formats/PlistFormat.py --- a/lnt/formats/PlistFormat.py +++ b/lnt/formats/PlistFormat.py @@ -1,29 +1,35 @@ import plistlib -def _matches_format(path_or_file): +def _load_format(path_or_file): try: if isinstance(path_or_file, str): with open(path_or_file, 'rb') as fp: - plistlib.load(fp) + return plistlib.load(fp) else: - plistlib.load(path_or_file) + return plistlib.load(path_or_file) + except AttributeError: + return plistlib.readPlist(path_or_file) + + +def _matches_format(path_or_file): + try: + _load_format(path_or_file) return True except Exception: return False -def _load_format(path_or_file): - if isinstance(path_or_file, str): - with open(path_or_file, 'rb') as fp: - return plistlib.load(fp) - else: - return plistlib.load(path_or_file) +def _dump_format(obj, fp): + try: + plistlib.dump(obj, fp) + except AttributeError: + plistlib.writePlist(obj, fp) format = { 'name': 'plist', 'predicate': _matches_format, 'read': _load_format, - 'write': plistlib.dump, + 'write': _dump_format, }