本文整理汇总了Python中elementtree.ElementTree.Element类的典型用法代码示例。如果您正苦于以下问题:Python Element类的具体用法?Python Element怎么用?Python Element使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Element类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dump
def dump(self, output):
tempo = {}
root = Element('resources')
root.tail = '\n'
tempo[()] = root
for key in self._resources_order:
for i in range(1, len(key)+1):
if key[0:i] not in tempo:
parent = tempo[key[0:i-1]]
value = self._resources.get(key[0:i], None)
if value is None:
elem = SubElement(parent, 'node', name=key[i-1])
else:
fullKey = key[0];
for j in range(1, i):
fullKey += '/' + key[j]
newValue = self._dictionary[fullKey]
elem = SubElement(parent, 'node', name=key[i-1], value=newValue)
parent.text = elem.tail = '\n' + i*SPACES
tempo[key[0:i]] = elem
fix_it(root)
print >> output, '<?xml version="1.0" encoding="UTF-8"?>'
ElementTree(root).write(output, 'ascii')
示例2: AdicionarUsuario
def AdicionarUsuario(self,Aluno):
"""
Método que cria o usuário no jenkins, atualmente o jenkins está vinculado com o ldap do sistema ead, por mais que o usuário esteja criado no jenkins, ele não conseguirá autenticar se não estiver cadastrado no LDAP também.
Para fazer o cadastro do aluno é adicionada mais uma linha do /var/lib/jenkins/config.xml dentro das tags <permission> somente com permissão de leitura.
:param Aluno: Aluno é uma string somente com o email do aluno.
:returns: Esse método não possui valor de retorno
"""
try:
tree = parse("/var/lib/jenkins/config.xml")
elem = tree.getroot()
perm = elem.find('authorizationStrategy')
busca = perm.findall("permission")
for b in busca:
if Aluno in b.text:
log.warning("[!] Usuario Ja cadastrado no jenkins")
return
user = Element("permission")
user.text = "hudson.model.Hudson.Read:%s"%Aluno
perm.append(user)
tree.write("/var/lib/jenkins/config.xml")
log.info("[+] Usuario %s adicionado ao jenkins com Sucesso",Aluno)
except Exception as e:
log.error("[-] Erro ao adicionar usuario ao jenkins %s",e)
示例3: __init__
def __init__(self, filename):
self.filename = filename
# we assume that the clock is the maximum length
self.period = 40
self.height = 20
self.signalspacing = 10
self.xzero = 90
self.signalcnt = 0
self.cycles = 0
self.colors = ['powderblue', 'palegreen', 'lightpink', 'lightsalmon', 'lightgrey']
self.classes = {}
self.svgelem = Element("{http://www.w3.org/2000/svg}svg")
self.signalselem = Element("g")
self.ypos = self.height + self.signalspacing
示例4: create_node
def create_node(tag, property_map, content):
'''新造一个节点
tag:节点标签
property_map:属性及属性值map
content: 节点闭合标签里的文本内容
return 新节点'''
element = Element(tag, property_map)
element.text = content
return element
示例5: ToElement
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
示例6: draw_clock
def draw_clock(self):
elem = Element("path")
ptuple = (self.x, self.y, self.period/2, -self.height, self.period/2, self.height)
elem.attrib['d'] = "M%f,%f h%f v%f h%f v%f" % ptuple
elem.attrib['stroke'] = "black"
elem.attrib['fill'] = "none"
elem.attrib['stroke-linecap'] = "square"
self.x += self.period
self.sval = 'L'
return elem
示例7: ConvertToKML
def ConvertToKML(report):
root = Element(KML("kml"))
root.attrib["xmlns"] = "http://earth.google.com/kml/2.2"
doc = SubElement(root, KML("Document"))
for entry in report:
placemark = SubElement(doc, KML("Placemark"))
SubElement(placemark, KML("name")).text = entry["Address"]
SubElement(placemark, KML("description")).text = BuildDescription(entry)
# SubElement(placemark, KML("description")).text = entry['Details']
SubElement(SubElement(placemark, KML("Point")), KML("coordinates")).text = Geocode(entry["Address"])
return ElementTree(root)
示例8: create_slide
def create_slide(self, buf, i,name=''):
# creating the name of the slide
# by parsing the title and removing any odd character
slidename = re.sub('[^a-zA-Z0-9\\s]','',name)
slidename = re.sub('\\s','_',slidename)
# we create a new div that will contain the slide
cont = Element("div") #etree_loader.importETree().Element('div')
cont.set('class', 'slide')
cont.set('id', slidename)
return cont
示例9: GetFeedElement
def GetFeedElement(feed):
"""Create an atom:feed element for the provided feed.
The provided feed must be in the format described at http://feedparser.org.
"""
rss = Element("rss")
rss.attrib["version"] = "2.0"
root = SubElement(rss, "channel")
TextElement(root, "title", feed.feed.get("title_detail"))
if feed.feed.has_key("links"):
for link in feed.feed.links:
if link.rel != "self": continue
SubElementIf(root, "link", link.href)
TextElement(root, "description", feed.feed.get("subtitle_detail"))
TextElement(root, "copyright", feed.feed.get("rights_detail"))
SubElement(root, "generator").text = "feedarchive"
if feed.feed.has_key("image"):
im = feed.feed.image
ie = SubElement(root, "image")
SubElementIf(ie, "url", im.get("href"))
SubElementIf(ie, "title", im.get("title"))
SubElementIf(ie, "link", im.get("link"))
if feed.feed.has_key("tags"):
for tag in feed.feed.tags:
te = SubElement(root, "category")
if (tag.has_key("scheme")): te.attrib["domain"] = tag.scheme
te.text = tag.term
for entry in feed.entries:
ee = SubElement(root, "item")
TextElement(ee, "title", entry.get("title_detail"))
SubElementIf(ee, "link", entry.get("link"))
TextElement(ee, "description", entry.get("summary_detail"))
SubElementIf(ee, "guid", entry.get("id"))
DateTimeElement(ee, "pubDate", entry, "published")
PersonElement(ee, "author", entry.get("author_detail"))
if entry.has_key("links"):
for link in entry.links:
if link.rel != "enclosure": continue
ence = SubElement(ee, "enclosure")
AttribIf(ence, "url", link.get("url"))
AttribIf(ence, "length", link.get("length"))
AttribIf(ence, "type", link.get("type"))
return rss
示例10: properties
def properties(self):
""" Export properties
"""
contentType = self.context.contentType
prop = Element("property", name="contentType")
prop.text = contentType
yield prop
data = self.context.data
prop = Element("property", name="data")
data = base64.encodestring(data)
prop.text = CDATA % data
yield prop
示例11: GetFeedElement
def GetFeedElement(feed):
"""Create an atom:feed element for the provided feed.
The provided feed must be in the format described at http://feedparser.org.
"""
root = Element("feed")
root.attrib["xmlns"] = "http://www.w3.org/2005/Atom"
TextElement(root, "title", feed.feed.get("title_detail"))
if feed.feed.has_key("links"):
for link in feed.feed.links:
LinkElement(root, "link", link)
TextElement(root, "subtitle", feed.feed.get("subtitle_detail"))
TextElement(root, "rights", feed.feed.get("rights_detail"))
SubElement(root, "generator").text = "feedarchive"
SubElement(root, "updated").text = rfc3339(time.time())
SubElementIf(root, "id", feed.feed.get("id"))
if feed.feed.has_key("image"):
SubElement(root, "icon").text = feed.feed.image.href
if feed.feed.has_key("tags"):
for tag in feed.feed.tags:
te = SubElement(root, "category")
if tag.get("term"): te.attrib["term"] = tag.term
if tag.get("scheme"): te.attrib["scheme"] = tag.scheme
if tag.get("label"): te.attrib["label"] = tag.label
PersonElement(root, "author", feed.feed.get("author_detail"))
for entry in feed.entries:
ee = SubElement(root, "entry")
TextElement(ee, "title", entry.get("title_detail"))
if entry.has_key("links"):
for link in entry.links:
LinkElement(ee, "link", link)
TextElement(ee, "summary", entry.get("summary_detail"))
TextElement(ee, "content", entry.get("content_detail"))
DateTimeElement(ee, "published", entry, "published")
DateTimeElement(ee, "updated", entry, "updated")
SubElementIf(ee, "id", entry.get("id"))
PersonElement(ee, "author", entry.get("author_detail"))
PersonElement(ee, "publisher", entry.get("publisher_detail"))
if entry.has_key("contributors"):
for contributor in entry.contributors:
PersonElement(ee, "contributor", contributor)
CreateSourceElement(ee, entry.get("source"))
return root
示例12: _format
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
示例13: body
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
示例14: createFilePodcast
def createFilePodcast(mediaFilePath, title, description=''):
"""
create the xml file using utf
"""
mediaItem = Element("media")
mediaItem.attrib["version"] = VERSION
titleNode = SubElement(mediaItem, "title")
titleNode.text = title
descrNode = SubElement(mediaItem, "description")
descrNode.text = description
createXmlFile(mediaFilePath + '.xml', mediaItem)
mediaItem.clear()
示例15: __init__
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))