diff --git a/tornado/platform/twisted.py b/tornado/platform/twisted.py index 044c333417..6474a4788b 100644 --- a/tornado/platform/twisted.py +++ b/tornado/platform/twisted.py @@ -56,7 +56,7 @@ from twisted.python import failure, log from twisted.internet import error -from zope.interface import implements +from zope.interface import implementer import tornado import tornado.ioloop @@ -66,13 +66,6 @@ class TornadoDelayedCall(object): """DelayedCall object for Tornado.""" - # Note that zope.interface.implements is deprecated in - # zope.interface 4.0, because it cannot work in python 3. The - # replacement is a class decorator, which cannot work on python - # 2.5. So when twisted supports python 3, we'll need to drop 2.5 - # support on this module to make it work. - implements(IDelayedCall) - def __init__(self, reactor, seconds, f, *args, **kw): self._reactor = reactor self._func = functools.partial(f, *args, **kw) @@ -111,6 +104,8 @@ def reset(self, seconds): def active(self): return self._active +# Fake class decorator for python 2.5 compatibility +TornadoDelayedCall = implementer(IDelayedCall)(TornadoDelayedCall) class TornadoReactor(PosixReactorBase): @@ -123,8 +118,6 @@ class TornadoReactor(PosixReactorBase): timed call functionality on top of `IOLoop.add_timeout` rather than using the implementation in `PosixReactorBase`. """ - implements(IReactorTime, IReactorFDSet) - def __init__(self, io_loop=None): if not io_loop: io_loop = tornado.ioloop.IOLoop.instance() @@ -300,6 +293,7 @@ def mainLoop(self): self._io_loop.start() if self._stopped: self.fireSystemEvent("shutdown") +TornadoReactor = implementer(IReactorTime, IReactorFDSet)(TornadoReactor) class _TestReactor(TornadoReactor): diff --git a/tornado/test/runtests.py b/tornado/test/runtests.py index 7a86366152..047d458986 100644 --- a/tornado/test/runtests.py +++ b/tornado/test/runtests.py @@ -51,13 +51,6 @@ def all(): warnings.filterwarnings("ignore", category=DeprecationWarning) warnings.filterwarnings("error", category=DeprecationWarning, module=r"tornado\..*") - # tornado.platform.twisted uses a deprecated function from - # zope.interface in order to maintain compatibility with - # python 2.5 - warnings.filterwarnings("ignore", category=DeprecationWarning, - module=r"tornado\.platform\.twisted") - warnings.filterwarnings("ignore", category=DeprecationWarning, - module=r"tornado\.test\.twisted_test") import tornado.testing tornado.testing.main() diff --git a/tornado/test/twisted_test.py b/tornado/test/twisted_test.py index 78542a7a42..327af2db7e 100644 --- a/tornado/test/twisted_test.py +++ b/tornado/test/twisted_test.py @@ -27,7 +27,6 @@ try: import fcntl - import twisted from twisted.internet.defer import Deferred from twisted.internet.interfaces import IReadDescriptor, IWriteDescriptor from twisted.internet.protocol import Protocol @@ -36,14 +35,10 @@ from twisted.web.server import Site from twisted.python import log from tornado.platform.twisted import TornadoReactor - from zope.interface import implements + from zope.interface import implementer + have_twisted = True except ImportError: - fcntl = None - twisted = None - IReadDescriptor = IWriteDescriptor = None - - def implements(f): - pass + have_twisted = False from tornado.httpclient import AsyncHTTPClient from tornado.ioloop import IOLoop @@ -187,9 +182,7 @@ def testCallInThread(self): self._reactor.run() -class Reader: - implements(IReadDescriptor) - +class Reader(object): def __init__(self, fd, callback): self._fd = fd self._callback = callback @@ -208,11 +201,11 @@ def connectionLost(self, reason): def doRead(self): self._callback(self._fd) +if have_twisted: + Reader = implementer(IReadDescriptor)(Reader) -class Writer: - implements(IWriteDescriptor) - +class Writer(object): def __init__(self, fd, callback): self._fd = fd self._callback = callback @@ -231,7 +224,8 @@ def connectionLost(self, reason): def doWrite(self): self._callback(self._fd) - +if have_twisted: + Writer = implementer(IWriteDescriptor)(Writer) class ReactorReaderWriterTest(ReactorTestCase): def _set_nonblocking(self, fd): @@ -426,7 +420,7 @@ def testTornadoServerTwistedClientReactor(self): self.assertEqual(response, 'Hello from tornado!') -if twisted is None: +if not have_twisted: del ReactorWhenRunningTest del ReactorCallLaterTest del ReactorTwoCallLaterTest