本文整理汇总了Python中xml.etree.ElementTree.SubElement.get方法的典型用法代码示例。如果您正苦于以下问题:Python SubElement.get方法的具体用法?Python SubElement.get怎么用?Python SubElement.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.etree.ElementTree.SubElement
的用法示例。
在下文中一共展示了SubElement.get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: voteStatistician2
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import get [as 别名]
def voteStatistician2(objA, objB, voter, tagError = 1) :
# TODO: make the function function
for subObjA in objA :
if subObjA.tag not in objList :
continue
nCandidate = len([x for x in subObjA.findall('t2_tag') if 'ET-' in x.get('name') or 'EC-' in x.get('name')])
foundMatchedObjB = 0
for subObjB in objB :
if subObjA.tag == subObjB.tag and getObjId(subObjA) == getObjId(subObjB) :
foundMatchedObjB = 1
if subObjA.tag == 't2_node' :
if nCandidate is 0 :
continue
elif nCandidate is not 1 :
print "error: too many candidate error tags. (", nCandidate, ")"
if tagError:
e = SubElement(subObjA, 't2_tag', {'name' : "ERROR-multiple-tag", 'key' : "E"})
continue
votedTagA = [x for x in subObjA.findall('t2_tag') if 'voted-' in x.get('name')]
if not votedTagA :
votedTagA = SubElement(subObjA, 't2_tag', {'name' : "voted-0/0", 'key' : "M"})
allVote = 0
voteYes = 0;
elif len(votedTagA) is not 1 :
print "error: too many voted tags."
if tagError :
e = SubElement(subObjA, 't2_tag', {'name' : "ERROR-multiple-vote-" + voter, 'key' : "E"})
continue
else :
votedTagA = votedTagA[0]
posLine = votedTagA.get('name').find('-')
posBias = votedTagA.get('name').find('/')
voteYes = int(votedTagA.get('name')[posLine + 1 : posBias])
allVote = int(votedTagA.get('name')[posBias + 1 :])
# voting tags, list of votes, as string
votingTagB = [x.get('name') for x in subObjB.findall('t2_tag') if 'VOTE-yes' in x.get('name') or 'VOTE-no' in x.get('name')]
if len(votingTagB) is not 1 :
# voting wrong, probably missing
r = SubElement(subObjA, 't2_tag', {'name' : "REVOTE-" + voter, 'key' : "R"})
print getObjId(subObjB), "vote tag wrong, needs revisit."
continue
else :
allVote += 1
if 'VOTE-yes' in votingTagB :
voteYes += 1
votedTagA.set('name', 'voted-' + str(voteYes) + '/' + str(allVote))
voteStatistician2(subObjA, subObjB, voter, tagError)
break
if not foundMatchedObjB :
if subObjA.tag == 't2_node' and nCandidate is 1:
# error on finding the same node in B
print "error: cannot find vote node, len(node) =", str(len(subObjB)), getObjId(subObjA)
if tagError:
e = SubElement(subObjA, 't2_tag', {'name' : "ERROR-" + str(len(subObjB)) + "-node-" + voter, 'key' : "E"})
else :
print "error: cannot find the same", subObjA.tag
示例2: generateShareSDKXmlFile
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import get [as 别名]
def generateShareSDKXmlFile(pluginInfo, decompileDir):
assetsPath = file_utils.getFullPath(decompileDir) + "/assets"
if not os.path.exists(assetsPath):
os.makedirs(assetsPath)
shareSdkXml = assetsPath + "/ShareSDK.xml"
if os.path.exists(shareSdkXml):
os.remove(shareSdkXml)
tree = ElementTree()
root = Element('DevInfor')
tree._setroot(root)
shareNode = SubElement(root, 'ShareSDK')
if 'params' in pluginInfo and pluginInfo['params'] != None and len(pluginInfo['params']) > 0:
for param in pluginInfo['params']:
paramName = param.get('name')
if paramName == 'AppKey':
paramValue = param.get('value')
shareNode.set('AppKey', paramValue)
break
subplugins = pluginInfo.get('subplugins')
if subplugins != None and len(subplugins) > 0:
index = 1
for subplg in subplugins:
subplgNode = SubElement(root, subplg['name'])
subparams = subplg.get('params')
if subparams != None and len(subparams) > 0:
for subparam in subparams:
subplgNode.set(subparam['name'], subparam['value'])
if subplgNode.get('Id') == None:
subplgNode.set('Id', str(index))
else:
subplgNode.attrib['Id'] = str(index)
if subplgNode.get('Enable') == None:
subplgNode.set('Enable', 'true')
else:
subplgNode.attrib['Enable'] = 'true'
index = index + 1
tree.write(shareSdkXml, 'UTF-8')
示例3: _add_Shield_Layer_By_Zoom
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import get [as 别名]
def _add_Shield_Layer_By_Zoom(self, field, maxZoom):
'''
Specifies shields (points and labels) of articles and the
datasource with its respective layer.
'''
for z in reversed(range(maxZoom)):
layer = SubElement(self.mapRoot, 'Layer', name=field[1:-1] + str(z) + 'Layer')
layer.set('srs', '+init=epsg:4236')
layer.set('cache-features', 'true')
layer.set('minzoom', self.getMinDenominator(z))
layer.set('maxzoom', self.getMaxDenominator(z))
assert layer.get('minzoom') is not None, 'no min denominator for %s' % z
assert layer.get('maxzoom') is not None, 'no max denominator for %s' % z
addStyle = SubElement(layer, 'StyleName')
addStyle.text = field[1:-1] + str(z) + 'LabelStyle'
if z != maxZoom:
self.addDataSource(layer, '(select * from ' + self.table + ' where maxzoom <= ' + str(z+1) + ' order by maxzoom) as foo')
else:
self.addDataSource(layer, '(select * from ' + self.table + ' where maxzoom <= ' + str(z) + ' order by maxzoom) as foo')
示例4: voteStatistician
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import get [as 别名]
def voteStatistician(rootA, rootB, voter, tagError = 1) :
if not isinstance(voter, basestring) :
print "wrong voter."
return
# iterate areatree and connector
for objA in itertools.chain(rootA.iter('t2_areatree'), rootA.iter('t2_connector')):
# prepare corresponding element in B
for objB in itertools.chain(rootB.iter('t2_areatree'), rootB.iter('t2_connector')):
if getObjId(objB) == getObjId(objA):
matchedObjB = objB
break
if matchedObjB is None:
# error, and skip to next areatree or connector
print "error: cannot find corresponding element for", getObjId(objA)
continue
# iterate node
for nodeA in objA.iter('t2_node'):
# determine whether this node is a candidate
candidate = [x.get('name') for x in nodeA.findall('t2_tag') if isCandidateTag(x)]
nCandidates = len(candidate)
if nCandidates <= 0:
# examine next node A
continue
elif nCandidates > 1:
# error, and examine next node A
print "error: multiple candidate tags on one node."
if tagError:
e = SubElement(nodeA, 't2_tag', {'name' : "ERROR-multiple-tag", 'key' : "E"})
continue
# the nodeA is a candidate
# get pre-existing vote results
votedTagA = [x for x in nodeA.findall('t2_tag') if 'voted-' in x.get('name')]
if len(votedTagA) > 1 :
# error, and skip this node
print "get voted tag error."
if tagError:
e = SubElement(nodeA, 't2_tag', {'name' : "ERROR-votetag-" + voter, 'key' : "E"})
continue
elif len(votedTagA) <= 0 :
# create new
votedTagA = SubElement(nodeA, 't2_tag', {'name' : "voted-0/0", 'key' : "M"})
allVote = 0
voteYes = 0;
else :
votedTagA = votedTagA[0]
posLine = votedTagA.get('name').find('-')
posBias = votedTagA.get('name').find('/')
voteYes = int(votedTagA.get('name')[posLine + 1 : posBias])
allVote = int(votedTagA.get('name')[posBias + 1 :])
# get corrisponding node in B
matchedNodeB = None
for nodeB in matchedObjB.iter('t2_node'):
if getObjId(nodeB) == getObjId(nodeA):
matchedNodeB = nodeB
break
if matchedNodeB is None:
# error, and skip to next node in A
print "error: cannot find vote node for", getObjId(nodeA)
if tagError:
e = SubElement(nodeA, 't2_tag', {'name' : "ERROR-no-match-node-" + voter, 'key' : "E"})
continue
# get vote in B
votingTagB = [x for x in matchedNodeB.findall('t2_tag') if 'VOTE-yes' in x.get('name') or 'VOTE-no' in x.get('name')]
if len(votingTagB) is not 1:
# voting wrong, probably missing
r = SubElement(nodeA, 't2_tag', {'name' : "REVOTE-" + voter, 'key' : "R"})
print getObjId(matchedNodeB), "vote tag wrong, revote."
continue
else :
# print getObjId(matchedNodeB) , "vote accepted."
allVote += 1
# voteAcceptTagA = SubElement(nodeA, 't2_tag', {'name' : "VALID-" + voter, 'key' : "O"})
if 'VOTE-yes' in votingTagB[0].get('name') :
voteYes += 1
votedTagA.set('name', 'voted-' + str(voteYes) + '/' + str(allVote))