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


Python etree.ElementBase方法代码示例

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


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

示例1: insert_errors

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import ElementBase [as 别名]
def insert_errors(
    el,
    errors,
    form_id=None,
    form_index=None,
    error_class="error",
    error_creator=default_error_creator,
    ):
    el = _find_form(el, form_id=form_id, form_index=form_index)
    for name, error in errors.items():
        if error is None:
            continue
        for error_el, message in _find_elements_for_name(el, name, error):
            assert isinstance(message, (basestring, type(None), ElementBase)), (
                "Bad message: %r" % message)
            _insert_error(error_el, message, error_class, error_creator) 
开发者ID:JFox,项目名称:aws-lambda-lxml,代码行数:18,代码来源:formfill.py

示例2: __call__

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import ElementBase [as 别名]
def __call__(self, el, is_block, message):
        error_el = el.makeelement(self.error_container_tag)
        if self.error_message_class:
            error_el.set('class', self.error_message_class)
        if is_block and self.error_block_class:
            error_el.set('class', error_el.get('class', '')+' '+self.error_block_class)
        if message is None or message == '':
            message = self.default_message
        if isinstance(message, ElementBase):
            error_el.append(message)
        else:
            assert isinstance(message, basestring), (
                "Bad message; should be a string or element: %r" % message)
            error_el.text = message or self.default_message
        if is_block and self.block_inside:
            if self.insert_before:
                error_el.tail = el.text
                el.text = None
                el.insert(0, error_el)
            else:
                el.append(error_el)
        else:
            parent = el.getparent()
            pos = parent.index(el)
            if self.insert_before:
                parent.insert(pos, error_el)
            else:
                error_el.tail = el.tail
                el.tail = None
                parent.insert(pos+1, error_el) 
开发者ID:JFox,项目名称:aws-lambda-lxml,代码行数:32,代码来源:formfill.py

示例3: GenerateAnyInfos

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import ElementBase [as 别名]
def GenerateAnyInfos(infos):

    def GetTextElement(tree):
        if infos["namespace"][0] == "##any":
            return tree.xpath("p")[0]
        return tree.xpath("ns:p", namespaces={"ns": infos["namespace"][0]})[0]

    def ExtractAny(tree):
        return GetTextElement(tree).text

    def GenerateAny(tree, value):
        GetTextElement(tree).text = etree.CDATA(value)

    def InitialAny():
        if infos["namespace"][0] == "##any":
            element_name = "p"
        else:
            element_name = "{%s}p" % infos["namespace"][0]
        p = etree.Element(element_name)
        p.text = etree.CDATA("")
        return p

    return {
        "type": COMPLEXTYPE,
        "extract": ExtractAny,
        "generate": GenerateAny,
        "initial": InitialAny,
        "check": lambda x: isinstance(x, (string_types, etree.ElementBase))
    } 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:31,代码来源:xmlclass.py


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