本文整理汇总了Python中elementtree.ElementTree.Element.append方法的典型用法代码示例。如果您正苦于以下问题:Python Element.append方法的具体用法?Python Element.append怎么用?Python Element.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elementtree.ElementTree.Element
的用法示例。
在下文中一共展示了Element.append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import append [as 别名]
def convert(self, data, cache, **kwargs):
bodydom = Element('div')
kmldom = XML(data)
ns = kmldom.tag.strip('kml')
placemarks = kmldom.findall('.//%sPlacemark' % ns)
for placemark in placemarks:
titles = placemark.findall(ns + 'name')
for title in titles:
t = Element('h2')
t.text = title.text
bodydom.append(t)
descriptions = placemark.findall(ns+'description')
for desc in descriptions:
if desc.text:
try:
text = desc.text.encode('ascii', 'xmlcharrefreplace').strip()
except:
text = desc.text.strip()
text = sanitize(text)
d = XML('<div>' + text.encode('ascii', 'xmlcharrefreplace') + '</div>')
bodydom.append(d)
body = tostring(bodydom)
cache.setData(body)
return cache
示例2: draw_bus
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import append [as 别名]
def draw_bus(self, title, color):
gelem = Element("g") # create a group
oelem = Element("path")
otuple = (self.x, self.y - self.height/2, self.period/8, -self.height/2, 6*self.period/8.0, self.period/8.0, self.height/2, -self.period/8, self.height/2.0, -6*self.period/8.0)
oelem.attrib['d']= "M%f,%f l%f,%f h%f l%f,%f l%f,%f h%f Z" % otuple
oelem.attrib['stroke'] = "black"
oelem.attrib['fill'] = color
oelem.attrib['stroke-linecap'] = "square"
gelem.append(oelem)
telem = Element("text")
telem.attrib['x'] = "%f" % (self.x + self.period/2)
telem.attrib['y'] = "%f" % (self.y - self.height/4.0-0.3)
telem.attrib['font-family'] = "Helvetica"
telem.attrib['font-size'] = "%f" % (self.height/1.9)
telem.attrib['text-anchor'] = "middle"
telem.text = title
gelem.append(telem)
self.x += self.period
self.sval = 'Z'
return gelem
示例3: setUp
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import append [as 别名]
def setUp(self):
from_string('<temp/>')
s1 = Element('class')
s1.set('name','test')
t.append(s1)
s2 = Element('handler')
s2.text = "print 'Hi!'"
s2.set('on','init')
s1.append(s2)
self.node1 = s1
doc2 = Element('class')
doc2.set('name','test2')
doc2.set('extends','test')
s3 = Element('handler')
s3.text = 'print Hi2!'
s3.set('on','init')
doc2.append(s3)
self.node2 = doc2
示例4: ToElement
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import append [as 别名]
def ToElement(self, it=None):
"""
Represents the store contents as an ElementTree.Element.
"""
if it is None:
it = self.entries.iteritems()
elt = Element("entities")
for peer_id, entry in it:
elt.append(entry.ToElement())
return elt
示例5: _format
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import append [as 别名]
def _format(self,elemap,obj):
defaults = self._defaults
out = Element(elemap[0])
for subspec in elemap[1:]:
if type(subspec) == type(''):
tmp = obj.get(subspec,None)
if tmp is None or str(tmp) == '':
tmp = defaults.get(subspec,'')
out.text = str(tmp)
continue
# here, subspec is really a recursive element map
subelem = self._format(subspec,obj)
out.append(subelem)
return out
示例6: body
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import append [as 别名]
def body(self):
""" Body exporter
"""
klass = self.context.__class__
factory = ".".join((klass.__module__, klass.__name__))
element = Element("object", name=self.context.__name__, factory=factory)
for prop in self.properties:
element.append(prop)
for child in self.children:
element.append(child)
return element
示例7: __init__
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import append [as 别名]
def __init__(self, root, showRoot = True):
QtCore.QAbstractItemModel.__init__(self)
if showRoot:
fakeroot = Element("fakeroot")
fakeroot.append(root)
self._root = fakeroot
else:
self._root = root
self._realroot = self._root
self._columns = ["Tag", "Attributes"]
self._np = dict((child, (parent, rowidx)) for parent in self._root.getiterator()
for rowidx, child in enumerate(parent))
示例8: writePolygon
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import append [as 别名]
def writePolygon(self, objGeo, elemPlace):
elemGeo = Element('Polygon')
#Now add the ring(s)
dctRings = objGeo.getRingInfo()
#get the external ring(s)
lstOuter = objGeo.getRing('Outer')
lstInner = objGeo.getRing('Inner')
for x in range(0, dctRings['Outer']):
elemRing = self.addRing(lstOuter[x], 'Outer')
elemGeo.append(elemRing)
for x in range(0, dctRings['Inner']):
elemRing = self.addRing(lstInner[x], 'Inner')
elemGeo.append(elemRing)
return elemGeo
示例9: encode_XMLDict
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import append [as 别名]
def encode_XMLDict(self, mapping):
"""!TXT!"""
def encode(key, value):
element = Element(key)
if isinstance(value, NoneType):
element.attrib['type'] = 'none'
elif isinstance(value, BooleanType):
element.attrib['type'] = 'bool'
element.attrib['value'] = value and 'true' or 'false'
elif isinstance(value, ComplexType):
element.attrib['type'] = 'complex'
element.attrib['re'] = repr(value.real)
element.attrib['im'] = repr(value.imag)
elif isinstance(value, FloatType):
element.attrib['type'] = 'float'
element.attrib['value'] = repr(value)
elif isinstance(value, IntType):
element.attrib['type'] = 'int'
element.attrib['value'] = repr(value)
elif isinstance(value, LongType):
element.attrib['type'] = 'long'
element.attrib['value'] = repr(value)
elif isinstance(value, StringType) or isinstance(value, UnicodeType):
element.attrib['type'] = 'cdata'
element.text = u"<![CDATA[%s]]>" % value
elif isinstance(value, DictType):
element.attrib['type'] = 'dict'
for key in value.keys():
element.append(encode(key, value[key]))
elif isinstance(value, ListType):
element.attrib['type'] = 'list'
for subvalue in value:
element.append(encode('value', subvalue))
elif isinstance(value, TupleType):
element.attrib['type'] = 'tuple'
for subvalue in value:
element.append(encode('value', subvalue))
else:
raise TypeError("Encoding of %s not supported (Key: %s)" % (repr(value), key))
return element
root = Element("data")
for key in mapping.keys():
root.append(self.encode(key, mapping[key]))
return tostring(root)
示例10: __split_models
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import append [as 别名]
def __split_models(self, xmlDoc):
"""generator that takes parameter xmlDoc and splits it into many
xml files, with only one model per each"""
elem = XML(xmlDoc)
models = elem.find("Models")
if models:
elem.remove(models)
for model in models:
to_return = copy.deepcopy(elem)
new_models = Element("Models")
for a in models.attrib:
new_models.attrib[a] = models.attrib[a]
new_models.append(model)
to_return.append(new_models)
yield (model.attrib['id'], to_return)
else:
pass #TODO return error
示例11: add_clock
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import append [as 别名]
def add_clock(self, name, datastr):
sigelem = Element('g')
# this is where we get the cycle count
self.cycles = len(datastr.split())
clksig = signal(name, self.xzero, self.ypos, self.period, self.height)
sigelem.append(clksig.draw_name())
for i in datastr.split():
sigelem.append(clksig.draw_clock())
self.ypos += self.signalspacing + self.height
self.signalselem.append(sigelem)
self.signalcnt += 1
示例12: __MultiplyRequiredElement
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import append [as 别名]
def __MultiplyRequiredElement(self, xmlFile, xmlTreePath):
'''
Multiplies the last element of the value of xmlTreePath
as many times as predefined number of self.instances.
'''
__name__ = '__MultiplyRequiredElement()'
self.logger.debug('[%s] Accessing %s...' % (self.__Blu('i'), __name__))
if 'Gw' in xmlFile:
xmlFile = pJoin(self.targetsXmlFolder, search('(^conf\..*)(_\d+)', xmlFile).group(1))
elif 'Radius' in xmlFile:
xmlFile = pJoin(self.radiusXmlFolder, search('(^conf\..*)(_\d+)', xmlFile).group(1))
Mapper, InPathNodes, tree, treeRoot = self.__ObtainRequiredVariables(xmlFile, xmlTreePath)
for inPathNode in InPathNodes:
for counter in range(self.counterStartsFrom, self.instances + 2):
if 'Gw' in xmlFile:
clonedChild = Element(inPathNode.tag)
for inPathNodeChild in inPathNode:
if inPathNodeChild.tag == 'outboundPort':
clonedChildChild = Element(inPathNodeChild.tag)
clonedChild.append(clonedChildChild)
clonedChildChild.text = str(int(self.defaultOutgoingPort) + self.portIncrement * (counter - 1))
elif inPathNodeChild.tag == 'inboundPort':
clonedChildChild = Element(inPathNodeChild.tag)
clonedChild.append(clonedChildChild)
clonedChildChild.text = str(int(self.defaultIncomingPort) + self.portIncrement * (counter - 1))
else:
clonedChild.append(inPathNodeChild)
Mapper[inPathNode].append(clonedChild)
elif 'Radius' in xmlFile:
clonedChild = Element(inPathNode.tag)
for inPathNodeChild in inPathNode:
if inPathNodeChild.tag == 'OutboundPort':
clonedChildChild = Element(inPathNodeChild.tag)
clonedChild.append(clonedChildChild)
clonedChildChild.text = str(int(self.defaultRadiusPort) + self.portIncrement * (counter - 1))
else:
clonedChild.append(inPathNodeChild)
Mapper[inPathNode].append(clonedChild)
self.__ReformatXmlTree(treeRoot, 0)
self.__WriteXmlTree(tree, xmlFile)
return xmlFile
示例13: draw_split
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import append [as 别名]
def draw_split(self):
""" Draws a set of hashmarks at the desired level """
gelem = Element("g") # create a group
level = self.sval
if level == 'H':
y = self.y-self.height
elif level == 'Z':
y = self.y - self.height/2.0
else:
y = self.y
l0elem = Element("line")
l0elem.attrib['x1'] = str(self.x)
l0elem.attrib['y1'] = str(y);
l0elem.attrib['x2'] = str(self.x + 3.5 * self.period/8.0)
l0elem.attrib['y2'] = str(y);
l0elem.attrib['stroke'] = "black"
gelem.append(l0elem)
l1elem = Element("line")
l1elem.attrib['x1'] = str(self.x + 3.0* self.period/8.0)
l1elem.attrib['y1'] = str(y + self.height/4.0);
l1elem.attrib['x2'] = str(self.x + 4*self.period/8.0)
l1elem.attrib['y2'] = str(y - self.height/4.0);
l1elem.attrib['stroke'] = "black"
gelem.append(l1elem)
l2elem = Element("line")
l2elem.attrib['x1'] = str(self.x + 4.0* self.period/8.0)
l2elem.attrib['y1'] = str(y + self.height/4.0);
l2elem.attrib['x2'] = str(self.x + 5.0*self.period/8.0)
l2elem.attrib['y2'] = str(y - self.height/4.0);
l2elem.attrib['stroke'] = "black"
gelem.append(l2elem)
l3elem = Element("line")
l3elem.attrib['x1'] = str(self.x + 4.5*self.period/8.0)
l3elem.attrib['y1'] = str(y);
l3elem.attrib['x2'] = str(self.x + self.period)
l3elem.attrib['y2'] = str(y);
l3elem.attrib['stroke'] = "black"
gelem.append(l3elem)
self.x += self.period
return gelem
示例14: add_signal
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import append [as 别名]
def add_signal(self, name, datastr):
sigelem = Element('g')
sig = signal(name, self.xzero, self.ypos, self.period, self.height)
sigelem.append(sig.draw_name())
for i in datastr.split():
if i == 'H':
sigelem.append(sig.draw_high())
elif i == 'L':
sigelem.append(sig.draw_low())
elif i == 'Z':
sigelem.append(sig.draw_z())
elif i == '//':
sigelem.append(sig.draw_split())
self.ypos += self.signalspacing + self.height
self.signalselem.append(sigelem)
self.signalcnt += 1
示例15: timinggrid
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import append [as 别名]
def timinggrid(self):
"""
This function uses the signalcnt, cycles, period, height, and spacing
to draw the light lines that will be the clock lines.
"""
gelem = Element("g") # create a group
for i in range(int(self.cycles)):
lelem = Element("line")
lelem.attrib['x1'] = str(i*self.period + self.period/2.0 + self.xzero)
lelem.attrib['y1'] = str(0);
lelem.attrib['x2'] = str(i*self.period + self.period/2.0 + self.xzero)
lelem.attrib['y2'] = str(self.signalcnt*(self.height + self.signalspacing) + self.signalspacing)
lelem.attrib['stroke'] = "grey"
lelem.attrib['stroke-width'] = "0.5"
gelem.append(lelem)
self.svgelem.append(gelem)
self.svgelem.append(self.signalselem)