From d1ac84d6ba67665a02d06efef1505a34d203a5ff Mon Sep 17 00:00:00 2001 From: Eric Naeseth Date: Thu, 25 Feb 2010 13:57:26 -0600 Subject: [PATCH] Include our own version of isgenerator() for Python 2.5 and below. --- swirl.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/swirl.py b/swirl.py index e9b9564..23dbd52 100644 --- a/swirl.py +++ b/swirl.py @@ -4,12 +4,19 @@ Provides some sugar to make Tornado's async stuff more palatable. """ -import inspect import logging import functools from tornado.ioloop import IOLoop from tornado.web import RequestHandler, asynchronous as web_async +try: + from inspect import isgenerator +except ImportError: + # Python < 2.6 + import types + def isgenerator(obj): + return isinstance(obj, types.GeneratorType) + __version__ = '0.1.0' def make_asynchronous_decorator(io_loop): @@ -37,7 +44,7 @@ def run_async_routine(*args, **kwargs): web_handler = None gen = routine(*args, **kwargs) - if not inspect.isgenerator(gen): + if not isgenerator(gen): # the "coroutine" isn't actually a coroutine; just return # its result like tornado.web.asynchronous would do return gen