Example #1
0
def tempconvert():
    "post input for temperature"
    temptype = request.form['temptype']
    temp = float(request.form['temp'])

    if temptype == 'C':
        txt = render([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('celcius to farenheit')
                ),
                html.body(
                    str(C2F(temp))
                    )
            )
        ])
    elif temptype == 'F':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('farenheit to celcius')
                    ),
                html.body(
                    str(F2C(temp))
                    )
                )
            ])
    else:
        txt = 'Not valid input'
    return txt
Example #2
0
def test_join():
    assert render(html.p(html.join(
        html.a, 'Text', html.b()))) == '<p>\n  <a />Text<b></b>\n</p>\n'
    assert render(html.join(html.p(html.a, 'Text',
                                   html.b()))) == '<p><a />Text<b></b></p>\n'
    assert rn(html.join(html.p(html.a, 'Text',
                               html.b()))) == '<p><a />Text<b></b></p>'
Example #3
0
def weightconvert():
    "post input for weight"
    masstype = request.form['masstype']
    weight = float(request.form['weight'])

    if masstype == 'kg':
        txt = render([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('kilograms -> lbs')
                ),
                html.body(
                    str(k2p(weight))
                    )
            )
        ])
    elif masstype == 'lb':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('lbs -> kilograms')
                    ),
                html.body(
                    str(p2k(weight))
                    )
                )
            ])
    else:
        txt = 'not valid input'
    
    return txt
Example #4
0
def liquidconvert():
    "post input for liquid"
    liquidtype = request.form['liquidtype']
    liquid = float(request.form['liquid'])

    if liquidtype == 'L':
        txt = render([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('liters -> gallons')
                ),
                html.body(
                    str(l2g(liquid))
                    )
            )
        ])
    elif liquidtype == 'G':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('gallons -> liters')
                    ),
                html.body(
                    str(g2l(liquid))
                    )
                )
            ])
    elif liquidtype == 'l':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('liters -> ounces')
                    ),
                html.body(
                    str(l2o(liquid))
                    )
                )
            ]) 

    elif liquidtype == 'o':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('ounces -> liters')
                    ),
                html.body(
                    str(o2l(liquid))
                    )
                )
            ])   

    else:
        txt = 'not valid input'
    
    return txt
Example #5
0
def test_newline():
    assert render([html.p('First'),
                   html.newline(),
                   html.p('Second')]) == '<p>First</p>\n\n<p>Second</p>\n'
    assert render(html.div(html.p('First'), html.newline(), html.p('Second'))) == \
           '<div>\n  <p>First</p>\n  \n  <p>Second</p>\n</div>\n'
    assert rn([html.p('First'),
               html.newline(),
               html.p('Second')]) == '<p>First</p><p>Second</p>'
Example #6
0
def distanceconvert():
    "post input for distance"
    distancetype = request.form['distancetype']
    distanceamount = float(request.form['distanceamount'])

    if distancetype == 'm':
        txt = render([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('meters -> feet')
                    ),
                html.body(
                    str(M2F(distanceamount))
                    )
                )
            ])
    elif distancetype == 'ft':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('feet -> meters')
                    ),
                html.body(
                    str(F2M(distanceamount))
                    )
                )
            ])
    elif distancetype == 'KM':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('kilometers -> miles')
                    ),
                html.body(
                    str(K2M(distanceamount))
                    )
                )
            ])
    elif distancetype == 'Miles':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('miles -> kilometers')
                    ),
                html.body(
                    str(M2K(distanceamount))
                    )
                )
            ])
    else:
        txt = 'Not valid input'
    return txt
Example #7
0
def test_safe():
    assert rn(html.safe('<strong>&nbsp;Text&nbsp;</strong>')
              ) == '<strong>&nbsp;Text&nbsp;</strong>'
    assert rn(html.p(html.safe('<strong>&nbsp;Text&nbsp;</strong>'))
              ) == '<p><strong>&nbsp;Text&nbsp;</strong></p>'
    assert render(html.p(html.safe('<strong>&nbsp;Text&nbsp;</strong>'))
                  ) == '<p>\n  <strong>&nbsp;Text&nbsp;</strong>\n</p>\n'
def test_markup():
    assert Markup(html.a(name='value')(html.b(first='one'), 'Text', html.c())) == '<a name="value"><b first="one" />Text<c></c></a>'
    assert Markup(html.p(html.comment('Comment'))) == '<p><!--Comment--></p>'
    assert Markup(html.p(html.safe('<strong>&nbsp;Text&nbsp;</strong>'))) == '<p><strong>&nbsp;Text&nbsp;</strong></p>'
    assert Markup(html.safe('<strong>&nbsp;Text&nbsp;</strong>')) == '<strong>&nbsp;Text&nbsp;</strong>'

    assert rn(html.p(Markup('<strong>&nbsp;Text&nbsp;</strong>'))) == '<p><strong>&nbsp;Text&nbsp;</strong></p>'
    assert rn(html.p(Markup('&nbsp; '), Markup('<strong>One</strong>'))) == '<p>&nbsp; <strong>One</strong></p>'
    assert render(html.p(Markup('&nbsp; '), Markup('<strong>One</strong>'))) == u'<p>\n  &nbsp; \n  <strong>One</strong>\n</p>\n'
