当前位置: 首页>>代码示例>>Python>>正文


Python Element.attrib["rel"]方法代码示例

本文整理汇总了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"))
开发者ID:lagleki,项目名称:lojban-website,代码行数:104,代码来源:generate-valsi-fixture.py


注:本文中的xml.etree.cElementTree.Element.attrib["rel"]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。