Skip to content

Instantly share code, notes, and snippets.

@FugiTech
Last active December 12, 2015 06:08
Show Gist options
  • Save FugiTech/4726330 to your computer and use it in GitHub Desktop.
Save FugiTech/4726330 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from twisted.internet defer
from functools import wraps
import json
def writeJSON(fn):
@wraps(fn)
def wrapped(request, *params, **kwargs):
request.setResponseCode(200)
d = fn(request, *params, **kwargs)
d.addCallback(json.dumps)
d.addCallback(request.write)
return d
return wrapped
@writeJSON
@defer.inlineCallbacks
def renderGET(request):
data = yield xxx
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment