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


Python builder.E类代码示例

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


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

示例1: _gen_header

    def _gen_header(self, ctx, cls, name, parent):
        logger.debug("Generate header for %r", cls)

        with parent.element('thead'):
            with parent.element('tr'):
                th_attrs = {}
                if self.field_name_attr is not None:
                    th_attrs[self.field_name_attr] = name

                if issubclass(cls, ComplexModelBase):
                    fti = cls.get_flat_type_info(cls)
                    if self.field_name_attr is None:
                        for k, v in fti.items():
                            attr = get_cls_attrs(self, v)
                            if attr.exc:
                                continue
                            header_name = self.trc(v, ctx.locale, k)
                            parent.write(E.th(header_name, **th_attrs))
                    else:
                        for k, v in fti.items():
                            attr = get_cls_attrs(self, v)
                            if attr.exc:
                                continue
                            th_attrs[self.field_name_attr] = k
                            header_name = self.trc(v, ctx.locale, k)
                            parent.write(E.th(header_name, **th_attrs))

                else:
                    if self.field_name_attr is not None:
                        th_attrs[self.field_name_attr] = name
                    header_name = self.trc(cls, ctx.locale, name)
                    parent.write(E.th(header_name, **th_attrs))

                self.extend_header_row(ctx, cls, name, parent)
开发者ID:DmitriyMoseev,项目名称:spyne,代码行数:34,代码来源:table.py

示例2: replace_youtube_videos_with_links

    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,代码行数:32,代码来源:cssselect.py

示例3: _gen_header

    def _gen_header(self, ctx, cls, name, parent):
        with parent.element('thead'):
            with parent.element('tr'):
                th_attrs = {}
                if self.field_name_attr is not None:
                    th_attrs[self.field_name_attr] = name

                # fti is none when the type inside Array is not a ComplexModel.
                if issubclass(cls, ComplexModelBase):
                    fti = cls.get_flat_type_info(cls)
                    if self.field_name_attr is None:
                        for k, v in fti.items():
                            if getattr(v.Attributes, 'exc_html', None):
                                continue
                            header_name = self.translate(v, ctx.locale, k)
                            parent.write(E.th(header_name, **th_attrs))
                    else:
                        for k, v in fti.items():
                            if getattr(v.Attributes, 'exc_html', None):
                                continue
                            th_attrs[self.field_name_attr] = k
                            header_name = self.translate(v, ctx.locale, k)
                            parent.write(E.th(header_name, **th_attrs))

                else:
                    if self.field_name_attr is not None:
                        th_attrs[self.field_name_attr] = name
                    header_name = self.translate(cls, ctx.locale, name)
                    parent.write(E.th(header_name, **th_attrs))

                self.extend_header_row(ctx, cls, name, parent)
开发者ID:lanwan,项目名称:spyne,代码行数:31,代码来源:table.py

示例4: _subvalue_to_html

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,代码行数:32,代码来源:html.py

示例5: _gen_thead

    def _gen_thead(self, ctx, cls, parent, name):
        logger.debug("Generate header for %r", cls)

        with parent.element('thead'):
            with parent.element('tr'):
                if issubclass(cls, ComplexModelBase):
                    fti = self.sort_fields(cls)
                    for k, v in fti:
                        cls_attr = self.get_cls_attrs(v)
                        if cls_attr.exc:
                            continue

                        th_attrs = {}
                        self.add_field_attrs(th_attrs, k, cls)

                        if cls_attr.hidden:
                            self.add_style(th_attrs, 'display:None')

                        header_name = self.trc(v, ctx.locale, k)
                        parent.write(E.th(header_name, **th_attrs))

                    m = cls.Attributes.methods
                    if m is not None and len(m) > 0:
                        th_attrs = {'class': 'mrpc-cell'}
                        parent.write(E.th(**th_attrs))

                else:
                    th_attrs = {}
                    self.add_field_attrs(th_attrs, name, cls)

                    header_name = self.trc(cls, ctx.locale, name)

                    parent.write(E.th(header_name, **th_attrs))

                self.extend_header_row(ctx, cls, parent, name)
