Skip to content

Commit

Permalink
Use non-deprecated zope.interface methods in twisted bridge.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdarnell committed Jun 29, 2012
1 parent 83b3882 commit b04e5b6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
14 changes: 4 additions & 10 deletions tornado/platform/twisted.py
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 0 additions & 7 deletions tornado/test/runtests.py
Expand Up @@ -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()
26 changes: 10 additions & 16 deletions tornado/test/twisted_test.py
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b04e5b6

Please sign in to comment.