]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
More flake8 cleanup.
authorBen Darnell <ben@bendarnell.com>
Sun, 8 Feb 2015 20:02:49 +0000 (15:02 -0500)
committerBen Darnell <ben@bendarnell.com>
Sun, 8 Feb 2015 20:02:49 +0000 (15:02 -0500)
The only remaining flake8 errors are for line length.

19 files changed:
tornado/auth.py
tornado/curl_httpclient.py
tornado/gen.py
tornado/iostream.py
tornado/options.py
tornado/platform/auto.py
tornado/platform/twisted.py
tornado/test/curl_httpclient_test.py
tornado/test/gen_test.py
tornado/test/gettext_translations/extract_me.py
tornado/test/httpserver_test.py
tornado/test/import_test.py
tornado/test/ioloop_test.py
tornado/test/iostream_test.py
tornado/test/twisted_test.py
tornado/test/web_test.py
tornado/test/websocket_test.py
tornado/util.py
tornado/web.py

index f28b1ee25a8d992a0731063ad2fa0901118a6022..00c833aa231a9321152c5ea361289412fd7d2fdb 100644 (file)
@@ -123,6 +123,7 @@ def _auth_return_future(f):
         if callback is not None:
             future.add_done_callback(
                 functools.partial(_auth_future_to_callback, callback))
+
         def handle_exception(typ, value, tb):
             if future.done():
                 return False
index 87d2ba488996bb2fb8dce3b5802d5f801def82a4..bced9499efacc7a735505c2a84afe75fe78cf8ce 100644 (file)
@@ -289,8 +289,8 @@ class CurlAsyncHTTPClient(AsyncHTTPClient):
                     functools.partial(self._curl_header_callback,
                                       headers, request.header_callback))
         if request.streaming_callback:
-            write_function = lambda chunk: self.io_loop.add_callback(
-                request.streaming_callback, chunk)
+            def write_function(chunk):
+                self.io_loop.add_callback(request.streaming_callback, chunk)
         else:
             write_function = buffer.write
         if bytes is str:  # py2
@@ -382,6 +382,7 @@ class CurlAsyncHTTPClient(AsyncHTTPClient):
                     % request.method)
 
             request_buffer = BytesIO(utf8(request.body))
+
             def ioctl(cmd):
                 if cmd == curl.IOCMD_RESTARTREAD:
                     request_buffer.seek(0)
index 5c40c6ed6468e48640f6e48a6353699e7035406d..f59f0d893a270722198999dd9e5999aa373e1622 100644 (file)
@@ -124,9 +124,11 @@ def engine(func):
     which use ``self.finish()`` in place of a callback argument.
     """
     func = _make_coroutine_wrapper(func, replace_callback=False)
+
     @functools.wraps(func)
     def wrapper(*args, **kwargs):
         future = func(*args, **kwargs)
+
         def final_callback(future):
             if future.result() is not None:
                 raise ReturnValueIgnoredError(
@@ -479,11 +481,13 @@ def Task(func, *args, **kwargs):
        yielded.
     """
     future = Future()
+
     def handle_exception(typ, value, tb):
         if future.done():
             return False
         future.set_exc_info((typ, value, tb))
         return True
+
     def set_result(result):
         if future.done():
             return
@@ -600,6 +604,7 @@ def multi_future(children):
     future = Future()
     if not children:
         future.set_result({} if keys is not None else [])
+
     def callback(f):
         unfinished_children.remove(f)
         if not unfinished_children:
@@ -665,6 +670,7 @@ def with_timeout(timeout, future, io_loop=None, quiet_exceptions=()):
     chain_future(future, result)
     if io_loop is None:
         io_loop = IOLoop.current()
+
     def error_callback(future):
         try:
             future.result()
@@ -672,6 +678,7 @@ def with_timeout(timeout, future, io_loop=None, quiet_exceptions=()):
             if not isinstance(e, quiet_exceptions):
                 app_log.error("Exception in Future %r after timeout",
                               future, exc_info=True)
+
     def timeout_callback():
         result.set_exception(TimeoutError("Timeout"))
         # In case the wrapped future goes on to fail, log it.
@@ -857,6 +864,7 @@ class Runner(object):
             # YieldPoints are too closely coupled to the Runner to go
             # through the generic convert_yielded mechanism.
             self.future = TracebackFuture()
