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


Python Element.attrib['uri']方法代码示例

本文整理汇总了Python中elementtree.ElementTree.Element.attrib['uri']方法的典型用法代码示例。如果您正苦于以下问题:Python Element.attrib['uri']方法的具体用法?Python Element.attrib['uri']怎么用?Python Element.attrib['uri']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在elementtree.ElementTree.Element的用法示例。


在下文中一共展示了Element.attrib['uri']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: modify

# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import attrib['uri'] [as 别名]
    def modify(self):
        assert self.feed.feedURL, 'feedURL must be provided' 
        assert self.feed.webURL, 'webURL must be provided'
        assert self.feed.baseURL, 'baseURL must be provided'
        assert self.feed.uid, 'uid must be provided' 

        ####################################
        # feed element RFC4248 Section 4.1.1
        root = self.tree.getroot()
        root.attrib['{%s}base' % xmlns] = self.feed.baseURL

        #############################################
        # let metadata appear before all feedentries.
        self.modifyMetadata(self.feed, root)    
        
        #########################################
        # generator element RFC4248 Section 4.2.4
        gen = self.feed.generator
        assert(isinstance(gen, dict), 'generator is provided, but not a '
                                      'dict instance')
        el = Element(self.namespace+'generator')
        el.text = cgi.escape(gen.get('text', 'cornerstone.feed'))
        if gen.get('uri', None):
            el.attrib['uri'] = gen.get('uri')
        if gen.get('version', None):
            el.attrib['version'] = gen.get('version')
        root.append(el)

        # icon element RFC4248 Section 4.2.5        
        if self.feed.iconURL:
            el = Element(self.namespace+'icon')
            el.text = self.feed.iconURL
            root.append(el)

        # link elements RFC4248 Section 4.2.7
        if self.feed.feedURL:
            root.append(createLink(self.feed.feedURL, 'self'))

        if self.feed.webURL:
            root.append(createLink(self.feed.feedURL, 'alternate'))                    

        # logo element RFC4248 Section 4.2.8
        if self.feed.imageURL:
            el = Element(self.namespace+'logo')
            el.text = self.feed.imageURL
            root.append(el)         

        #####################################
        # entry element RFC4248 Section 4.1.2
        producer = getUtility(IAtomFeedEntrySkeletonProducer)
        namespaces = Set([self.namespace, xmlns])
        for entry in self.feed.getFeedEntries():
            node = producer()
            named_modifiers = list(getAdapters((entry, node), 
                                               IFeedEntryModifier))
            named_modifiers.sort(key=operator.itemgetter(0))
            for name, modifier in named_modifiers:
                ns = modifier.modify()
                namespaces.update(ns)
            root.append(node)


        return namespaces
开发者ID:bluedynamics,项目名称:cornerstone.feed.core,代码行数:65,代码来源:modifiers.py


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