]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Re-apply autopep8.
authorBen Darnell <ben@bendarnell.com>
Mon, 4 Mar 2013 04:09:57 +0000 (23:09 -0500)
committerBen Darnell <ben@bendarnell.com>
Mon, 4 Mar 2013 04:09:57 +0000 (23:09 -0500)
24 files changed:
tornado/auth.py
tornado/concurrent.py
tornado/gen.py
tornado/httpclient.py
tornado/httputil.py
tornado/ioloop.py
tornado/netutil.py
tornado/platform/caresresolver.py
tornado/platform/twisted.py
tornado/tcpserver.py
tornado/test/auth_test.py
tornado/test/concurrent_test.py
tornado/test/curl_httpclient_test.py
tornado/test/gen_test.py
tornado/test/httpclient_test.py
tornado/test/iostream_test.py
tornado/test/netutil_test.py
tornado/test/simple_httpclient_test.py
tornado/test/util_test.py
tornado/test/web_test.py
tornado/test/websocket_test.py
tornado/testing.py
tornado/web.py
tornado/websocket.py

index 7ffe8e8f64324b6c1ec5af14a3e30be6e55d6723..b2b7e165374814e228e2ea1c70a98418f297e97c 100644 (file)
@@ -72,9 +72,11 @@ try:
 except ImportError:
     import urllib as urllib_parse  # py2
 
+
 class AuthError(Exception):
     pass
 
+
 def _auth_future_to_callback(callback, future):
     try:
         result = future.result()
@@ -83,6 +85,7 @@ def _auth_future_to_callback(callback, future):
         result = None
     callback(result)
 
+
 def _auth_return_future(f):
     """Similar to tornado.concurrent.return_future, but uses the auth
     module's legacy callback interface.
@@ -91,6 +94,7 @@ def _auth_return_future(f):
     inside the function will actually be a future.
     """
     replacer = ArgReplacer(f, 'callback')
+
     @functools.wraps(f)
     def wrapper(*args, **kwargs):
         future = Future()
@@ -102,6 +106,7 @@ def _auth_return_future(f):
         return future
     return wrapper
 
+
 class OpenIdMixin(object):
     """Abstract implementation of OpenID and Attribute Exchange.
 
@@ -192,8 +197,8 @@ class OpenIdMixin(object):
     def _on_authentication_verified(self, future, response):
         if response.error or b"is_valid:true" not in response.body:
             future.set_exception(AuthError(
-                    "Invalid OpenID response: %s" % (response.error or
-                                                     response.body)))
+                "Invalid OpenID response: %s" % (response.error or
+                                                 response.body)))
             return
 
         # Make sure we got back at least an email from attribute exchange
@@ -315,13 +320,13 @@ class OAuthMixin(object):
         request_cookie = self.get_cookie("_oauth_request_token")
         if not request_cookie:
             future.set_exception(AuthError(
-                    "Missing OAuth request token cookie"))
+                "Missing OAuth request token cookie"))
             return
         self.clear_cookie("_oauth_request_token")
         cookie_key, cookie_secret = [base64.b64decode(escape.utf8(i)) for i in request_cookie.split("|")]
         if cookie_key != request_key:
             future.set_exception(AuthError(
-                    "Request token does not match cookie"))
+                "Request token does not match cookie"))
             return
         token = dict(key=cookie_key, secret=cookie_secret)
         if oauth_verifier:
@@ -617,8 +622,8 @@ class TwitterMixin(OAuthMixin):
     def _on_twitter_request(self, future, response):
         if response.error:
             future.set_exception(AuthError(
-                    "Error response %s fetching %s" % (response.error,
-                                                       response.request.url)))
+                "Error response %s fetching %s" % (response.error,
+                                                   response.request.url)))
             return
         future.set_result(escape.json_decode(response.body))
 
@@ -738,8 +743,8 @@ class FriendFeedMixin(OAuthMixin):
     def _on_friendfeed_request(self, future, response):
         if response.error:
             future.set_exception(AuthError(
-                    "Error response %s fetching %s" % (response.error,
-                                                       response.request.url)))
+                "Error response %s fetching %s" % (response.error,
+                                                   response.request.url)))
             return
         future.set_result(escape.json_decode(response.body))
 
index 1779fed39312389d3d31eeb6ad3b95484db8907e..6b0121d7da82504ee166b63d1a87d9f367041318 100644 (file)
@@ -26,9 +26,11 @@ try:
 except ImportError:
     futures = None
 
+
 class ReturnValueIgnoredError(Exception):
     pass
 
+
 class _DummyFuture(object):
     def __init__(self):
         self._done = False
@@ -143,6 +145,7 @@ def run_on_executor(fn):
 
 _NO_RESULT = object()
 
+
 def return_future(f):
     """Decorator to make a function that returns via callback return a `Future`.
 
