本文整理汇总了Python中xml.etree.cElementTree.Element.attrib["pk"]方法的典型用法代码示例。如果您正苦于以下问题:Python Element.attrib["pk"]方法的具体用法?Python Element.attrib["pk"]怎么用?Python Element.attrib["pk"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.etree.cElementTree.Element
的用法示例。
在下文中一共展示了Element.attrib["pk"]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_noargs
# 需要导入模块: from xml.etree.cElementTree import Element [as 别名]
# 或者: from xml.etree.cElementTree.Element import attrib["pk"] [as 别名]
def handle_noargs(self, **options):
base_dir = normpath(join(dirname(__file__), pardir, pardir, pardir, pardir))
data_dir = join(base_dir, 'data')
fixture_dir = join(base_dir, 'lojban/main/fixtures')
valsi_file = join(data_dir, 'valsi.xml')
valsi_uri = 'http://jbovlaste.lojban.org/export/xml-export.html?lang=en'
sys.path.append(base_dir)
os.environ['DJANGO_SETTINGS_MODULE'] = 'lojban.settings'
if not exists(data_dir):
mkdir(data_dir)
if not exists(valsi_file):
print "The valsi file is not available locally, so it will be downloaded. This may take a while..."
def report(count, size, total):
accuracy = ""
if total == -1:
# Filesize is around 1MB.
total = 1024**2
accuracy = "(approx.)"
progress = float(count*size)/total
if progress > 1:
progress = 1
print "\r%d%% complete %s." % (progress*100, accuracy),
sys.stdout.flush()
urlretrieve(valsi_uri, valsi_file, report)
print "\rThe valsi file has been downloaded."
if not exists(fixture_dir):
mkdir(fixture_dir)
fixture = ElementTree(Element("django-objects"))
fixture_root = fixture.getroot()
fixture_root.attrib["version"] = "1.0"
parser = iterparse(valsi_file, events=("start", "end"))
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)
#.........这里部分代码省略.........