How to use the ipwb.util.padDigits14 function in ipwb

To help you get started, we’ve selected a few ipwb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oduwsdl / ipwb / tests / test_util.py View on Github external
def test_padDigits14(expected, input):
    assert expected == util.padDigits14(input)
github oduwsdl / ipwb / tests / test_util.py View on Github external
def test_padDigits14_inalid(input):
    with pytest.raises(ValueError):
        util.padDigits14(input, validate=True)
github oduwsdl / ipwb / ipwb / replay.py View on Github external
def showMemento(urir, datetime):
    try:
        datetime = ipwbUtils.padDigits14(datetime, validate=True)
    except ValueError as e:
        msg = 'Expected a 4-14 digits valid datetime: {}'.format(datetime)
        return Response(msg, status=400)
    resolvedMemento = resolveMemento(urir, datetime)

    # resolved to a 404, flask Response object returned instead of tuple
    if isinstance(resolvedMemento, Response):
        return resolvedMemento
    (newDatetime, linkHeader, uri) = resolvedMemento

    if newDatetime != datetime:
        resp = redirect('/memento/{0}/{1}'.format(newDatetime, urir), code=302)
    else:
        resp = show_uri(uri, newDatetime)

    resp.headers['Link'] = linkHeader