@@ -177,6 +180,7 @@ def return_future(f):
     consider using ``@gen.coroutine`` instead of this combination.
     """
     replacer = ArgReplacer(f, 'callback')
+
     @functools.wraps(f)
     def wrapper(*args, **kwargs):
         future = TracebackFuture()
@@ -221,6 +225,7 @@ def return_future(f):
         return future
     return wrapper
 
+
 def chain_future(a, b):
     """Chain two futures together so that when one completes, so does the other.
 
@@ -229,7 +234,7 @@ def chain_future(a, b):
     def copy(future):
         assert future is a
         if (isinstance(a, TracebackFuture) and isinstance(b, TracebackFuture)
-            and a.exc_info() is not None):
+                and a.exc_info() is not None):
             b.set_exc_info(a.exc_info())
         elif a.exception() is not None:
             b.set_exception(a.exception())
index bd58de197c496bf7f3fd8cfbf472a7cc06c498ea..ec5648ae1d032518fbb388966b89632506f5e9c1 100644 (file)
@@ -373,7 +373,7 @@ class Multi(YieldPoint):
 
     def is_ready(self):
         finished = list(itertools.takewhile(
-                lambda i: i.is_ready(), self.unfinished_children))
+            lambda i: i.is_ready(), self.unfinished_children))
         self.unfinished_children.difference_update(finished)
         return not self.unfinished_children
 
index a9ac0e70a334e7702cc38b9a29d0cda3b091d8f1..b5a4debc9ba444f31f625cf6c1cee35ecdb3d3dc 100644 (file)
@@ -83,7 +83,7 @@ class HTTPClient(object):
         If an error occurs during the fetch, we raise an `HTTPError`.
         """
         response = self._io_loop.run_sync(functools.partial(
-                self._async_client.fetch, request, **kwargs))
+            self._async_client.fetch, request, **kwargs))
         response.rethrow()
         return response
 
@@ -177,6 +177,7 @@ class AsyncHTTPClient(Configurable):
         future = Future()
         if callback is not None:
             callback = stack_context.wrap(callback)
+
             def handle_future(future):
                 exc = future.exception()
                 if isinstance(exc, HTTPError) and exc.response is not None:
@@ -189,6 +190,7 @@ class AsyncHTTPClient(Configurable):
                     response = future.result()
                 self.io_loop.add_callback(callback, response)
             future.add_done_callback(handle_future)
+
         def handle_response(response):
             if response.error:
                 future.set_exception(response.error)
index 85a86a6cd85918c9fb6df5a0422aeadcc5c60e07..b9cd10658013716ef9b40763dfddc4ddbf9fad1f 100644 (file)
@@ -318,6 +318,8 @@ def format_timestamp(ts):
 # _parseparam and _parse_header are copied and modified from python2.7's cgi.py
 # The original 2.7 version of this code did not correctly support some
 # combinations of semicolons and double quotes.
+
+
 def _parseparam(s):
     while s[:1] == ';':
         s = s[1:]
index 09e2c955bbba41bf29fff42022a5f5e828e5ad60..2c5152215eaa2ac2b199a4833d99e7688fa50ea6 100644 (file)
@@ -308,6 +308,7 @@ class IOLoop(Configurable):
                 IOLoop.instance().run_sync(main)
         """
         future_cell = [None]
+
         def run():
             try:
                 result = func()
@@ -331,7 +332,6 @@ class IOLoop(Configurable):
             raise TimeoutError('Operation timed out after %s seconds' % timeout)
         return future_cell[0].result()
 
-
     def time(self):
         """Returns the current time according to the IOLoop's clock.
 
index e60bfedf19c7576ce2293a2de61befedae64dacc..86a3fa437ba46a469a197a0fb00c59b1c6fce5d0 100644 (file)
@@ -197,16 +197,19 @@ class ExecutorResolver(Resolver):
             results.append((family, address))
         return results
 
+
 class BlockingResolver(ExecutorResolver):
     def initialize(self, io_loop=None):
         super(BlockingResolver, self).initialize(io_loop=io_loop)
 
+
 class ThreadedResolver(ExecutorResolver):
     def initialize(self, io_loop=None, num_threads=10):
         from concurrent.futures import ThreadPoolExecutor
         super(ThreadedResolver, self).initialize(
             io_loop=io_loop, executor=ThreadPoolExecutor(num_threads))
 
+
 class OverrideResolver(Resolver):
     """Wraps a resolver with a mapping of overrides.
 
