當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。