本文整理汇总了Python中xml.etree.cElementTree.Element.attrib["rel"]方法的典型用法代码示例。如果您正苦于以下问题:Python Element.attrib["rel"]方法的具体用法?Python Element.attrib["rel"]怎么用?Python Element.attrib["rel"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.etree.cElementTree.Element
的用法示例。
在下文中一共展示了Element.attrib["rel"]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_noargs
# 需要导入模块: from xml.etree.cElementTree import Element [as 别名]
# 或者: from xml.etree.cElementTree.Element import attrib["rel"] [as 别名]
#.........这里部分代码省略.........
parser = iter(parser)
event, root = parser.next()
keys = {}
selmaho = {}
for event, element in parser:
if event != "end":
root.clear()
continue
if element.tag != "valsi":
root.clear()
continue
if element.attrib["type"] == "gismu" or element.attrib["type"] == "experimental gismu":
valsi_type = "gismu"
elif element.attrib["type"] == "cmavo" or element.attrib["type"] == "experimental cmavo":
valsi_type = "cmavo"
elif element.attrib["type"] == "cmavo cluster":
root.clear()
continue
elif element.attrib["type"] == "cmene":
root.clear()
continue
elif element.attrib["type"] == "fu'ivla":
valsi_type = "fuhivla"
elif element.attrib["type"] == "lujvo":
valsi_type = "lujvo"
else:
raise Exception("Unrecognised type of valsi found: '%s'." % element.attrib["type"])
valsi = Element("object")
keys[valsi_type] = keys.get(valsi_type, 0) + 1
valsi.attrib["pk"] = str(keys[valsi_type])
valsi.attrib["model"] = "main." + valsi_type
name = Element("field")
name.attrib["type"] = "CharField"
name.attrib["name"] = "name"
name.text = element.attrib["word"]
valsi.append(name)
definition = Element("field")
definition.attrib["type"] = "TextField"
definition.attrib["name"] = "definition"
definition.text = element.findtext("definition")
valsi.append(definition)
notes_text = element.findtext("notes")
if notes_text is not None:
notes = Element("field")
notes.attrib["type"] = "TextField"
notes.attrib["name"] = "notes"
notes.text = notes_text
valsi.append(notes)
if element.attrib.get("unofficial", "false") == "true":
official = Element("field")
official.attrib["type"] = "BooleanField"
official.attrib["name"] = "official"
official.text = "False"
valsi.append(official)
if valsi_type == "gismu":
for rafsi in element.findall("rafsi"):
new_rafsi = Element("field")
new_rafsi.attrib["type"] = "CharField"
if len(rafsi.text) == 4:
new_rafsi.attrib["name"] = "cvv_rafsi"
elif rafsi.text[1:2] in "aeiou":
new_rafsi.attrib["name"] = "cvc_rafsi"
else:
new_rafsi.attrib["name"] = "ccv_rafsi"
new_rafsi.text = rafsi.text
valsi.append(new_rafsi)
if valsi_type == "cmavo":
cmavo_selmaho = element.findtext("selmaho")
if cmavo_selmaho not in selmaho:
selmaho[cmavo_selmaho] = len(selmaho) + 1
selmaho_element = Element("object")
selmaho_element.attrib["pk"] = str(len(selmaho))
selmaho_element.attrib["model"] = "main.selmaho"
name = Element("field")
name.attrib["type"] = "CharField"
name.attrib["name"] = "name"
name.text = cmavo_selmaho or "Unknown"
selmaho_element.append(name)
fixture_root.append(selmaho_element)
selmaho_ref = Element("field")
selmaho_ref.attrib["to"] = "main.selmaho"
selmaho_ref.attrib["name"] = "selmaho"
selmaho_ref.attrib["rel"] = "ManyToOneRel"
selmaho_ref.text = str(selmaho[cmavo_selmaho])
valsi.append(selmaho_ref)
fixture_root.append(valsi)
root.clear()
fixture.write(join(fixture_dir, "valsi.xml"))