From dd9a8ac18ca4a67761489d10386490bb29061f40 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sun, 27 May 2012 20:07:56 -0700 Subject: [PATCH] Another round of minor whitespace cleanups from autopep8 --- tornado/auth.py | 2 +- tornado/curl_httpclient.py | 2 +- tornado/database.py | 2 +- tornado/httputil.py | 4 ++-- tornado/iostream.py | 4 ++-- tornado/options.py | 1 - tornado/platform/common.py | 1 + tornado/platform/windows.py | 2 -- tornado/stack_context.py | 1 + tornado/test/gen_test.py | 2 ++ tornado/test/options_test.py | 1 + tornado/test/simple_httpclient_test.py | 1 + tornado/test/stack_context_test.py | 5 +++++ tornado/test/template_test.py | 1 + tornado/test/testing_test.py | 5 +++-- tornado/test/twisted_test.py | 3 +++ tornado/test/util_test.py | 1 + tornado/test/web_test.py | 12 ++++++++---- tornado/testing.py | 1 - tornado/web.py | 4 ++-- 20 files changed, 36 insertions(+), 19 deletions(-) diff --git a/tornado/auth.py b/tornado/auth.py index 11b2ea4e..a61e359a 100644 --- a/tornado/auth.py +++ b/tornado/auth.py @@ -1069,7 +1069,7 @@ class FacebookGraphMixin(OAuth2Mixin): if access_token: all_args["access_token"] = access_token all_args.update(args) - + if all_args: url += "?" + urllib.urlencode(all_args) callback = self.async_callback(self._on_facebook_request, callback) diff --git a/tornado/curl_httpclient.py b/tornado/curl_httpclient.py index 04887631..95958c19 100644 --- a/tornado/curl_httpclient.py +++ b/tornado/curl_httpclient.py @@ -397,7 +397,7 @@ def _curl_setup_request(curl, request, buffer, headers): if request.client_cert is not None: curl.setopt(pycurl.SSLCERT, request.client_cert) - + if request.client_key is not None: curl.setopt(pycurl.SSLKEY, request.client_key) diff --git a/tornado/database.py b/tornado/database.py index 837746bb..982c5db5 100644 --- a/tornado/database.py +++ b/tornado/database.py @@ -33,6 +33,7 @@ except ImportError: # which has limitations on third-party modules) MySQLdb = None + class Connection(object): """A lightweight wrapper around MySQLdb DB-API connections. @@ -232,7 +233,6 @@ if MySQLdb is not None: for field_type in field_types: CONVERSIONS[field_type] = [(FLAG.BINARY, str)] + CONVERSIONS[field_type] - # Alias some common MySQL exceptions IntegrityError = MySQLdb.IntegrityError OperationalError = MySQLdb.OperationalError diff --git a/tornado/httputil.py b/tornado/httputil.py index 2cbf677b..6201dd18 100644 --- a/tornado/httputil.py +++ b/tornado/httputil.py @@ -61,8 +61,8 @@ class HTTPHeaders(dict): if (len(args) == 1 and len(kwargs) == 0 and isinstance(args[0], HTTPHeaders)): # Copy constructor - for k,v in args[0].get_all(): - self.add(k,v) + for k, v in args[0].get_all(): + self.add(k, v) else: # Dict-style initialization self.update(*args, **kwargs) diff --git a/tornado/iostream.py b/tornado/iostream.py index 927dc92c..47e981b4 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -203,7 +203,7 @@ class IOStream(object): WRITE_BUFFER_CHUNK_SIZE = 128 * 1024 if len(data) > WRITE_BUFFER_CHUNK_SIZE: for i in range(0, len(data), WRITE_BUFFER_CHUNK_SIZE): - self._write_buffer.append(data[i:i+WRITE_BUFFER_CHUNK_SIZE]) + self._write_buffer.append(data[i:i + WRITE_BUFFER_CHUNK_SIZE]) else: self._write_buffer.append(data) self._write_callback = stack_context.wrap(callback) @@ -364,7 +364,6 @@ class IOStream(object): else: self._maybe_run_close_callback() - def _set_read_callback(self, callback): assert not self._read_callback, "Already reading" self._read_callback = callback @@ -712,6 +711,7 @@ class SSLIOStream(IOStream): return None return chunk + def _double_prefix(deque): """Grow by doubling, but don't split the second chunk just because the first one is small. diff --git a/tornado/options.py b/tornado/options.py index 1763e8d2..537891e0 100644 --- a/tornado/options.py +++ b/tornado/options.py @@ -303,7 +303,6 @@ class _Option(object): return _unicode(value) - options = _Options() """Global options dictionary. diff --git a/tornado/platform/common.py b/tornado/platform/common.py index e1eafc2d..176ce2e5 100644 --- a/tornado/platform/common.py +++ b/tornado/platform/common.py @@ -7,6 +7,7 @@ import socket from tornado.platform import interface from tornado.util import b + class Waker(interface.Waker): """Create an OS independent asynchronous pipe. diff --git a/tornado/platform/windows.py b/tornado/platform/windows.py index 58016bfa..80c8a6e2 100644 --- a/tornado/platform/windows.py +++ b/tornado/platform/windows.py @@ -18,5 +18,3 @@ def set_close_exec(fd): success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, 0) if not success: raise ctypes.GetLastError() - - diff --git a/tornado/stack_context.py b/tornado/stack_context.py index 3e0bea85..96719bc6 100644 --- a/tornado/stack_context.py +++ b/tornado/stack_context.py @@ -77,6 +77,7 @@ import threading from tornado.util import raise_exc_info + class _State(threading.local): def __init__(self): self.contexts = () diff --git a/tornado/test/gen_test.py b/tornado/test/gen_test.py index c45ba540..d9ac9dab 100644 --- a/tornado/test/gen_test.py +++ b/tornado/test/gen_test.py @@ -253,10 +253,12 @@ class GenTest(AsyncTestCase): # regression test: repeated invocations of a gen-based # function should not result in accumulated stack_contexts from tornado import stack_context + @gen.engine def inner(callback): yield gen.Task(self.io_loop.add_callback) callback() + @gen.engine def outer(): for i in xrange(10): diff --git a/tornado/test/options_test.py b/tornado/test/options_test.py index dabc2c9c..faf1fdb9 100644 --- a/tornado/test/options_test.py +++ b/tornado/test/options_test.py @@ -2,6 +2,7 @@ import unittest from tornado.options import _Options + class OptionsTest(unittest.TestCase): def setUp(self): self.options = _Options() diff --git a/tornado/test/simple_httpclient_test.py b/tornado/test/simple_httpclient_test.py index 29987a55..db7562f5 100644 --- a/tornado/test/simple_httpclient_test.py +++ b/tornado/test/simple_httpclient_test.py @@ -84,6 +84,7 @@ class SeeOther303GetHandler(RequestHandler): assert not self.request.body self.write("ok") + class HostEchoHandler(RequestHandler): def get(self): self.write(self.request.headers["Host"]) diff --git a/tornado/test/stack_context_test.py b/tornado/test/stack_context_test.py index f3572875..dc717596 100644 --- a/tornado/test/stack_context_test.py +++ b/tornado/test/stack_context_test.py @@ -95,18 +95,22 @@ class StackContextTest(AsyncTestCase, LogTrapTestCase): def test_deactivate(self): deactivate_callbacks = [] + def f1(): with StackContext(functools.partial(self.context, 'c1')) as c1: deactivate_callbacks.append(c1) self.io_loop.add_callback(f2) + def f2(): with StackContext(functools.partial(self.context, 'c2')) as c2: deactivate_callbacks.append(c2) self.io_loop.add_callback(f3) + def f3(): with StackContext(functools.partial(self.context, 'c3')) as c3: deactivate_callbacks.append(c3) self.io_loop.add_callback(f4) + def f4(): self.assertEqual(self.active_contexts, ['c1', 'c2', 'c3']) deactivate_callbacks[1]() @@ -114,6 +118,7 @@ class StackContextTest(AsyncTestCase, LogTrapTestCase): # but it will be missing from the next iteration self.assertEqual(self.active_contexts, ['c1', 'c2', 'c3']) self.io_loop.add_callback(f5) + def f5(): self.assertEqual(self.active_contexts, ['c1', 'c3']) self.stop() diff --git a/tornado/test/template_test.py b/tornado/test/template_test.py index 061f9d39..d70e4875 100644 --- a/tornado/test/template_test.py +++ b/tornado/test/template_test.py @@ -322,6 +322,7 @@ raw: {% raw name %}""", self.assertEqual(render("foo.py", ["not a string"]), b("""s = "['not a string']"\n""")) + class TemplateLoaderTest(LogTrapTestCase): def setUp(self): self.loader = Loader(os.path.join(os.path.dirname(__file__), "templates")) diff --git a/tornado/test/testing_test.py b/tornado/test/testing_test.py index b0301857..1de20df1 100644 --- a/tornado/test/testing_test.py +++ b/tornado/test/testing_test.py @@ -21,9 +21,10 @@ class AsyncTestCaseTest(AsyncTestCase, LogTrapTestCase): clears the first timeout. """ self.io_loop.add_timeout(time.time() + 0.01, self.stop) - self.wait(timeout = 0.02) + self.wait(timeout=0.02) self.io_loop.add_timeout(time.time() + 0.03, self.stop) - self.wait(timeout = 0.1) + self.wait(timeout=0.1) + class SetUpTearDownTest(unittest.TestCase): def test_set_up_tear_down(self): diff --git a/tornado/test/twisted_test.py b/tornado/test/twisted_test.py index 544c24fa..3fe7ee97 100644 --- a/tornado/test/twisted_test.py +++ b/tornado/test/twisted_test.py @@ -52,6 +52,7 @@ from tornado.testing import get_unused_port from tornado.util import import_object from tornado.web import RequestHandler, Application + def save_signal_handlers(): saved = {} for sig in [signal.SIGINT, signal.SIGTERM, signal.SIGCHLD]: @@ -59,10 +60,12 @@ def save_signal_handlers(): assert "twisted" not in repr(saved), repr(saved) return saved + def restore_signal_handlers(saved): for sig, handler in saved.iteritems(): signal.signal(sig, handler) + class ReactorTestCase(unittest.TestCase): def setUp(self): self._saved_signals = save_signal_handlers() diff --git a/tornado/test/util_test.py b/tornado/test/util_test.py index 24f607a4..8707b0d5 100644 --- a/tornado/test/util_test.py +++ b/tornado/test/util_test.py @@ -4,6 +4,7 @@ import unittest from tornado.util import raise_exc_info + class RaiseExcInfoTest(unittest.TestCase): def test_two_arg_exception(self): # This test would fail on python 3 if raise_exc_info were simply diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index 8d3675b9..bb316b56 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -108,7 +108,7 @@ class CookieTest(AsyncHTTPTestCase, LogTrapTestCase): class SetCookieOverwriteHandler(RequestHandler): def get(self): self.set_cookie("a", "b", domain="example.com") - self.set_cookie("c", "d" ,domain="example.com") + self.set_cookie("c", "d", domain="example.com") # A second call with the same name clobbers the first. # Attributes from the first call are not carried over. self.set_cookie("a", "e") @@ -411,6 +411,7 @@ class RedirectHandler(RequestHandler): else: raise Exception("didn't get permanent or status arguments") + class EmptyFlushCallbackHandler(RequestHandler): @gen.engine @asynchronous @@ -437,6 +438,7 @@ class HeaderInjectionHandler(RequestHandler): class WebTest(AsyncHTTPTestCase, LogTrapTestCase): COOKIE_SECRET = "WebTest.COOKIE_SECRET" + def get_app(self): loader = DictLoader({ "linkify.html": "{% module linkify(message) %}", @@ -772,6 +774,7 @@ class CustomStaticFileTest(AsyncHTTPTestCase, LogTrapTestCase): response = self.fetch("/static_url/foo.txt") self.assertEqual(response.body, b("/static/foo.42.txt")) + class NamedURLSpecGroupsTest(AsyncHTTPTestCase, LogTrapTestCase): def get_app(self): class EchoHandler(RequestHandler): @@ -788,6 +791,7 @@ class NamedURLSpecGroupsTest(AsyncHTTPTestCase, LogTrapTestCase): response = self.fetch("/unicode/bar") self.assertEqual(response.body, b("bar")) + class ClearHeaderTest(SimpleHandlerTestCase): class Handler(RequestHandler): def get(self): @@ -800,19 +804,19 @@ class ClearHeaderTest(SimpleHandlerTestCase): response = self.fetch("/") self.assertTrue("h1" not in response.headers) self.assertEqual(response.headers["h2"], "bar") - + class Header304Test(SimpleHandlerTestCase): class Handler(RequestHandler): def get(self): self.set_header("Content-Language", "en_US") self.write("hello") - + def test_304_headers(self): response1 = self.fetch('/') self.assertEqual(response1.headers["Content-Length"], "5") self.assertEqual(response1.headers["Content-Language"], "en_US") - + response2 = self.fetch('/', headers={ 'If-None-Match': response1.headers["Etag"]}) self.assertEqual(response2.code, 304) diff --git a/tornado/testing.py b/tornado/testing.py index 30fd87ec..fccdb861 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -145,7 +145,6 @@ class AsyncTestCase(unittest.TestCase): self.__failure = None raise_exc_info(failure) - def run(self, result=None): with StackContext(self._stack_context): super(AsyncTestCase, self).run(result) diff --git a/tornado/web.py b/tornado/web.py index fa1fcd55..a7c9637f 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -1134,7 +1134,7 @@ def removeslash(method): if uri: # don't try to redirect '/' to '' if self.request.query: uri += "?" + self.request.query - self.redirect(uri, permanent = True) + self.redirect(uri, permanent=True) return else: raise HTTPError(404) @@ -1156,7 +1156,7 @@ def addslash(method): uri = self.request.path + "/" if self.request.query: uri += "?" + self.request.query - self.redirect(uri, permanent = True) + self.redirect(uri, permanent=True) return raise HTTPError(404) return method(self, *args, **kwargs)