Created
October 14, 2011 17:16
-
-
Save pneff/1287714 to your computer and use it in GitHub Desktop.
Example for WsgiService validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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