]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Use real class decorators and remove other py25-era workarounds
authorBen Darnell <ben@bendarnell.com>
Sat, 19 Jan 2013 19:33:37 +0000 (14:33 -0500)
committerBen Darnell <ben@bendarnell.com>
Sat, 19 Jan 2013 19:33:37 +0000 (14:33 -0500)
12 files changed:
tornado/httpserver.py
tornado/locale.py
tornado/platform/twisted.py
tornado/simple_httpclient.py
tornado/test/curl_httpclient_test.py
tornado/test/httpserver_test.py
tornado/test/ioloop_test.py
tornado/test/iostream_test.py
tornado/test/log_test.py
tornado/test/netutil_test.py
tornado/test/process_test.py
tornado/test/twisted_test.py

index 2738d7801d06dad89e98e48485702a343bfe83cd..5a981ccebd5ddfcf990f28c3ea1c90b6fe48302f 100644 (file)
@@ -259,10 +259,7 @@ class HTTPConnection(object):
             headers = httputil.HTTPHeaders.parse(data[eol:])
 
             # HTTPRequest wants an IP, not a full socket address
-            if getattr(self.stream.socket, 'family', socket.AF_INET) in (
-                    socket.AF_INET, socket.AF_INET6):
-                # Jython 2.5.2 doesn't have the socket.family attribute,
-                # so just assume IP in that case.
+            if self.stream.socket.family in (socket.AF_INET, socket.AF_INET6):
                 remote_ip = self.address[0]
             else:
                 # Unix (or other) socket; fake the remote address
index 732a767f3a6ae557002302b75205928892b7f107..e4e1a154453c37e192413be57fc01bf2dd7f93f1 100644 (file)
@@ -129,8 +129,6 @@ def load_translations(directory):
             f = open(full_path, "r", encoding="utf-8")
         except TypeError:
             # python 2: files return byte strings, which are decoded below.
-            # Once we drop python 2.5, this could use io.open instead
-            # on both 2 and 3.
             f = open(full_path, "r")
         _translations[locale] = {}
         for i, row in enumerate(csv.reader(f)):
index 5902b739c9cca0d4afd36511ec0c3cee6de77e58..3821ad01c3d854554868c335e90f279ced92639a 100644 (file)
@@ -84,6 +84,7 @@ from tornado.stack_context import NullContext, wrap
 from tornado.ioloop import IOLoop
 
 
+@implementer(IDelayedCall)
 class TornadoDelayedCall(object):
     """DelayedCall object for Tornado."""
     def __init__(self, reactor, seconds, f, *args, **kw):
@@ -124,10 +125,9 @@ class TornadoDelayedCall(object):
 
     def active(self):
         return self._active
