Last active
August 29, 2015 14:23
Revisions
-
gtkesh revised this gist
Jun 23, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ @app.route('/', methods=['POST']) @json @authenticate def foo(): -
gtkesh revised this gist
Jun 23, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ def foo(): do_stuff() # Decorators def json(f): @functools.wraps(f) -
gtkesh revised this gist
Jun 23, 2015 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,6 @@ def foo(): do_stuff() # Decorators def json(f): @functools.wraps(f) def wrapped(*args, **kwargs): -
gtkesh revised this gist
Jun 23, 2015 . 1 changed file with 0 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,10 +6,6 @@ def foo(): # Decorators def json(f): @functools.wraps(f) def wrapped(*args, **kwargs): response = f(*args, **kwargs) -
gtkesh revised this gist
Jun 23, 2015 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -29,5 +29,3 @@ def wrapped(*args, **kwargs): return f(*args, **kwargs) return wrapped return decorator -
gtkesh revised this gist
Jun 23, 2015 . 1 changed file with 0 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,8 @@ @json @authenticate def foo(): do_stuff() # Decorators def json(f): -
gtkesh created this gist
Jun 23, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ @json @authenticate def foo(): do_stuff() # Decorators def json(f): """ Returns a JSON response to the client f: route function that returns a dict """ @functools.wraps(f) def wrapped(*args, **kwargs): response = f(*args, **kwargs) return jsonify(response) return wrapped def authenticate(auth_callable): def decorator(f): @functools.wraps(f) def wrapped(*args, **kwargs): authentication = auth_callable(request) if not authentication.valid: reason = authentication.reason or "Unauthorized" raise errors.ValidationError(reason, 403) return f(*args, **kwargs) return wrapped return decorator