Remove async_callback wrapper functions, which have been obsolete since 1.1.
Closes #283.
This commit is contained in:
parent
409ddc474a
commit
7a0eda1338
|
@ -149,7 +149,7 @@ class AuthLoginHandler(BaseHandler, tornado.auth.GoogleMixin):
|
|||
@tornado.web.asynchronous
|
||||
def get(self):
|
||||
if self.get_argument("openid.mode", None):
|
||||
self.get_authenticated_user(self.async_callback(self._on_auth))
|
||||
self.get_authenticated_user(self._on_auth)
|
||||
return
|
||||
self.authenticate_redirect()
|
||||
|
||||
|
|
|
@ -96,7 +96,6 @@
|
|||
|
||||
The `Application` object serving this request
|
||||
|
||||
.. automethod:: RequestHandler.async_callback
|
||||
.. automethod:: RequestHandler.check_etag_header
|
||||
.. automethod:: RequestHandler.check_xsrf_cookie
|
||||
.. automethod:: RequestHandler.compute_etag
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
Other
|
||||
-----
|
||||
|
||||
.. automethod:: WebSocketHandler.async_callback
|
||||
.. automethod:: WebSocketHandler.ping
|
||||
.. automethod:: WebSocketHandler.on_pong
|
||||
.. autoexception:: WebSocketClosedError
|
||||
|
|
|
@ -1242,27 +1242,6 @@ class RequestHandler(object):
|
|||
|
||||
return base + get_url(self.settings, path, **kwargs)
|
||||
|
||||
def async_callback(self, callback, *args, **kwargs):
|
||||
"""Obsolete - catches exceptions from the wrapped function.
|
||||
|
||||
This function is unnecessary since Tornado 1.1.
|
||||
"""
|
||||
if callback is None:
|
||||
return None
|
||||
if args or kwargs:
|
||||
callback = functools.partial(callback, *args, **kwargs)
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return callback(*args, **kwargs)
|
||||
except Exception as e:
|
||||
if self._headers_written:
|
||||
app_log.error("Exception after headers written",
|
||||
exc_info=True)
|
||||
else:
|
||||
self._handle_request_exception(e)
|
||||
return wrapper
|
||||
|
||||
def require_setting(self, name, feature="this feature"):
|
||||
"""Raises an exception if the given app setting is not defined."""
|
||||
if not self.application.settings.get(name):
|
||||
|
|
|
@ -346,14 +346,6 @@ class WebSocketHandler(tornado.web.RequestHandler):
|
|||
"""
|
||||
return "wss" if self.request.protocol == "https" else "ws"
|
||||
|
||||
def async_callback(self, callback, *args, **kwargs):
|
||||
"""Obsolete - catches exceptions from the wrapped function.
|
||||
|
||||
This function is normally unncecessary thanks to
|
||||
`tornado.stack_context`.
|
||||
"""
|
||||
return self.ws_connection.async_callback(callback, *args, **kwargs)
|
||||
|
||||
def _not_supported(self, *args, **kwargs):
|
||||
raise Exception("Method not supported for Web Sockets")
|
||||
|
||||
|
@ -379,23 +371,17 @@ class WebSocketProtocol(object):
|
|||
self.client_terminated = False
|
||||
self.server_terminated = False
|
||||
|
||||
def async_callback(self, callback, *args, **kwargs):
|
||||
"""Wrap callbacks with this if they are used on asynchronous requests.
|
||||
def _run_callback(self, callback, *args, **kwargs):
|
||||
"""Runs the given callback with exception handling.
|
||||
|
||||
Catches exceptions properly and closes this WebSocket if an exception
|
||||
is uncaught.
|
||||
On error, aborts the websocket connection and returns False.
|
||||
"""
|
||||
if args or kwargs:
|
||||
callback = functools.partial(callback, *args, **kwargs)
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return callback(*args, **kwargs)
|
||||
callback(*args, **kwargs)
|
||||
except Exception:
|
||||
app_log.error("Uncaught exception in %s",
|
||||
self.request.path, exc_info=True)
|
||||
self._abort()
|
||||
return wrapper
|
||||
|
||||
def on_connection_close(self):
|
||||
self._abort()
|
||||
|
@ -486,7 +472,8 @@ class WebSocketProtocol76(WebSocketProtocol):
|
|||
|
||||
def _write_response(self, challenge):
|
||||
self.stream.write(challenge)
|
||||
self.async_callback(self.handler.open)(*self.handler.open_args, **self.handler.open_kwargs)
|
||||
self._run_callback(self.handler.open, *self.handler.open_args,
|
||||
**self.handler.open_kwargs)
|
||||
self._receive_message()
|
||||
|
||||
def _handle_websocket_headers(self):
|
||||
|
@ -534,7 +521,7 @@ class WebSocketProtocol76(WebSocketProtocol):
|
|||
|
||||
def _on_end_delimiter(self, frame):
|
||||
if not self.client_terminated:
|
||||
self.async_callback(self.handler.on_message)(
|
||||
self._run_callback(self.handler.on_message,
|
||||
frame[:-1].decode("utf-8", "replace"))
|
||||
if not self.client_terminated:
|
||||
self._receive_message()
|
||||
|
@ -645,7 +632,8 @@ class WebSocketProtocol13(WebSocketProtocol):
|
|||
"%s"
|
||||
"\r\n" % (self._challenge_response(), subprotocol_header)))
|
||||
|
||||
self.async_callback(self.handler.open)(*self.handler.open_args, **self.handler.open_kwargs)
|
||||
self._run_callback(self.handler.open, *self.handler.open_args,
|
||||
**self.handler.open_kwargs)
|
||||
self._receive_frame()
|
||||
|
||||
def _write_frame(self, fin, opcode, data):
|
||||
|
@ -803,10 +791,10 @@ class WebSocketProtocol13(WebSocketProtocol):
|
|||
except UnicodeDecodeError:
|
||||
self._abort()
|
||||
return
|
||||
self.async_callback(self.handler.on_message)(decoded)
|
||||
self._run_callback(self.handler.on_message, decoded)
|
||||
elif opcode == 0x2:
|
||||
# Binary data
|
||||
self.async_callback(self.handler.on_message)(data)
|
||||
self._run_callback(self.handler.on_message, decoded)
|
||||
elif opcode == 0x8:
|
||||
# Close
|
||||
self.client_terminated = True
|
||||
|
@ -820,7 +808,7 @@ class WebSocketProtocol13(WebSocketProtocol):
|
|||
self._write_frame(True, 0xA, data)
|
||||
elif opcode == 0xA:
|
||||
# Pong
|
||||
self.async_callback(self.handler.on_pong)(data)
|
||||
self._run_callback(self.handler.on_pong, data)
|
||||
else:
|
||||
self._abort()
|
||||
|
||||
|
|
Loading…
Reference in New Issue