mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			23 lines
		
	
	
		
			627 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			627 B
		
	
	
	
		
			Python
		
	
	
	
	
	
import tornado.web
 | 
						|
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
 | 
						|
    return wrapper
 |