<s> from random import choice , randint <EOL> from string import ascii_letters as letters , digits <EOL> from flask import abort , render_template , request <EOL> from flask . views import MethodView <EOL> from sqlalchemy . exc import OperationalError <EOL> from testapp . models import Page <EOL> class PageView ( MethodView ) : <EOL> def get ( self , page_id ) : <EOL> return page ( page_id ) <EOL> def database_page ( page_id = None ) : <EOL> page_id = randint ( <NUM_LIT:1> , <NUM_LIT> ) <EOL> try : <EOL> page = Page . query . get ( page_id ) <EOL> except OperationalError : <EOL> page = Page ( id = page_id , <EOL> title = '<STR_LIT>' . format ( page_id ) , <EOL> text = '<STR_LIT>' ) <EOL> return render_template ( '<STR_LIT>' , page = page . id , text = page . text ) <EOL> def custom_error ( code ) : <EOL> raise abort ( code ) <EOL> def error ( err ) : <EOL> code = err . code if hasattr ( err , '<STR_LIT:code>' ) else <NUM_LIT> <EOL> return ( render_template ( '<STR_LIT>' , code = code , error = err ) , code ) <EOL> def home ( ) : <EOL> """<STR_LIT>""" <EOL> query = ( request . args . get ( '<STR_LIT:q>' ) or <EOL> u'<STR_LIT>' . join ( [ choice ( letters + digits ) for i in range ( <NUM_LIT:16> ) ] ) ) <EOL> return render_template ( '<STR_LIT>' , query = query ) <EOL> def page ( page_id ) : <EOL> page = int ( page_id ) <EOL> return render_template ( '<STR_LIT>' , page = page ) <EOL> def server_error ( ) : <EOL> assert False , '<STR_LIT>' </s>
