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


Python E.img方法代码示例

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


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

示例1: _subvalue_to_html

# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import img [as 别名]
def _subvalue_to_html(cls, value):
    if issubclass(cls.type, AnyUri):
        href = getattr(value, 'href', None)
        if href is None: # this is not a AnyUri.Value instance.
            href = value
            text = getattr(cls.type.Attributes, 'text', None)
            content = None

        else:
            text = getattr(value, 'text', None)
            if text is None:
                text = getattr(cls.type.Attributes, 'text', None)

            content = getattr(value, 'content', None)

        if issubclass(cls.type, ImageUri):
            retval = E.img(src=href)

            if text is not None:
                retval.attrib['alt'] = text
            # content is ignored with ImageUri.

        else:
            retval = E.a(href=href)
            retval.text = text
            if content is not None:
                retval.append(content)

    else:
        retval = cls.type.to_string(value)

    return retval
开发者ID:drowolath,项目名称:spyne,代码行数:34,代码来源:html.py

示例2: replace_youtube_videos_with_links

# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import img [as 别名]
    def replace_youtube_videos_with_links(self, doc):
        """Replace any iframe elements found with a link to the src and a
        placeholder image from youtube"""

        def get_yt_id(src):
            """Return the youtube video id"""
            split_src = src.split("/")
            if "embed" in split_src:
                yt_id_index = split_src.index("embed") + 1
                return split_src[yt_id_index]

        iframes = doc.xpath("//iframe")

        for iframe in iframes:
            src = iframe.get("src")
            yt_id = get_yt_id(src)
            if not yt_id:
                continue
            else:
                yt_img = "https://img.youtube.com/vi/{0}/0.jpg".format(yt_id)
                yt_href = "https://youtu.be/{0}".format(yt_id)
                yt_link = E.a(
                    E.img(
                        src=yt_img,
                        width="480",
                        height="360",
                    ),
                    href=yt_href,
                    target="_blank",
                )
                parent = iframe.getparent()
                parent.replace(iframe, yt_link)
开发者ID:EU-OSHA,项目名称:osha.theme,代码行数:34,代码来源:cssselect.py

示例3: imageuri_to_parent

# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import img [as 别名]
    def imageuri_to_parent(self, ctx, cls, inst, parent, name, **kwargs):
        # with ImageUri, content is ignored.
        href = getattr(inst, 'href', None)
        if href is None: # this is not a AnyUri.Value instance.
            href = inst
            text = getattr(cls.Attributes, 'text', None)

        else:
            text = getattr(inst, 'text', None)
            if text is None:
                text = getattr(cls.Attributes, 'text', None)

        retval = E.img(src=href)
        if text is not None:
            retval.attrib['alt'] = text
        parent.write(retval)
开发者ID:jpunwin,项目名称:spyne,代码行数:18,代码来源:_base.py

示例4: serialize_complex_model

# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import img [as 别名]
    def serialize_complex_model(self, cls, value, locale):
        sti = None
        fti = cls.get_flat_type_info(cls)
        is_array = False

        first_child = iter(fti.values()).next()
        if len(fti) == 1:
            fti = first_child.get_flat_type_info(first_child)
            first_child_2 = iter(fti.values()).next()

            if len(fti) == 1 and first_child_2.Attributes.max_occurs > 1:
                if issubclass(first_child_2, ComplexModelBase):
                    sti = first_child_2.get_simple_type_info(first_child_2)
                is_array = True

            else:
                if issubclass(first_child, ComplexModelBase):
                    sti = first_child.get_simple_type_info(first_child)
            
            value = value[0]

        else:
            raise NotImplementedError("Can only serialize single return types")

        tr = {}
        if self.row_class is not None:
            tr['class'] = self.row_class

        td = {}
        if self.cell_class is not None:
            td['class'] = self.cell_class

        th = {}
        if self.header_cell_class is not None:
            th['class'] = self.header_cell_class

        class_name = first_child.get_type_name()
        if sti is None:
            if self.field_name_attr is not None:
                td[self.field_name_attr] = class_name

            if is_array:
                for val in value:
                    yield E.tr(E.td(first_child_2.to_string(val), **td), **tr)
            else:
                yield E.tr(E.td(first_child_2.to_string(value), **td), **tr)

        else:
            for k, v in sti.items():
                row = E.tr(**tr)
                subvalue = value
                for p in v.path:
                    subvalue = getattr(subvalue, p, None)

                if subvalue is None:
                    if v.type.Attributes.min_occurs == 0:
                        continue
                    else:
                        subvalue = ""
                else:
                    subvalue = v.type.to_string(subvalue)

                    text = getattr(v.type.Attributes,'text', None)
                    if issubclass(v.type, ImageUri):
                        subvalue = E.img(src=subvalue)
                        if text is not None:
                            subvalue.attrib['alt']=text

                    elif issubclass(v.type, AnyUri):
                        if text is None:
                            text = subvalue
                        subvalue = E.a(text, href=subvalue)

                if self.produce_header:
                    header_text = translate(v.type, locale, k)
                    if self.field_name_attr is None:
                        row.append(E.th(header_text, **th))
                    else:
                        th[self.field_name_attr] = k
                        row.append(E.th(header_text, **th))

                if self.field_name_attr is None:
                    row.append(E.td(subvalue, **td))

                else:
                    td[self.field_name_attr] = k
                    row.append(E.td(subvalue, **td))

                yield row
开发者ID:66ru,项目名称:spyne,代码行数:91,代码来源:html.py


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