Example #9
0
def test_nested_indentating():
    elements = [
        html.doctype('html'),
        html.html(lang='en',
                  class_='no-js')(html.head(html.title('Hello')),
                                  html.body(html.comment(' Body starts here '),
                                            html.p('Hello World!')))
    ]

    assert render(elements) == """<!doctype html>
def test_nested_indentating():
    elements = [
        html.doctype('html'),
        html.html(lang='en', class_='no-js')(
            html.head(
                html.title('Hello')
            ),
            html.body(
                html.comment(' Body starts here '),
                html.p('Hello World!')
            )
        )
    ]

    assert render(elements) == """<!doctype html>
Example #11
0
def test_markup():
    assert Markup(html.a(name='value')(
        html.b(first='one'), 'Text',
        html.c())) == '<a name="value"><b first="one" />Text<c></c></a>'
    assert Markup(html.p(html.comment('Comment'))) == '<p><!--Comment--></p>'
    assert Markup(html.p(html.safe('<strong>&nbsp;Text&nbsp;</strong>'))
                  ) == '<p><strong>&nbsp;Text&nbsp;</strong></p>'
    assert Markup(html.safe('<strong>&nbsp;Text&nbsp;</strong>')
                  ) == '<strong>&nbsp;Text&nbsp;</strong>'

    assert rn(html.p(Markup('<strong>&nbsp;Text&nbsp;</strong>'))
              ) == '<p><strong>&nbsp;Text&nbsp;</strong></p>'
    assert rn(html.p(Markup('&nbsp; '), Markup(
        '<strong>One</strong>'))) == '<p>&nbsp; <strong>One</strong></p>'
    assert render(html.p(Markup('&nbsp; '), Markup('<strong>One</strong>'))
                  ) == u'<p>\n  &nbsp; \n  <strong>One</strong>\n</p>\n'
def addserverpost():
    "post input for server total"
    servers = request.form['servers']
    txt = render([
        html.doctype('html'),
        html.html(lang='en')(
            html.head(
                html.title('Scalelab Server Calculator 5000')
            ),
            html.body(
                "%s Dell R620 node(s) with cabling, 2 x 10gbe ports (20GbE in/out) will cost $%s USD" \
                        % (servers,addserver(servers))
                )
            )
        ])

    return txt
def test_doctype():
    assert rn(html.doctype('html')) == '<!doctype html>'
    assert render(html.doctype('html')) == '<!doctype html>\n'
def test_comment():
    assert rn(html.comment('Comment')) == '<!--Comment-->'
    assert render(html.p(html.comment('Comment'))) == '<p>\n  <!--Comment-->\n</p>\n'
def test_join():
    assert render(html.p(html.join(html.a, 'Text', html.b()))) == '<p>\n  <a />Text<b></b>\n</p>\n'
    assert render(html.join(html.p(html.a, 'Text', html.b()))) == '<p><a />Text<b></b></p>\n'
    assert rn(html.join(html.p(html.a, 'Text', html.b()))) == '<p><a />Text<b></b></p>'
def rn(element):
    return render(element, None)
Example #17
0
def test_render_level():
    assert render(html.p(html.a('Text')),
                  level=1) == '  <p>\n    <a>Text</a>\n  </p>\n'
    assert render(html.p(html.a('Text')),
                  level=2) == '    <p>\n      <a>Text</a>\n    </p>\n'
def test_escape_numbers():
    render(html.a(5))
def test_render_level():
    assert render(html.p(html.a('Text')), level=1) == '  <p>\n    <a>Text</a>\n  </p>\n'
    assert render(html.p(html.a('Text')), level=2) == '    <p>\n      <a>Text</a>\n    </p>\n'
def test_many_child_indenting():
    assert render(html.a(name='value')(html.b(first='one'), 'Text', html.c())) == '<a name="value">\n  <b first="one" />\n  Text\n  <c></c>\n</a>\n'
def test_one_non_text_child_indenting():
    assert render(html.a(html.b)) == '<a>\n  <b />\n</a>\n'
def test_single_element_indenting():
    assert render(html.a) == '<a />\n'
    assert render(html.a()) == '<a></a>\n'
    assert render(html.a(name='value')) == '<a name="value" />\n'
    assert render(html.a(name='value')()) == '<a name="value"></a>\n'
