本文整理汇总了Python中XML类的典型用法代码示例。如果您正苦于以下问题:Python XML类的具体用法?Python XML怎么用?Python XML使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XML类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_countChildren_multipleChildren
def test_countChildren_multipleChildren(self):
s = "<xml><THU><Team><ACRush></ACRush><Jelly></Jelly><Cooly></Cooly></Team><JiaJia><Team><Ahyangyi></Ahyangyi><Dragon></Dragon><Cooly><Amber></Amber></Cooly></Team></JiaJia></THU><Team><Cooly></Cooly><Jelly></Jelly></Team></xml>"
a = fromstring(s)
pattern = XML.getPattern(a)
patternChildren = 0
patternChildren = XML.countChildren(pattern)
self.assertTrue(patternChildren == 2)
示例2: main
def main():
# part1:
#-------------------------------------------------------------------
Part1.Part1()
#-------------------------------------------------------------------
# part2:
#-------------------------------------------------------------------
# set last parameter to true to enable export of shots
stitched_shots, all_shots, outstitched_shots = Part2.Part2(False)
#-------------------------------------------------------------------
#html stuff:
#-------------------------------------------------------------------
HTML.html_stuff(stitched_shots, all_shots, outstitched_shots, 'Oberstdorf16-shots.csv',
'./html_input/index_part1.txt', './html_input/index_part2.txt', './html_output/index.html')
#-------------------------------------------------------------------
#xml stuff:
#-------------------------------------------------------------------
XML.create_XML('caffe_output.txt')
示例3: dbIter
def dbIter(self):
if os.path.isfile(self.path):
dom = XML.parseStream(open(self.path))
for element in XML.getChildElements(dom.documentElement):
if element.nodeName == "ruleset":
yield element
else:
log.msg("The file %r does not exist, loading no rulesets" % self.path)
示例4: preprocess
def preprocess(self):
message = XML.dig(self.xml, "message")
if not message:
raise XML.XMLValidityError("A Message's root node must be named 'message'")
# Stamp it with the current time if it has no timestamp yet
if not XML.dig(message, "timestamp"):
XML.addElement(message, "timestamp", "%d" % time.time())
示例5: test_count
def test_count(self):
s = "<xml><THU>\n\t<Team>\n\t\t<ACRush></ACRush>\n\t\t<Jelly></Jelly>\n\t\t<Cooly></Cooly>\n\t</Team>\n\t<JiaJia>\n\t\t<Team>\n\t\t\t<Ahyangyi></Ahyangyi>\n\t\t\t<Dragon></Dragon>\n\t\t\t<Cooly><Amber></Amber></Cooly>\n\t\t</Team>\n\t</JiaJia>\n</THU>\n<Team><Cooly></Cooly></Team>\n</xml>"
a = fromstring(s)
pattern = XML.getPattern(a)
patternChildren = 0
patternChildren = XML.countChildren(pattern)
XML.numElements = 0
XML.numElements = XML.count(a, pattern, patternChildren)
self.assertTrue(XML.numElements == 13)
示例6: test_count_breadth
def test_count_breadth(self):
s = "<xml><THU><Team></Team><ACRush></ACRush><Jelly></Jelly><Cooly></Cooly><JiaJia></JiaJia><Ahyangyi></Ahyangyi><Dragon></Dragon></THU></xml>"
a = fromstring(s)
pattern = XML.getPattern(a)
patternChildren = 0
patternChildren = XML.countChildren(pattern)
XML.numElements = 0
XML.numElements = XML.count(a, pattern, patternChildren)
self.assertTrue(XML.numElements == 8)
示例7: test_findMatches
def test_findMatches(self):
s = "<xml><THU><Team><ACRush></ACRush><Jelly></Jelly><Cooly></Cooly></Team><JiaJia><Team><Ahyangyi></Ahyangyi><Dragon></Dragon><Cooly><Amber></Amber></Cooly></Team></JiaJia></THU><Team><Cooly></Cooly></Team></xml>"
a = fromstring(s)
pattern = XML.getPattern(a)
patternChildren = 0
patternChildren = XML.countChildren(pattern)
XML.locations = []
XML.locations = XML.findMatches(a, pattern, patternChildren)
self.assertTrue(XML.locations == []) #function only works in conjunction with the count function
示例8: textComponent
def textComponent(self, element, args, *path):
"""A convenience function for defining components that just look for a node
in the message and return its shallowText.
"""
element = XML.dig(args.message.xml, *path)
if element:
return [XML.shallowText(element)]
else:
return [MarkAsHidden()]
示例9: test_findMatches_guaranteed_match
def test_findMatches_guaranteed_match(self):
s = "<xml><THU><Team></Team></THU><THU></THU></xml>"
a = fromstring(s)
pattern = XML.getPattern(a)
patternChildren = 0
patternChildren = XML.countChildren(pattern)
XML.matches = 0
XML.findMatches(a, pattern, patternChildren)
self.assertTrue(XML.matches == 0)
示例10: getXMLMailHeaders
def getXMLMailHeaders(self, document):
"""Return a <mailHeaders> tag representing a subset of the headers
for this message. This is placed in the <generator> tag of any
message passing through this module, to document and log the
message's true source.
"""
node = document.createElementNS(None, "mailHeaders")
for name, value in self.message.items():
if name in interestingHeaders:
XML.addElement(node, "header", content=str(value)).setAttributeNS(None, 'name', name)
return node
示例11: rulesetReturn
def rulesetReturn(msg):
nodes = xp.queryObject(msg)
if nodes:
self.result = XML.allText(nodes[0]).strip()
else:
self.result = None
raise RulesetReturnException()
示例12: element_like
def element_like(self, element):
"""Compare a given variable to the element's content using SQL's 'LIKE' operator,
not including leading and trailing whitespace. This is case-insensitive, and includes
the '%' wildcard which may be placed at the beginning or end of the string.
"""
return "(%s LIKE %s)" % (self.varLookup(element.getAttributeNS(None, 'var')),
quote(XML.shallowText(element).strip(), 'varchar'))
示例13: run_probes
def run_probes(self):
""" run probes and upload probe data """
try:
probes = XML.XML(str(self.proxy.GetProbes()))
except (Proxy.ProxyError,
Proxy.CertificateError,
socket.gaierror,
socket.error):
err = sys.exc_info()[1]
self.fatal_error("Failed to download probes from bcfg2: %s" % err)
except XML.ParseError:
err = sys.exc_info()[1]
self.fatal_error("Server returned invalid probe requests: %s" %
err)
self.times['probe_download'] = time.time()
# execute probes
probedata = XML.Element("ProbeData")
for probe in probes.findall(".//probe"):
probedata.append(self.run_probe(probe))
if len(probes.findall(".//probe")) > 0:
try:
# upload probe responses
self.proxy.RecvProbeData(
XML.tostring(probedata,
xml_declaration=False).decode('utf-8'))
except Proxy.ProxyError:
err = sys.exc_info()[1]
self.fatal_error("Failed to upload probe data: %s" % err)
self.times['probe_upload'] = time.time()
示例14: matches
def matches(self, msg):
match = self.projectPath.queryObject(msg)
if match:
for node in match:
project = XML.shallowText(node)
if (project.strip().lower() in self.projects):
return True
return False
示例15: loadGames
def loadGames():
try:
f = open("./xml/packlist.chess", "r")
except FileNotFoundError:
return
saves = f.readlines()
for save in saves:
save = save.rstrip()
gameID = save[:save.find(":")]
lastNum = save[save.find(":")+1:]
g = Game()
g.id = int(gameID)
xmlPath = "./xml/"+gameID+"/"+lastNum+".xml"
try:
m = XML.parse_meta(xmlPath)
g.password = m["password"]
g.board.whoseTurn = WHITE if m["turn"] == "white" else BLACK
g.board.xSize = int(m["sizeX"])
g.board.ySize = int(m["sizeY"])
g.movesmade = int(m["movesmade"])
g.board.setup_fields()
except KeyError:
continue
figures = XML.parse_figures(xmlPath)
for figure in figures:
g.board.getFieldByCords(figure.posx, figure.posy).figure = figure
g.board.postMoveUpdate()
if g.password is None:
g.password = ""
if g.movesmade > 3:
glist.append(g)
print("Loaded Game:", g.id)
else:
removeLine("./xml/packlist.chess", str(g.id)+":"+str(g.movesmade)+"\n")
rmdir("./xml/"+str(g.id))
print("Removed SaveGame:", g.id)