From 210312c4aed28c91febbfd73f9c4d2cbba8c6d59 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Mon, 27 May 2013 17:18:38 -0400 Subject: [PATCH] Autopep8 fixes. --- tornado/gen.py | 2 +- tornado/httpclient.py | 2 +- tornado/httpserver.py | 1 - tornado/httputil.py | 5 +++++ tornado/iostream.py | 4 ++-- tornado/test/curl_httpclient_test.py | 1 + tornado/test/gen_test.py | 5 +++-- tornado/test/httpclient_test.py | 1 + tornado/test/httpserver_test.py | 7 ++++--- tornado/test/iostream_test.py | 2 +- tornado/test/runtests.py | 2 +- tornado/test/stack_context_test.py | 1 - tornado/test/web_test.py | 26 +++++++++++++++----------- tornado/test/websocket_test.py | 1 + tornado/web.py | 8 ++++---- tornado/websocket.py | 2 +- tornado/wsgi.py | 2 +- 17 files changed, 42 insertions(+), 30 deletions(-) diff --git a/tornado/gen.py b/tornado/gen.py index 62ee0a30f..cbff9ff6e 100644 --- a/tornado/gen.py +++ b/tornado/gen.py @@ -542,7 +542,7 @@ class Runner(object): self.exc_info = sys.exc_info() else: self.exc_info = (BadYieldError( - "yielded unknown object %r" % (yielded,)),) + "yielded unknown object %r" % (yielded,)),) finally: self.running = False diff --git a/tornado/httpclient.py b/tornado/httpclient.py index e933c416b..e0cff2ee1 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -327,7 +327,7 @@ class HTTPRequest(object): self.body = utf8(body) self.auth_username = auth_username self.auth_password = auth_password - self.auth_mode = auth_mode + self.auth_mode = auth_mode self.connect_timeout = connect_timeout self.request_timeout = request_timeout self.follow_redirects = follow_redirects diff --git a/tornado/httpserver.py b/tornado/httpserver.py index 11f083299..d2ac7c2f5 100644 --- a/tornado/httpserver.py +++ b/tornado/httpserver.py @@ -446,7 +446,6 @@ class HTTPRequest(object): if proto in ("http", "https"): self.protocol = proto - self.host = host or self.headers.get("Host") or "127.0.0.1" self.files = files or {} self.connection = connection diff --git a/tornado/httputil.py b/tornado/httputil.py index ef3545030..36ac61063 100644 --- a/tornado/httputil.py +++ b/tornado/httputil.py @@ -43,6 +43,7 @@ try: except ImportError: from urllib.parse import urlencode # py3 + class _NormalizedHeaderCache(dict): """Dynamic cached mapping of header names to Http-Header-Case. @@ -73,6 +74,7 @@ class _NormalizedHeaderCache(dict): _normalized_headers = _NormalizedHeaderCache(1000) + class HTTPHeaders(dict): """A dictionary that maintains ``Http-Header-Case`` for all keys. @@ -236,6 +238,7 @@ class HTTPFile(ObjectDict): """ pass + def _parse_request_range(range_header): """Parses a Range header. @@ -281,6 +284,7 @@ def _parse_request_range(range_header): end += 1 return (start, end) + def _get_content_range(start, end, total): """Returns a suitable Content-Range header: @@ -295,6 +299,7 @@ def _get_content_range(start, end, total): end = (end or total) - 1 return "%s-%s/%s" % (start, end, total) + def _int_or_none(val): val = val.strip() if val == "": diff --git a/tornado/iostream.py b/tornado/iostream.py index 425d3299d..633737af8 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -235,7 +235,7 @@ class BaseIOStream(object): self.error = exc_info[1] if self._read_until_close: if (self._streaming_callback is not None and - self._read_buffer_size): + self._read_buffer_size): self._run_callback(self._streaming_callback, self._consume(self._read_buffer_size)) callback = self._read_callback @@ -745,7 +745,7 @@ class IOStream(BaseIOStream): def set_nodelay(self, value): if (self.socket is not None and - self.socket.family in (socket.AF_INET, socket.AF_INET6)): + self.socket.family in (socket.AF_INET, socket.AF_INET6)): try: self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1 if value else 0) diff --git a/tornado/test/curl_httpclient_test.py b/tornado/test/curl_httpclient_test.py index 0ea96a330..e9ba8a76c 100644 --- a/tornado/test/curl_httpclient_test.py +++ b/tornado/test/curl_httpclient_test.py @@ -65,6 +65,7 @@ class DigestAuthHandler(RequestHandler): 'Digest realm="%s", nonce="%s", opaque="%s"' % (realm, nonce, opaque)) + @unittest.skipIf(pycurl is None, "pycurl module not present") class CurlHTTPClientTestCase(AsyncHTTPTestCase): def setUp(self): diff --git a/tornado/test/gen_test.py b/tornado/test/gen_test.py index cbfdff2d7..52de8da53 100644 --- a/tornado/test/gen_test.py +++ b/tornado/test/gen_test.py @@ -23,7 +23,7 @@ from tornado import gen skipBefore33 = unittest.skipIf(sys.version_info < (3, 3), 'PEP 380 not available') skipNotCPython = unittest.skipIf(platform.python_implementation() != 'CPython', - 'Not CPython implementation') + 'Not CPython implementation') class GenEngineTest(AsyncTestCase): @@ -510,7 +510,8 @@ class GenEngineTest(AsyncTestCase): # without waiting for garbage collection. @gen.engine def f(): - class Foo(object): pass + class Foo(object): + pass arg = Foo() self.arg_ref = weakref.ref(arg) task = gen.Task(self.io_loop.add_callback, arg=arg) diff --git a/tornado/test/httpclient_test.py b/tornado/test/httpclient_test.py index a513a9f37..d34d8a826 100644 --- a/tornado/test/httpclient_test.py +++ b/tornado/test/httpclient_test.py @@ -82,6 +82,7 @@ class ContentLength304Handler(RequestHandler): # want to simulate servers that include the headers anyway. pass + class AllMethodsHandler(RequestHandler): SUPPORTED_METHODS = RequestHandler.SUPPORTED_METHODS + ('OTHER',) diff --git a/tornado/test/httpserver_test.py b/tornado/test/httpserver_test.py index a4079812e..d90385403 100644 --- a/tornado/test/httpserver_test.py +++ b/tornado/test/httpserver_test.py @@ -263,6 +263,7 @@ class EchoHandler(RequestHandler): def post(self): self.write(recursive_unicode(self.request.arguments)) + class TypeCheckHandler(RequestHandler): def prepare(self): self.errors = {} @@ -347,8 +348,8 @@ class HTTPServerTest(AsyncHTTPTestCase): class HTTPServerRawTest(AsyncHTTPTestCase): def get_app(self): return Application([ - ('/echo', EchoHandler), - ]) + ('/echo', EchoHandler), + ]) def setUp(self): super(HTTPServerRawTest, self).setUp() @@ -386,7 +387,7 @@ class XHeaderTest(HandlerBaseTestCase): class Handler(RequestHandler): def get(self): self.write(dict(remote_ip=self.request.remote_ip, - remote_protocol=self.request.protocol)) + remote_protocol=self.request.protocol)) def get_httpserver_options(self): return dict(xheaders=True) diff --git a/tornado/test/iostream_test.py b/tornado/test/iostream_test.py index d01d2db94..0650c1104 100644 --- a/tornado/test/iostream_test.py +++ b/tornado/test/iostream_test.py @@ -156,7 +156,7 @@ class TestIOStreamMixin(object): self.fail() server.read_until_close(callback=closed_callback, streaming_callback=self.stop) - #self.io_loop.add_timeout(self.io_loop.time() + 0.01, self.stop) + # self.io_loop.add_timeout(self.io_loop.time() + 0.01, self.stop) data = self.wait() self.assertEqual(data, b"efgh") server.close() diff --git a/tornado/test/runtests.py b/tornado/test/runtests.py index 1f4c08c96..2c8bb1db9 100644 --- a/tornado/test/runtests.py +++ b/tornado/test/runtests.py @@ -95,7 +95,7 @@ if __name__ == '__main__': help="A comma-separated list of gc module debug constants, " "e.g. DEBUG_STATS or DEBUG_COLLECTABLE,DEBUG_OBJECTS", callback=lambda values: gc.set_debug( - reduce(operator.or_, (getattr(gc, v) for v in values)))) + reduce(operator.or_, (getattr(gc, v) for v in values)))) define('locale', type=str, default=None, callback=lambda x: locale.setlocale(locale.LC_ALL, x)) diff --git a/tornado/test/stack_context_test.py b/tornado/test/stack_context_test.py index a8af08ae8..d6f8239e6 100644 --- a/tornado/test/stack_context_test.py +++ b/tornado/test/stack_context_test.py @@ -174,7 +174,6 @@ class StackContextTest(AsyncTestCase): deactivate_callbacks[2]() self.assertEqual(func(), ['c0', 'c1']) - def test_isolation_nonempty(self): # f2 and f3 are a chain of operations started in context c1. # f2 is incidentally run under context c2, but that context should diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index 9ed42040e..e7735a056 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -24,6 +24,7 @@ wsgi_safe_tests = [] relpath = lambda *a: os.path.join(os.path.dirname(__file__), *a) + def wsgi_safe(cls): wsgi_safe_tests.append(cls) return cls @@ -189,7 +190,7 @@ class CookieTest(WebTestCase): data = [('foo=a=b', 'a=b'), ('foo="a=b"', 'a=b'), ('foo="a;b"', 'a;b'), - #('foo=a\\073b', 'a;b'), # even encoded, ";" is a delimiter + # ('foo=a\\073b', 'a;b'), # even encoded, ";" is a delimiter ('foo="a\\073b"', 'a;b'), ('foo="a\\"b"', 'a"b'), ] @@ -854,7 +855,7 @@ class StaticFileTest(WebTestCase): # negative values, and at least one client (processing.js) seems # to use if-modified-since 1/1/1960 as a cache-busting technique. response = self.fetch("/static/robots.txt", headers={ - 'If-Modified-Since': 'Fri, 01 Jan 1960 00:00:00 GMT'}) + 'If-Modified-Since': 'Fri, 01 Jan 1960 00:00:00 GMT'}) self.assertEqual(response.code, 200) def test_static_if_modified_since_time_zone(self): @@ -865,10 +866,10 @@ class StaticFileTest(WebTestCase): stat = os.stat(relpath('static/robots.txt')) response = self.fetch('/static/robots.txt', headers={ - 'If-Modified-Since': format_timestamp(stat.st_mtime - 1)}) + 'If-Modified-Since': format_timestamp(stat.st_mtime - 1)}) self.assertEqual(response.code, 200) response = self.fetch('/static/robots.txt', headers={ - 'If-Modified-Since': format_timestamp(stat.st_mtime + 1)}) + 'If-Modified-Since': format_timestamp(stat.st_mtime + 1)}) self.assertEqual(response.code, 304) def test_static_etag(self): @@ -878,7 +879,7 @@ class StaticFileTest(WebTestCase): def test_static_with_range(self): response = self.fetch('/static/robots.txt', headers={ - 'Range': 'bytes=0-9'}) + 'Range': 'bytes=0-9'}) self.assertEqual(response.code, 206) self.assertEqual(response.body, b"User-agent") self.assertEqual(utf8(response.headers.get("Etag")), @@ -889,7 +890,7 @@ class StaticFileTest(WebTestCase): def test_static_with_range_full_file(self): response = self.fetch('/static/robots.txt', headers={ - 'Range': 'bytes=0-'}) + 'Range': 'bytes=0-'}) # Note: Chrome refuses to play audio if it gets an HTTP 206 in response # to ``Range: bytes=0-`` :( self.assertEqual(response.code, 200) @@ -901,7 +902,7 @@ class StaticFileTest(WebTestCase): def test_static_with_range_end_edge(self): response = self.fetch('/static/robots.txt', headers={ - 'Range': 'bytes=22-'}) + 'Range': 'bytes=22-'}) self.assertEqual(response.body, b": /\n") self.assertEqual(response.headers.get("Content-Length"), "4") self.assertEqual(response.headers.get("Content-Range"), @@ -909,7 +910,7 @@ class StaticFileTest(WebTestCase): def test_static_with_range_neg_end(self): response = self.fetch('/static/robots.txt', headers={ - 'Range': 'bytes=-4'}) + 'Range': 'bytes=-4'}) self.assertEqual(response.body, b": /\n") self.assertEqual(response.headers.get("Content-Length"), "4") self.assertEqual(response.headers.get("Content-Range"), @@ -917,7 +918,7 @@ class StaticFileTest(WebTestCase): def test_static_invalid_range(self): response = self.fetch('/static/robots.txt', headers={ - 'Range': 'asdf'}) + 'Range': 'asdf'}) self.assertEqual(response.code, 416) def test_static_head(self): @@ -1364,8 +1365,8 @@ class UIMethodUIModuleTest(SimpleHandlerTestCase): x, self.handler.value()) loader = DictLoader({ - 'foo.html': '{{ my_ui_method(42) }} {% module MyModule(123) %}', - }) + 'foo.html': '{{ my_ui_method(42) }} {% module MyModule(123) %}', + }) return dict(template_loader=loader, ui_methods={'my_ui_method': my_ui_method}, ui_modules={'MyModule': MyModule}) @@ -1457,6 +1458,7 @@ class UnimplementedHTTPMethodsTest(SimpleHandlerTestCase): response = self.fetch('/', method=method, body=b'') self.assertEqual(response.code, 405) + class UnimplementedNonStandardMethodsTest(SimpleHandlerTestCase): # wsgiref.validate complains about unknown methods in a way that makes # this test not wsgi_safe. @@ -1477,6 +1479,7 @@ class UnimplementedNonStandardMethodsTest(SimpleHandlerTestCase): allow_nonstandard_methods=True) self.assertEqual(response.code, 405) + @wsgi_safe class AllHTTPMethodsTest(SimpleHandlerTestCase): class Handler(RequestHandler): @@ -1495,6 +1498,7 @@ class AllHTTPMethodsTest(SimpleHandlerTestCase): response = self.fetch('/', method=method, body=b'') self.assertEqual(response.body, utf8(method)) + class PatchMethodTest(SimpleHandlerTestCase): class Handler(RequestHandler): SUPPORTED_METHODS = RequestHandler.SUPPORTED_METHODS + ('OTHER',) diff --git a/tornado/test/websocket_test.py b/tornado/test/websocket_test.py index 65b02be14..f416fea4b 100644 --- a/tornado/test/websocket_test.py +++ b/tornado/test/websocket_test.py @@ -9,6 +9,7 @@ class EchoHandler(WebSocketHandler): def on_message(self, message): self.write_message(message, isinstance(message, bytes)) + class NonWebSocketHandler(RequestHandler): def get(self): self.write('ok') diff --git a/tornado/web.py b/tornado/web.py index 7ddd2fbe3..138a8131c 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -244,7 +244,7 @@ class RequestHandler(object): self.set_default_headers() if (not self.request.supports_http_1_1() and getattr(self.request, 'connection', None) and - not self.request.connection.no_keep_alive): + not self.request.connection.no_keep_alive): conn_header = self.request.headers.get("Connection") if conn_header and (conn_header.lower() == "keep-alive"): self.set_header("Connection", "Keep-Alive") @@ -328,7 +328,7 @@ class RequestHandler(object): # additional headers or split the request. Also cap length to # prevent obviously erroneous values. if (len(value) > 4000 or - RequestHandler._INVALID_HEADER_CHAR_RE.search(value)): + RequestHandler._INVALID_HEADER_CHAR_RE.search(value)): raise ValueError("Unsafe header value %r", value) return value @@ -1845,7 +1845,7 @@ class StaticFileHandler(RequestHandler): version_hash = self._get_cached_version(self.absolute_path) if not version_hash: return None - return '"%s"' %(version_hash, ) + return '"%s"' % (version_hash, ) def set_headers(self): """Sets the content and caching headers on the response.""" @@ -1924,7 +1924,7 @@ class StaticFileHandler(RequestHandler): raise HTTPError(403, "%s is not in root static directory", self.path) if (os.path.isdir(absolute_path) and - self.default_filename is not None): + self.default_filename is not None): # need to look at the request.path here for when path is empty # but there is some prefix to the path that was already # trimmed by the routing diff --git a/tornado/websocket.py b/tornado/websocket.py index 54f73ecfc..e0a5e1aef 100644 --- a/tornado/websocket.py +++ b/tornado/websocket.py @@ -773,7 +773,7 @@ class WebSocketClientConnection(simple_httpclient._HTTPConnection): self.connect_future.set_exception(response.error) else: self.connect_future.set_exception(WebSocketError( - "Non-websocket response")) + "Non-websocket response")) def _handle_1xx(self, code): assert code == 101 diff --git a/tornado/wsgi.py b/tornado/wsgi.py index ae90674e0..6b5bfb8f6 100644 --- a/tornado/wsgi.py +++ b/tornado/wsgi.py @@ -285,7 +285,7 @@ class WSGIContainer(object): "REQUEST_METHOD": request.method, "SCRIPT_NAME": "", "PATH_INFO": to_wsgi_str(escape.url_unescape( - request.path, encoding=None, plus=False)), + request.path, encoding=None, plus=False)), "QUERY_STRING": request.query, "REMOTE_ADDR": request.remote_ip, "SERVER_NAME": host, -- 2.47.2