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


Python E.tr方法代码示例

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


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

示例1: build_title_content

# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import tr [as 别名]
    def build_title_content(self):
        content = E.table(
            E.tr(
                E.th(self.T('Time')),
                E.th(self.T('Message')),
                E.th(self.T('Count'))
            )
        )

        for message in self._messages:
            message_dict = dict(message.data_iter)

            row = E.tr(
                E.td(self.handler.locale.format_date(message.datetime),
                    rowspan=str(len(message_dict)))
            )

            for key, count in sorted(message_dict.items()):
                row.extend([E.td(to_hex(key)), E.td(str(count))])
                content.append(row)
                row = E.tr()

        self.elements.content.append(content)

        if self._pager_next:
            self.elements.content.append(
                E.a(self.T('Older'), href='?before=' + str(self._pager_next))
            )

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

示例2: serialize_complex_model

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

        first_child = iter(fti.values()).next()
        if len(fti) == 1:
            fti = first_child.get_flat_type_info(first_child)
            first_child = iter(fti.values()).next()
            if len(fti) == 1 and first_child.Attributes.max_occurs > 1:
                if issubclass(first_child, ComplexModelBase):
                    sti = first_child.get_simple_type_info(first_child)
                value = value[0]
            else:
                raise Exception("Can only serialize Array(...) types")
        else:
            raise Exception("Can only serialize single Array(...) return types")

        header_row = E.tr()
        class_name = first_child.get_type_name()
        if sti is None:
            header_row.append(E.th(class_name))
        else:
            if self.field_name_attr is None:
                for k, v in sti.items():
                    header_row.append(E.th(k))
            else:
                for k, v in sti.items():
                    header_row.append(E.th(k,
                                        **{self.field_name_attr: k}))

        yield header_row

        if sti is None:
            if self.field_name_attr is None:
                for val in value:
                    yield E.tr(E.td(first_child.to_string(val)), )
            else:
                for val in value:
                    yield E.tr(E.td(first_child.to_string(val)),
                                           **{self.field_name_attr: class_name})

        else:
            for val in value:
                row = E.tr()
                print val
                for k, v in sti.items():
                    subvalue = val
                    for p in v.path:
                        subvalue = getattr(subvalue, p, "`%s`" % k)
                    if self.field_name_attr is None:
                        row.append(E.td(v.type.to_string(subvalue)))
                    else:
                        row.append(E.td(v.type.to_string(subvalue),
                                                   **{self.field_name_attr: k}))
                yield row
开发者ID:surajbarkale,项目名称:rpclib,代码行数:57,代码来源:html.py

示例3: model_base_to_parent

# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import tr [as 别名]
 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,代码行数:10,代码来源:table.py

示例4: model_base_to_parent

# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import tr [as 别名]
    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,代码行数:11,代码来源:table.py

示例5: model_base_to_parent

# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import tr [as 别名]
    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,代码行数:17,代码来源:column.py

示例6: model_base_to_parent

# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import tr [as 别名]
    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,代码行数:17,代码来源:table.py

示例7: serialize_complex_model

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

        if len(fti) == 1:
            first_child, = fti.values()

            try:
                fti = first_child.get_flat_type_info(first_child)
            except AttributeError:
                raise NotImplementedError("Can only serialize complex return types")

            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:
                        break

                if subvalue is None:
                    if v.type.Attributes.min_occurs == 0:
                        continue
                    else:
                        subvalue = ""
                else:
                    subvalue = _subvalue_to_html(v, 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:drowolath,项目名称:spyne,代码行数:87,代码来源:html.py

示例8: serialize_complex_model

# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import tr [as 别名]
    def serialize_complex_model(self, cls, value, locale):
        fti = cls.get_flat_type_info(cls)
        if cls.Attributes._wrapper and not issubclass(cls, Array):
            if len(fti) > 1:
                raise NotImplementedError("Can only serialize one array at a time")
            cls, = cls._type_info.values()
            value, = value

        fti = cls.get_flat_type_info(cls)
        first_child = iter(fti.values()).next()
        if not issubclass(cls, Array):
            raise NotImplementedError("Can only serialize Array(...) types")

        sti = None
        if issubclass(first_child, ComplexModelBase):
            sti = first_child.get_simple_type_info(first_child)

        # Here, sti can be None when the return type does not have _type_info
        # attribute
        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

        class_name = first_child.get_type_name()
        if self.produce_header:
            header_row = E.tr(**tr)

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

            # sti is none when the type inside Array is not a ComplexModel.
            if sti is None:
                header_row.append(E.th(class_name, **th))

            else:
                if self.field_name_attr is None:
                    for k, v in sti.items():
                        header_name = translate(v.type, locale, k)
                        header_row.append(E.th(header_name, **th))

                else:
                    for k, v in sti.items():
                        th[self.field_name_attr] = k
                        header_name = translate(v.type, locale, k)
                        header_row.append(E.th(header_name, **th))

            yield header_row

        if value is None:
            raise StopIteration()

        if sti is None:
            if self.field_name_attr is None:
                for val in value:
                    yield E.tr(E.td(self.to_string(first_child, val),**td),**tr)

            else:
                for val in value:
                    td[self.field_name_attr] = class_name
                    yield E.tr(E.td(self.to_string(first_child, val),**td),**tr)

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

                    if subvalue is None:
                        subvalue = ""
                    else:
                        subvalue = _subvalue_to_html(self, v, subvalue)

                    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:harshil07,项目名称:spyne,代码行数:88,代码来源:html.py

示例9: subserialize

# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import tr [as 别名]
    def subserialize(self, ctx, cls, inst, parent, ns=None, name=None):
        attrs = {}
        if self.table_name_attr is not None:
            attrs[self.table_name_attr] = name

        locale = ctx.locale
        with parent.element('table', attrs):
            fti = None
            if issubclass(cls, ComplexModelBase):
                fti = cls.get_flat_type_info(cls)
            if self.produce_header:
                with parent.element('thead'):
                    header_row = E.tr()

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

                    # fti is none when the type inside Array is not a ComplexModel.
                    if fti is None:
                        if self.field_name_attr is not None:
                            th[self.field_name_attr] = name
                        header_name = self.translate(cls, ctx.locale, name)
                        header_row.append(E.th(header_name, **th))

                    else:
                        if self.field_name_attr is None:
                            for k, v in fti.items():
                                header_name = self.translate(v, ctx.locale, k)
                                header_row.append(E.th(header_name, **th))

                        else:
                            for k, v in fti.items():
                                th[self.field_name_attr] = k
                                header_name = self.translate(v, ctx.locale, k)
                                header_row.append(E.th(header_name, **th))

                    parent.write(header_row)

            with parent.element('tbody'):
                if cls.Attributes.max_occurs > 1:
                    ret = self.array_to_parent(ctx, cls, inst, parent, name)
                    if isgenerator(ret):
                        try:
                            while True:
                                y = (yield)
                                ret.send(y)
                        except Break as b:
                            try:
                                ret.throw(b)
                            except StopIteration:
                                pass

                else:
                    with parent.element('tr'):
                        ret = self.to_parent(ctx, cls, inst, parent, name)
                        if isgenerator(ret):
                            try:
                                while True:
                                    y = (yield)
                                    ret.send(y)
                            except Break as b:
                                try:
                                    ret.throw(b)
                                except StopIteration:
                                    pass
开发者ID:jpunwin,项目名称:spyne,代码行数:68,代码来源:table.py


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