示例#1
0
def test_make_wrappable():
    assert '<wbr>' in formatter.make_wrappable('x'*1000)
    # I'm just going to test that this doesn't excede the stack limit:
    formatter.make_wrappable(';'*2000)
    assert (formatter.make_wrappable('this that the other')
            == 'this that the other')
    assert (formatter.make_wrappable('this that ' + ('x'*50) + ';' + ('y'*50) + ' and the other')
            == 'this that '+('x'*50) + ';<wbr>' + ('y'*50) + ' and the other')
def test_make_wrappable():
    assert "<wbr>" in formatter.make_wrappable("x" * 1000)
    # I'm just going to test that this doesn't excede the stack limit:
    formatter.make_wrappable(";" * 2000)
    assert formatter.make_wrappable("this that the other") == "this that the other"
    assert (
        formatter.make_wrappable("this that " + ("x" * 50) + ";" + ("y" * 50) + " and the other")
        == "this that " + ("x" * 50) + ";<wbr>" + ("y" * 50) + " and the other"
    )
示例#3
0
def test_make_wrappable():
    assert '<wbr>' in formatter.make_wrappable('x' * 1000)
    # I'm just going to test that this doesn't excede the stack limit:
    formatter.make_wrappable(';' * 2000)
    assert (formatter.make_wrappable('this that the other') ==
            'this that the other')
    assert (formatter.make_wrappable('this that ' + ('x' * 50) + ';' +
                                     ('y' * 50) +
                                     ' and the other') == 'this that ' +
            ('x' * 50) + ';<wbr>' + ('y' * 50) + ' and the other')
示例#4
0
def make_table(items):
    if isinstance(items, dict):
        items = list(items.items())
        items.sort()
    rows = []
    i = 0
    for name, value in items:
        i += 1
        out = StringIO()
        try:
            pprint.pprint(value, out)
        except Exception as e:
            print('Error: %s' % e, file=out)
        value = html_quote(out.getvalue())
        if len(value) > 100:
            # @@: This can actually break the HTML :(
            # should I truncate before quoting?
            orig_value = value
            value = value[:100]
            value += '<a class="switch_source" style="background-color: #999" href="#" onclick="return expandLong(this)">...</a>'
            value += '<span style="display: none">%s</span>' % orig_value[100:]
        value = formatter.make_wrappable(value)
        if i % 2:
            attr = ' class="even"'
        else:
            attr = ' class="odd"'
        rows.append('<tr%s style="vertical-align: top;"><td>'
                    '<b>%s</b></td><td style="overflow: auto">%s<td></tr>'
                    % (attr, html_quote(name),
                       preserve_whitespace(value, quote=False)))
    return '<table>%s</table>' % (
        '\n'.join(rows))
示例#5
0
def make_table(items):
    if isinstance(items, dict):
        items = items.items()
        items.sort()
    rows = []
    i = 0
    for name, value in items:
        i += 1
        out = StringIO()
        try:
            pprint.pprint(value, out)
        except Exception as e:
            print('Error: %s' % e, file=out)
        value = html_quote(out.getvalue())
        if len(value) > 100:
            # @@: This can actually break the HTML :(
            # should I truncate before quoting?
            orig_value = value
            value = value[:100]
            value += '<a class="switch_source" style="background-color: #999" href="#" onclick="return expandLong(this)">...</a>'
            value += '<span style="display: none">%s</span>' % orig_value[100:]
        value = formatter.make_wrappable(value)
        if i % 2:
            attr = ' class="even"'
        else:
            attr = ' class="odd"'
        rows.append(
            '<tr%s style="vertical-align: top;"><td>'
            '<b>%s</b></td><td style="overflow: auto">%s<td></tr>' %
            (attr, html_quote(name), preserve_whitespace(value, quote=False)))
    return '<table>%s</table>' % ('\n'.join(rows))