开发者ID:knoxsp,项目名称:spyne,代码行数:35,代码来源:column.py

示例6: _gen_thead

    def _gen_thead(self, ctx, cls, name, parent):
        logger.debug("Generate header for %r", cls)

        with parent.element('thead'):
            with parent.element('tr'):
                if issubclass(cls, ComplexModelBase):
                    fti = self.sort_fields(cls)
                    for k, v in fti:
                        attr = self.get_cls_attrs(v)
                        if attr.exc:
                            continue

                        th_attrs = {}
                        if self.field_name_attr is not None:
                            th_attrs[self.field_name_attr] = k
                        if attr.hidden:
                            th_attrs['style'] = 'display:None'

                        header_name = self.trc(v, ctx.locale, k)
                        parent.write(E.th(header_name, **th_attrs))

                    m = cls.Attributes.methods
                    if m is not None and len(m) > 0:
                        parent.write(E.th())

                else:
                    th_attrs = {}
                    if self.field_name_attr is not None:
                        th_attrs[self.field_name_attr] = name
                    header_name = self.trc(cls, ctx.locale, name)
                    parent.write(E.th(header_name, **th_attrs))

                self.extend_header_row(ctx, cls, parent, name)
开发者ID:mahdi-b,项目名称:spyne,代码行数:33,代码来源:table.py

示例7: model_base_to_parent

 def model_base_to_parent(self, ctx, cls, inst, parent, name,  tr_child=False, **kwargs):
     attrs = {}
     if self.field_name_attr is not None:
         attrs = {self.field_name_attr: name}
     retval = E.td(self.to_string(cls, inst), **attrs)
     if not tr_child:
         retval = E.tr(retval)
     parent.write(retval)
开发者ID:jpunwin,项目名称:spyne,代码行数:8,代码来源:table.py

示例8: model_base_to_parent

    def model_base_to_parent(self, ctx, cls, inst, parent, name, from_arr=False, **kwargs):
        if from_arr:
            td_attrib = {}
            if False and self.field_name_attr:
                td_attrib[self.field_name_attr] = name

            parent.write(E.tr(E.td(self.to_unicode(cls, inst), **td_attrib)))
        else:
            parent.write(self.to_unicode(cls, inst))
开发者ID:DmitriyMoseev,项目名称:spyne,代码行数:9,代码来源:table.py

示例9: add_footer

 def add_footer(self):
     self.elements.content.append(
         E.footer(
             E.a(self.T('Wuff Signal'),
                 href=self.handler.reverse_url('textshow.index')),
             ' ',
             E.a(self.T('About'),
                 href=self.handler.reverse_url('textshow.about'))
         )
     )
开发者ID:chfoo,项目名称:wuff,代码行数:10,代码来源:textshow.py

示例10: _build_html_header

    def _build_html_header(self):
        '''Add banner and account links'''
        header = self.elements.header
        index_url = self.links.get(
            'index', self.handler.reverse_url('index'))

        header.append(E.div(
            E.a(self.meta.app_name, href=index_url, id='logo-link'),
            id='logo-wrapper'
        ))
开发者ID:chfoo,项目名称:wuff,代码行数:10,代码来源:html.py

示例11: _build_html_footer

 def _build_html_footer(self):
     '''Adds the site visual footer links'''
     self.elements.footer.extend([
         E.nav(
             E.a(self.handler.application.settings['application_name'],
                 href=self.handler.reverse_url('index')),
             ' ',
             E.a(self.T('About'),
                 href=self.handler.reverse_url('index.about'))
         )
     ])
开发者ID:chfoo,项目名称:wuff,代码行数:11,代码来源:html.py

示例12: google_fonts

