From: Pierce Lopez Date: Mon, 1 Jan 2018 19:43:18 +0000 (-0500) Subject: style fix: 2 blank lines around top-level class and function defs X-Git-Tag: v5.0.0~20^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e2fef9fb12097b49b066a4041ef0f216a25251b;p=thirdparty%2Ftornado.git style fix: 2 blank lines around top-level class and function defs flake8 codes E302 and E305 --- diff --git a/demos/benchmark/benchmark.py b/demos/benchmark/benchmark.py index 1e8375d72..d1f32d33e 100755 --- a/demos/benchmark/benchmark.py +++ b/demos/benchmark/benchmark.py @@ -46,6 +46,7 @@ define("num_runs", type=int, default=1) define("ioloop", type=str, default=None) + class RootHandler(RequestHandler): def get(self): self.write("Hello, world") @@ -53,9 +54,11 @@ class RootHandler(RequestHandler): def _log(self): pass + def handle_sigchld(sig, frame): IOLoop.current().add_callback_from_signal(IOLoop.current().stop) + def main(): parse_command_line() if options.ioloop: @@ -63,6 +66,7 @@ def main(): for i in xrange(options.num_runs): run() + def run(): io_loop = IOLoop(make_current=True) app = Application([("/", RootHandler)]) @@ -83,5 +87,6 @@ def run(): io_loop.close() io_loop.clear_current() + if __name__ == '__main__': main() diff --git a/demos/benchmark/gen_benchmark.py b/demos/benchmark/gen_benchmark.py index 1b5281fb9..a46296264 100644 --- a/demos/benchmark/gen_benchmark.py +++ b/demos/benchmark/gen_benchmark.py @@ -16,24 +16,29 @@ define('num', default=10000, help='number of iterations') # This removes noise from the results, but it's easy to change things # in a way that completely invalidates the results. + @gen.engine def e2(callback): callback() + @gen.engine def e1(): for i in range(10): yield gen.Task(e2) + @gen.coroutine def c2(): pass + @gen.coroutine def c1(): for i in range(10): yield c2() + def main(): parse_command_line() t = Timer(e1) @@ -43,5 +48,6 @@ def main(): results = t.timeit(options.num) / options.num print('coroutine: %0.3f ms per iteration' % (results * 1000)) + if __name__ == '__main__': main() diff --git a/demos/benchmark/stack_context_benchmark.py b/demos/benchmark/stack_context_benchmark.py index 158f06520..2b4a388fe 100755 --- a/demos/benchmark/stack_context_benchmark.py +++ b/demos/benchmark/stack_context_benchmark.py @@ -8,6 +8,7 @@ import sys from tornado import stack_context + class Benchmark(object): def enter_exit(self, count): """Measures the overhead of the nested "with" statements @@ -37,6 +38,7 @@ class Benchmark(object): queue.append(stack_context.wrap( functools.partial(self.call_wrapped_inner, queue, count - 1))) + class StackBenchmark(Benchmark): def make_context(self): return stack_context.StackContext(self.__context) @@ -45,6 +47,7 @@ class StackBenchmark(Benchmark): def __context(self): yield + class ExceptionBenchmark(Benchmark): def make_context(self): return stack_context.ExceptionStackContext(self.__handle_exception) @@ -52,6 +55,7 @@ class ExceptionBenchmark(Benchmark): def __handle_exception(self, typ, value, tb): pass + def main(): base_cmd = [ sys.executable, '-m', 'timeit', '-s', @@ -71,5 +75,6 @@ def main(): print(cmd) subprocess.check_call(base_cmd + [cmd]) + if __name__ == '__main__': main() diff --git a/demos/benchmark/template_benchmark.py b/demos/benchmark/template_benchmark.py index 08055fb66..c0e67cecd 100755 --- a/demos/benchmark/template_benchmark.py +++ b/demos/benchmark/template_benchmark.py @@ -51,9 +51,11 @@ tmpl = Template("""\ \ """) + def render(): tmpl.generate(**context) + def main(): parse_command_line() if options.dump: @@ -63,5 +65,6 @@ def main(): results = t.timeit(options.num) / options.num print('%0.3f ms per iteration' % (results * 1000)) + if __name__ == '__main__': main() diff --git a/demos/s3server/s3server.py b/demos/s3server/s3server.py index ff289f025..6ca104d1e 100644 --- a/demos/s3server/s3server.py +++ b/demos/s3server/s3server.py @@ -43,6 +43,7 @@ from tornado import httpserver from tornado import ioloop from tornado import web + def start(port, root_directory="/tmp/s3", bucket_depth=0): """Starts the mock S3 server on the given port at the given path.""" application = S3Application(root_directory, bucket_depth) diff --git a/demos/twitter/twitterdemo.py b/demos/twitter/twitterdemo.py index 73aa6ba3f..c674c65c2 100644 --- a/demos/twitter/twitterdemo.py +++ b/demos/twitter/twitterdemo.py @@ -39,6 +39,7 @@ define('cookie_secret', type=str, group='application', default='__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE__', help="signing key for secure cookies") + class BaseHandler(RequestHandler): COOKIE_NAME = 'twitterdemo_user' @@ -48,6 +49,7 @@ class BaseHandler(RequestHandler): return None return json_decode(user_json) + class MainHandler(BaseHandler, TwitterMixin): @authenticated @gen.coroutine @@ -57,6 +59,7 @@ class MainHandler(BaseHandler, TwitterMixin): access_token=self.current_user['access_token']) self.render('home.html', timeline=timeline) + class LoginHandler(BaseHandler, TwitterMixin): @gen.coroutine def get(self): @@ -68,10 +71,12 @@ class LoginHandler(BaseHandler, TwitterMixin): else: yield self.authorize_redirect(callback_uri=self.request.full_url()) + class LogoutHandler(BaseHandler): def get(self): self.clear_cookie(self.COOKIE_NAME) + def main(): parse_command_line(final=False) parse_config_file(options.config_file) @@ -89,5 +94,6 @@ def main(): logging.info('Listening on http://localhost:%d' % options.port) IOLoop.current().start() + if __name__ == '__main__': main() diff --git a/demos/websocket/chatdemo.py b/demos/websocket/chatdemo.py index 36b0ed06d..a3fa2a69f 100755 --- a/demos/websocket/chatdemo.py +++ b/demos/websocket/chatdemo.py @@ -51,6 +51,7 @@ class MainHandler(tornado.web.RequestHandler): def get(self): self.render("index.html", messages=ChatSocketHandler.cache) + class ChatSocketHandler(tornado.websocket.WebSocketHandler): waiters = set() cache = [] diff --git a/maint/scripts/custom_fixers/fix_future_imports.py b/maint/scripts/custom_fixers/fix_future_imports.py index 45aff61af..48553c4a6 100644 --- a/maint/scripts/custom_fixers/fix_future_imports.py +++ b/maint/scripts/custom_fixers/fix_future_imports.py @@ -5,11 +5,13 @@ from lib2to3 import pytree from lib2to3.pgen2 import token from lib2to3.fixer_util import FromImport, Name, Comma, Newline + # copied from fix_tuple_params.py def is_docstring(stmt): return isinstance(stmt, pytree.Node) and \ stmt.children[0].type == token.STRING + class FixFutureImports(fixer_base.BaseFix): BM_compatible = True diff --git a/maint/scripts/test_resolvers.py b/maint/scripts/test_resolvers.py index 971395ba0..2a466c1ac 100644 --- a/maint/scripts/test_resolvers.py +++ b/maint/scripts/test_resolvers.py @@ -22,6 +22,7 @@ except ImportError: define('family', default='unspec', help='Address family to query: unspec, inet, or inet6') + @gen.coroutine def main(): args = parse_command_line() @@ -54,5 +55,6 @@ def main(): pprint.pformat(addrinfo))) print() + if __name__ == '__main__': IOLoop.instance().run_sync(main) diff --git a/maint/test/appengine/common/cgi_runtests.py b/maint/test/appengine/common/cgi_runtests.py index 44ddf7ae8..7041a42d9 100644 --- a/maint/test/appengine/common/cgi_runtests.py +++ b/maint/test/appengine/common/cgi_runtests.py @@ -36,9 +36,11 @@ TEST_MODULES = [ #'tornado.test.wsgi_test', ] + def all(): return unittest.defaultTestLoader.loadTestsFromNames(TEST_MODULES) + def main(): print "Content-Type: text/plain\r\n\r\n", @@ -50,5 +52,6 @@ def main(): else: raise + if __name__ == '__main__': main() diff --git a/maint/test/cython/pythonmodule.py b/maint/test/cython/pythonmodule.py index e532693d1..e7c2af517 100644 --- a/maint/test/cython/pythonmodule.py +++ b/maint/test/cython/pythonmodule.py @@ -1,5 +1,6 @@ from tornado import gen + @gen.coroutine def hello(): yield gen.sleep(0.001) diff --git a/maint/test/redbot/red_test.py b/maint/test/redbot/red_test.py index f47334907..055b47956 100644 --- a/maint/test/redbot/red_test.py +++ b/maint/test/redbot/red_test.py @@ -11,19 +11,23 @@ from tornado.testing import AsyncHTTPTestCase from tornado.web import RequestHandler, Application, asynchronous import unittest + class HelloHandler(RequestHandler): def get(self): self.write("Hello world") + class RedirectHandler(RequestHandler): def get(self, path): self.redirect(path, status=int(self.get_argument('status', '302'))) + class PostHandler(RequestHandler): def post(self): assert self.get_argument('foo') == 'bar' self.redirect('/hello', status=303) + class ChunkedHandler(RequestHandler): @asynchronous @gen.engine @@ -34,6 +38,7 @@ class ChunkedHandler(RequestHandler): yield gen.Task(self.flush) self.finish() + class CacheHandler(RequestHandler): def get(self, computed_etag): self.write(computed_etag) @@ -41,6 +46,7 @@ class CacheHandler(RequestHandler): def compute_etag(self): return self._write_buffer[0] + class TestMixin(object): def get_handlers(self): return [ @@ -231,10 +237,12 @@ class TestMixin(object): headers=[('If-None-Match', etags)], expected_status=200) + class DefaultHTTPTest(AsyncHTTPTestCase, TestMixin): def get_app(self): return Application(self.get_handlers(), **self.get_app_kwargs()) + class GzipHTTPTest(AsyncHTTPTestCase, TestMixin): def get_app(self): return Application(self.get_handlers(), gzip=True, **self.get_app_kwargs()) @@ -249,6 +257,7 @@ class GzipHTTPTest(AsyncHTTPTestCase, TestMixin): rs.VARY_ETAG_DOESNT_CHANGE, ] + if __name__ == '__main__': parse_command_line() unittest.main() diff --git a/maint/test/websocket/client.py b/maint/test/websocket/client.py index 9df1a82a4..d1b1aaf56 100644 --- a/maint/test/websocket/client.py +++ b/maint/test/websocket/client.py @@ -10,6 +10,7 @@ from tornado.websocket import websocket_connect define('url', default='ws://localhost:9001') define('name', default='Tornado') + @gen.engine def run_tests(): url = options.url + '/getCaseCount' @@ -35,6 +36,7 @@ def run_tests(): assert msg is None IOLoop.instance().stop() + def main(): parse_command_line() @@ -42,5 +44,6 @@ def main(): IOLoop.instance().start() + if __name__ == '__main__': main() diff --git a/maint/test/websocket/server.py b/maint/test/websocket/server.py index 40b5eeaba..5d86b1316 100644 --- a/maint/test/websocket/server.py +++ b/maint/test/websocket/server.py @@ -7,6 +7,7 @@ from tornado.web import Application define('port', default=9000) + class EchoHandler(WebSocketHandler): def on_message(self, message): self.write_message(message, binary=isinstance(message, bytes)) @@ -14,6 +15,7 @@ class EchoHandler(WebSocketHandler): def get_compression_options(self): return {} + if __name__ == '__main__': parse_command_line() app = Application([ diff --git a/maint/vm/windows/bootstrap.py b/maint/vm/windows/bootstrap.py index d481d034d..e795e97f7 100644 --- a/maint/vm/windows/bootstrap.py +++ b/maint/vm/windows/bootstrap.py @@ -37,6 +37,7 @@ EASY_INSTALL = os.path.join(SCRIPTS_DIR, 'easy_install.exe') PY_PACKAGES = ['tox', 'virtualenv', 'pip'] + def download_to_cache(url, local_name=None): if local_name is None: local_name = url.split('/')[-1] @@ -47,6 +48,7 @@ def download_to_cache(url, local_name=None): f.write(data) return filename + def main(): if not os.path.exists(TMPDIR): os.mkdir(TMPDIR) diff --git a/tornado/test/util.py b/tornado/test/util.py index 1d34ec083..1d998f0ea 100644 --- a/tornado/test/util.py +++ b/tornado/test/util.py @@ -41,6 +41,7 @@ skipPypy3V58 = unittest.skipIf(platform.python_implementation() == 'PyPy' and sys.pypy_version_info < (5, 9), 'pypy3 5.8 has buggy ssl module') + def _detect_ipv6(): if not socket.has_ipv6: # socket.has_ipv6 check reports whether ipv6 was present at compile @@ -57,6 +58,7 @@ def _detect_ipv6(): sock.close() return True + skipIfNoIPv6 = unittest.skipIf(not _detect_ipv6(), 'ipv6 support not present')