Skip to content

Instantly share code, notes, and snippets.

@anish
Created April 11, 2016 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anish/eb05639e9c4ac1165313311a0ce34986 to your computer and use it in GitHub Desktop.
Save anish/eb05639e9c4ac1165313311a0ce34986 to your computer and use it in GitHub Desktop.
#!/usr/bin/python2
import web
import json
def add_global_hook(x):
g = web.storage({"auth": x})
def _wrapper(handler):
web.ctx.globals = g
return handler()
return _wrapper
class hooks:
def POST(self):
print "%s" % web.ctx.globals.auth['username']
if __name__ == '__main__':
with open('test') as f:
x = json.load(f)
urls = ("/.*", 'hooks')
app = web.application(urls, globals())
app.add_processor(add_global_hook(x))
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment