<s> from flask import request , url_for <EOL> from flask . ext . api import FlaskAPI , status , exceptions <EOL> app = FlaskAPI ( __name__ ) <EOL> notes = { <EOL> <NUM_LIT:0> : '<STR_LIT>' , <EOL> <NUM_LIT:1> : '<STR_LIT>' , <EOL> <NUM_LIT:2> : '<STR_LIT>' , <EOL> } <EOL> def note_repr ( key ) : <EOL> return { <EOL> '<STR_LIT:url>' : request . host_url . rstrip ( '<STR_LIT:/>' ) + url_for ( '<STR_LIT>' , key = key ) , <EOL> '<STR_LIT:text>' : notes [ key ] <EOL> } <EOL> @ app . route ( "<STR_LIT:/>" , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def notes_list ( ) : <EOL> """<STR_LIT>""" <EOL> if request . method == '<STR_LIT:POST>' : <EOL> note = str ( request . data . get ( '<STR_LIT:text>' , '<STR_LIT>' ) ) <EOL> idx = max ( notes . keys ( ) ) + <NUM_LIT:1> <EOL> notes [ idx ] = note <EOL> return note_repr ( idx ) , status . HTTP_201_CREATED <EOL> return [ note_repr ( idx ) for idx in sorted ( notes . keys ( ) ) ] <EOL> @ app . route ( "<STR_LIT>" , methods = [ '<STR_LIT:GET>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def notes_detail ( key ) : <EOL> """<STR_LIT>""" <EOL> if request . method == '<STR_LIT>' : <EOL> note = str ( request . data . get ( '<STR_LIT:text>' , '<STR_LIT>' ) ) <EOL> notes [ key ] = note <EOL> return note_repr ( key ) <EOL> elif request . method == '<STR_LIT>' : <EOL> notes . pop ( key , None ) <EOL> return '<STR_LIT>' , status . HTTP_204_NO_CONTENT <EOL> if key not in notes : <EOL> raise exceptions . NotFound ( ) <EOL> return note_repr ( key ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> app . run ( debug = True ) </s>