def google_fonts(font_names, standalone=False):
    GOOGLE_API_KEY = "AIzaSyCXe6WAu7i4CYL9ee-RFNZirObwT4zJyqI"
    url = "https://www.googleapis.com/webfonts/v1/webfonts"
    https_proxy = os.environ.get("https_proxy")
    if https_proxy is not None:   
        proxy_support = urllib2.ProxyHandler({"https": https_proxy})
        opener = urllib2.build_opener(proxy_support)
        urllib2.install_opener(opener)
    info = json.loads(urllib2.urlopen(url + "?key=" + GOOGLE_API_KEY).read())
    if standalone:
        css = ""
        css_template = \
"""
@font-face {{
  font-family: {name!r};
  font-style: {style};
  font-weight: {weight}; 
  src: url({file!r});
 }}
"""
        for font_name in font_names:
            for font_info in info["items"]:
                if font_info["family"] == font_name:
                    variants = font_info["variants"]
                    files = font_info["files"]
                    for variant in variants:
                        subinfo("downloading {0}".format(font_name + " " + variant))
                        ttf_bytes = urllib.urlopen(files[variant]).read()
                        ttf_path = Path("fonts") / (font_name + " " + variant + ".ttf")
                        ttf_file = (ARTDOC / ttf_path).open("wb")
                        ttf_file.write(ttf_bytes)
                        ttf_file.close()
                        style = "normal" if "italic" not in variant else "italic"
                        weight = re.match("[0-9]*", variant).group() or "400"
                        css += css_template.format(name=font_name,  
                                                   style=style,
                                                   weight=weight,
                                                   file=str(Path("..") / ttf_path))
                    break
        (ARTDOC / "css" / "fonts.css").open("wb").write(css)
        return [HTML.link(rel="stylesheet", href=".artdoc/css/fonts.css")]
    else:
        families = []
        for font_name in font_names:
            for font_info in info["items"]:
                if font_info["family"] == font_name:
                    family = font_name.replace(" ", "+") + ":"
                    variants = font_info["variants"]
                    family += ",".join(variants)
                    families.append(family)
                    break
        family = "|".join(families) + "&subset=latin,latin-ext"
        url = "http://fonts.googleapis.com/css?family=" + family
        return [HTML.link(rel="stylesheet", href=url)]
开发者ID:boisgera,项目名称:artdoc,代码行数:54,代码来源:__init__.py

示例13: build_title_content

    def build_title_content(self):
        self.elements.content.extend([
            E.p('''Wuff Signal allows you to share messages without revealing
            the contents of your message. It lossily scrambles your message
            and shows them as points on the page. These points are called
            Signals.
            '''),
            E.p('You can view a ', E.a('complete list of recent Signals',
                href=self.handler.reverse_url('textshow.recent')), '.'),
        ])

        self.add_footer()
开发者ID:chfoo,项目名称:wuff,代码行数:12,代码来源:textshow.py

示例14: model_base_to_parent

    def model_base_to_parent(self, ctx, cls, inst, parent, name,
                                                      from_arr=False, **kwargs):
        if from_arr:
            td_attrs = {}
            #if self.field_name_attr:
            #    td_attrs[self.field_name_attr] = name
            parent.write(E.tr(
                E.td(
                    self.to_string(cls, inst),
                    **td_attrs
                )
            ))

        else:
            parent.write(self.to_string(cls, inst))
开发者ID:lanwan,项目名称:spyne,代码行数:15,代码来源:table.py

示例15: model_base_to_parent

    def model_base_to_parent(self, ctx, cls, inst, parent, name,
                                                      from_arr=False, **kwargs):
        inst_str = ''
        if inst is not None:
            inst_str = self.to_unicode(cls, inst)

        if from_arr:
            td_attrs = {}

            self.add_field_attrs(td_attrs, name, cls)

            parent.write(E.tr(E.td(inst_str, **td_attrs)))

        else:
            parent.write(inst_str)
开发者ID:ashleysommer,项目名称:spyne,代码行数:15,代码来源:column.py


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