@@ -227,13 +230,13 @@ class OverrideResolver(Resolver):
         return self.resolver.resolve(host, port, *args, **kwargs)
 
 
-
 # These are the keyword arguments to ssl.wrap_socket that must be translated
 # to their SSLContext equivalents (the other arguments are still passed
 # to SSLContext.wrap_socket).
 _SSL_CONTEXT_KEYWORDS = frozenset(['ssl_version', 'certfile', 'keyfile',
                                    'cert_reqs', 'ca_certs', 'ciphers'])
 
+
 def ssl_options_to_context(ssl_options):
     """Try to Convert an ssl_options dictionary to an SSLContext object.
 
@@ -247,7 +250,7 @@ def ssl_options_to_context(ssl_options):
     if isinstance(ssl_options, dict):
         assert all(k in _SSL_CONTEXT_KEYWORDS for k in ssl_options), ssl_options
     if (not hasattr(ssl, 'SSLContext') or
-        isinstance(ssl_options, ssl.SSLContext)):
+            isinstance(ssl_options, ssl.SSLContext)):
         return ssl_options
     context = ssl.SSLContext(
         ssl_options.get('ssl_version', ssl.PROTOCOL_SSLv23))
@@ -294,7 +297,6 @@ else:
     class SSLCertificateError(ValueError):
         pass
 
-
     def _dnsname_to_pat(dn):
         pats = []
         for frag in dn.split(r'.'):
@@ -308,7 +310,6 @@ else:
                 pats.append(frag.replace(r'\*', '[^.]*'))
         return re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE)
 
-
     def ssl_match_hostname(cert, hostname):
         """Verify that *cert* (in decoded format as returned by
         SSLSocket.getpeercert()) matches the *hostname*.  RFC 2818 rules
index b2b43b443d0f78c396c265d535215890438250b7..f0052f1598c6978373cb629c18edc62b93d77783 100644 (file)
@@ -5,6 +5,7 @@ from tornado import gen
 from tornado.ioloop import IOLoop
 from tornado.netutil import Resolver, is_valid_ip
 
+
 class CaresResolver(Resolver):
     """Name resolver based on the c-ares library.
 
index a95b009fd1c5ea53434cb1803e91d41935545770..240997f0c5ce1ea3ce4018b2fb183b141e32e489 100644 (file)
@@ -540,5 +540,5 @@ class TwistedResolver(Resolver):
                             (family, resolved_family))
         result = [
             (resolved_family, (resolved, port)),
-            ]
+        ]
         raise gen.Return(result)
index 41a5eceab4a2d091475a4af3cf95ef2c29fa949e..e0c5f3b640f9fcecf2503860d67039e22349272b 100644 (file)
@@ -28,6 +28,7 @@ from tornado.iostream import IOStream, SSLIOStream
 from tornado.netutil import bind_sockets, add_accept_handler, ssl_wrap_socket
 from tornado import process
 
+
 class TCPServer(object):
     r"""A non-blocking, single-threaded TCP server.
 
index 9808a0c289658a9c6ed35029759a31db13d3efc5..f26e036738ba5d935fa7794ead3e91088f476d32 100644 (file)
@@ -108,7 +108,6 @@ class TwitterClientHandler(RequestHandler, TwitterMixin):
         self._OAUTH_AUTHORIZE_URL = test.get_url('/oauth1/server/authorize')
         self._TWITTER_BASE_URL = test.get_url('/twitter/api')
 
-
     def get_auth_http_client(self):
         return self.settings['http_client']
 
index 3eca29632b91b23abd77b27dd50cb44c482201ff..854f1160ef944acc3d524cd386834b718bb686af 100644 (file)
@@ -166,6 +166,8 @@ class ReturnFutureTest(AsyncTestCase):
 
 # The following series of classes demonstrate and test various styles
 # of use, with and without generators and futures.
+
+
 class CapServer(TCPServer):
     def handle_stream(self, stream, address):
         logging.info("handle_stream")
