<s> """<STR_LIT>""" <EOL> import datetime as dt <EOL> from flask import Flask , jsonify <EOL> from webargs import fields , validate <EOL> from webargs . flaskparser import use_args , use_kwargs <EOL> app = Flask ( __name__ ) <EOL> hello_args = { <EOL> '<STR_LIT:name>' : fields . Str ( missing = '<STR_LIT>' ) <EOL> } <EOL> @ app . route ( '<STR_LIT:/>' , methods = [ '<STR_LIT:GET>' ] ) <EOL> @ use_args ( hello_args ) <EOL> def index ( args ) : <EOL> """<STR_LIT>""" <EOL> return jsonify ( { '<STR_LIT:message>' : '<STR_LIT>' . format ( args [ '<STR_LIT:name>' ] ) } ) <EOL> add_args = { <EOL> '<STR_LIT:x>' : fields . Float ( required = True ) , <EOL> '<STR_LIT:y>' : fields . Float ( required = True ) , <EOL> } <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> @ use_kwargs ( add_args ) <EOL> def add ( x , y ) : <EOL> """<STR_LIT>""" <EOL> return jsonify ( { '<STR_LIT:result>' : x + y } ) <EOL> dateadd_args = { <EOL> '<STR_LIT:value>' : fields . DateTime ( required = False ) , <EOL> '<STR_LIT>' : fields . Int ( required = True , validate = validate . Range ( min = <NUM_LIT:1> ) ) , <EOL> '<STR_LIT>' : fields . Str ( missing = '<STR_LIT>' , validate = validate . OneOf ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> } <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> @ use_kwargs ( dateadd_args ) <EOL> def dateadd ( value , addend , unit ) : <EOL> """<STR_LIT>""" <EOL> value = value or dt . datetime . utcnow ( ) <EOL> if unit == '<STR_LIT>' : <EOL> delta = dt . timedelta ( minutes = addend ) <EOL> else : <EOL> delta = dt . timedelta ( days = addend ) <EOL> result = value + delta <EOL> return jsonify ( { '<STR_LIT:result>' : result . isoformat ( ) } ) <EOL> @ app . errorhandler ( <NUM_LIT> ) <EOL> def handle_validation_error ( err ) : <EOL> exc = err . data [ '<STR_LIT>' ] <EOL> return jsonify ( { '<STR_LIT>' : exc . messages } ) , <NUM_LIT> <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app . run ( port = <NUM_LIT> , debug = True ) </s>
