[PATCH] D112202: Fixed plistlib API usage for both python 2.7 and 3.x
Thomas Preud'homme via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 22 02:02:28 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rLNT4510c28bad3b: Fixed plistlib API usage for both python 2.7 and 3.x (authored by thopre).
Repository:
rLNT LNT
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112202/new/
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.381488.patch
Type: text/x-patch
Size: 1047 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211022/26411515/attachment.bin>
More information about the llvm-commits
mailing list