Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Created November 1, 2011 23:57
Show Gist options
  • Save waffle2k/1332318 to your computer and use it in GitHub Desktop.
Save waffle2k/1332318 to your computer and use it in GitHub Desktop.
#!/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