Example #1
0
def object_xml_repr(value, host = None, depth = 1, memo = None):
    values = [value]
    if hasattr(value, '__class__'):
        if hasattr(value.__class__, '__mro__'):
            values.extend(value.__class__.__mro__)
    elif hasattr(value, '__bases__'):
        considers = [value]
        while considers:
            consider = considers.pop(0)
            values.append(consider)
            considers.extend(consider.__bases__)
    return tags.div(
        tags.p(
            tags.b(repr(value)),
            tags.ol(    # for prettiness
                hasattr(value, '__dict__') and (
                    tags.table(
                        {'class': 'definition'},
                        (
                            tags.tr(
                                tags.th(xml_repr(heading, host, depth - 1, memo)),
                                tags.td(xml_repr(row, host, depth - 1, memo)),
                            )
                            for heading, row in sorted(vars(value).items())
                        )
                    )
                ) or ''
            )
        ) for value in values[::-1]
    )
Example #2
0
def dict_xml_repr(value, host = None, depth = 1, memo = None):
    return tags.p(
        tags.b(name_repr(value, memo)),
        tags.ol(    # for prettiness
            tags.table(
                {'class': 'definition'},
                (
                    tags.tr(
                        tags.th(xml_repr(heading, host, depth - 1, memo)),
                        tags.td(xml_repr(row, host, depth - 1, memo)),
                    )
                    for heading, row in sorted(value.items())
                )
            )
        )
    )