diff --git a/lnt/formats/PlistFormat2.py b/lnt/formats/PlistFormat2.py new file mode 100644 --- /dev/null +++ b/lnt/formats/PlistFormat2.py @@ -0,0 +1,17 @@ +import plistlib + + +def _matches_format(path_or_file): + try: + plistlib.readPlist(path_or_file) + return True + except Exception: + return False + + +format = { + 'name': 'plist', + 'predicate': _matches_format, + 'read': plistlib.readPlist, + 'write': plistlib.writePlist, +} diff --git a/lnt/formats/__init__.py b/lnt/formats/__init__.py --- a/lnt/formats/__init__.py +++ b/lnt/formats/__init__.py @@ -9,7 +9,11 @@ from __future__ import absolute_import from typing import List, Dict -from .PlistFormat import format as plist +try: + from plistlib import readPlist + from .PlistFormat2 import format as plist # for Python 2 +except ImportError: + from .PlistFormat import format as plist # for Python 3 from .JSONFormat import format as json formats = [plist, json] # type: List[Dict]