Example #23
0
def test_single_element_indenting():
    assert render(html.a) == '<a />\n'
    assert render(html.a()) == '<a></a>\n'
    assert render(html.a(name='value')) == '<a name="value" />\n'
    assert render(html.a(name='value')()) == '<a name="value"></a>\n'
Example #24
0
def test_escape_numbers():
    render(html.a(5))
Example #25
0
def test_escape_attribute_numbers():
    render(html.a(x=5))
def test_safe():
    assert rn(html.safe('<strong>&nbsp;Text&nbsp;</strong>')) == '<strong>&nbsp;Text&nbsp;</strong>'
    assert rn(html.p(html.safe('<strong>&nbsp;Text&nbsp;</strong>'))) == '<p><strong>&nbsp;Text&nbsp;</strong></p>'
    assert render(html.p(html.safe('<strong>&nbsp;Text&nbsp;</strong>'))) == '<p>\n  <strong>&nbsp;Text&nbsp;</strong>\n</p>\n'
def test_newline():
    assert render([html.p('First'), html.newline(), html.p('Second')]) == '<p>First</p>\n\n<p>Second</p>\n'
    assert render(html.div(html.p('First'), html.newline(), html.p('Second'))) == \
           '<div>\n  <p>First</p>\n  \n  <p>Second</p>\n</div>\n'
    assert rn([html.p('First'), html.newline(), html.p('Second')]) == '<p>First</p><p>Second</p>'
Example #28
0
def test_comment():
    assert rn(html.comment('Comment')) == '<!--Comment-->'
    assert render(html.p(
        html.comment('Comment'))) == '<p>\n  <!--Comment-->\n</p>\n'
def test_escape_attribute_numbers():
    render(html.a(x=5))
Example #30
0
def test_many_child_indenting():
    assert render(html.a(name='value')(html.b(first='one'), 'Text', html.c(
    ))) == '<a name="value">\n  <b first="one" />\n  Text\n  <c></c>\n</a>\n'
Example #31
0
def rn(element):
    return render(element, None)
Example #32
0
def test_doctype():
    assert rn(html.doctype('html')) == '<!doctype html>'
    assert render(html.doctype('html')) == '<!doctype html>\n'
def test_one_text_child_indenting():
    assert render(html.a(name='value')('Text')) == '<a name="value">Text</a>\n'
    assert render(html.a('Text')) == '<a>Text</a>\n'
Example #34
0
def test_one_text_child_indenting():
    assert render(html.a(name='value')('Text')) == '<a name="value">Text</a>\n'
    assert render(html.a('Text')) == '<a>Text</a>\n'
def test_many_text_child_indenting():
    assert render(html.a('One', 'Two')) == '<a>\n  One\n  Two\n</a>\n'
Example #36
0
def test_one_non_text_child_indenting():
    assert render(html.a(html.b)) == '<a>\n  <b />\n</a>\n'
Example #37
0
def test_many_text_child_indenting():
    assert render(html.a('One', 'Two')) == '<a>\n  One\n  Two\n</a>\n'
Example #38
0
def currencyconvert():
    "post input for currency"
    currencytype = request.form['currencytype']
    currencyamount = float(request.form['currencyamount'])

    if currencytype == 'USD':
        txt = render([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('USD -> CZK')
                    ),
                html.body(
                    str(usdtoczk(currencyamount))
                    )
                )
            ])

    elif currencytype == 'CZK':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('CZK -> USD')
                    ),
                html.body(
                    str(czktousd(currencyamount))
                    )
                )
            ])

    elif currencytype == 'HRK':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('HRK -> USD')
                    ),
                html.body(
                    str(hrktousd(currencyamount))
                    )
                )
            ])

    elif currencytype == 'USD-H':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('USD -> HRK')
                    ),
                html.body(
                    str(usdtohrk(currencyamount))
                    )
                )
            ])

    elif currencytype == 'USD-E':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('USD -> EU')
                    ),
                html.body(
                    str(usdtoeu(currencyamount))
                    )
                )
            ])

    elif currencytype == 'E-USD':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('EU -> USD')
                    ),
                html.body(
                    str(eutousd(currencyamount))
                    )
                )
            ])

    elif currencytype == 'CZK-E':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('CZK -> EU')
                    ),
                html.body(
                    str(czktoeu(currencyamount))
                    )
                )
            ])

    elif currencytype == 'E-CZK':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('EU -> CZK')
                    ),
                html.body(
                    str(eutoczk(currencyamount))
                    )
                )
            ])

    elif currencytype == 'B-USD':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('BAHT -> USD')
                    ),
                html.body(
                    str(bhtousd(currencyamount))
                    )
                )
            ])

    elif currencytype == 'USD-B':
        txt = render ([
            html.doctype('html'),
            html.html(lang='en')(
                html.head(
                    html.title('BAHT -> USD')
                    ),
                html.body(
                    str(usdtobh(currencyamount))
                    )
                )
            ])

    else:
        txt = 'not valid input'

    return txt