+
             def start_yield_point():
                 try:
                     yielded.start(self)
@@ -875,6 +883,7 @@ class Runner(object):
                 with stack_context.ExceptionStackContext(
                         self.handle_exception) as deactivate:
                     self.stack_context_deactivate = deactivate
+
                     def cb():
                         start_yield_point()
                         self.run()
index 1bd33b42a6004d1647647f40d778390cd8c93d82..371a02d3e86e305403e3681b300f6bbb4a942762 100644 (file)
@@ -1104,6 +1104,7 @@ class IOStream(BaseIOStream):
         # If we had an "unwrap" counterpart to this method we would need
         # to restore the original callback after our Future resolves
         # so that repeated wrap/unwrap calls don't build up layers.
+
         def close_callback():
             if not future.done():
                 future.set_exception(ssl_stream.error or StreamClosedError())
index c855407c295ea475f864eae9497402192aa24a14..89a9e4326539e5d4d330ab1aea2b74d138f97cf3 100644 (file)
@@ -256,7 +256,7 @@ class OptionParser(object):
             arg = args[i].lstrip("-")
             name, equals, value = arg.partition("=")
             name = name.replace('-', '_')
-            if not name in self._options:
+            if name not in self._options:
                 self.print_help()
                 raise Error('Unrecognized command line option: %r' % name)
             option = self._options[name]
index ddfe06b4a5e2c33ea2b12f90ce3196c53bf4b09a..d3eeb56b2e519fa77293677eccfd6eba46e5f2a7 100644 (file)
@@ -32,6 +32,7 @@ if os.name == 'nt':
     from tornado.platform.windows import set_close_exec
 elif 'APPENGINE_RUNTIME' in os.environ:
     from tornado.platform.common import Waker
+
     def set_close_exec(fd):
         pass
 else:
@@ -41,9 +42,13 @@ try:
     # monotime monkey-patches the time module to have a monotonic function
     # in versions of python before 3.3.
     import monotime
+    # Silence pyflakes warning about this unused import
+    monotime
 except ImportError:
     pass
 try:
     from time import monotonic as monotonic_time
 except ImportError:
     monotonic_time = None
+
+__all__ = ['Waker', 'set_close_exec', 'monotonic_time']
index 09b328366b6796dccaa69f7d40f59794fd814dd5..3d7eba42273a8c65c812bce5d15b52d508b11758 100644 (file)
@@ -572,6 +572,7 @@ if hasattr(gen.convert_yielded, 'register'):
     @gen.convert_yielded.register(Deferred)
     def _(d):
         f = Future()
+
         def errback(failure):
             try:
                 failure.raiseException()
index 8d7065dfe34287c62f7e9e3e34d7fb07bc61854d..3ac21f4d7260be0f4927695e61580a7c6c628118 100644 (file)
@@ -8,7 +8,7 @@ from tornado.stack_context import ExceptionStackContext
 from tornado.testing import AsyncHTTPTestCase
 from tornado.test import httpclient_test
 from tornado.test.util import unittest
-from tornado.web import Application, RequestHandler, URLSpec
+from tornado.web import Application, RequestHandler
 
 
 try:
index a5d78b5a9b16fad78f0e27d2e3e43ea239b8ee82..31acadd8b4e7578c136cace24b6b5a4d7699d993 100644 (file)
@@ -816,6 +816,7 @@ class GenCoroutineTest(AsyncTestCase):
     @gen_test
     def test_moment(self):
         calls = []
+
         @gen.coroutine
         def f(name, yieldable):
             for i in range(5):
index 75406ecc77d70611d2a3986cdeb82c788063a7c2..db70fb9375d09e26d16e78fe9c9798a4ac3c3132 100644 (file)
@@ -1,3 +1,4 @@
+# flake8: noqa
 # Dummy source file to allow creation of the initial .po file in the
 # same way as a real project.  I'm not entirely sure about the real
 # workflow here, but this seems to work.
index 64ef96d459406d7224bbe1e968da62824ffc6291..62ef6ca3d5f2373f1ab90dcd11e7e1c0bc7e5c87 100644 (file)
@@ -32,6 +32,7 @@ def read_stream_body(stream, callback):
     """Reads an HTTP response from `stream` and runs callback with its
     headers and body."""
     chunks = []
+
     class Delegate(HTTPMessageDelegate):
         def headers_received(self, start_line, headers):
             self.headers = headers
@@ -589,6 +590,7 @@ class KeepAliveTest(AsyncHTTPTestCase):
         class HelloHandler(RequestHandler):
             def get(self):
                 self.finish('Hello world')
+
             def post(self):
                 self.finish('Hello world')
 
@@ -863,6 +865,7 @@ class StreamingChunkSizeTest(AsyncHTTPTestCase):
     def test_chunked_compressed(self):
         compressed = self.compress(self.BODY)
         self.assertGreater(len(compressed), 20)
+
         def body_producer(write):
             write(compressed[:20])
             write(compressed[20:])
index de7cc0b9fbf51e7cf464944107cc77fc9f77f619..1be6427f19aa7d52d814c0fc045d4f057e011855 100644 (file)
@@ -1,3 +1,4 @@
+# flake8: noqa
 from __future__ import absolute_import, division, print_function, with_statement
 from tornado.test.util import unittest
 
index 15f8a2cdbbcedf3df77c75b47346f08f21c0d8ec..0bad57588aa3f9ec9b84d0cc75f27efffe277cba 100644 (file)
@@ -180,10 +180,12 @@ class TestIOLoop(AsyncTestCase):
         # t2 should be cancelled by t1, even though it is already scheduled to
         # be run before the ioloop even looks at it.
         now = self.io_loop.time()
+
         def t1():
             calls[0] = True
             self.io_loop.remove_timeout(t2_handle)
         self.io_loop.add_timeout(now + 0.01, t1)
+
         def t2():
             calls[1] = True
         t2_handle = self.io_loop.add_timeout(now + 0.02, t2)
@@ -252,6 +254,7 @@ class TestIOLoop(AsyncTestCase):
         """The handler callback receives the same fd object it passed in."""
         server_sock, port = bind_unused_port()
         fds = []
+
         def handle_connection(fd, events):
             fds.append(fd)
             conn, addr = server_sock.accept()
@@ -274,6 +277,7 @@ class TestIOLoop(AsyncTestCase):
 
     def test_mixed_fd_fileobj(self):
         server_sock, port = bind_unused_port()
+
         def f(fd, events):
             pass
         self.io_loop.add_handler(server_sock, f, IOLoop.READ)
@@ -288,6 +292,7 @@ class TestIOLoop(AsyncTestCase):
         """Calling start() twice should raise an error, not deadlock."""
         returned_from_start = [False]
         got_exception = [False]
+
         def callback():
             try:
                 self.io_loop.start()
@@ -344,6 +349,7 @@ class TestIOLoop(AsyncTestCase):
 
             # After reading from one fd, remove the other from the IOLoop.
             chunks = []
+
             def handle_read(fd, events):
                 chunks.append(fd.recv(1024))
                 if fd is client:
index 9d0bd4f69c9c338359c9464e02fb29df3e35799b..81ce4cac28d14b8a3fee6a4c1d263cd226291898 100644 (file)
@@ -310,6 +310,7 @@ class TestIOStreamMixin(object):
             def streaming_callback(data):
                 chunks.append(data)
                 self.stop()
+
             def close_callback(data):
                 assert not data, data
                 closed[0] = True
@@ -355,6 +356,7 @@ class TestIOStreamMixin(object):
     def test_future_delayed_close_callback(self):
         # Same as test_delayed_close_callback, but with the future interface.
         server, client = self.make_iostream_pair()
+
         # We can't call make_iostream_pair inside a gen_test function
         # because the ioloop is not reentrant.
         @gen_test
@@ -534,6 +536,7 @@ class TestIOStreamMixin(object):
         # and IOStream._maybe_add_error_listener.
         server, client = self.make_iostream_pair()
         closed = [False]
+
         def close_callback():
             closed[0] = True
             self.stop()
index 315b3b758d3cd2288458a5c040cc9c5ceb7888d4..cc445247cc592ed2e9720cde6cc92c782ec69745 100644 (file)
@@ -453,6 +453,7 @@ class CompatibilityTests(unittest.TestCase):
 
     def twisted_coroutine_fetch(self, url, runner):
         body = [None]
+
         @gen.coroutine
         def f():
             # This is simpler than the non-coroutine version, but it cheats
@@ -553,7 +554,7 @@ if have_twisted:
             'test_changeUID',
         ],
         # Process tests appear to work on OSX 10.7, but not 10.6
-        #'twisted.internet.test.test_process.PTYProcessTestsBuilder': [
+        # 'twisted.internet.test.test_process.PTYProcessTestsBuilder': [
         #    'test_systemCallUninterruptedByChildExit',
         #    ],
         'twisted.internet.test.test_tcp.TCPClientTestsBuilder': [
@@ -572,7 +573,7 @@ if have_twisted:
         'twisted.internet.test.test_threads.ThreadTestsBuilder': [],
         'twisted.internet.test.test_time.TimeTestsBuilder': [],
         # Extra third-party dependencies (pyOpenSSL)
-        #'twisted.internet.test.test_tls.SSLClientTestsMixin': [],
+        # 'twisted.internet.test.test_tls.SSLClientTestsMixin': [],
         'twisted.internet.test.test_udp.UDPServerTestsBuilder': [],
         'twisted.internet.test.test_unix.UNIXTestsBuilder': [
             # Platform-specific.  These tests would be skipped automatically
index 3c470428b991faf889aefb72c0365177fb723364..a643435c6819ea107316b87ffb372391e1a5f995 100644 (file)
@@ -1549,6 +1549,7 @@ class UIMethodUIModuleTest(SimpleHandlerTestCase):
         def my_ui_method(handler, x):
             return "In my_ui_method(%s) with handler value %s." % (
                 x, handler.value())
+
         class MyModule(UIModule):
             def render(self, x):
                 return "In MyModule(%s) with handler value %s." % (
@@ -2167,6 +2168,7 @@ class SignedValueTest(unittest.TestCase):
     def test_payload_tampering(self):
         # These cookies are variants of the one in test_known_values.
         sig = "3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152"
+
         def validate(prefix):
             return (b'value' ==
                     decode_signed_value(SignedValueTest.SECRET, "key",
@@ -2181,6 +2183,7 @@ class SignedValueTest(unittest.TestCase):
 
     def test_signature_tampering(self):
         prefix = "2|1:0|10:1300000000|3:key|8:dmFsdWU=|"
+
         def validate(sig):
             return (b'value' ==
                     decode_signed_value(SignedValueTest.SECRET, "key",
index 42599382d8c2c0392b17d748a47a1775cd253746..6b182d0765ba7256d9a340143f057a6e97712322 100644 (file)
@@ -12,7 +12,7 @@ from tornado.web import Application, RequestHandler
 from tornado.util import u
 
 try:
-    import tornado.websocket
+    import tornado.websocket  # noqa
     from tornado.util import _websocket_mask_python
 except ImportError:
     # The unittest module presents misleading errors on ImportError
index bc66beaebfe07e7ad7fbd69c27586239ec93b5ad..d943ce2ba9649e6c1f2257c77007f6d928e78580 100644 (file)
@@ -83,7 +83,7 @@ class GzipDecompressor(object):
 # unicode_literals" have other problems (see PEP 414).  u() can be applied
 # to ascii strings that include \u escapes (but they must not contain
 # literal non-ascii characters).
-if type('') is not type(b''):
+if not isinstance(b'', type('')):
     def u(s):
         return s
     unicode_type = str
@@ -91,8 +91,10 @@ if type('') is not type(b''):
 else:
     def u(s):
         return s.decode('unicode_escape')
-    unicode_type = unicode
-    basestring_type = basestring
+    # These names don't exist in py3, so use noqa comments to disable
+    # warnings in flake8.
+    unicode_type = unicode  # noqa
+    basestring_type = basestring  # noqa
 
 
 def import_object(name):
index f6cb99429a8efd1c8ddc6f737401ea29df6c1708..c1614db71cba2f44186e0e4a208d65987b1837a3 100644 (file)
@@ -1487,6 +1487,7 @@ def asynchronous(method):
     """
     # Delay the IOLoop import because it's not available on app engine.
     from tornado.ioloop import IOLoop
+
     @functools.wraps(method)
     def wrapper(self, *args, **kwargs):
         self._auto_finish = False