Files
zulip/zephyr/decorator.py
Keegan McAllister 9689887cbd Copy the csrf_exempt attribute in @asynchronous
Needed for @csrf_exempt to work.

(imported from commit 563ab11b0d26262511e9a6d9cc2735b0b835a391)
2012-10-27 17:56:18 -04:00

24 lines
689 B
Python

import types
class TornadoAsyncException(Exception): pass
class _DefGen_Return(BaseException):
def __init__(self, value):
self.value = value
def returnResponse(value):
raise _DefGen_Return(value)
def asynchronous(method):
def wrapper(request, *args, **kwargs):
try:
v = method(request, request._tornado_handler, *args, **kwargs)
if v == None or type(v) == types.GeneratorType:
raise TornadoAsyncException
except _DefGen_Return, e:
request._tornado_handler.finish(e.value.content)
return v
if getattr(method, 'csrf_exempt', False):
wrapper.csrf_exempt = True
return wrapper