Skip to content

Commit 87eb031

Browse files
author
Pavel Kosov
committed
Fixed plistlib API usage
plistlib API required the file object opened in the binary mode. Test command: lnt checkformat tests/SharedInputs/sample-a-small.plist Related to: https://reviews.llvm.org/D109235 Reviewed By: thopre Differential Revision: https://reviews.llvm.org/D112136 Huawei Russian Research Institute, Saint-Petersburg
1 parent be3643c commit 87eb031

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lnt/formats/PlistFormat.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,27 @@
33

44
def _matches_format(path_or_file):
55
try:
6-
plistlib.load(path_or_file)
6+
if isinstance(path_or_file, str):
7+
with open(path_or_file, 'rb') as fp:
8+
plistlib.load(fp)
9+
else:
10+
plistlib.load(path_or_file)
711
return True
812
except Exception:
913
return False
1014

1115

16+
def _load_format(path_or_file):
17+
if isinstance(path_or_file, str):
18+
with open(path_or_file, 'rb') as fp:
19+
return plistlib.load(fp)
20+
else:
21+
return plistlib.load(path_or_file)
22+
23+
1224
format = {
1325
'name': 'plist',
1426
'predicate': _matches_format,
15-
'read': plistlib.load,
27+
'read': _load_format,
1628
'write': plistlib.dump,
1729
}

0 commit comments

Comments
 (0)