当前位置: 首页>>代码示例>>Python>>正文


Python ElementTree.Element类代码示例

本文整理汇总了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')
开发者ID:ALEXGUOQ,项目名称:FBReader,代码行数:32,代码来源:restore-i18n.py

示例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)
开发者ID:4linux,项目名称:BeavOps-Modulos,代码行数:25,代码来源:JenkinsOps.py

示例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
开发者ID:somaproject,项目名称:doctools,代码行数:25,代码来源:timing.py

示例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
开发者ID:DreamsFuture,项目名称:pytools,代码行数:9,代码来源:xml_op.py

示例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
开发者ID:BackupTheBerlios,项目名称:solipsis-svn,代码行数:10,代码来源:entitycache.py

示例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
开发者ID:somaproject,项目名称:doctools,代码行数:11,代码来源:timing.py

示例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)
开发者ID:DeCarabas,项目名称:mlsfu,代码行数:11,代码来源:Converters.py

示例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
开发者ID:tlamadon,项目名称:markdown2deckjs,代码行数:12,代码来源:mdx_slider.py

示例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
开发者ID:DeCarabas,项目名称:feedarchive,代码行数:52,代码来源:rsswriter.py

示例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
开发者ID:avoinea,项目名称:stiamro,代码行数:13,代码来源:export.py

示例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
开发者ID:DeCarabas,项目名称:feedarchive,代码行数:51,代码来源:feedwriter.py

示例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
开发者ID:Huskyeder,项目名称:augustus,代码行数:14,代码来源:any_writer.py

示例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
开发者ID:avoinea,项目名称:stiamro,代码行数:14,代码来源:export.py

示例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()
开发者ID:visualtecnologicc,项目名称:mediastream,代码行数:15,代码来源:utils.py

示例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))
开发者ID:IMAGE-ET,项目名称:dicomimport,代码行数:15,代码来源:treemodel.py


注:本文中的elementtree.ElementTree.Element类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。