Ejemplo n.º 1
0
def repr_html(tbl, index_header=None, representation=unicode, caption=None, encoding='utf-8'):
    if index_header is None:
        index_header = repr_index_header  # use default
    if index_header:
        indexed_header = [u'%s|%s' % (i, f) for (i, f) in enumerate(petl.util.header(tbl))]
        target = petl.transform.setheader(tbl, indexed_header)
    else:
        target = tbl
    buf = StringSource()
    if representation is unicode:
        touhtml(target, buf, caption=caption, encoding=encoding)
    else:
        tohtml(target, buf, representation=representation, caption=caption)
    return buf.getvalue()
Ejemplo n.º 2
0
def repr_html(tbl,
              limit=None,
              index_header=None,
              representation=unicode,
              caption=None,
              encoding='utf-8'):

    # add column indices to header?
    if index_header is None:
        index_header = repr_index_header  # use default
    if index_header:
        indexed_header = [
            u'%s|%s' % (i, f) for (i, f) in enumerate(petl.util.header(tbl))
        ]
        target = petl.transform.setheader(tbl, indexed_header)
    else:
        target = tbl

    # limit number of rows output?
    # N.B., limit is max number of data rows (not including header)
    if limit is None:
        # use default
        limit = repr_html_limit

    overflow = False
    if limit > 0:
        # try reading one more than the limit, to see if there are more rows
        target = list(islice(target, 0, limit + 2))
        if len(target) > limit + 1:
            overflow = True
            target = target[:-1]
    else:
        # render the entire table
        pass

    # write to html string
    buf = StringSource()
    if representation is unicode:
        touhtml(target, buf, caption=caption, encoding=encoding)
    else:
        tohtml(target, buf, representation=representation, caption=caption)

    if overflow:
        return buf.getvalue() + u'<p><strong>...</strong></p>'
    else:
        return buf.getvalue()
Ejemplo n.º 3
0
def repr_html(tbl,
              index_header=None,
              representation=unicode,
              caption=None,
              encoding='utf-8'):
    if index_header is None:
        index_header = repr_index_header  # use default
    if index_header:
        indexed_header = [
            u'%s|%s' % (i, f) for (i, f) in enumerate(petl.util.header(tbl))
        ]
        target = petl.transform.setheader(tbl, indexed_header)
    else:
        target = tbl
    buf = StringSource()
    if representation is unicode:
        touhtml(target, buf, caption=caption, encoding=encoding)
    else:
        tohtml(target, buf, representation=representation, caption=caption)
    return buf.getvalue()
Ejemplo n.º 4
0
def repr_html(tbl, limit=None, index_header=None, representation=unicode,
              caption=None, encoding='utf-8'):

    # add column indices to header?
    if index_header is None:
        index_header = repr_index_header  # use default
    if index_header:
        indexed_header = [u'%s|%s' % (i, f) for (i, f) in enumerate(petl.util.header(tbl))]
        target = petl.transform.setheader(tbl, indexed_header)
    else:
        target = tbl

    # limit number of rows output?
    # N.B., limit is max number of data rows (not including header)
    if limit is None:
        # use default
        limit = repr_html_limit

    overflow = False
    if limit > 0:
        # try reading one more than the limit, to see if there are more rows
        target = list(islice(target, 0, limit+2))
        if len(target) > limit+1:
            overflow = True
            target = target[:-1]
    else:
        # render the entire table
        pass

    # write to html string
    buf = StringSource()
    if representation is unicode:
        touhtml(target, buf, caption=caption, encoding=encoding)
    else:
        tohtml(target, buf, representation=representation, caption=caption)

    if overflow:
        return buf.getvalue() + u'<p><strong>...</strong></p>'
    else:
        return buf.getvalue()