<s> """<STR_LIT>""" <EOL> from __future__ import with_statement <EOL> from sqlite3 import dbapi2 as sqlite3 <EOL> from contextlib import closing <EOL> from flask import Flask , request , session , g , redirect , url_for , abort , render_template , flash <EOL> from flask . ext . zodb import ZODB , List <EOL> ZODB_STORAGE = '<STR_LIT>' <EOL> DEBUG = True <EOL> SECRET_KEY = '<STR_LIT>' <EOL> USERNAME = '<STR_LIT>' <EOL> PASSWORD = '<STR_LIT:default>' <EOL> app = Flask ( __name__ ) <EOL> db = ZODB ( app ) <EOL> app . config . from_object ( __name__ ) <EOL> app . config . from_envvar ( '<STR_LIT>' , silent = True ) <EOL> @ app . before_request <EOL> def set_db_defaults ( ) : <EOL> if '<STR_LIT>' not in db : <EOL> db [ '<STR_LIT>' ] = List ( ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def show_entries ( ) : <EOL> return render_template ( '<STR_LIT>' , entries = db [ '<STR_LIT>' ] ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> def add_entry ( ) : <EOL> if not session . get ( '<STR_LIT>' ) : <EOL> abort ( <NUM_LIT> ) <EOL> db [ '<STR_LIT>' ] . append ( request . form ) <EOL> flash ( '<STR_LIT>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def login ( ) : <EOL> error = None <EOL> if request . method == '<STR_LIT:POST>' : <EOL> if request . form [ '<STR_LIT:username>' ] != app . config [ '<STR_LIT>' ] : <EOL> error = '<STR_LIT>' <EOL> elif request . form [ '<STR_LIT:password>' ] != app . config [ '<STR_LIT>' ] : <EOL> error = '<STR_LIT>' <EOL> else : <EOL> session [ '<STR_LIT>' ] = True <EOL> flash ( '<STR_LIT>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> return render_template ( '<STR_LIT>' , error = error ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def logout ( ) : <EOL> session . pop ( '<STR_LIT>' , None ) <EOL> flash ( '<STR_LIT>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app . run ( ) </s>
