Created
November 1, 2011 23:57
-
-
Save waffle2k/1332318 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
import json | |
class AuthenticationException( Exception ): | |
pass | |
def loginrequired( fn ): | |
def wrapper( *args, **kwargs ): | |
print "args:",args | |
print "kwargs:",kwargs | |
j = args[1] | |
if not j['authenticated']: | |
raise AuthenticationException( "Not authenticated" ) | |
fn( *args, **kwargs ) | |
return wrapper | |
class foo: | |
def __init__(self): | |
pass | |
@loginrequired | |
def process_json(self, JSON=json): | |
print "I would process some json here" | |
jsonstrings = [ '{ "foo": "bar", "authenticated": 1 }', | |
'{ "foo": "bar", "authenticated": 0 }', | |
] | |
f = foo() | |
for s in jsonstrings: | |
print "Processing: %s" % ( s ) | |
jsonobj = json.loads( s ) | |
f.process_json( jsonobj ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment