本文整理汇总了Python中XMLHelpers类的典型用法代码示例。如果您正苦于以下问题:Python XMLHelpers类的具体用法?Python XMLHelpers怎么用?Python XMLHelpers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XMLHelpers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_grablinks2
def test_grablinks2(self):
XMLHelpers.clearGlobals()
person = Element("person", {"id" : "globetrotter"})
ref = SubElement(person, "ref")
img = SubElement(ref, "image")
site = SubElement(img, "site")
site.text = "i'm a site"
title = SubElement(img, "title")
title.text = "i'm a title"
url = SubElement(img, "url")
url.text = "i'm a url"
description = SubElement(img, "description")
description.text = "i'm a description"
img2 = SubElement(ref, "video")
site2 = SubElement(img, "site")
site2.text = "youtube"
title2 = SubElement(img, "title")
title2.text = "dancing cats"
url2 = SubElement(img, "url")
url2.text = "http://youtube.com/watch?v=si7f8f7tiuhsfi"
description2 = SubElement(img, "description")
description2.text = "the cats are dancing!!!"
temp = XMLHelpers.grabLinks(person)
self.assert_(len(temp) == 2)
XMLHelpers.clearGlobals()
示例2: test_parse2
def test_parse2(self):
xml_file = open("test/test_parse2.xml", 'rb')
XMLHelpers.parseXML2(xml_file,{'check': False, 'merge' : False})
temp = db.GqlQuery("SELECT * FROM Link")
for i in temp:
if i.link_type == "image":
self.assertEqual(i.link_url, "asdfasdfsadf")
break
db.delete(db.Query())
示例3: test_parse1
def test_parse1(self):
xml_file = open("test/test_parse1.xml", 'rb')
XMLHelpers.parseXML2(xml_file,{'check': False, 'merge' : False})
temp = db.GqlQuery("SELECT * FROM Link")
for i in temp:
if i.link_type == "image":
self.assert_(i.link_url == "https://www.google.com")
break
db.delete(db.Query())
示例4: test_parse4
def test_parse4(self):
xml_file = open("test/test_parse4.xml", 'rb')
XMLHelpers.parseXML2(xml_file,{'check': False, 'merge' : False})
temp = db.GqlQuery("SELECT * FROM Link")
for i in temp:
if i.link_type == "image":
assert i.link_url == "aaaa"
break
db.delete(db.Query())
示例5: test_parse3
def test_parse3(self):
xml_file = open("test/test_parse3.xml", 'rb')
XMLHelpers.parseXML(xml_file,1)
temp = db.GqlQuery("SELECT * FROM Link")
for i in temp:
if i.link_type == "image":
self.assert_(i.link_url == None)
break
db.delete(db.Query())
示例6: test_exportlinks1
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)
示例7: test_mergeLinks2
def test_mergeLinks2(self):
xml_file = open("test/test_mergelinks2.xml", 'rb')
XMLHelpers.parseXML2(xml_file,{'check': False, 'merge' : False})
xml_file = open("test/test_mergelinks4.xml", 'rb')
XMLHelpers.parseXML2(xml_file,{'check': False, 'merge' : True})
temp = db.GqlQuery("SELECT * FROM Link")
#Stuff
db.delete(db.Query())
示例8: test_addorg3
def test_addorg3(self):
xml_file = open("test/test_add3.xml", 'rb')
tree = ElementTree.parse(xml_file)
test_list = db.GqlQuery("SELECT * FROM Crisis")
orgs = tree.findall(".//organization")
for org in orgs:
if (org.find('.//info')):
XMLHelpers.addOrganization(org)
test_list = db.GqlQuery("SELECT * from Organization")
self.assertEqual(test_list.count(),0)
db.delete(db.Query())
示例9: test_addperson3
def test_addperson3(self):
xml_file = open("test/test_add3.xml", 'rb')
tree = ElementTree.parse(xml_file)
test_list = db.GqlQuery("SELECT * FROM Crisis")
people = tree.findall(".//person")
for person in people:
if (person.find('.//info')):
XMLHelpers.addPerson(person)
test_list = db.GqlQuery("SELECT * from Person")
self.assertEqual(test_list.count(),0)
db.delete(db.Query())
示例10: test_addcrisis2
def test_addcrisis2(self):
xml_file = open("test/test_add2.xml", 'rb')
tree = ElementTree.parse(xml_file)
crises = tree.findall(".//crisis")
for crisis in crises:
if (crisis.find('.//info')):
XMLHelpers.addCrisis(crisis)
test_list = db.GqlQuery("SELECT * FROM Crisis")
self.assertEqual(test_list.count(),2)
db.delete(db.Query())
示例11: test_mergeLinks3
def test_mergeLinks3(self):
xml_file = open("test/test_mergelinks1.xml", 'rb')
XMLHelpers.parseXML2(xml_file,{'check': False, 'merge' : False})
xml_file = open("test/test_mergelinks1.xml", 'rb')
XMLHelpers.parseXML2(xml_file,{'check': False, 'merge' : True})
temp = db.GqlQuery("SELECT * FROM Link")
for i in temp:
if i.link_type == "image":
self.assert_(i.link_url == "")
break
db.delete(db.Query())
示例12: test_mergeLinks1
def test_mergeLinks1(self):
xml_file = open("test/test_mergelinks1.xml", 'rb')
XMLHelpers.parseXML2(xml_file,{'check': False, 'merge' : False})
xml_file = open("test/test_mergelinks4.xml", 'rb')
XMLHelpers.parseXML2(xml_file,{'check': False, 'merge' : True})
temp = db.GqlQuery("SELECT * FROM Link")
#Stuff
for i in temp:
if i.link_type == "image":
self.assert_(i.link_url == "http://images5.fanpop.com/image/photos/30600000/Mr-President-WTF-weegee-vs-tails-doll-30625832-435-360.jpg")
break
db.delete(db.Query())
示例13: test_grablinks2
def test_grablinks2(self):
db.delete(db.Query())
person = Element("person", {"id" : "globetrotter"})
ref = SubElement(person, "ref")
img = SubElement(ref, "image")
site = SubElement(img, "site")
site.text = "i'm a site"
title = SubElement(img, "title")
title.text = "i'm a title"
url = SubElement(img, "url")
url.text = "http://img.timeinc.net/time/photoessays/2010/haiti_time_z/haiti_time_z_01.jpg"
description = SubElement(img, "description")
description.text = "i'm a description"
img2 = SubElement(ref, "video")
site2 = SubElement(img, "site")
site2.text = "youtube"
title2 = SubElement(img, "title")
title2.text = "dancing cats"
url2 = SubElement(img, "url")
url2.text = "http://youtube.com/watch?v=si7f8f7tiuhsfi"
description2 = SubElement(img, "description")
description2.text = "the cats are dancing!!!"
linkList = XMLHelpers.grabLinks(person)
self.assert_(len(linkList) == 1)
db.delete(db.Query())
示例14: test_buildperson3
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)
示例15: test_grablinks1
def test_grablinks1(self):
XMLHelpers.clearGlobals()
crisis = Element("crisis", {"id" : "wow"})
ref = SubElement(crisis, "ref")
img = SubElement(ref, "image")
site = SubElement(img, "site")
site.text = "i'm a site"
title = SubElement(img, "title")
title.text = "i'm a title"
url = SubElement(img, "url")
url.text = "i'm a url"
description = SubElement(img, "description")
description.text = "i'm a description"
temp = XMLHelpers.grabLinks(crisis)
self.assert_(temp[0].link_site == "i'm a site")
XMLHelpers.clearGlobals()