Skip to content

Commit 4510c28

Browse files
author
Thomas Preud'homme
committed
Fixed plistlib API usage for both python 2.7 and 3.x
Reverted plistlib API for python 2.7 Related to: https://reviews.llvm.org/D109235 and https://reviews.llvm.org/D112136 Reviewed By: thopre Differential Revision: https://reviews.llvm.org/D112202
1 parent a00494c commit 4510c28

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lnt/formats/PlistFormat2.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import plistlib
2+
3+
4+
def _matches_format(path_or_file):
5+
try:
6+
plistlib.readPlist(path_or_file)
7+
return True
8+
except Exception:
9+
return False
10+
11+
12+
format = {
13+
'name': 'plist',
14+
'predicate': _matches_format,
15+
'read': plistlib.readPlist,
16+
'write': plistlib.writePlist,
17+
}

lnt/formats/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99

1010
from __future__ import absolute_import
1111
from typing import List, Dict
12-
from .PlistFormat import format as plist
12+
try:
13+
from plistlib import readPlist
14+
from .PlistFormat2 import format as plist # for Python 2
15+
except ImportError:
16+
from .PlistFormat import format as plist # for Python 3
1317
from .JSONFormat import format as json
1418

1519
formats = [plist, json] # type: List[Dict]

0 commit comments

Comments
 (0)