本文整理汇总了Python中XMLHelpers.buildPerson方法的典型用法代码示例。如果您正苦于以下问题:Python XMLHelpers.buildPerson方法的具体用法?Python XMLHelpers.buildPerson怎么用?Python XMLHelpers.buildPerson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLHelpers
的用法示例。
在下文中一共展示了XMLHelpers.buildPerson方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_exportlinks1
# 需要导入模块: import XMLHelpers [as 别名]
# 或者: from XMLHelpers import buildPerson [as 别名]
def test_exportlinks1(self):
tree = Element("worldCrises", {"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" : "wc.xsd"})
person1 = Person(elemid = "bobs",
name = "Bob",
info_type = "Salamander",
info_birthdate_time = "12:00PM",
info_birthdate_day = 12,
info_birthdate_month = 12,
info_birthdate_year = 1900,
info_birthdate_misc = "born under the full moon...",
info_nationality = "Swedish",
info_biography = "Bob swam a lot, as salamanders do...",
orgrefs = ["salamanders united", "salamander liberation front"],
crisisrefs = ["swamp famine", "west swamp drought"])
ptree = SubElement(tree, "person", {"id" : "bobs"})
XMLHelpers.buildPerson(ptree, person1)
link1 = Link(link_parent = "bobs",
link_type = "salad",
title = "don't click me!!!",
link_url = "http://www.nevergohere.com",
description = "you really shouldn't go there...",
link_site = "a bad place")
link1.put()
r = ElementTree.SubElement(ptree, "ref")
XMLHelpers.exportLinks(person1, r)
for ref in ptree.findall('.//ref'):
for l in ref:
new_link = Link()
if (l.tag):
new_link.link_type = l.tag
if (l.find('./site') != None):
new_link.link_site = l.find('./site').text
if (l.find('./title') != None):
new_link.title = l.find('./title').text
if (l.find('./url') != None):
new_link.link_url = db.Link(l.find('./url').text)
if (l.find('./description') != None):
new_link.description = l.find('./description').text
new_link.link_parent = ptree.attrib['id']
#self.assert_(False)
self.assertEqual(new_link.link_type , link1.link_type)
self.assert_(new_link.link_site == link1.link_site)
self.assert_(new_link.title == link1.title)
self.assert_(new_link.link_url == link1.link_url)
self.assert_(new_link.description == link1.description)
self.assert_(new_link.link_parent == link1.link_parent)
示例2: test_buildperson3
# 需要导入模块: import XMLHelpers [as 别名]
# 或者: from XMLHelpers import buildPerson [as 别名]
def test_buildperson3(self):
tree = Element("worldCrises", {"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" : "wc.xsd"})
person3 = Person(elemid = "null",
name = "nully",
info_type = "",
info_birthdate_time = "",
info_birthdate_day = 0,
info_birthdate_month = 0,
info_birthdate_year = 0,
info_birthdate_misc = "",
info_nationality = "",
info_biography = "",
orgrefs = [],
crisisrefs = [])
ptree = SubElement(tree, "person", {"id" : "null"})
XMLHelpers.buildPerson(ptree, person3)
elemid = ptree.attrib['id']
name = ptree.find('.//name').text
info_type = ptree.find('.//info').find('.//type').text
info_birthdate_time = ptree.find('.//info').find('.//birthdate').find('.//time').text
info_birthdate_day = int(ptree.find('.//info').find('.//birthdate').find('.//day').text)
info_birthdate_month = int(ptree.find('.//info').find('.//birthdate').find('.//month').text)
info_birthdate_year = int(ptree.find('.//info').find('.//birthdate').find('.//year').text)
info_birthdate_misc = ptree.find('.//info').find('.//birthdate').find('.//misc').text
info_nationality = ptree.find('.//info').find('.//nationality').text
info_biography = ptree.find('.//info').find('.//biography').text
orgrefs = [x.attrib['idref'] for x in ptree.findall('.//org')]
crisisrefs = [x.attrib['idref'] for x in ptree.findall('.//crisis')]
self.assertEqual(elemid, person3.elemid)
self.assert_(name == person3.name)
self.assert_(info_type == person3.info_type)
self.assert_(info_birthdate_time == person3.info_birthdate_time)
self.assert_(info_birthdate_day == person3.info_birthdate_day)
self.assert_(info_birthdate_month == person3.info_birthdate_month)
self.assert_(info_birthdate_year == person3.info_birthdate_year)
self.assert_(info_birthdate_misc == person3.info_birthdate_misc)
self.assert_(info_nationality == person3.info_nationality)
self.assert_(info_biography == person3.info_biography)
self.assert_(orgrefs == person3.orgrefs)
self.assert_(crisisrefs == person3.crisisrefs)
示例3: test_buildperson2
# 需要导入模块: import XMLHelpers [as 别名]
# 或者: from XMLHelpers import buildPerson [as 别名]
def test_buildperson2(self):
tree = Element("worldCrises", {"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" : "wc.xsd"})
person2 = Person(elemid = "sally",
name = "Sally",
info_type = "seahorse",
info_birthdate_time = "0:00PM",
info_birthdate_day = 1124,
info_birthdate_month = 1132,
info_birthdate_year = 19000,
info_birthdate_misc = "born in a clamshell...",
info_nationality = "French",
info_biography = "Sally was boring...",
orgrefs = ["seahorse united", "seahorse liberation front"],
crisisrefs = ["swamp famine", "west swamp drought"])
ptree = SubElement(tree, "person", {"id" : "sally"})
XMLHelpers.buildPerson(ptree, person2)
elemid = ptree.attrib['id'],
name = ptree.find('.//name').text
info_type = ptree.find('.//info').find('.//type').text
info_birthdate_time = ptree.find('.//info').find('.//birthdate').find('.//time').text
info_birthdate_day = int(ptree.find('.//info').find('.//birthdate').find('.//day').text)
info_birthdate_month = int(ptree.find('.//info').find('.//birthdate').find('.//month').text)
info_birthdate_year = int(ptree.find('.//info').find('.//birthdate').find('.//year').text)
info_birthdate_misc = ptree.find('.//info').find('.//birthdate').find('.//misc').text
info_nationality = ptree.find('.//info').find('.//nationality').text
info_biography = ptree.find('.//info').find('.//biography').text
orgrefs = [x.attrib['idref'] for x in ptree.findall('.//org')]
crisisrefs = [x.attrib['idref'] for x in ptree.findall('.//crisis')]
self.assertEqual(elemid[0], person2.elemid)
self.assert_(name == person2.name)
self.assert_(info_type == person2.info_type)
self.assert_(info_birthdate_time == person2.info_birthdate_time)
self.assert_(info_birthdate_day == person2.info_birthdate_day)
self.assert_(info_birthdate_month == person2.info_birthdate_month)
self.assert_(info_birthdate_year == person2.info_birthdate_year)
self.assert_(info_birthdate_misc == person2.info_birthdate_misc)
self.assert_(info_nationality == person2.info_nationality)
self.assert_(info_biography == person2.info_biography)
self.assert_(orgrefs == person2.orgrefs)
self.assert_(crisisrefs == person2.crisisrefs)
示例4: test_buildperson1
# 需要导入模块: import XMLHelpers [as 别名]
# 或者: from XMLHelpers import buildPerson [as 别名]
def test_buildperson1(self):
tree = Element("worldCrises", {"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" : "wc.xsd"})
person1 = Person(elemid = "bobs",
name = "Bob",
info_type = "Salamander",
info_birthdate_time = "12:00PM",
info_birthdate_day = 12,
info_birthdate_month = 12,
info_birthdate_year = 1900,
info_birthdate_misc = "born under the full moon...",
info_nationality = "Swedish",
info_biography = "Bob swam a lot, as salamanders do...",
orgrefs = ["salamanders united", "salamander liberation front"],
crisisrefs = ["swamp famine", "west swamp drought"])
ptree = SubElement(tree, "person", {"id" : "bobs"})
XMLHelpers.buildPerson(ptree, person1)
elemid = ptree.attrib['id'],
name = ptree.find('.//name').text
info_type = ptree.find('.//info').find('.//type').text
info_birthdate_time = ptree.find('.//info').find('.//birthdate').find('.//time').text
info_birthdate_day = int(ptree.find('.//info').find('.//birthdate').find('.//day').text)
info_birthdate_month = int(ptree.find('.//info').find('.//birthdate').find('.//month').text)
info_birthdate_year = int(ptree.find('.//info').find('.//birthdate').find('.//year').text)
info_birthdate_misc = ptree.find('.//info').find('.//birthdate').find('.//misc').text
info_nationality = ptree.find('.//info').find('.//nationality').text
info_biography = ptree.find('.//info').find('.//biography').text
orgrefs = [x.attrib['idref'] for x in ptree.findall('.//org')]
crisisrefs = [x.attrib['idref'] for x in ptree.findall('.//crisis')]
self.assertEqual(elemid[0], person1.elemid)
self.assert_(name == person1.name)
self.assert_(info_type == person1.info_type)
self.assert_(info_birthdate_time == person1.info_birthdate_time)
self.assert_(info_birthdate_day == person1.info_birthdate_day)
self.assert_(info_birthdate_month == person1.info_birthdate_month)
self.assert_(info_birthdate_year == person1.info_birthdate_year)
self.assert_(info_birthdate_misc == person1.info_birthdate_misc)
self.assert_(info_nationality == person1.info_nationality)
self.assert_(info_biography == person1.info_biography)
self.assert_(orgrefs == person1.orgrefs)
self.assert_(crisisrefs == person1.crisisrefs)