def flash_processor(handler):
    flashes_json = web.cookies(flashes="[]").flashes
    try:
        flashes = [web.storage(d) for d in json.loads(flashes_json)
                   if isinstance(d, dict) and 'category' in d and
                   'message' in d]
    except ValueError:
        flashes = []

    web.ctx.flashes = list(flashes)

    try:
        return handler()
    finally:
        # Flash changed. Need to save it.
        if flashes != web.ctx.flashes:
            if web.ctx.flashes:
                web.setcookie('flashes', json.dumps(web.ctx.flashes))
            else:
                web.setcookie('flashes', '', expires=-1)
dataset/ETHPy150Open anandology/broadgauge/broadgauge/flash.py/flash_processor/original