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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
from twisted.python import failure, log from twisted.python import failure, log
from twisted.internet import error from twisted.internet import error


from zope.interface import implements from zope.interface import implementer


import tornado import tornado
import tornado.ioloop import tornado.ioloop
Expand All @@ -66,13 +66,6 @@


class TornadoDelayedCall(object): class TornadoDelayedCall(object):
"""DelayedCall object for Tornado.""" """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): def __init__(self, reactor, seconds, f, *args, **kw):
self._reactor = reactor self._reactor = reactor
self._func = functools.partial(f, *args, **kw) self._func = functools.partial(f, *args, **kw)
Expand Down Expand Up @@ -111,6 +104,8 @@ def reset(self, seconds):


def active(self): def active(self):
return self._active return self._active
# Fake class decorator for python 2.5 compatibility
TornadoDelayedCall = implementer(IDelayedCall)(TornadoDelayedCall)




class TornadoReactor(PosixReactorBase): class TornadoReactor(PosixReactorBase):
Expand All @@ -123,8 +118,6 @@ class TornadoReactor(PosixReactorBase):
timed call functionality on top of `IOLoop.add_timeout` rather than timed call functionality on top of `IOLoop.add_timeout` rather than
using the implementation in `PosixReactorBase`. using the implementation in `PosixReactorBase`.
""" """
implements(IReactorTime, IReactorFDSet)

def __init__(self, io_loop=None): def __init__(self, io_loop=None):
if not io_loop: if not io_loop:
io_loop = tornado.ioloop.IOLoop.instance() io_loop = tornado.ioloop.IOLoop.instance()
Expand Down Expand Up @@ -300,6 +293,7 @@ def mainLoop(self):
self._io_loop.start() self._io_loop.start()
if self._stopped: if self._stopped:
self.fireSystemEvent("shutdown") self.fireSystemEvent("shutdown")
TornadoReactor = implementer(IReactorTime, IReactorFDSet)(TornadoReactor)




class _TestReactor(TornadoReactor): class _TestReactor(TornadoReactor):
Expand Down
7 changes: 0 additions & 7 deletions tornado/test/runtests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ def all():
warnings.filterwarnings("ignore", category=DeprecationWarning) warnings.filterwarnings("ignore", category=DeprecationWarning)
warnings.filterwarnings("error", category=DeprecationWarning, warnings.filterwarnings("error", category=DeprecationWarning,
module=r"tornado\..*") 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 import tornado.testing
tornado.testing.main() tornado.testing.main()
26 changes: 10 additions & 16 deletions tornado/test/twisted_test.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@


try: try:
import fcntl import fcntl
import twisted
from twisted.internet.defer import Deferred from twisted.internet.defer import Deferred
from twisted.internet.interfaces import IReadDescriptor, IWriteDescriptor from twisted.internet.interfaces import IReadDescriptor, IWriteDescriptor
from twisted.internet.protocol import Protocol from twisted.internet.protocol import Protocol
Expand All @@ -36,14 +35,10 @@
from twisted.web.server import Site from twisted.web.server import Site
from twisted.python import log from twisted.python import log
from tornado.platform.twisted import TornadoReactor from tornado.platform.twisted import TornadoReactor
from zope.interface import implements from zope.interface import implementer
have_twisted = True
except ImportError: except ImportError:
fcntl = None have_twisted = False
twisted = None
IReadDescriptor = IWriteDescriptor = None

def implements(f):
pass


from tornado.httpclient import AsyncHTTPClient from tornado.httpclient import AsyncHTTPClient
from tornado.ioloop import IOLoop from tornado.ioloop import IOLoop
Expand Down Expand Up @@ -187,9 +182,7 @@ def testCallInThread(self):
self._reactor.run() self._reactor.run()




class Reader: class Reader(object):
implements(IReadDescriptor)

def __init__(self, fd, callback): def __init__(self, fd, callback):
self._fd = fd self._fd = fd
self._callback = callback self._callback = callback
Expand All @@ -208,11 +201,11 @@ def connectionLost(self, reason):


def doRead(self): def doRead(self):
self._callback(self._fd) self._callback(self._fd)
if have_twisted:
Reader = implementer(IReadDescriptor)(Reader)




class Writer: class Writer(object):
implements(IWriteDescriptor)

def __init__(self, fd, callback): def __init__(self, fd, callback):
self._fd = fd self._fd = fd
self._callback = callback self._callback = callback
Expand All @@ -231,7 +224,8 @@ def connectionLost(self, reason):


def doWrite(self): def doWrite(self):
self._callback(self._fd) self._callback(self._fd)

if have_twisted:
Writer = implementer(IWriteDescriptor)(Writer)


class ReactorReaderWriterTest(ReactorTestCase): class ReactorReaderWriterTest(ReactorTestCase):
def _set_nonblocking(self, fd): def _set_nonblocking(self, fd):
Expand Down Expand Up @@ -426,7 +420,7 @@ def testTornadoServerTwistedClientReactor(self):
self.assertEqual(response, 'Hello from tornado!') self.assertEqual(response, 'Hello from tornado!')




if twisted is None: if not have_twisted:
del ReactorWhenRunningTest del ReactorWhenRunningTest
del ReactorCallLaterTest del ReactorCallLaterTest
del ReactorTwoCallLaterTest del ReactorTwoCallLaterTest
Expand Down

0 comments on commit b04e5b6

Please sign in to comment.