twilio/flask-restful — pull request #43 by yaniv-aknin (2013-02-06 08:18:49+00:00)
Title: Add @parse_with to reqparse

This decorator allows you to easily augment any function (typically a view
method) to access reqparse based arguments, i.e.:

class Users(Resource):
@parse_with(RequestParser().add_argument('profession'))
def post(self, params, username):
create_new_user(username, params.profession)
return 'CREATED', 201

api.add_resource(Users, '/', endpoint='users')

The decorator is fairly magical in order to be able to decorate methods,
classmethods, staticmethods and plain functions. Rather than wrapping
the decorated function with another function, it wraps it with an
autogenerated callable descriptor that detects the invocation context
(function, method, etc) and alters the wrapped function's arguments
accordingly.

The descriptor assumes the wrapped function's name, docstring and module
string, what `@functools.wraps(f)` usually takes care of.