index bc0c2daab12392f61d05cc2e21ce5d981963750e..10e3e83fb3a668fdd6b0e466f46fdabe99a1006b 100644 (file)
@@ -14,6 +14,7 @@ except ImportError:
 if pycurl is not None:
     from tornado.curl_httpclient import CurlAsyncHTTPClient
 
+
 @unittest.skipIf(pycurl is None, "pycurl module not present")
 class CurlHTTPClientCommonTestCase(httpclient_test.HTTPClientCommonTestCase):
     def get_http_client(self):
index f76f9324e9435c20bf41365112cbd509f2e5c36d..bfe92d7395a13d6c8a0fcda0da86ab196be52a42 100644 (file)
@@ -561,7 +561,7 @@ class GenCoroutineTest(AsyncTestCase):
         # can be caught and replaced.
         @gen.coroutine
         def f2():
-            self.io_loop.add_callback(lambda: 1/ 0)
+            self.io_loop.add_callback(lambda: 1 / 0)
             try:
                 yield gen.Task(self.io_loop.add_timeout,
                                self.io_loop.time() + 10)
@@ -579,7 +579,7 @@ class GenCoroutineTest(AsyncTestCase):
         # can be caught and ignored.
         @gen.coroutine
         def f2():
-            self.io_loop.add_callback(lambda: 1/ 0)
+            self.io_loop.add_callback(lambda: 1 / 0)
             try:
                 yield gen.Task(self.io_loop.add_timeout,
                                self.io_loop.time() + 10)
@@ -591,7 +591,6 @@ class GenCoroutineTest(AsyncTestCase):
         self.finished = True
 
 
-
 class GenSequenceHandler(RequestHandler):
     @asynchronous
     @gen.engine
index 02fb4f18d3ac59aaa84e36013757f9b7674b2908..36f312d72f06c5c4b1506527a7073171c58fd192 100644 (file)
@@ -26,6 +26,7 @@ try:
 except ImportError:
     from cStringIO import StringIO as BytesIO
 
+
 class HelloWorldHandler(RequestHandler):
     def get(self):
         name = self.get_argument("name", "world")
index 1aa85a6fa4ee34e64c065c03d283cb62c7343ea0..138282dc7a25b3cbec18ab622ac67235f5be1436 100644 (file)
@@ -151,6 +151,7 @@ class TestIOStreamMixin(object):
         server.read_until(b"\r\n", self.stop)
         data = self.wait()
         self.assertEqual(data, b"abcd\r\n")
+
         def closed_callback(chunk):
             self.fail()
         server.read_until_close(callback=closed_callback,
index e83189fc072337c85324fc7050953eabad789ced..245ef096fff3a92d87cdc509434bd3fd8492f1a4 100644 (file)
@@ -25,6 +25,7 @@ except ImportError:
 else:
     from tornado.platform.twisted import TwistedResolver
 
+
 class _ResolverTestMixin(object):
     def test_localhost(self):
         self.resolver.resolve('localhost', 80, callback=self.stop)
index 0c243e94ca897fe01fc35b3fbd10c2a97fb66eac..1c24dc570243af2b9426d42558e15d3eaf9681b5 100644 (file)
@@ -367,10 +367,10 @@ class HostnameMappingTestCase(AsyncHTTPTestCase):
             hostname_mapping={
                 'www.example.com': '127.0.0.1',
                 ('foo.example.com', 8000): ('127.0.0.1', self.get_http_port()),
-                })
+            })
 
     def get_app(self):
