From: Ben Darnell Date: Mon, 10 Apr 2017 03:07:00 +0000 (-0400) Subject: *: Run the new autopep8 X-Git-Tag: v4.5.0~4^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e9bcce2c14a2aa6c533510e2e2f1f543aba9684;p=thirdparty%2Ftornado.git *: Run the new autopep8 Mainly adds a bunch of blank lines. --- diff --git a/tornado/autoreload.py b/tornado/autoreload.py index 5b50ce933..60571efe7 100644 --- a/tornado/autoreload.py +++ b/tornado/autoreload.py @@ -243,6 +243,7 @@ def _reload(): # unwind, so just exit uncleanly. os._exit(0) + _USAGE = """\ Usage: python -m tornado.autoreload -m module.to.run [args...] diff --git a/tornado/concurrent.py b/tornado/concurrent.py index 312fdf4ff..667e6b178 100644 --- a/tornado/concurrent.py +++ b/tornado/concurrent.py @@ -343,6 +343,7 @@ class Future(object): app_log.error('Future %r exception was never retrieved: %s', self, ''.join(tb).rstrip()) + TracebackFuture = Future if futures is None: @@ -367,6 +368,7 @@ class DummyExecutor(object): def shutdown(self, wait=True): pass + dummy_executor = DummyExecutor() diff --git a/tornado/curl_httpclient.py b/tornado/curl_httpclient.py index ab54bc0b1..eef4a17a6 100644 --- a/tornado/curl_httpclient.py +++ b/tornado/curl_httpclient.py @@ -278,9 +278,9 @@ class CurlAsyncHTTPClient(AsyncHTTPClient): if curl_log.isEnabledFor(logging.DEBUG): curl.setopt(pycurl.VERBOSE, 1) curl.setopt(pycurl.DEBUGFUNCTION, self._curl_debug) - if hasattr(pycurl,'PROTOCOLS'): # PROTOCOLS first appeared in pycurl 7.19.5 (2014-07-12) - curl.setopt(pycurl.PROTOCOLS, pycurl.PROTO_HTTP|pycurl.PROTO_HTTPS) - curl.setopt(pycurl.REDIR_PROTOCOLS, pycurl.PROTO_HTTP|pycurl.PROTO_HTTPS) + if hasattr(pycurl, 'PROTOCOLS'): # PROTOCOLS first appeared in pycurl 7.19.5 (2014-07-12) + curl.setopt(pycurl.PROTOCOLS, pycurl.PROTO_HTTP | pycurl.PROTO_HTTPS) + curl.setopt(pycurl.REDIR_PROTOCOLS, pycurl.PROTO_HTTP | pycurl.PROTO_HTTPS) return curl def _curl_setup_request(self, curl, request, buffer, headers): diff --git a/tornado/escape.py b/tornado/escape.py index c4b2fa3b4..2ca3fe3fe 100644 --- a/tornado/escape.py +++ b/tornado/escape.py @@ -199,6 +199,7 @@ def utf8(value): ) return value.encode("utf-8") + _TO_UNICODE_TYPES = (unicode_type, type(None)) @@ -216,6 +217,7 @@ def to_unicode(value): ) return value.decode("utf-8") + # to_unicode was previously named _unicode not because it was private, # but to avoid conflicts with the built-in unicode() function/type _unicode = to_unicode @@ -264,6 +266,7 @@ def recursive_unicode(obj): else: return obj + # I originally used the regex from # http://daringfireball.net/2010/07/improved_regex_for_matching_urls # but it gets all exponential on certain patterns (such as too many trailing @@ -391,4 +394,5 @@ def _build_unicode_map(): unicode_map[name] = unichr(value) return unicode_map + _HTML_UNICODE_MAP = _build_unicode_map() diff --git a/tornado/gen.py b/tornado/gen.py index 9ac1d6e35..0ce4dc9f2 100644 --- a/tornado/gen.py +++ b/tornado/gen.py @@ -245,6 +245,7 @@ def coroutine(func, replace_callback=True): """ return _make_coroutine_wrapper(func, replace_callback=True) + # Ties lifetime of runners to their result futures. Github Issue #1769 # Generators, like any object in Python, must be strong referenced # in order to not be cleaned up by the garbage collector. When using @@ -264,6 +265,7 @@ def coroutine(func, replace_callback=True): # Runner alive. _futures_to_runners = weakref.WeakKeyDictionary() + def _make_coroutine_wrapper(func, replace_callback): """The inner workings of ``@gen.coroutine`` and ``@gen.engine``. @@ -718,6 +720,7 @@ def multi(children, quiet_exceptions=()): else: return multi_future(children, quiet_exceptions=quiet_exceptions) + Multi = multi @@ -1169,6 +1172,7 @@ class Runner(object): self.stack_context_deactivate() self.stack_context_deactivate = None + Arguments = collections.namedtuple('Arguments', ['args', 'kwargs']) @@ -1188,6 +1192,7 @@ def _argument_adapter(callback): callback(None) return wrapper + # Convert Awaitables into Futures. It is unfortunately possible # to have infinite recursion here if those Awaitables assume that # we're using a different coroutine runner and yield objects @@ -1276,6 +1281,7 @@ def convert_yielded(yielded): else: raise BadYieldError("yielded unknown object %r" % (yielded,)) + if singledispatch is not None: convert_yielded = singledispatch(convert_yielded) diff --git a/tornado/httpclient.py b/tornado/httpclient.py index 6f45367ca..8436ece46 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -673,5 +673,6 @@ def main(): print(native_str(response.body)) client.close() + if __name__ == "__main__": main() diff --git a/tornado/httpserver.py b/tornado/httpserver.py index 6ae32e6f7..d757be188 100644 --- a/tornado/httpserver.py +++ b/tornado/httpserver.py @@ -321,4 +321,5 @@ class _ProxyAdapter(httputil.HTTPMessageDelegate): def _cleanup(self): self.connection.context._unapply_xheaders() + HTTPRequest = httputil.HTTPServerRequest diff --git a/tornado/httputil.py b/tornado/httputil.py index 39a27f78c..dc206fc8c 100644 --- a/tornado/httputil.py +++ b/tornado/httputil.py @@ -99,6 +99,7 @@ class _NormalizedHeaderCache(dict): del self[old_key] return normalized + _normalized_headers = _NormalizedHeaderCache(1000) @@ -936,10 +937,12 @@ def split_host_and_port(netloc): port = None return (host, port) + _OctalPatt = re.compile(r"\\[0-3][0-7][0-7]") _QuotePatt = re.compile(r"[\\].") _nulljoin = ''.join + def _unquote_cookie(str): """Handle double quotes and escaping in cookie values. @@ -981,11 +984,11 @@ def _unquote_cookie(str): k = q_match.start(0) if q_match and (not o_match or k < j): # QuotePatt matched res.append(str[i:k]) - res.append(str[k+1]) + res.append(str[k + 1]) i = k + 2 else: # OctalPatt matched res.append(str[i:j]) - res.append(chr(int(str[j+1:j+4], 8))) + res.append(chr(int(str[j + 1:j + 4], 8))) i = j + 4 return _nulljoin(res) diff --git a/tornado/iostream.py b/tornado/iostream.py index 691251ad2..a1619c497 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -908,8 +908,8 @@ class BaseIOStream(object): assert loc <= self._read_buffer_size # Slice the bytearray buffer into bytes, without intermediate copying b = (memoryview(self._read_buffer) - [self._read_buffer_pos:self._read_buffer_pos + loc] - ).tobytes() + [self._read_buffer_pos:self._read_buffer_pos + loc] + ).tobytes() self._read_buffer_pos += loc self._read_buffer_size -= loc # Amortized O(1) shrink diff --git a/tornado/netutil.py b/tornado/netutil.py index 9653421fe..c34c8c8bb 100644 --- a/tornado/netutil.py +++ b/tornado/netutil.py @@ -200,6 +200,7 @@ def bind_sockets(port, address=None, family=socket.AF_UNSPEC, sockets.append(sock) return sockets + if hasattr(socket, 'AF_UNIX'): def bind_unix_socket(file, mode=0o600, backlog=_DEFAULT_BACKLOG): """Creates a listening unix socket. diff --git a/tornado/platform/asyncio.py b/tornado/platform/asyncio.py index 549a1cc00..830ee1f3b 100644 --- a/tornado/platform/asyncio.py +++ b/tornado/platform/asyncio.py @@ -30,7 +30,7 @@ from tornado import stack_context try: # Import the real asyncio module for py33+ first. Older versions of the # trollius backport also use this name. - import asyncio # type: ignore + import asyncio # type: ignore except ImportError as e: # Asyncio itself isn't available; see if trollius is (backport to py26+). try: @@ -217,5 +217,6 @@ def to_asyncio_future(tornado_future): tornado.concurrent.chain_future(tornado_future, af) return af + if hasattr(convert_yielded, 'register'): convert_yielded.register(asyncio.Future, to_tornado_future) # type: ignore diff --git a/tornado/platform/common.py b/tornado/platform/common.py index f51f49acc..a73f8db7f 100644 --- a/tornado/platform/common.py +++ b/tornado/platform/common.py @@ -8,6 +8,7 @@ import time from tornado.platform import interface from tornado.util import errno_from_exception + def try_close(f): # Avoid issue #875 (race condition when using the file in another # thread). diff --git a/tornado/platform/interface.py b/tornado/platform/interface.py index e4d92736a..c0ef2905c 100644 --- a/tornado/platform/interface.py +++ b/tornado/platform/interface.py @@ -62,5 +62,6 @@ class Waker(object): """Closes the waker's file descriptor(s).""" raise NotImplementedError() + def monotonic_time(): raise NotImplementedError() diff --git a/tornado/platform/twisted.py b/tornado/platform/twisted.py index ec269413b..0f9787e84 100644 --- a/tornado/platform/twisted.py +++ b/tornado/platform/twisted.py @@ -574,6 +574,7 @@ class TwistedResolver(Resolver): ] raise gen.Return(result) + if hasattr(gen.convert_yielded, 'register'): @gen.convert_yielded.register(Deferred) # type: ignore def _(d): diff --git a/tornado/stack_context.py b/tornado/stack_context.py index 74e393856..61ae51f4e 100644 --- a/tornado/stack_context.py +++ b/tornado/stack_context.py @@ -82,6 +82,8 @@ class StackContextInconsistentError(Exception): class _State(threading.local): def __init__(self): self.contexts = (tuple(), None) + + _state = _State() diff --git a/tornado/test/concurrent_test.py b/tornado/test/concurrent_test.py index fd0f4a67f..4d89f5723 100644 --- a/tornado/test/concurrent_test.py +++ b/tornado/test/concurrent_test.py @@ -178,7 +178,7 @@ class ReturnFutureTest(AsyncTestCase): @gen.coroutine def f(): yield gen.moment - 1/0 + 1 / 0 g = f() diff --git a/tornado/test/gen_test.py b/tornado/test/gen_test.py index de803a8b3..fea4c6449 100644 --- a/tornado/test/gen_test.py +++ b/tornado/test/gen_test.py @@ -26,6 +26,7 @@ try: except ImportError: futures = None + class GenEngineTest(AsyncTestCase): def setUp(self): super(GenEngineTest, self).setUp() @@ -1444,6 +1445,7 @@ class RunnerGCTest(AsyncTestCase): """Runners shouldn't GC if future is alive""" # Create the weakref weakref_scope = [None] + def callback(): gc.collect(2) weakref_scope[0]().set_result(123) @@ -1460,5 +1462,6 @@ class RunnerGCTest(AsyncTestCase): tester() ) + if __name__ == '__main__': unittest.main() diff --git a/tornado/test/runtests.py b/tornado/test/runtests.py index 81ae9a27d..b81c5f225 100644 --- a/tornado/test/runtests.py +++ b/tornado/test/runtests.py @@ -185,5 +185,6 @@ def main(): log_counter.warning_count, log_counter.error_count) sys.exit(1) + if __name__ == '__main__': main() diff --git a/tornado/test/stack_context_test.py b/tornado/test/stack_context_test.py index d55e0ee35..59d25474c 100644 --- a/tornado/test/stack_context_test.py +++ b/tornado/test/stack_context_test.py @@ -284,5 +284,6 @@ class StackContextTest(AsyncTestCase): f1) self.assertEqual(self.active_contexts, []) + if __name__ == '__main__': unittest.main() diff --git a/tornado/test/tcpserver_test.py b/tornado/test/tcpserver_test.py index 18473a55e..9afb54202 100644 --- a/tornado/test/tcpserver_test.py +++ b/tornado/test/tcpserver_test.py @@ -68,4 +68,3 @@ class TCPServerTest(AsyncTestCase): server.add_socket(sock) server.stop() server.stop() - diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index 913818f99..d79ea52c1 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -1574,7 +1574,6 @@ class GzipTestCase(SimpleHandlerTestCase): response.headers.get('X-Consumed-Content-Encoding')), 'gzip') - def test_gzip(self): response = self.fetch('/') self.assert_compressed(response) @@ -1605,6 +1604,7 @@ class GzipTestCase(SimpleHandlerTestCase): self.assertEqual([s.strip() for s in response.headers['Vary'].split(',')], ['Accept-Language', 'Cookie', 'Accept-Encoding']) + @wsgi_safe class PathArgsInPrepareTest(WebTestCase): class Handler(RequestHandler): diff --git a/tornado/test/windows_test.py b/tornado/test/windows_test.py index f136c8aab..e5cb33813 100644 --- a/tornado/test/windows_test.py +++ b/tornado/test/windows_test.py @@ -8,6 +8,7 @@ from tornado.platform.auto import set_close_exec skipIfNonWindows = unittest.skipIf(os.name != 'nt', 'non-windows platform') + @skipIfNonWindows class WindowsTest(unittest.TestCase): def test_set_close_exec(self): diff --git a/tornado/test/wsgi_test.py b/tornado/test/wsgi_test.py index 78da7853f..e6ccc82ae 100644 --- a/tornado/test/wsgi_test.py +++ b/tornado/test/wsgi_test.py @@ -83,6 +83,8 @@ def wrap_web_tests_application(): return WSGIContainer(validator(self.app)) result["WSGIApplication_" + cls.__name__] = WSGIApplicationWrappedTest return result + + globals().update(wrap_web_tests_application()) @@ -96,4 +98,6 @@ def wrap_web_tests_adapter(): return WSGIContainer(validator(WSGIAdapter(self.app))) result["WSGIAdapter_" + cls.__name__] = WSGIAdapterWrappedTest return result + + globals().update(wrap_web_tests_adapter()) diff --git a/tornado/testing.py b/tornado/testing.py index eff2684d2..74d04b600 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -737,5 +737,6 @@ def main(**kwargs): gen_log.error('FAIL') raise + if __name__ == '__main__': main() diff --git a/tornado/util.py b/tornado/util.py index b9960cf74..981b94c8e 100644 --- a/tornado/util.py +++ b/tornado/util.py @@ -236,6 +236,7 @@ def _re_unescape_replacement(match): raise ValueError("cannot unescape '\\\\%s'" % group[0]) return group + _re_unescape_pattern = re.compile(r'\\(.)', re.DOTALL) @@ -454,6 +455,7 @@ def _websocket_mask_python(mask, data): else: return unmasked_arr.tostring() + if (os.environ.get('TORNADO_NO_EXTENSION') or os.environ.get('TORNADO_EXTENSION') == '0'): # These environment variables exist to make it easier to do performance diff --git a/tornado/web.py b/tornado/web.py index 6d6ce92e7..8ff52e9ce 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -3119,6 +3119,7 @@ def create_signed_value(secret, name, value, version=None, clock=None, else: raise ValueError("Unsupported version %d" % version) + # A leading version number in decimal # with no leading zeros, followed by a pipe. _signed_value_version_re = re.compile(br"^([1-9][0-9]*)\|(.*)$") diff --git a/tornado/websocket.py b/tornado/websocket.py index 0af9e8f8e..1668a5968 100644 --- a/tornado/websocket.py +++ b/tornado/websocket.py @@ -285,7 +285,7 @@ class WebSocketHandler(tornado.web.RequestHandler): Added ``compression_level`` and ``mem_level``. """ - #TODO: Add wbits option. + # TODO: Add wbits option. return None def open(self, *args, **kwargs): @@ -603,7 +603,6 @@ class WebSocketProtocol13(WebSocketProtocol): self.last_ping = 0 self.last_pong = 0 - def accept_connection(self): try: self._handle_websocket_headers() @@ -826,7 +825,7 @@ class WebSocketProtocol13(WebSocketProtocol): new_len = self._frame_length if self._fragmented_message_buffer is not None: new_len += len(self._fragmented_message_buffer) - if new_len > (self.handler.max_message_size or 10*1024*1024): + if new_len > (self.handler.max_message_size or 10 * 1024 * 1024): self.close(1009, "message too big") return self.stream.read_bytes( @@ -997,7 +996,7 @@ class WebSocketProtocol13(WebSocketProtocol): if self.ping_interval > 0: self.last_ping = self.last_pong = IOLoop.current().time() self.ping_callback = PeriodicCallback( - self.periodic_ping, self.ping_interval*1000) + self.periodic_ping, self.ping_interval * 1000) self.ping_callback.start() def periodic_ping(self): @@ -1015,7 +1014,7 @@ class WebSocketProtocol13(WebSocketProtocol): now = IOLoop.current().time() since_last_pong = now - self.last_pong since_last_ping = now - self.last_ping - if (since_last_ping < 2*self.ping_interval and + if (since_last_ping < 2 * self.ping_interval and since_last_pong > self.ping_timeout): self.close() return