-# Fake class decorator for python 2.5 compatibility
-TornadoDelayedCall = implementer(IDelayedCall)(TornadoDelayedCall)
 
 
+@implementer(IReactorTime, IReactorFDSet)
 class TornadoReactor(PosixReactorBase):
     """Twisted reactor built on the Tornado IOLoop.
 
@@ -315,7 +315,6 @@ class TornadoReactor(PosixReactorBase):
 
     def mainLoop(self):
         self._io_loop.start()
-TornadoReactor = implementer(IReactorTime, IReactorFDSet)(TornadoReactor)
 
 
 class _TestReactor(TornadoReactor):
@@ -352,6 +351,7 @@ def install(io_loop=None):
     return reactor
 
 
+@implementer(IReadDescriptor, IWriteDescriptor)
 class _FD(object):
     def __init__(self, fd, handler):
         self.fd = fd
@@ -378,7 +378,6 @@ class _FD(object):
 
     def logPrefix(self):
         return ''
-_FD = implementer(IReadDescriptor, IWriteDescriptor)(_FD)
 
 
 class TwistedIOLoop(tornado.ioloop.IOLoop):
index 43908ea451a9e2d4e4bd5baa4938c3e14a6c95c2..535be909e482a8b4d5fc6a660be07ce1d3ac7896 100644 (file)
@@ -44,10 +44,6 @@ class SimpleAsyncHTTPClient(AsyncHTTPClient):
     supported.  In particular, proxies are not supported, connections
     are not reused, and callers cannot select the network interface to be
     used.
-
-    Python 2.6 or higher is required for HTTPS support.  Users of Python 2.5
-    should use the curl-based AsyncHTTPClient if HTTPS support is required.
-
     """
     def initialize(self, io_loop=None, max_clients=10,
                    hostname_mapping=None, max_buffer_size=104857600,
index 9f4eeaaf6ad72db753b6a80a38d56023251d824f..bc0c2daab12392f61d05cc2e21ce5d981963750e 100644 (file)
@@ -14,18 +14,16 @@ except ImportError:
 if pycurl is not None:
     from tornado.curl_httpclient import CurlAsyncHTTPClient
 
-
+@unittest.skipIf(pycurl is None, "pycurl module not present")
 class CurlHTTPClientCommonTestCase(httpclient_test.HTTPClientCommonTestCase):
     def get_http_client(self):
         client = CurlAsyncHTTPClient(io_loop=self.io_loop)
         # make sure AsyncHTTPClient magic doesn't give us the wrong class
         self.assertTrue(isinstance(client, CurlAsyncHTTPClient))
         return client
-CurlHTTPClientCommonTestCase = unittest.skipIf(pycurl is None,
-                                               "pycurl module not present")(
-                                                   CurlHTTPClientCommonTestCase)
 
 
+@unittest.skipIf(pycurl is None, "pycurl module not present")
 class CurlHTTPClientTestCase(AsyncHTTPTestCase):
     def setUp(self):
         super(CurlHTTPClientTestCase, self).setUp()
@@ -49,6 +47,3 @@ class CurlHTTPClientTestCase(AsyncHTTPTestCase):
         self.wait()
         self.assertEqual(1, len(exc_info))
         self.assertIs(exc_info[0][0], ZeroDivisionError)
-CurlHTTPClientTestCase = unittest.skipIf(pycurl is None,
-                                         "pycurl module not present")(
-                                             CurlHTTPClientTestCase)
index f0f409189ebbb32c250e5de39f2e7d94d8fe9c14..f910c9bb4fb4eb2e55002a71bd35922da6b0cd84 100644 (file)
@@ -98,22 +98,24 @@ class SSLTestMixin(object):
 # of SSLv23 allows it.
 
 
+@skipIfNoSSL
 class SSLv23Test(BaseSSLTest, SSLTestMixin):
     def get_ssl_version(self):
         return ssl.PROTOCOL_SSLv23
-SSLv23Test = skipIfNoSSL(SSLv23Test)
 
 
+@skipIfNoSSL
+@skipIfOldSSL
 class SSLv3Test(BaseSSLTest, SSLTestMixin):
     def get_ssl_version(self):
         return ssl.PROTOCOL_SSLv3
-SSLv3Test = skipIfNoSSL(skipIfOldSSL(SSLv3Test))
 
 
+@skipIfNoSSL
+@skipIfOldSSL
 class TLSv1Test(BaseSSLTest, SSLTestMixin):
     def get_ssl_version(self):
         return ssl.PROTOCOL_TLSv1
-TLSv1Test = skipIfNoSSL(skipIfOldSSL(TLSv1Test))
 
 
 class BadSSLOptionsTest(unittest.TestCase):
@@ -380,6 +382,8 @@ class ManualProtocolTest(HandlerBaseTestCase):
         self.assertEqual(self.fetch_json('/')['protocol'], 'https')
 
 
+@unittest.skipIf(not hasattr(socket, 'AF_UNIX') or sys.platform == 'cygwin',
+                 "unix sockets not supported on this platform")
 class UnixSocketTest(AsyncTestCase):
     """HTTPServers can listen on Unix sockets too.
 
@@ -418,9 +422,6 @@ class UnixSocketTest(AsyncTestCase):
         self.assertEqual(body, b"Hello world")
         stream.close()
         server.stop()
-UnixSocketTest = unittest.skipIf(
-    not hasattr(socket, 'AF_UNIX') or sys.platform == 'cygwin',
-    "unix sockets not supported on this platform")
 
 
 class KeepAliveTest(AsyncHTTPTestCase):
index 98783debaaa5546ea520f8c42f814248acac61b2..431c3a4708e6998c80cb5cb353f58aaaf5362913 100644 (file)
@@ -185,6 +185,7 @@ class TestIOLoopAddCallbackFromSignal(TestIOLoopAddCallback):
         self.io_loop.add_callback_from_signal(callback, *args, **kwargs)
 
 
+@unittest.skipIf(futures is None, "futures module not present")
 class TestIOLoopFutures(AsyncTestCase):
     def test_add_future_threads(self):
         with futures.ThreadPoolExecutor(1) as pool:
@@ -225,8 +226,6 @@ class TestIOLoopFutures(AsyncTestCase):
 
         self.assertEqual(self.exception.args[0], "callback")
         self.assertEqual(self.future.exception().args[0], "worker")
-TestIOLoopFutures = unittest.skipIf(
-    futures is None, "futures module not present")(TestIOLoopFutures)
 
 
 if __name__ == "__main__":
index f31d37ffac2d93f5c6f5b5c4d6b9b6115c25d431..23062bb6430969a4e006ea4b7cf8f63d5f2f4397 100644 (file)
@@ -357,18 +357,13 @@ class TestIOStreamMixin(object):
         # seconds.
         server, client = self.make_iostream_pair()
         try:
-            try:
-                # This test fails on pypy with ssl.  I think it's because
-                # pypy's gc defeats moves objects, breaking the
-                # "frozen write buffer" assumption.
-                if (isinstance(server, SSLIOStream) and
-                        platform.python_implementation() == 'PyPy'):
-                    raise unittest.SkipTest(
-                        "pypy gc causes problems with openssl")
-            except AttributeError:
-                # python 2.5 didn't have platform.python_implementation,
-                # but there was no pypy for 2.5
-                pass
+            # This test fails on pypy with ssl.  I think it's because
+            # pypy's gc defeats moves objects, breaking the
+            # "frozen write buffer" assumption.
+            if (isinstance(server, SSLIOStream) and
+                    platform.python_implementation() == 'PyPy'):
+                raise unittest.SkipTest(
+                    "pypy gc causes problems with openssl")
             NUM_KB = 4096
             for i in range(NUM_KB):
                 client.write(b"A" * 1024)
@@ -445,10 +440,10 @@ class TestIOStreamWebHTTP(TestIOStreamWebMixin, AsyncHTTPTestCase):
         return IOStream(socket.socket(), io_loop=self.io_loop)
 
 
+@skipIfNoSSL
 class TestIOStreamWebHTTPS(TestIOStreamWebMixin, AsyncHTTPSTestCase):
     def _make_client_iostream(self):
         return SSLIOStream(socket.socket(), io_loop=self.io_loop)
-TestIOStreamWebHTTPS = skipIfNoSSL(TestIOStreamWebHTTPS)
 
 
 class TestIOStream(TestIOStreamMixin, AsyncTestCase):
@@ -459,6 +454,7 @@ class TestIOStream(TestIOStreamMixin, AsyncTestCase):
         return IOStream(connection, io_loop=self.io_loop, **kwargs)
 
 
+@skipIfNoSSL
 class TestIOStreamSSL(TestIOStreamMixin, AsyncTestCase):
     def _make_server_iostream(self, connection, **kwargs):
         ssl_options = dict(
@@ -473,9 +469,9 @@ class TestIOStreamSSL(TestIOStreamMixin, AsyncTestCase):
 
     def _make_client_iostream(self, connection, **kwargs):
         return SSLIOStream(connection, io_loop=self.io_loop, **kwargs)
-TestIOStreamSSL = skipIfNoSSL(TestIOStreamSSL)
 
 
+@skipIfNonUnix
 class TestPipeIOStream(AsyncTestCase):
     def test_pipe_iostream(self):
         r, w = os.pipe()
@@ -501,4 +497,3 @@ class TestPipeIOStream(AsyncTestCase):
         self.assertEqual(data, b"ld")
 
         rs.close()
-TestPipeIOStream = skipIfNonUnix(TestPipeIOStream)
index 0c4fe053050017bf99e6c4c612c16c0c5ff079fd..9fc29074879076d50b09affcb9dc5c7ccb8f19e7 100644 (file)
@@ -32,11 +32,6 @@ from tornado.util import u, bytes_type, basestring_type
 
 @contextlib.contextmanager
 def ignore_bytes_warning():
-    if not hasattr(warnings, 'catch_warnings'):
-        # python 2.5 doesn't have catch_warnings, but it doesn't have
-        # BytesWarning either so there's nothing to catch.
-        yield
-        return
     with warnings.catch_warnings():
         warnings.simplefilter('ignore', category=BytesWarning)
         yield
index 285ca9c666cbb1269eb7008c43f5c98d6edb5070..a96b858ab62b60db529636cf2c2d1359115a56f9 100644 (file)
@@ -30,6 +30,7 @@ class SyncResolverTest(AsyncTestCase, _ResolverTestMixin):
         self.resolver = Resolver(self.io_loop)
 
 
+@unittest.skipIf(futures is None, "futures module not present")
 class ThreadedResolverTest(AsyncTestCase, _ResolverTestMixin):
     def setUp(self):
         super(ThreadedResolverTest, self).setUp()
@@ -40,5 +41,3 @@ class ThreadedResolverTest(AsyncTestCase, _ResolverTestMixin):
     def tearDown(self):
         self.executor.shutdown()
         super(ThreadedResolverTest, self).tearDown()
-ThreadedResolverTest = unittest.skipIf(
-    futures is None, "futures module not present")(ThreadedResolverTest)
index 2394670e3a252f51f1773b731121fa499fa34433..db03906d54cab57e08c536e570b66452c2786a12 100644 (file)
@@ -25,6 +25,7 @@ def skip_if_twisted():
 # Not using AsyncHTTPTestCase because we need control over the IOLoop.
 
 
+@skipIfNonUnix
 class ProcessTest(unittest.TestCase):
     def get_app(self):
         class ProcessHandler(RequestHandler):
@@ -129,9 +130,9 @@ class ProcessTest(unittest.TestCase):
             except Exception:
                 logging.error("exception in child process %d", id, exc_info=True)
                 raise
-ProcessTest = skipIfNonUnix(ProcessTest)
 
 
+@skipIfNonUnix
 class SubprocessTest(AsyncTestCase):
     def test_subprocess(self):
         subproc = Subprocess([sys.executable, '-u', '-i'],
@@ -177,4 +178,3 @@ class SubprocessTest(AsyncTestCase):
         ret = self.wait()
         self.assertEqual(subproc.returncode, ret)
         self.assertEqual(ret, -signal.SIGTERM)
-SubprocessTest = skipIfNonUnix(SubprocessTest)
index 795bb0f954793f3d86d9bb89755acd7a1006e4ae..197589826caba187529643a715a8930c69291456 100644 (file)
@@ -87,6 +87,7 @@ class ReactorTestCase(unittest.TestCase):
         restore_signal_handlers(self._saved_signals)
 
 
+@skipIfNoTwisted
 class ReactorWhenRunningTest(ReactorTestCase):
     def test_whenRunning(self):
         self._whenRunningCalled = False
@@ -103,9 +104,9 @@ class ReactorWhenRunningTest(ReactorTestCase):
 
     def anotherWhenRunningCallback(self):
         self._anotherWhenRunningCalled = True
-ReactorWhenRunningTest = skipIfNoTwisted(ReactorWhenRunningTest)
 
 
+@skipIfNoTwisted
 class ReactorCallLaterTest(ReactorTestCase):
     def test_callLater(self):
         self._laterCalled = False
@@ -122,9 +123,9 @@ class ReactorCallLaterTest(ReactorTestCase):
         self._laterCalled = True
         self._called = self._reactor.seconds()
         self._reactor.stop()
-ReactorCallLaterTest = skipIfNoTwisted(ReactorCallLaterTest)
 
 
+@skipIfNoTwisted
 class ReactorTwoCallLaterTest(ReactorTestCase):
     def test_callLater(self):
         self._later1Called = False
@@ -151,9 +152,9 @@ class ReactorTwoCallLaterTest(ReactorTestCase):
         self._later2Called = True
         self._called2 = self._reactor.seconds()
         self._reactor.stop()
-ReactorTwoCallLaterTest = skipIfNoTwisted(ReactorTwoCallLaterTest)
 
 
+@skipIfNoTwisted
 class ReactorCallFromThreadTest(ReactorTestCase):
     def setUp(self):
         super(ReactorCallFromThreadTest, self).setUp()
@@ -180,9 +181,9 @@ class ReactorCallFromThreadTest(ReactorTestCase):
     def testCallFromThread(self):
         self._reactor.callWhenRunning(self._whenRunningCallback)
         self._reactor.run()
-ReactorCallFromThreadTest = skipIfNoTwisted(ReactorCallFromThreadTest)
 
 
+@skipIfNoTwisted
 class ReactorCallInThread(ReactorTestCase):
     def setUp(self):
         super(ReactorCallInThread, self).setUp()
@@ -198,7 +199,6 @@ class ReactorCallInThread(ReactorTestCase):
     def testCallInThread(self):
         self._reactor.callWhenRunning(self._whenRunningCallback)
         self._reactor.run()
-ReactorCallInThread = skipIfNoTwisted(ReactorCallInThread)
 
 
 class Reader(object):
@@ -250,6 +250,7 @@ if have_twisted:
     Writer = implementer(IWriteDescriptor)(Writer)
 
 
+@skipIfNoTwisted
 class ReactorReaderWriterTest(ReactorTestCase):
     def _set_nonblocking(self, fd):
         flags = fcntl.fcntl(fd, fcntl.F_GETFL)
@@ -331,12 +332,12 @@ class ReactorReaderWriterTest(ReactorTestCase):
     def testNoWriter(self):
         self._reactor.callWhenRunning(self._testNoWriter)
         self._reactor.run()
-ReactorReaderWriterTest = skipIfNoTwisted(ReactorReaderWriterTest)
 
 # Test various combinations of twisted and tornado http servers,
 # http clients, and event loop interfaces.
 
 
+@skipIfNoTwisted
 class CompatibilityTests(unittest.TestCase):
     def setUp(self):
         self.saved_signals = save_signal_handlers()
@@ -443,7 +444,6 @@ class CompatibilityTests(unittest.TestCase):
         response = self.twisted_fetch(
             'http://localhost:%d' % self.tornado_port, self.run_reactor)
         self.assertEqual(response, 'Hello from tornado!')
-CompatibilityTests = skipIfNoTwisted(CompatibilityTests)
 
 
 if have_twisted:
@@ -467,8 +467,6 @@ if have_twisted:
             "test_lostFileDescriptor",  # incompatible with epoll and kqueue
         ],
         'twisted.internet.test.test_process.ProcessTestsBuilder': [
-            # Doesn't work on python 2.5
-            'test_systemCallUninterruptedByChildExit',
         ],
         # Process tests appear to work on OSX 10.7, but not 10.6
         #'twisted.internet.test.test_process.PTYProcessTestsBuilder': [