本文整理汇总了Python中elementtree.ElementTree.Element.text方法的典型用法代码示例。如果您正苦于以下问题:Python Element.text方法的具体用法?Python Element.text怎么用?Python Element.text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elementtree.ElementTree.Element
的用法示例。
在下文中一共展示了Element.text方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import text [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
示例2: properties
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import text [as 别名]
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
示例3: AdicionarUsuario
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import text [as 别名]
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)
示例4: draw_bus
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import text [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
示例5: convert
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import text [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
示例6: saveScriptConfig
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import text [as 别名]
def saveScriptConfig(config):
"""
save it into the the config
"""
elemConfig = Element("config")
lognode = Element("logvalue")
elemConfig.append(lognode)
lognode.text = str(config.logvalue)
mediaNode = Element("media")
mediaNode.attrib["updateurl"] = config.mediaUpdateURL
elemConfig.append(mediaNode)
podcastNode = Element("podcast")
if config.podcastDownload:
podcastNode.attrib["download"] = 'true'
else:
podcastNode.attrib["download"] = 'false'
podcastNode.attrib["localpath"] = config.podcastDownloadPath
elemConfig.append(podcastNode)
# create the userdata dir when not exist
if not os.path.exists(CONFIG_DIR_ROOT):
createDirectory(CONFIG_DIR_ROOT, recursive=True)
#if os.path.exists(CONFIG_DIR):
createXmlFile(CONFIG_FULL_PATH, elemConfig) #, encoding='ascii')
示例7: createNewProfiles
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import text [as 别名]
def createNewProfiles(self, baseElem):
for i in range(0, len(self.UniqueCos)):
self.logger.info('New Default Profile element was created.')
newElem = Element('DefaultProfile')
for key, val in self.config['ProfileTags'].iteritems():
e = Element(key)
if e.tag == 'Id' or e.tag == 'ProfileId':
self.logger.info('The id is %s' % str(self.NewCosIds[i]))
e.text = str(self.NewCosIds[i])
elif e.tag == 'CoSId':
self.logger.info('The CoSId is %s' % str(self.UniqueCos[i]))
e.text = self.UniqueCos[i]
else:
e.text = val
newElem._children.append(e)
baseElem._children.append(newElem)
示例8: create_node
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import text [as 别名]
def create_node(tag, property_map, content):
'''新造一个节点
tag:节点标签
property_map:属性及属性值map
content: 节点闭合标签里的文本内容
return 新节点'''
element = Element(tag, property_map)
element.text = content
return element
示例9: __MultiplyRequiredElement
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import text [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
示例10: modify
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import text [as 别名]
def modify(self):
# self.node is an atom entry, see RFC4248 Section 4.1.2
########################################
# content elements RFC4248 Section 4.1.3
contents = self.entry.contents
if not (isinstance(contents, list) or isinstance(contents, tuple)):
contents = [contents]
for content in contents:
el = Element(self.namespace+"content")
# see RFC4248 Section 4.1.3.1 to 4.1.3.3
if content.get('body', None):
type = content.get('type', 'text')
if 'xhtml' in type:
el.attrib['type'] = 'xhtml'
applyAtomText(el, {'text':content.get('body'),
'type': 'xhtml'})
elif 'html' in type:
el.attrib['type'] = 'html'
applyAtomText(el, {'text':content.get('body'),
'type': 'html'})
elif '/plain' in type or type=='text':
el.attrib['type'] = 'text'
applyAtomText(el, {'text':content.get('body'),
'type': 'text'})
elif type.endswith('+xml') or type.endswith('/xml'):
el.attrib['type'] = type
el.text = content.get('body')
else: # base64 encode body
el.attrib['type'] = type
raise NotImplementedError, 'TODO: support base64.'
elif content.get('src', None):
type = content.get('type', 'application/octet-stream')
el.attrib['type'] = type
el.attrib['src'] = content.get('src')
self.node.append(el)
#######################################
# metadata elements RFC4248 Section 4.2
self.modifyMetadata(self.entry, self.node)
# link elements RFC4248 Section 4.2.7
if self.entry.webURL:
self.node.append(createLink(self.entry.webURL, 'alternate'))
# handle enclosures RFC4248 Section 4.2.7.2. The "rel" Attribute
if self.entry.enclosures:
for enclosure in self.entry.enclosures:
el = Element(self.namespace+"link")
el.attrib['rel'] = 'enclosure'
el.attrib['type'] = enclosure.mimetype
el.attrib['length'] = str(len(enclosure))
el.attrib['href'] = enclosure.url
self.node.append(el)
return [self.namespace, xhtmlns]
示例11: draw_name
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import text [as 别名]
def draw_name(self):
""" the name is to the left of the original draw point"""
elem = Element("text")
elem.attrib['x'] = "%f" % (self.startx -4)
elem.attrib['y'] = "%f" % (self.starty-4)
elem.attrib['font-family'] = "Helvetica"
elem.attrib['font-size'] = "%f" % (self.height/1.4)
elem.attrib['text-anchor'] = "end"
elem.text = self.name
return elem
示例12: __call__
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import text [as 别名]
def __call__(self):
s = Element("settings")
f = Element("filters")
f.text = self.context.extra_filters
s.append(f)
p = Element("verp_prefix")
p.text = self.context.verp_prefix
s.append(p)
e_ns = Element("newsletters")
for nl in self.context.objectValues("Newsletter"):
n = Element("newsletter")
n.text = nl.id
e_ns.append(n)
s.append(e_ns)
return tostring(s, 'utf-8')
示例13: new_tree_term
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import text [as 别名]
def new_tree_term(self, termIdentifier, caption, description):
term = Element(NS + "term")
treeTermIdentifier = Element(NS + "termIdentifier")
treeTermIdentifier.text = termIdentifier
term.append(treeTermIdentifier)
treeCaption = Element(NS + "caption")
self.addLangs(treeCaption, caption)
term.append(treeCaption)
treeDesc = Element("description")
self.addLangs(treeDesc, description)
term.append(treeDesc)
return term
示例14: new_tree_term
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import text [as 别名]
def new_tree_term(termIdentifier, caption, description):
term = Element(ns + 'term')
treeTermIdentifier = Element(ns + 'termIdentifier')
treeTermIdentifier.text = termIdentifier
term.append(treeTermIdentifier)
treeCaption = Element('caption')
addLangs(treeCaption, caption)
term.append(treeCaption)
treeDesc = Element('description')
addLangs(treeDesc, description)
term.append(treeDesc)
return term
示例15: add_task
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import text [as 别名]
def add_task(self, taskid, tasktype, folder=None):
"""Add a task to the default xml task sheet
Args:
taskid: unique ID for new task for tracking individual tasks
tasktype: Identifier to track purpose of task
folder: Name of output folder if necessary
Returns:
None
Raises:
None
"""
if tasktype == "processSolr":
if folder == None:
folder = self.solrFolder
root = self.tree.getroot()
newTask = SubElement(root, "task")
newNode = Element("status")
newNode.text = "pending"
newTask.append(newNode)
newNode = Element("taskid")
newNode.text = str(taskid)
newTask.append(newNode)
newNode = Element("directory")
newNode.text = str(folder)
newTask.append(newNode)
self.tree.write("outfile.xml")
elif tasktype == "processTopic":
print "Processing topic modeling data"
if folder == None:
folder = self.topicFolder
else:
print "Unknown task" + tasktype