})
http.fetch(self._OAUTH_ACCESS_TOKEN_URL,
- self.async_callback(self._on_access_token, callback),
- method="POST", headers={'Content-Type': 'application/x-www-form-urlencoded'}, body=body)
+ self.async_callback(self._on_access_token, callback),
+ method="POST", headers={'Content-Type': 'application/x-www-form-urlencoded'}, body=body)
def _on_access_token(self, future, response):
"""Callback function for the exchange to the access token."""
else:
return self.result
+
class Multi(YieldPoint):
"""Runs multiple asynchronous operations in parallel.
# They should be caught and handled less noisily than other errors.
_ERRNO_CONNRESET = (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE)
+
class StreamClosedError(IOError):
"""Exception raised by `IOStream` methods when the stream is closed.
# localhost, so handle them the same way as an error
# reported later in _handle_connect.
if (e.args[0] != errno.EINPROGRESS and
- e.args[0] not in _ERRNO_WOULDBLOCK):
+ e.args[0] not in _ERRNO_WOULDBLOCK):
gen_log.warning("Connect error on fd %d: %s",
self.socket.fileno(), e)
self.close(exc_info=True)
from tornado.ioloop import IOLoop
from tornado import stack_context
+
class BaseAsyncIOLoop(IOLoop):
def initialize(self, asyncio_loop, close_loop=False):
self.asyncio_loop = asyncio_loop
else:
raise TypeError("Unsupported deadline %r", deadline)
return self.asyncio_loop.call_later(delay, self._run_callback,
- stack_context.wrap(callback))
+ stack_context.wrap(callback))
def remove_timeout(self, timeout):
timeout.cancel()
raise RuntimeError("IOLoop is closing")
if kwargs:
self.asyncio_loop.call_soon_threadsafe(functools.partial(
- self._run_callback, stack_context.wrap(callback),
- *args, **kwargs))
+ self._run_callback, stack_context.wrap(callback),
+ *args, **kwargs))
else:
self.asyncio_loop.call_soon_threadsafe(
self._run_callback, stack_context.wrap(callback), *args)
super(AsyncIOMainLoop, self).initialize(asyncio.get_event_loop(),
close_loop=False)
+
class AsyncIOLoop(BaseAsyncIOLoop):
def initialize(self):
super(AsyncIOLoop, self).initialize(asyncio.new_event_loop(),
self.queue.append((key, request, callback))
if not len(self.active) < self.max_clients:
timeout_handle = self.io_loop.add_timeout(
- self.io_loop.time() + min(request.connect_timeout,
- request.request_timeout),
- functools.partial(self._on_timeout, key))
+ self.io_loop.time() + min(request.connect_timeout,
+ request.request_timeout),
+ functools.partial(self._on_timeout, key))
else:
timeout_handle = None
self.waiting[key] = (request, callback, timeout_handle)
request, callback, timeout_handle = self.waiting[key]
self.queue.remove((key, request, callback))
timeout_response = HTTPResponse(
- request, 599, error=HTTPError(599, "Timeout"),
- request_time=self.io_loop.time() - request.start_time)
+ request, 599, error=HTTPError(599, "Timeout"),
+ request_time=self.io_loop.time() - request.start_time)
self.io_loop.add_callback(callback, timeout_response)
del self.waiting[key]
b"X-Header-encoding-test: \xe9",
],
b"\r\n".join([
- b"Content-Disposition: form-data; name=argument",
- b"",
- u("\u00e1").encode("utf-8"),
- b"--1234567890",
- u('Content-Disposition: form-data; name="files"; filename="\u00f3"').encode("utf8"),
- b"",
- u("\u00fa").encode("utf-8"),
- b"--1234567890--",
- b"",
+ b"Content-Disposition: form-data; name=argument",
+ b"",
+ u("\u00e1").encode("utf-8"),
+ b"--1234567890",
+ u('Content-Disposition: form-data; name="files"; filename="\u00f3"').encode("utf8"),
+ b"",
+ u("\u00fa").encode("utf-8"),
+ b"--1234567890--",
+ b"",
]))
data = json_decode(response.body)
self.assertEqual(u("\u00e9"), data["header"])
self.assertEqual(response, b"")
-
class KeepAliveTest(AsyncHTTPTestCase):
"""Tests various scenarios for HTTP 1.1 keep-alive support.
b'<html><title>404: Not Found</title>'
b'<body>404: Not Found</body></html>')
+
@wsgi_safe
class Custom404Test(WebTestCase):
def get_handlers(self):
self.assertEqual(response.code, 404)
self.assertEqual(response.body, b'custom 404 response')
+
@wsgi_safe
class DefaultHandlerArgumentsTest(WebTestCase):
def get_handlers(self):
except ImportError:
speedups = None
+
class TestWebSocketHandler(WebSocketHandler):
"""Base class for testing handlers that exposes the on_close event.
def mask(self, mask, data):
return _websocket_mask_python(mask, data)
+
@unittest.skipIf(speedups is None, "tornado.speedups module not present")
class CythonMaskFunctionTest(MaskFunctionMixin, unittest.TestCase):
def mask(self, mask, data):
# content, or when a suffix with length 0 is specified
self.set_status(416) # Range Not Satisfiable
self.set_header("Content-Type", "text/plain")
- self.set_header("Content-Range", "bytes */%s" %(size, ))
+ self.set_header("Content-Range", "bytes */%s" % (size, ))
return
if start is not None and start < 0:
start += size
"Sec-WebSocket-Location: %(scheme)s://%(host)s%(uri)s\r\n"
"%(subprotocol)s"
"\r\n" % (dict(
- version=tornado.version,
- origin=self.request.headers["Origin"],
- scheme=scheme,
- host=self.request.host,
- uri=self.request.uri,
- subprotocol=subprotocol_header))))
+ version=tornado.version,
+ origin=self.request.headers["Origin"],
+ scheme=scheme,
+ host=self.request.host,
+ uri=self.request.uri,
+ subprotocol=subprotocol_header))))
self.stream.read_bytes(8, self._handle_challenge)
def challenge_response(self, challenge):
io_loop.add_future(conn.connect_future, callback)
return conn.connect_future
+
def _websocket_mask_python(mask, data):
"""Websocket masking function.
"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,