-        return Application([url("/hello", HelloWorldHandler),])
+        return Application([url("/hello", HelloWorldHandler), ])
 
     def test_hostname_mapping(self):
         self.http_client.fetch(
index 038602a8e2a0f8ddb844878bec44796f6ce268b6..5df54f5e53c0bf3a4e47bf257a99a0a12cf8b941 100644 (file)
@@ -11,6 +11,7 @@ try:
 except ImportError:
     from io import StringIO  # py3
 
+
 class RaiseExcInfoTest(unittest.TestCase):
     def test_two_arg_exception(self):
         # This test would fail on python 3 if raise_exc_info were simply
index 0f93644332e3ee80bcb48acf7dd2ea3a6eb68cb9..17a6c67c86abe58cb1be498673359c55f823b122 100644 (file)
@@ -20,10 +20,12 @@ import sys
 
 wsgi_safe_tests = []
 
+
 def wsgi_safe(cls):
     wsgi_safe_tests.append(cls)
     return cls
 
+
 class WebTestCase(AsyncHTTPTestCase):
     """Base class for web tests that also supports WSGI mode.
 
index ca10b4a135bb80b6d860425013690b434618413e..5cd7f0f97b32d5114c173fadf6ac48eef8e4fb0d 100644 (file)
@@ -2,15 +2,17 @@ from tornado.testing import AsyncHTTPTestCase, gen_test
 from tornado.web import Application
 from tornado.websocket import WebSocketHandler, WebSocketConnect
 
+
 class EchoHandler(WebSocketHandler):
     def on_message(self, message):
         self.write_message(message, isinstance(message, bytes))
 
+
 class WebSocketTest(AsyncHTTPTestCase):
     def get_app(self):
         return Application([
-                ('/echo', EchoHandler),
-                ])
+            ('/echo', EchoHandler),
+        ])
 
     @gen_test
     def test_websocket_gen(self):
index 3fc38c1bb497f20a69c5fd712db4f59ebf3563d5..a3b448ec2da34a218cd7139db054ad6d902e553d 100644 (file)
@@ -378,6 +378,7 @@ def gen_test(f):
 
     """
     f = gen.coroutine(f)
+
     @functools.wraps(f)
     def wrapper(self):
         return self.io_loop.run_sync(functools.partial(f, self), timeout=5)
@@ -406,7 +407,7 @@ class LogTrapTestCase(unittest.TestCase):
             logging.basicConfig()
         handler = logger.handlers[0]
         if (len(logger.handlers) > 1 or
-            not isinstance(handler, logging.StreamHandler)):
+                not isinstance(handler, logging.StreamHandler)):
             # Logging has been configured in a way we don't recognize,
             # so just leave it alone.
             super(LogTrapTestCase, self).run(result)
index 3cccba5645c7c87ac00b9d9ef461a7054504f0b0..fa3089f15c773ca0d0698e9948195d086a30ea38 100644 (file)
@@ -228,10 +228,10 @@ class RequestHandler(object):
     def clear(self):
         """Resets all headers and content for this response."""
         self._headers = httputil.HTTPHeaders({
-                "Server": "TornadoServer/%s" % tornado.version,
-                "Content-Type": "text/html; charset=UTF-8",
-                "Date": httputil.format_timestamp(time.gmtime()),
-                })
+            "Server": "TornadoServer/%s" % tornado.version,
+            "Content-Type": "text/html; charset=UTF-8",
+            "Date": httputil.format_timestamp(time.gmtime()),
+        })
         self.set_default_headers()
         if not self.request.supports_http_1_1():
             if self.request.headers.get("Connection") == "Keep-Alive":
index a6386018346dc4412226bb68d13a07d3bf52da5d..4bff6cd03660896344d7e536721a070c555f147a 100644 (file)
@@ -45,6 +45,7 @@ try:
 except NameError:
     xrange = range  # py3
 
+
 class WebSocketHandler(tornado.web.RequestHandler):
     """Subclass this class to create a basic WebSocket handler.
 
@@ -511,7 +512,6 @@ class WebSocketProtocol13(WebSocketProtocol):
         return WebSocketProtocol13.compute_accept_value(
             self.request.headers.get("Sec-Websocket-Key"))
 
-
     def _accept_connection(self):
         subprotocol_header = ''
         subprotocols = self.request.headers.get("Sec-WebSocket-Protocol", '')
@@ -729,11 +729,11 @@ class _WebSocketClientConnection(simple_httpclient._HTTPConnection):
         scheme = {'ws': 'http', 'wss': 'https'}[scheme]
         request.url = scheme + sep + rest
         request.headers.update({
-                'Upgrade': 'websocket',
-                'Connection': 'Upgrade',
-                'Sec-WebSocket-Key': self.key,
-                'Sec-WebSocket-Version': '13',
-                })
+            'Upgrade': 'websocket',
+            'Connection': 'Upgrade',
+            'Sec-WebSocket-Key': self.key,
+            'Sec-WebSocket-Version': '13',
+        })
 
         super(_WebSocketClientConnection, self).__init__(
             io_loop, None, request, lambda: None, lambda response: None,
@@ -742,7 +742,6 @@ class _WebSocketClientConnection(simple_httpclient._HTTPConnection):
     def _on_close(self):
         self.on_message(None)
 
-
     def _handle_1xx(self, code):
         assert code == 101
         assert self.headers['Upgrade'].lower() == 'websocket'