[PATCH] D112136: Fixed plistlib API usage
Pavel Kosov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 20 06:13:10 PDT 2021
kpdev42 created this revision.
kpdev42 added reviewers: cmatthews, thopre, danilaml.
kpdev42 added a project: LLVM.
Herald added a subscriber: dkolesnichenko.
kpdev42 requested review of this revision.
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
Repository:
rLNT LNT
https://reviews.llvm.org/D112136
Files:
lnt/formats/PlistFormat.py
Index: lnt/formats/PlistFormat.py
===================================================================
--- lnt/formats/PlistFormat.py
+++ lnt/formats/PlistFormat.py
@@ -3,15 +3,27 @@
def _matches_format(path_or_file):
try:
- plistlib.load(path_or_file)
+ if isinstance(path_or_file, str):
+ with open(path_or_file, 'rb') as fp:
+ plistlib.load(fp)
+ else:
+ plistlib.load(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)
+
+
format = {
'name': 'plist',
'predicate': _matches_format,
- 'read': plistlib.load,
+ 'read': _load_format,
'write': plistlib.dump,
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112136.380930.patch
Type: text/x-patch
Size: 892 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211020/12d3f200/attachment.bin>
More information about the llvm-commits
mailing list