代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/scap-security-guide 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From 435ad2a81f4d56da42a2b24cad9e0e04d0523fd4 Mon Sep 17 00:00:00 2001
From: Vojtech Polasek <vpolasek@redhat.com>
Date: Tue, 9 Jun 2020 18:55:42 +0200
Subject: [PATCH] fix for older python versions lacking .iter method
Signed-off-by: HuaxinLu <luhuaxin1@huawei.com>
---
build-scripts/verify_references.py | 8 +++++-
.../pcidss/transform_benchmark_to_pcidss.py | 8 +++++-
ssg/build_cpe.py | 28 +++++++++++++++++--
ssg/id_translate.py | 9 +++++-
4 files changed, 47 insertions(+), 6 deletions(-)
diff --git a/build-scripts/verify_references.py b/build-scripts/verify_references.py
index 95d387f46f..003aa4c48c 100755
--- a/build-scripts/verify_references.py
+++ b/build-scripts/verify_references.py
@@ -179,7 +179,13 @@ def main():
check_content_refs = xccdftree.findall(".//{%s}check-content-ref"
% xccdf_ns)
- xccdf_parent_map = dict((c, p) for p in xccdftree.iter() for c in p)
+ # decide on usage of .iter or .getiterator method of elementtree class.
+ # getiterator is deprecated in Python 3.9, but iter is not available in
+ # older versions
+ if getattr(xccdftree, 'iter', None) == None:
+ xccdf_parent_map = dict((c, p) for p in xccdftree.getiterator() for c in p)
+ else:
+ xccdf_parent_map = dict((c, p) for p in xccdftree.iter() for c in p)
# now we can actually do the verification work here
if options.rules_with_invalid_checks or options.all_checks:
for check_content_ref in check_content_refs:
diff --git a/shared/transforms/pcidss/transform_benchmark_to_pcidss.py b/shared/transforms/pcidss/transform_benchmark_to_pcidss.py
index c94b12c45c..05df5a9889 100755
--- a/shared/transforms/pcidss/transform_benchmark_to_pcidss.py
+++ b/shared/transforms/pcidss/transform_benchmark_to_pcidss.py
@@ -111,7 +111,13 @@ def main():
benchmark.findall(".//{%s}Value" % (XCCDF_NAMESPACE)):
values.append(value)
- parent_map = dict((c, p) for p in benchmark.iter() for c in p)
+ # decide on usage of .iter or .getiterator method of elementtree class.
+ # getiterator is deprecated in Python 3.9, but iter is not available in
+ # older versions
+ if getattr(benchmark, "iter", None) == None:
+ parent_map = dict((c, p) for p in benchmark.getiterator() for c in p)
+ else:
+ parent_map = dict((c, p) for p in benchmark.iter() for c in p)
for rule in \
benchmark.findall(".//{%s}Rule" % (XCCDF_NAMESPACE)):
parent_map[rule].remove(rule)
diff --git a/ssg/build_cpe.py b/ssg/build_cpe.py
index 8c046777a5..26f182395e 100644
--- a/ssg/build_cpe.py
+++ b/ssg/build_cpe.py
@@ -17,7 +17,14 @@ def extract_subelement(objects, sub_elem_type):
"""
for obj in objects:
- for subelement in obj.iter():
+ # decide on usage of .iter or .getiterator method of elementtree class.
+ # getiterator is deprecated in Python 3.9, but iter is not available in
+ # older versions
+ if getattr(obj, "iter", None) == None:
+ obj_iterator = obj.getiterator()
+ else:
+ obj_iterator = obj.iter()
+ for subelement in obj_iterator:
if subelement.get(sub_elem_type):
sub_element = subelement.get(sub_elem_type)
return sub_element
@@ -44,12 +51,27 @@ def extract_referred_nodes(tree_with_refs, tree_with_ids, attrname):
reflist = []
elementlist = []
- for element in tree_with_refs.iter():
+
+ # decide on usage of .iter or .getiterator method of elementtree class.
+ # getiterator is deprecated in Python 3.9, but iter is not available in
+ # older versions
+ if getattr(tree_with_refs, "iter", None) == None:
+ tree_with_refs_iterator = tree_with_refs.getiterator()
+ else:
+ tree_with_refs_iterator = tree_with_refs.iter()
+ for element in tree_with_refs_iterator:
value = element.get(attrname)
if value is not None:
reflist.append(value)
- for element in tree_with_ids.iter():
+ # decide on usage of .iter or .getiterator method of elementtree class.
+ # getiterator is deprecated in Python 3.9, but iter is not available in
+ # older versions
+ if getattr(tree_with_ids, "iter", None) == None:
+ tree_with_ids_iterator = tree_with_ids.getiterator()
+ else:
+ tree_with_ids_iterator = tree_with_ids.iter()
+ for element in tree_with_ids_iterator:
if element.get("id") in reflist:
elementlist.append(element)
diff --git a/ssg/id_translate.py b/ssg/id_translate.py
index ba92259049..520c47fbfd 100644
--- a/ssg/id_translate.py
+++ b/ssg/id_translate.py
@@ -64,7 +64,14 @@ class IDTranslator(object):
)
def translate(self, tree, store_defname=False):
- for element in tree.iter():
+ # decide on usage of .iter or .getiterator method of elementtree class.
+ # getiterator is deprecated in Python 3.9, but iter is not available in
+ # older versions
+ if getattr(tree, "iter", None) == None:
+ tree_iterator = tree.getiterator()
+ else:
+ tree_iterator = tree.iter()
+ for element in tree_iterator:
idname = element.get("id")
if idname:
# store the old name if requested (for OVAL definitions)
--
2.30.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。