本文整理汇总了Python中cElementTree.SubElement方法的典型用法代码示例。如果您正苦于以下问题:Python cElementTree.SubElement方法的具体用法?Python cElementTree.SubElement怎么用?Python cElementTree.SubElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cElementTree
的用法示例。
在下文中一共展示了cElementTree.SubElement方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: xccdf_subelement
# 需要导入模块: import cElementTree [as 别名]
# 或者: from cElementTree import SubElement [as 别名]
def xccdf_subelement(xccdftree, xccdf_element, yamlcontent, yaml_key, override=None, attrib=None):
yaml_key = yaml_key_value(yamlcontent, yaml_key)
if yaml_key:
new_element = ET.SubElement(xccdftree, xccdf_element)
if type(yaml_key) is dict:
if 'id' in yaml_key.keys():
new_element.set("id", yaml_key["id"])
if "clause" in yaml_key.keys():
new_element.set("clause", yaml_key["clause"])
if "description" in yaml_key.keys():
new_element.text = yaml_key["description"]
else:
if xccdf_element is not "oval":
new_element.text = str(yaml_key)
if yaml_key_value(yamlcontent, override) is not None:
new_element.set("override", str(yaml_key_value(yamlcontent, override)).lower())
if attrib is not None:
if type(attrib) is dict:
new_element = add_attrib_to_element(new_element, attrib, yamlcontent)
else:
new_element = add_attrib_to_element(new_element, attrib)
return xccdftree
示例2: script_to_rule_mapping
# 需要导入模块: import cElementTree [as 别名]
# 或者: from cElementTree import SubElement [as 别名]
def script_to_rule_mapping(self, xccdftree, filename, script_content):
if filename.endswith(".yml"):
system = "urn:xccdf:fix:script:ansible"
elif filename.endswith(".sh"):
system = "urn:xccdf:fix:script:sh"
elif filename.endswith(".anaconda"):
system = "urn:redhat:anaconda:pre"
elif filename.endswith(".pp"):
system = "urn:xccdf:fix:script:puppet"
elif filename.endswith(".chef"):
system = "urn:xccdf:fix:script:chef"
elif filename.endswith(".rb"):
system = "urn:xccdf:fix:script:ruby"
elif filename.endswith(".py"):
system = "urn:xccdf:fix:script:python"
filename = os.path.basename(filename).split(".")[0]
for rule in xccdftree.iter("Rule"):
if rule.attrib["id"] == filename:
script = ET.SubElement(rule, "fix", system=system)
script.text = script_content
return xccdftree
示例3: to_etree
# 需要导入模块: import cElementTree [as 别名]
# 或者: from cElementTree import SubElement [as 别名]
def to_etree(self, element):
if self.category == MixedContainer.CategoryText:
# Prevent exporting empty content as empty lines.
if self.value.strip():
if len(element) > 0:
if element[-1].tail is None:
element[-1].tail = self.value
else:
element[-1].tail += self.value
else:
if element.text is None:
element.text = self.value
else:
element.text += self.value
elif self.category == MixedContainer.CategorySimple:
subelement = etree_.SubElement(element, '%s' % self.name)
subelement.text = self.to_etree_simple()
else: # category == MixedContainer.CategoryComplex
self.value.to_etree(element)
示例4: xccdf_multiple_subelements
# 需要导入模块: import cElementTree [as 别名]
# 或者: from cElementTree import SubElement [as 别名]
def xccdf_multiple_subelements(xccdftree, xccdf_element, yamlcontent, yaml_key):
yaml_key = yaml_key_value(yamlcontent, yaml_key)
value = ""
attrib_type = "idref"
attrib = "true"
if yaml_key:
if type(yaml_key) is dict:
for key, val in yaml_key.iteritems():
if val is None:
val = ""
dict_element = ET.SubElement(xccdftree, xccdf_element)
dict_element.set(key, val)
return xccdftree
if type(yaml_key) is list:
for rules in yaml_key:
if "item" in rules.keys():
value = rules["item"]
if "rule" in rules.keys():
value = rules["rule"]
if "option" in rules.keys():
for key, val in rules["option"].iteritems():
opt = ET.SubElement(xccdftree, xccdf_element)
opt.set(attrib_type, key)
opt.text = val
else:
rule = ET.SubElement(xccdftree, xccdf_element)
rule.set(attrib_type, value)
if "selector" in rules.keys():
rule.set("selector", rules["selector"])
if "selected" in rules.keys():
rule.set("selected", str(rules["selected"]).lower())
else:
if "item" not in rules.keys():
rule.set("selected", "true")
return xccdftree
示例5: elem_create
# 需要导入模块: import cElementTree [as 别名]
# 或者: from cElementTree import SubElement [as 别名]
def elem_create(self, class_tag, xml_doc=None, override_tag=None):
if xml_doc is None:
xml_obj = Element(class_tag)
else:
if override_tag:
xml_obj = SubElement(xml_doc, override_tag)
else:
xml_obj = SubElement(xml_doc, class_tag)
return xml_obj
示例6: to_xml
# 需要导入模块: import cElementTree [as 别名]
# 或者: from cElementTree import SubElement [as 别名]
def to_xml(self, xml_doc=None, option=None, cookie=None):
"""
This method returns the xml element node for the current object
with it's hierarchy.
Args:
xml_doc: document to which the Mo attributes are added.
Can be None.
option: not required for Generic Mo class object
Example:
from imcmsdk.imcmo import GenericMo\n
args = {"a": 1, "b": 2, "c":3}\n
obj = GenericMo("testLsA", "org-root", **args)\n
obj1 = GenericMo("testLsB", "org-root", **args)\n
obj.add_child(obj1)\n
elem = obj.write_xml()\n
import imcmsdk.imcxmlcodec as xc\n
xc.to_xml_str(elem)\n
Output:
'<testLsA a="1" b="2" c="3" dn="org-root/" rn="">\n
<testLsB a="1" b="2" c="3" dn="org-root/" rn="" />\n
</testLsA>'
"""
if xml_doc is None:
xml_obj = Element(imcgenutils.word_l(self._class_id))
else:
xml_obj = SubElement(xml_doc, imcgenutils.word_l(self._class_id))
for key in self.__dict__:
if not key.startswith('_'):
xml_obj.set(key, getattr(self, key))
self.child_to_xml(xml_obj)
return xml_obj
示例7: process_trackpoint
# 需要导入模块: import cElementTree [as 别名]
# 或者: from cElementTree import SubElement [as 别名]
def process_trackpoint(trackpoint, lever):
for child in trackpoint:
for elem in child.iter():
if elem.tag == '{%s}TPX'%ns2:
#elem.attrib['xmlns'] = ns2
for node in elem.iter():
if node.tag == '{%s}Speed'%ns2:
speed_in_m_per_sec = float(node.text)
speed_km_per_h = speed_in_m_per_sec /1000.0 * 60 *60
power = s2p(speed_km_per_h, lever)
# add power to trackpoint
w = etree.SubElement(elem, '{%s}Watts'%ns2)
w.text = str(power)
w.tail = '\n'
示例8: to_xml
# 需要导入模块: import cElementTree [as 别名]
# 或者: from cElementTree import SubElement [as 别名]
def to_xml(self, xml_doc=None, option=None):
"""
This method returns the xml element node for the current object
with it's hierarchy.
Args:
xml_doc: document to which the Mo attributes are added.
Can be None.
option: not required for Generic Mo class object
Example:
from ucscsdk.ucscmo import GenericMo\n
args = {"a": 1, "b": 2, "c":3}\n
obj = GenericMo("testLsA", "org-root", **args)\n
obj1 = GenericMo("testLsB", "org-root", **args)\n
obj.add_child(obj1)\n
elem = obj.write_xml()\n
import ucscsdk.ucscxmlcodec as xc\n
xc.to_xml_str(elem)\n
Output:
'<testLsA a="1" b="2" c="3" dn="org-root/" rn="">\n
<testLsB a="1" b="2" c="3" dn="org-root/" rn="" />\n
</testLsA>'
"""
if xml_doc is None:
xml_obj = Element(ucscgenutils.word_l(self._class_id))
else:
xml_obj = SubElement(xml_doc, ucscgenutils.word_l(
self._class_id))
for key in self.__dict__:
if not key.startswith('_'):
xml_obj.set(key, getattr(self, key))
self.child_to_xml(xml_obj)
return xml_obj