Skip to content

Instantly share code, notes, and snippets.

@pneff
Created October 14, 2011 17:16
Show Gist options
  • Save pneff/1287714 to your computer and use it in GitHub Desktop.
Save pneff/1287714 to your computer and use it in GitHub Desktop.
Example for WsgiService validation
def asbool(s):
"""Simple function to convert any string into a boolean."""
return str(s).lower() in ('true', '1')
@mount('/validate/{user_id}')
@validate('user_id', re='[0-9]*', convert=int, doc='An integer user id')
class ValidatingResource(Resource):
@validate('activate', convert=asbool, doc='Will aways be True or False (default False)')
@validate('email', re='.*@.*', doc='Must contain an @')
def GET(self, user_id, email, activate=False):
return {'email': email, 'activate': activate, 'user_id': user_id}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment