From: Ben Darnell Date: Sun, 8 Feb 2015 19:40:04 +0000 (-0500) Subject: Run autopep8 X-Git-Tag: v4.2.0b1~127 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f098ca1e63246a1829b312a0d30bc05d215794f3;p=thirdparty%2Ftornado.git Run autopep8 --- diff --git a/tornado/auth.py b/tornado/auth.py index ac2fd0d19..f28b1ee25 100644 --- a/tornado/auth.py +++ b/tornado/auth.py @@ -1307,7 +1307,7 @@ class FacebookGraphMixin(OAuth2Mixin): http.fetch(self._oauth_request_token_url(**args), functools.partial(self._on_access_token, redirect_uri, client_id, - client_secret, callback, fields)) + client_secret, callback, fields)) def _on_access_token(self, redirect_uri, client_id, client_secret, future, fields, response): diff --git a/tornado/concurrent.py b/tornado/concurrent.py index acfbcd83e..a3f15dcde 100644 --- a/tornado/concurrent.py +++ b/tornado/concurrent.py @@ -44,12 +44,14 @@ except ImportError: _GC_CYCLE_FINALIZERS = (platform.python_implementation() == 'CPython' and sys.version_info >= (3, 4)) + class ReturnValueIgnoredError(Exception): pass # This class and associated code in the future object is derived # from the Trollius project, a backport of asyncio to Python 2.x - 3.x + class _TracebackLogger(object): """Helper to log a traceback upon destruction if not cleared. diff --git a/tornado/curl_httpclient.py b/tornado/curl_httpclient.py index ebbe0e84b..87d2ba488 100644 --- a/tornado/curl_httpclient.py +++ b/tornado/curl_httpclient.py @@ -35,6 +35,7 @@ from tornado.httpclient import HTTPResponse, HTTPError, AsyncHTTPClient, main curl_log = logging.getLogger('tornado.curl_httpclient') + class CurlAsyncHTTPClient(AsyncHTTPClient): def initialize(self, io_loop, max_clients=10, defaults=None): super(CurlAsyncHTTPClient, self).initialize(io_loop, defaults=defaults) @@ -286,7 +287,7 @@ class CurlAsyncHTTPClient(AsyncHTTPClient): curl.setopt(pycurl.HEADERFUNCTION, functools.partial(self._curl_header_callback, - headers, request.header_callback)) + headers, request.header_callback)) if request.streaming_callback: write_function = lambda chunk: self.io_loop.add_callback( request.streaming_callback, chunk) @@ -404,7 +405,7 @@ class CurlAsyncHTTPClient(AsyncHTTPClient): curl.setopt(pycurl.USERPWD, native_str(userpwd)) curl_log.debug("%s %s (username: %r)", request.method, request.url, - request.auth_username) + request.auth_username) else: curl.unsetopt(pycurl.USERPWD) curl_log.debug("%s %s", request.method, request.url) diff --git a/tornado/gen.py b/tornado/gen.py index 86fe2f195..5c40c6ed6 100644 --- a/tornado/gen.py +++ b/tornado/gen.py @@ -263,6 +263,7 @@ class Return(Exception): super(Return, self).__init__() self.value = value + class WaitIterator(object): """Provides an iterator to yield the results of futures as they finish. @@ -846,10 +847,10 @@ class Runner(object): # Lists containing YieldPoints require stack contexts; # other lists are handled via multi_future in convert_yielded. if (isinstance(yielded, list) and - any(isinstance(f, YieldPoint) for f in yielded)): + any(isinstance(f, YieldPoint) for f in yielded)): yielded = Multi(yielded) elif (isinstance(yielded, dict) and - any(isinstance(f, YieldPoint) for f in yielded.values())): + any(isinstance(f, YieldPoint) for f in yielded.values())): yielded = Multi(yielded) if isinstance(yielded, YieldPoint): diff --git a/tornado/http1connection.py b/tornado/http1connection.py index 181319c42..6226ef7af 100644 --- a/tornado/http1connection.py +++ b/tornado/http1connection.py @@ -37,6 +37,7 @@ class _QuietException(Exception): def __init__(self): pass + class _ExceptionLoggingContext(object): """Used with the ``with`` statement when calling delegate methods to log any exceptions with the given logger. Any exceptions caught are @@ -53,6 +54,7 @@ class _ExceptionLoggingContext(object): self.logger.error("Uncaught exception", exc_info=(typ, value, tb)) raise _QuietException + class HTTP1ConnectionParameters(object): """Parameters for `.HTTP1Connection` and `.HTTP1ServerConnection`. """ @@ -202,7 +204,7 @@ class HTTP1Connection(httputil.HTTPConnection): # 1xx responses should never indicate the presence of # a body. if ('Content-Length' in headers or - 'Transfer-Encoding' in headers): + 'Transfer-Encoding' in headers): raise httputil.HTTPInputError( "Response code %d cannot have body" % code) # TODO: client delegates will get headers_received twice diff --git a/tornado/httputil.py b/tornado/httputil.py index 9c99b3efa..21b170919 100644 --- a/tornado/httputil.py +++ b/tornado/httputil.py @@ -884,6 +884,7 @@ def doctests(): import doctest return doctest.DocTestSuite() + def split_host_and_port(netloc): """Returns ``(host, port)`` tuple from ``netloc``. diff --git a/tornado/iostream.py b/tornado/iostream.py index cdb6250b9..1bd33b42a 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -83,6 +83,8 @@ if hasattr(errno, "WSAEINPROGRESS"): _ERRNO_INPROGRESS += (errno.WSAEINPROGRESS,) ####################################################### + + class StreamClosedError(IOError): """Exception raised by `IOStream` methods when the stream is closed. @@ -1222,7 +1224,7 @@ class SSLIOStream(IOStream): # quiet as well. # https://groups.google.com/forum/?fromgroups#!topic/python-tornado/ApucKJat1_0 if (err.args[0] in _ERRNO_CONNRESET or - err.args[0] == errno.EBADF): + err.args[0] == errno.EBADF): return self.close(exc_info=True) raise except AttributeError: diff --git a/tornado/netutil.py b/tornado/netutil.py index 17e958040..06923b2af 100644 --- a/tornado/netutil.py +++ b/tornado/netutil.py @@ -68,6 +68,7 @@ if hasattr(errno, "WSAEWOULDBLOCK"): # Default backlog used when calling sock.listen() _DEFAULT_BACKLOG = 128 + def bind_sockets(port, address=None, family=socket.AF_UNSPEC, backlog=_DEFAULT_BACKLOG, flags=None): """Creates listening sockets bound to the given port and address. diff --git a/tornado/platform/asyncio.py b/tornado/platform/asyncio.py index bc6851750..cf1bf7a44 100644 --- a/tornado/platform/asyncio.py +++ b/tornado/platform/asyncio.py @@ -29,6 +29,7 @@ except ImportError as e: # Re-raise the original asyncio error, not the trollius one. raise e + class BaseAsyncIOLoop(IOLoop): def initialize(self, asyncio_loop, close_loop=False): self.asyncio_loop = asyncio_loop @@ -141,12 +142,14 @@ class AsyncIOLoop(BaseAsyncIOLoop): super(AsyncIOLoop, self).initialize(asyncio.new_event_loop(), close_loop=True) + def to_tornado_future(asyncio_future): """Convert an ``asyncio.Future`` to a `tornado.concurrent.Future`.""" tf = tornado.concurrent.Future() tornado.concurrent.chain_future(asyncio_future, tf) return tf + def to_asyncio_future(tornado_future): """Convert a `tornado.concurrent.Future` to an ``asyncio.Future``.""" af = asyncio.Future() diff --git a/tornado/platform/select.py b/tornado/platform/select.py index 1e1265547..db52ef910 100644 --- a/tornado/platform/select.py +++ b/tornado/platform/select.py @@ -47,7 +47,7 @@ class _Select(object): # Closed connections are reported as errors by epoll and kqueue, # but as zero-byte reads by select, so when errors are requested # we need to listen for both read and error. - #self.read_fds.add(fd) + # self.read_fds.add(fd) def modify(self, fd, events): self.unregister(fd) diff --git a/tornado/simple_httpclient.py b/tornado/simple_httpclient.py index 31d076e2d..13400207a 100644 --- a/tornado/simple_httpclient.py +++ b/tornado/simple_httpclient.py @@ -317,7 +317,7 @@ class _HTTPConnection(httputil.HTTPMessageDelegate): body_present = (self.request.body is not None or self.request.body_producer is not None) if ((body_expected and not body_present) or - (body_present and not body_expected)): + (body_present and not body_expected)): raise ValueError( 'Body must %sbe None for method %s (unelss ' 'allow_nonstandard_methods is true)' % diff --git a/tornado/test/asyncio_test.py b/tornado/test/asyncio_test.py index cb990748f..1be0e54f3 100644 --- a/tornado/test/asyncio_test.py +++ b/tornado/test/asyncio_test.py @@ -27,6 +27,7 @@ except ImportError: skipIfNoSingleDispatch = unittest.skipIf( gen.singledispatch is None, "singledispatch module not present") + @unittest.skipIf(asyncio is None, "asyncio module not present") class AsyncIOLoopTest(AsyncTestCase): def get_new_ioloop(self): diff --git a/tornado/test/escape_test.py b/tornado/test/escape_test.py index f64042888..98a234638 100644 --- a/tornado/test/escape_test.py +++ b/tornado/test/escape_test.py @@ -217,9 +217,8 @@ class EscapeTestCase(unittest.TestCase): self.assertRaises(UnicodeDecodeError, json_encode, b"\xe9") def test_squeeze(self): - self.assertEqual(squeeze(u('sequences of whitespace chars')) - , u('sequences of whitespace chars')) - + self.assertEqual(squeeze(u('sequences of whitespace chars')), u('sequences of whitespace chars')) + def test_recursive_unicode(self): tests = { 'dict': {b"foo": b"bar"}, diff --git a/tornado/test/gen_test.py b/tornado/test/gen_test.py index 5d646d150..a5d78b5a9 100644 --- a/tornado/test/gen_test.py +++ b/tornado/test/gen_test.py @@ -1072,6 +1072,7 @@ class WithTimeoutTest(AsyncTestCase): yield gen.with_timeout(datetime.timedelta(seconds=3600), executor.submit(lambda: None)) + class WaitIteratorTest(AsyncTestCase): @gen_test def test_empty_iterator(self): @@ -1121,10 +1122,10 @@ class WaitIteratorTest(AsyncTestCase): while not dg.done(): dr = yield dg.next() if dg.current_index == "f1": - self.assertTrue(dg.current_future==f1 and dr==24, + self.assertTrue(dg.current_future == f1 and dr == 24, "WaitIterator dict status incorrect") elif dg.current_index == "f2": - self.assertTrue(dg.current_future==f2 and dr==42, + self.assertTrue(dg.current_future == f2 and dr == 42, "WaitIterator dict status incorrect") else: self.fail("got bad WaitIterator index {}".format( @@ -1145,7 +1146,7 @@ class WaitIteratorTest(AsyncTestCase): futures[3].set_result(84) if iteration < 8: - self.io_loop.add_callback(self.finish_coroutines, iteration+1, futures) + self.io_loop.add_callback(self.finish_coroutines, iteration + 1, futures) @gen_test def test_iterator(self): diff --git a/tornado/test/httpclient_test.py b/tornado/test/httpclient_test.py index 875864ac6..f62cb5ca1 100644 --- a/tornado/test/httpclient_test.py +++ b/tornado/test/httpclient_test.py @@ -459,7 +459,7 @@ Transfer-Encoding: chunked # Twisted's reactor does not. The removeReader call fails and so # do all future removeAll calls (which our tests do at cleanup). # - #def test_post_307(self): + # def test_post_307(self): # response = self.fetch("/redirect?status=307&url=/post", # method="POST", body=b"arg1=foo&arg2=bar") # self.assertEqual(response.body, b"Post arg1: foo, arg2: bar") @@ -589,5 +589,5 @@ class HTTPRequestTestCase(unittest.TestCase): def test_if_modified_since(self): http_date = datetime.datetime.utcnow() request = HTTPRequest('http://example.com', if_modified_since=http_date) - self.assertEqual(request.headers, - {'If-Modified-Since': format_timestamp(http_date)}) + self.assertEqual(request.headers, + {'If-Modified-Since': format_timestamp(http_date)}) diff --git a/tornado/test/httputil_test.py b/tornado/test/httputil_test.py index 3995abe8b..2ddc15fab 100644 --- a/tornado/test/httputil_test.py +++ b/tornado/test/httputil_test.py @@ -237,14 +237,14 @@ Foo: even # and cpython's unicodeobject.c (which defines the implementation # of unicode_type.splitlines(), and uses a different list than TR13). newlines = [ - u('\u001b'), # VERTICAL TAB - u('\u001c'), # FILE SEPARATOR - u('\u001d'), # GROUP SEPARATOR - u('\u001e'), # RECORD SEPARATOR - u('\u0085'), # NEXT LINE - u('\u2028'), # LINE SEPARATOR - u('\u2029'), # PARAGRAPH SEPARATOR - ] + u('\u001b'), # VERTICAL TAB + u('\u001c'), # FILE SEPARATOR + u('\u001d'), # GROUP SEPARATOR + u('\u001e'), # RECORD SEPARATOR + u('\u0085'), # NEXT LINE + u('\u2028'), # LINE SEPARATOR + u('\u2029'), # PARAGRAPH SEPARATOR + ] for newline in newlines: # Try the utf8 and latin1 representations of each newline for encoding in ['utf8', 'latin1']: @@ -278,7 +278,7 @@ Foo: even [('Cr', 'cr\rMore: more'), ('Crlf', 'crlf'), ('Lf', 'lf'), - ]) + ]) class FormatTimestampTest(unittest.TestCase): diff --git a/tornado/test/ioloop_test.py b/tornado/test/ioloop_test.py index 7eb7594fd..15f8a2cdb 100644 --- a/tornado/test/ioloop_test.py +++ b/tornado/test/ioloop_test.py @@ -305,7 +305,7 @@ class TestIOLoop(AsyncTestCase): # Use a NullContext to keep the exception from being caught by # AsyncTestCase. with NullContext(): - self.io_loop.add_callback(lambda: 1/0) + self.io_loop.add_callback(lambda: 1 / 0) self.io_loop.add_callback(self.stop) with ExpectLog(app_log, "Exception in callback"): self.wait() @@ -316,7 +316,7 @@ class TestIOLoop(AsyncTestCase): @gen.coroutine def callback(): self.io_loop.add_callback(self.stop) - 1/0 + 1 / 0 self.io_loop.add_callback(callback) with ExpectLog(app_log, "Exception in callback"): self.wait() @@ -324,12 +324,12 @@ class TestIOLoop(AsyncTestCase): def test_spawn_callback(self): # An added callback runs in the test's stack_context, so will be # re-arised in wait(). - self.io_loop.add_callback(lambda: 1/0) + self.io_loop.add_callback(lambda: 1 / 0) with self.assertRaises(ZeroDivisionError): self.wait() # A spawned callback is run directly on the IOLoop, so it will be # logged without stopping the test. - self.io_loop.spawn_callback(lambda: 1/0) + self.io_loop.spawn_callback(lambda: 1 / 0) self.io_loop.add_callback(self.stop) with ExpectLog(app_log, "Exception in callback"): self.wait() diff --git a/tornado/test/iostream_test.py b/tornado/test/iostream_test.py index ca35de69b..9d0bd4f69 100644 --- a/tornado/test/iostream_test.py +++ b/tornado/test/iostream_test.py @@ -884,7 +884,6 @@ class TestIOStreamStartTLS(AsyncTestCase): with self.assertRaises((ssl.SSLError, socket.error)): yield server_future - @unittest.skipIf(not hasattr(ssl, 'create_default_context'), 'ssl.create_default_context not present') @gen_test diff --git a/tornado/test/locale_test.py b/tornado/test/locale_test.py index d12ad52ff..2c3dae910 100644 --- a/tornado/test/locale_test.py +++ b/tornado/test/locale_test.py @@ -58,7 +58,7 @@ class EnglishTest(unittest.TestCase): self.assertEqual(locale.format_date(date, full_format=True), 'April 28, 2013 at 6:35 pm') - self.assertEqual(locale.format_date(datetime.datetime.utcnow() - datetime.timedelta(seconds=2), full_format=False), + self.assertEqual(locale.format_date(datetime.datetime.utcnow() - datetime.timedelta(seconds=2), full_format=False), '2 seconds ago') self.assertEqual(locale.format_date(datetime.datetime.utcnow() - datetime.timedelta(minutes=2), full_format=False), '2 minutes ago') diff --git a/tornado/test/netutil_test.py b/tornado/test/netutil_test.py index 1df1e3204..7d9cad34a 100644 --- a/tornado/test/netutil_test.py +++ b/tornado/test/netutil_test.py @@ -67,10 +67,12 @@ class _ResolverErrorTestMixin(object): yield self.resolver.resolve('an invalid domain', 80, socket.AF_UNSPEC) + def _failing_getaddrinfo(*args): """Dummy implementation of getaddrinfo for use in mocks""" raise socket.gaierror("mock: lookup failed") + @skipIfNoNetwork class BlockingResolverTest(AsyncTestCase, _ResolverTestMixin): def setUp(self): diff --git a/tornado/test/twisted_test.py b/tornado/test/twisted_test.py index b31ae94cb..315b3b758 100644 --- a/tornado/test/twisted_test.py +++ b/tornado/test/twisted_test.py @@ -75,6 +75,7 @@ skipIfNoTwisted = unittest.skipUnless(have_twisted, skipIfNoSingleDispatch = unittest.skipIf( gen.singledispatch is None, "singledispatch module not present") + def save_signal_handlers(): saved = {} for sig in [signal.SIGINT, signal.SIGTERM, signal.SIGCHLD]: diff --git a/tornado/test/util.py b/tornado/test/util.py index 358809f21..9dd9c0ce1 100644 --- a/tornado/test/util.py +++ b/tornado/test/util.py @@ -31,6 +31,7 @@ skipIfNoNetwork = unittest.skipIf('NO_NETWORK' in os.environ, skipIfNoIPv6 = unittest.skipIf(not socket.has_ipv6, 'ipv6 support not present') + def refusing_port(): """Returns a local port number that will refuse all connections. diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index adf6be974..3c470428b 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -245,7 +245,7 @@ class CookieTest(WebTestCase): headers = response.headers.get_list("Set-Cookie") self.assertEqual(sorted(headers), ["foo=bar; Max-Age=10; Path=/"]) - + def test_set_cookie_expires_days(self): response = self.fetch("/set_expires_days") header = response.headers.get("Set-Cookie") @@ -2312,7 +2312,7 @@ class XSRFTest(SimpleHandlerTestCase): token2 = self.get_token() # Each token can be used to authenticate its own request. for token in (self.xsrf_token, token2): - response = self.fetch( + response = self.fetch( "/", method="POST", body=urllib_parse.urlencode(dict(_xsrf=token)), headers=self.cookie_headers(token)) diff --git a/tornado/test/websocket_test.py b/tornado/test/websocket_test.py index 7e93d1714..42599382d 100644 --- a/tornado/test/websocket_test.py +++ b/tornado/test/websocket_test.py @@ -53,7 +53,7 @@ class EchoHandler(TestWebSocketHandler): class ErrorInOnMessageHandler(TestWebSocketHandler): def on_message(self, message): - 1/0 + 1 / 0 class HeaderHandler(TestWebSocketHandler): @@ -106,6 +106,7 @@ class WebSocketBaseTestCase(AsyncHTTPTestCase): ws.close() yield self.close_future + class WebSocketTest(WebSocketBaseTestCase): def get_app(self): self.close_future = Future() @@ -250,7 +251,7 @@ class WebSocketTest(WebSocketBaseTestCase): headers = {'Origin': 'http://127.0.0.1:%d' % port} ws = yield websocket_connect(HTTPRequest(url, headers=headers), - io_loop=self.io_loop) + io_loop=self.io_loop) ws.write_message('hello') response = yield ws.read_message() self.assertEqual(response, 'hello') @@ -264,7 +265,7 @@ class WebSocketTest(WebSocketBaseTestCase): headers = {'Origin': 'http://127.0.0.1:%d/something' % port} ws = yield websocket_connect(HTTPRequest(url, headers=headers), - io_loop=self.io_loop) + io_loop=self.io_loop) ws.write_message('hello') response = yield ws.read_message() self.assertEqual(response, 'hello') diff --git a/tornado/util.py b/tornado/util.py index cac4e3aae..bc66beaeb 100644 --- a/tornado/util.py +++ b/tornado/util.py @@ -343,7 +343,7 @@ def _websocket_mask_python(mask, data): return unmasked.tostring() if (os.environ.get('TORNADO_NO_EXTENSION') or - os.environ.get('TORNADO_EXTENSION') == '0'): + os.environ.get('TORNADO_EXTENSION') == '0'): # These environment variables exist to make it easier to do performance # comparisons; they are not guaranteed to remain supported in the future. _websocket_mask = _websocket_mask_python diff --git a/tornado/websocket.py b/tornado/websocket.py index c009225ce..7c7866369 100644 --- a/tornado/websocket.py +++ b/tornado/websocket.py @@ -39,9 +39,9 @@ from tornado.tcpclient import TCPClient from tornado.util import _websocket_mask try: - from urllib.parse import urlparse # py2 + from urllib.parse import urlparse # py2 except ImportError: - from urlparse import urlparse # py3 + from urlparse import urlparse # py3 try: xrange # py2 @@ -160,7 +160,6 @@ class WebSocketHandler(tornado.web.RequestHandler): else: origin = self.request.headers.get("Sec-Websocket-Origin", None) - # If there was an origin header, check to make sure it matches # according to check_origin. When the origin is None, we assume it # did not come from a browser and that it can be passed on. @@ -549,12 +548,12 @@ class WebSocketProtocol13(WebSocketProtocol): extensions = self._parse_extensions_header(self.request.headers) for ext in extensions: if (ext[0] == 'permessage-deflate' and - self._compression_options is not None): + self._compression_options is not None): # TODO: negotiate parameters if compression_options # specifies limits. self._create_compressors('server', ext[1]) if ('client_max_window_bits' in ext[1] and - ext[1]['client_max_window_bits'] is None): + ext[1]['client_max_window_bits'] is None): # Don't echo an offered client_max_window_bits # parameter with no value. del ext[1]['client_max_window_bits'] @@ -599,7 +598,7 @@ class WebSocketProtocol13(WebSocketProtocol): extensions = self._parse_extensions_header(headers) for ext in extensions: if (ext[0] == 'permessage-deflate' and - self._compression_options is not None): + self._compression_options is not None): self._create_compressors('client', ext[1]) else: raise ValueError("unsupported extension %r", ext)