<s> import sys <EOL> import os <EOL> import time <EOL> from flask import Flask , jsonify <EOL> from flask . ext . sqlalchemy import SQLAlchemy <EOL> if "<STR_LIT>" in os . environ : <EOL> from gevent . monkey import patch_all <EOL> patch_all ( ) <EOL> from psycogreen . gevent import patch_psycopg <EOL> patch_psycopg ( ) <EOL> using_gevent = True <EOL> else : <EOL> using_gevent = False <EOL> app = Flask ( __name__ ) <EOL> app . config . from_pyfile ( '<STR_LIT>' ) <EOL> db = SQLAlchemy ( app ) <EOL> if using_gevent : <EOL> db . engine . pool . _use_threadlocal = True <EOL> class Todo ( db . Model ) : <EOL> """<STR_LIT>""" <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> title = db . Column ( db . String ( <NUM_LIT> ) ) <EOL> done = db . Column ( db . Boolean ) <EOL> priority = db . Column ( db . Integer ) <EOL> def as_dict ( self ) : <EOL> """<STR_LIT>""" <EOL> return { <EOL> '<STR_LIT:id>' : self . id , <EOL> '<STR_LIT:title>' : self . title , <EOL> '<STR_LIT>' : self . done , <EOL> '<STR_LIT>' : self . priority <EOL> } <EOL> @ classmethod <EOL> def jsonify_all ( cls ) : <EOL> """<STR_LIT>""" <EOL> return jsonify ( todos = [ todo . as_dict ( ) for todo in cls . query . all ( ) ] ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def sleep_postgres ( ) : <EOL> """<STR_LIT>""" <EOL> db . session . execute ( '<STR_LIT>' ) <EOL> return Todo . jsonify_all ( ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def sleep_python ( ) : <EOL> """<STR_LIT>""" <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> return Todo . jsonify_all ( ) <EOL> def create_data ( ) : <EOL> """<STR_LIT>""" <EOL> db . create_all ( ) <EOL> todos = [ ] <EOL> for i in range ( <NUM_LIT:50> ) : <EOL> todo = Todo ( <EOL> title = "<STR_LIT>" . format ( i ) , <EOL> done = ( i % <NUM_LIT:2> == <NUM_LIT:0> ) , <EOL> priority = ( i % <NUM_LIT:5> ) <EOL> ) <EOL> todos . append ( todo ) <EOL> db . session . add_all ( todos ) <EOL> db . session . commit ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if '<STR_LIT:-c>' in sys . argv : <EOL> create_data ( ) <EOL> else : <EOL> app . run ( ) </s>
