本文整理汇总了Python中XMLHelpers.exportLinks方法的典型用法代码示例。如果您正苦于以下问题:Python XMLHelpers.exportLinks方法的具体用法?Python XMLHelpers.exportLinks怎么用?Python XMLHelpers.exportLinks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLHelpers
的用法示例。
在下文中一共展示了XMLHelpers.exportLinks方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_exportlinks1
# 需要导入模块: import XMLHelpers [as 别名]
# 或者: from XMLHelpers import exportLinks [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_exportlinks3
# 需要导入模块: import XMLHelpers [as 别名]
# 或者: from XMLHelpers import exportLinks [as 别名]
def test_exportlinks3(self):
tree = Element("worldCrises", {"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" : "wc.xsd"})
crisis1 = Crisis(elemid = "hunger",
name = "hunger",
misc = "na",
info_history = "this year",
info_help = "help",
info_resources = "awareness",
info_type = "hunger attack",
date_time = "11 am",
date_day = 18,
date_month = 03,
date_year = 2012,
date_misc = "still alive",
location_city = "houston",
location_region = "texas",
location_country = "USA",
impact_human_deaths = 200,
impact_human_displaced = 20,
impact_human_injured = 1,
impact_human_missing = 32,
impact_human_misc = "none",
impact_economic_amount = 400,
impact_economic_currency = "yen",
impact_economic_misc = "misc",
orgrefs = ["dea", "cia"],
personrefs = ["you", "me"])
ctree = SubElement(tree, "crisis", {"id" : "hunger"})
XMLHelpers.buildCrisis(ctree, crisis1)
link1 = Link(link_parent = "hunger",
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")
XMLHelpers.link_list = []
XMLHelpers.link_list.append(link1)
XMLHelpers.exportLinks(crisis1, ctree)
for ref in ctree.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 = ctree.attrib['id']
self.assert_(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.assertEqual(new_link.link_parent, link1.link_parent)
示例3: test_exportlinks2
# 需要导入模块: import XMLHelpers [as 别名]
# 或者: from XMLHelpers import exportLinks [as 别名]
def test_exportlinks2(self):
tree = Element("worldCrises", {"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" : "wc.xsd"})
organization1 = Organization(elemid = "Franch",
name = "French pride",
info_type = "non-existant",
info_history = "white flags",
info_contacts_phone = "1234567890",
info_contacts_email = "[email protected]",
info_contacts_address = "French",
info_contacts_city = "Paris",
info_contacts_state = "Canada",
info_contacts_country = "USA",
info_contacts_zip = "7890",
info_loc_city = "Alaska",
info_loc_region = "Ukraine",
info_loc_country = "Antarctica",
personrefs = ["baquettes", "crumpets"],
crisisrefs = ["war", "nazis"],
misc = "")
otree = SubElement(tree, "organization", {"id" : "Franch"})
XMLHelpers.buildOrganization(otree, organization1)
link1 = Link(link_parent = "Franch",
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")
XMLHelpers.link_list = []
XMLHelpers.link_list.append(link1)
XMLHelpers.exportLinks(organization1, otree)
for ref in otree.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 = otree.attrib['id']
self.assert_(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.assertEqual(new_link.link_parent, link1.link_parent)