From: Ben Darnell Date: Sat, 19 Jan 2013 19:33:37 +0000 (-0500) Subject: Use real class decorators and remove other py25-era workarounds X-Git-Tag: v3.0.0~169 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05b8d05143e6d9deed17dc10a23cf5a9d0e6fc3c;p=thirdparty%2Ftornado.git Use real class decorators and remove other py25-era workarounds --- diff --git a/tornado/httpserver.py b/tornado/httpserver.py index 2738d7801..5a981cceb 100644 --- a/tornado/httpserver.py +++ b/tornado/httpserver.py @@ -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 diff --git a/tornado/locale.py b/tornado/locale.py index 732a767f3..e4e1a1544 100644 --- a/tornado/locale.py +++ b/tornado/locale.py @@ -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)): diff --git a/tornado/platform/twisted.py b/tornado/platform/twisted.py index 5902b739c..3821ad01c 100644 --- a/tornado/platform/twisted.py +++ b/tornado/platform/twisted.py @@ -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): diff --git a/tornado/simple_httpclient.py b/tornado/simple_httpclient.py index 43908ea45..535be909e 100644 --- a/tornado/simple_httpclient.py +++ b/tornado/simple_httpclient.py @@ -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, diff --git a/tornado/test/curl_httpclient_test.py b/tornado/test/curl_httpclient_test.py index 9f4eeaaf6..bc0c2daab 100644 --- a/tornado/test/curl_httpclient_test.py +++ b/tornado/test/curl_httpclient_test.py @@ -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) diff --git a/tornado/test/httpserver_test.py b/tornado/test/httpserver_test.py index f0f409189..f910c9bb4 100644 --- a/tornado/test/httpserver_test.py +++ b/tornado/test/httpserver_test.py @@ -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): diff --git a/tornado/test/ioloop_test.py b/tornado/test/ioloop_test.py index 98783deba..431c3a470 100644 --- a/tornado/test/ioloop_test.py +++ b/tornado/test/ioloop_test.py @@ -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__": diff --git a/tornado/test/iostream_test.py b/tornado/test/iostream_test.py index f31d37ffa..23062bb64 100644 --- a/tornado/test/iostream_test.py +++ b/tornado/test/iostream_test.py @@ -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) diff --git a/tornado/test/log_test.py b/tornado/test/log_test.py index 0c4fe0530..9fc290748 100644 --- a/tornado/test/log_test.py +++ b/tornado/test/log_test.py @@ -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 diff --git a/tornado/test/netutil_test.py b/tornado/test/netutil_test.py index 285ca9c66..a96b858ab 100644 --- a/tornado/test/netutil_test.py +++ b/tornado/test/netutil_test.py @@ -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) diff --git a/tornado/test/process_test.py b/tornado/test/process_test.py index 2394670e3..db03906d5 100644 --- a/tornado/test/process_test.py +++ b/tornado/test/process_test.py @@ -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) diff --git a/tornado/test/twisted_test.py b/tornado/test/twisted_test.py index 795bb0f95..197589826 100644 --- a/tornado/test/twisted_test.py +++ b/tornado/test/twisted_test.py @@ -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': [