html.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:slugiot-client 作者: slugiot 项目源码 文件源码
def _xml(self):
        """
        Helper for xml generation. Returns separately:
        - the component attributes
        - the generated xml of the inner components

        Component attributes start with an underscore ('_') and
        do not have a False or None value. The underscore is removed.
        A value of True is replaced with the attribute name.

        Returns:
            tuple: (attributes, components)
        """

        # get the attributes for this component
        # (they start with '_', others may have special meanings)
        attr = []
        for key, value in self.attributes.iteritems():
            if key[:1] != '_':
                continue
            name = key[1:]
            if value is True:
                value = name
            elif value is False or value is None:
                continue
            attr.append((name, value))
        data = self.attributes.get('data', {})
        for key, value in data.iteritems():
            name = 'data-' + key
            value = data[key]
            attr.append((name, value))
        attr.sort()
        fa = ''
        for name, value in attr:
            fa += ' %s="%s"' % (name, xmlescape(value, True))
        # get the xml for the inner components
        co = join([xmlescape(component) for component in
                   self.components])

        return (fa, co)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号