[PATCH] D112202: Fixed plistlib API usage for both python 2.7 and 3.x
Pavel Kosov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 20 23:58:11 PDT 2021
kpdev42 created this revision.
kpdev42 added reviewers: thopre, cmatthews, tnfchris.
kpdev42 added a project: LLVM.
Herald added a subscriber: dkolesnichenko.
kpdev42 requested review of this revision.
Reverted plistlib API for python 2.7
Related to: https://reviews.llvm.org/D109235 and https://reviews.llvm.org/D112136
Repository:
rLNT LNT
https://reviews.llvm.org/D112202
Files:
lnt/formats/PlistFormat2.py
lnt/formats/__init__.py
Index: lnt/formats/__init__.py
===================================================================
--- lnt/formats/__init__.py
+++ 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]
Index: lnt/formats/PlistFormat2.py
===================================================================
--- /dev/null
+++ 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,
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112202.381153.patch
Type: text/x-patch
Size: 1047 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211021/11f31cf7/attachment.bin>
More information about the llvm-commits
mailing list