Another round of minor whitespace cleanups from autopep8

This commit is contained in:
Ben Darnell 2012-05-27 20:07:56 -07:00
parent 5e514195b1
commit dd9a8ac18c
20 changed files with 36 additions and 19 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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.

View File

@ -303,7 +303,6 @@ class _Option(object):
return _unicode(value)
options = _Options()
"""Global options dictionary.

View File

@ -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.

View File

@ -18,5 +18,3 @@ def set_close_exec(fd):
success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, 0)
if not success:
raise ctypes.GetLastError()

View File

@ -77,6 +77,7 @@ import threading
from tornado.util import raise_exc_info
class _State(threading.local):
def __init__(self):
self.contexts = ()

View File

@ -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):

View File

@ -2,6 +2,7 @@ import unittest
from tornado.options import _Options
class OptionsTest(unittest.TestCase):
def setUp(self):
self.options = _Options()

View File

@ -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"])

View File

@ -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()

View File

@ -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"))

View File

@ -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):

View File

@ -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()

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)