Browse Source

Update Tornado_py3 Web Server 6.0.3 (ff985fe) → 6.0.xx (18b653c).

pull/1289/head
JackDandy 5 years ago
parent
commit
de51d873f3
  1. 1
      CHANGES.md
  2. 2
      lib/tornado/auth.pyi
  3. 4
      lib/tornado/httpclient.pyi
  4. 2
      lib/tornado/iostream.pyi
  5. 4
      lib/tornado/testing.pyi
  6. 4
      lib/tornado_py3/auth.py
  7. 4
      lib/tornado_py3/autoreload.py
  8. 4
      lib/tornado_py3/http1connection.py
  9. 8
      lib/tornado_py3/httpclient.py
  10. 6
      lib/tornado_py3/httputil.py
  11. 8
      lib/tornado_py3/ioloop.py
  12. 2
      lib/tornado_py3/iostream.py
  13. 2
      lib/tornado_py3/netutil.py
  14. 11
      lib/tornado_py3/platform/asyncio.py
  15. 16
      lib/tornado_py3/process.py
  16. 8
      lib/tornado_py3/routing.py
  17. 7
      lib/tornado_py3/speedups.c
  18. 2
      lib/tornado_py3/tcpclient.py
  19. 25
      lib/tornado_py3/testing.py
  20. 66
      lib/tornado_py3/web.py
  21. 2
      lib/tornado_py3/websocket.py

1
CHANGES.md

@ -12,6 +12,7 @@
* Update PySocks 1.7.0 (91dcdf0) to 1.7.1 (c2fa43c) * Update PySocks 1.7.0 (91dcdf0) to 1.7.1 (c2fa43c)
* Update Requests library 2.22.0 (3d968ff) to 2.22.0 (d2f65af) * Update Requests library 2.22.0 (3d968ff) to 2.22.0 (d2f65af)
* Update Six compatibility library 1.13.0 (ec58185) to 1.14.0 (3a3db75) * Update Six compatibility library 1.13.0 (ec58185) to 1.14.0 (3a3db75)
* Update Tornado_py3 Web Server 6.0.3 (ff985fe) to 6.0.xx (18b653c)
* Update urllib3 release 1.25.6 (4a6c288) to 1.25.7 (37ba61a) * Update urllib3 release 1.25.6 (4a6c288) to 1.25.7 (37ba61a)

2
lib/tornado/auth.pyi

@ -18,7 +18,7 @@ class OAuthMixin:
def get_auth_http_client(self) -> httpclient.AsyncHTTPClient: ... def get_auth_http_client(self) -> httpclient.AsyncHTTPClient: ...
class OAuth2Mixin: class OAuth2Mixin:
def authorize_redirect(self, redirect_uri: Optional[str]=..., client_id: Optional[str]=..., client_secret: Optional[str]=..., extra_params: Optional[Dict[str, Any]]=..., scope: Optional[str]=..., response_type: str=...) -> None: ... def authorize_redirect(self, redirect_uri: Optional[str]=..., client_id: Optional[str]=..., client_secret: Optional[str]=..., extra_params: Optional[Dict[str, Any]]=..., scope: Optional[[List[str]]=..., response_type: str=...) -> None: ...
async def oauth2_request(self, url: str, access_token: Optional[str]=..., post_args: Optional[Dict[str, Any]]=..., **args: Any) -> Any: ... async def oauth2_request(self, url: str, access_token: Optional[str]=..., post_args: Optional[Dict[str, Any]]=..., **args: Any) -> Any: ...
def get_auth_http_client(self) -> httpclient.AsyncHTTPClient: ... def get_auth_http_client(self) -> httpclient.AsyncHTTPClient: ...

4
lib/tornado/httpclient.pyi

@ -8,7 +8,7 @@ from io import BytesIO
from tornado_py3 import httputil from tornado_py3 import httputil
from tornado_py3.concurrent import Future from tornado_py3.concurrent import Future
from tornado_py3.util import Configurable from tornado_py3.util import Configurable
from typing import Any, Awaitable, Callable, Dict, Optional, Type, Union from typing import Any, Callable, Dict, Optional, Type, Union
class HTTPClient: class HTTPClient:
def __init__(self, async_client_class: Optional[Type[AsyncHTTPClient]]=..., **kwargs: Any) -> None: ... def __init__(self, async_client_class: Optional[Type[AsyncHTTPClient]]=..., **kwargs: Any) -> None: ...
@ -26,7 +26,7 @@ class AsyncHTTPClient(Configurable):
defaults: Any = ... defaults: Any = ...
def initialize(self, defaults: Optional[Dict[str, Any]]=...) -> None: ... def initialize(self, defaults: Optional[Dict[str, Any]]=...) -> None: ...
def close(self) -> None: ... def close(self) -> None: ...
def fetch(self, request: Union[str, HTTPRequest], raise_error: bool=..., **kwargs: Any) -> Awaitable[HTTPResponse]: ... def fetch(self, request: Union[str, HTTPRequest], raise_error: bool=..., **kwargs: Any) -> Future[HTTPResponse]: ...
def fetch_impl(self, request: HTTPRequest, callback: Callable[[HTTPResponse], None]) -> None: ... def fetch_impl(self, request: HTTPRequest, callback: Callable[[HTTPResponse], None]) -> None: ...
@classmethod @classmethod
def configure(cls: Any, impl: Union[None, str, Type[Configurable]], **kwargs: Any) -> None: ... def configure(cls: Any, impl: Union[None, str, Type[Configurable]], **kwargs: Any) -> None: ...

2
lib/tornado/iostream.pyi

@ -56,7 +56,7 @@ class IOStream(BaseIOStream):
def get_fd_error(self) -> Optional[Exception]: ... def get_fd_error(self) -> Optional[Exception]: ...
def read_from_fd(self, buf: Union[bytearray, memoryview]) -> Optional[int]: ... def read_from_fd(self, buf: Union[bytearray, memoryview]) -> Optional[int]: ...
def write_to_fd(self, data: memoryview) -> int: ... def write_to_fd(self, data: memoryview) -> int: ...
def connect(self, address: tuple, server_hostname: Optional[str]=...) -> Future[_IOStreamType]: ... def connect(self, address: Any, server_hostname: Optional[str]=...) -> Future[_IOStreamType]: ...
def start_tls(self, server_side: bool, ssl_options: Optional[Union[Dict[str, Any], ssl.SSLContext]]=..., server_hostname: Optional[str]=...) -> Awaitable[SSLIOStream]: ... def start_tls(self, server_side: bool, ssl_options: Optional[Union[Dict[str, Any], ssl.SSLContext]]=..., server_hostname: Optional[str]=...) -> Awaitable[SSLIOStream]: ...
def set_nodelay(self, value: bool) -> None: ... def set_nodelay(self, value: bool) -> None: ...

4
lib/tornado/testing.pyi

@ -31,7 +31,7 @@ class AsyncTestCase(unittest.TestCase):
def get_new_ioloop(self) -> IOLoop: ... def get_new_ioloop(self) -> IOLoop: ...
def run(self, result: Optional[unittest.TestResult]=...) -> Optional[unittest.TestResult]: ... def run(self, result: Optional[unittest.TestResult]=...) -> Optional[unittest.TestResult]: ...
def stop(self, _arg: Any=..., **kwargs: Any) -> None: ... def stop(self, _arg: Any=..., **kwargs: Any) -> None: ...
def wait(self, condition: Optional[Callable[..., bool]]=..., timeout: Optional[float]=...) -> None: ... def wait(self, condition: Optional[Callable[..., bool]]=..., timeout: Optional[float]=...) -> Any: ...
class AsyncHTTPTestCase(AsyncTestCase): class AsyncHTTPTestCase(AsyncTestCase):
http_client: Any = ... http_client: Any = ...
@ -63,7 +63,7 @@ class ExpectLog(logging.Filter):
required: Any = ... required: Any = ...
matched: bool = ... matched: bool = ...
logged_stack: bool = ... logged_stack: bool = ...
def __init__(self, logger: Union[logging.Logger, basestring_type], regex: str, required: bool=...) -> None: ... def __init__(self, logger: Union[logging.Logger, basestring_type], regex: str, required: bool=..., level: Optional[int] = None) -> None: ...
def filter(self, record: logging.LogRecord) -> bool: ... def filter(self, record: logging.LogRecord) -> bool: ...
def __enter__(self) -> ExpectLog: ... def __enter__(self) -> ExpectLog: ...
def __exit__(self, typ: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[TracebackType]) -> None: ... def __exit__(self, typ: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[TracebackType]) -> None: ...

4
lib/tornado_py3/auth.py

@ -204,7 +204,7 @@ class OpenIdMixin(object):
) -> Dict[str, Any]: ) -> Dict[str, Any]:
handler = cast(RequestHandler, self) handler = cast(RequestHandler, self)
if b"is_valid:true" not in response.body: if b"is_valid:true" not in response.body:
raise AuthError("Invalid OpenID response: %s" % response.body) raise AuthError("Invalid OpenID response: %r" % response.body)
# Make sure we got back at least an email from attribute exchange # Make sure we got back at least an email from attribute exchange
ax_ns = None ax_ns = None
@ -556,7 +556,7 @@ class OAuth2Mixin(object):
client_id: Optional[str] = None, client_id: Optional[str] = None,
client_secret: Optional[str] = None, client_secret: Optional[str] = None,
extra_params: Optional[Dict[str, Any]] = None, extra_params: Optional[Dict[str, Any]] = None,
scope: Optional[str] = None, scope: Optional[List[str]] = None,
response_type: str = "code", response_type: str = "code",
) -> None: ) -> None:
"""Redirects the user to obtain OAuth authorization for this service. """Redirects the user to obtain OAuth authorization for this service.

4
lib/tornado_py3/autoreload.py

@ -253,8 +253,8 @@ def _reload() -> None:
# Unfortunately the errno returned in this case does not # Unfortunately the errno returned in this case does not
# appear to be consistent, so we can't easily check for # appear to be consistent, so we can't easily check for
# this error specifically. # this error specifically.
os.spawnv( # type: ignore os.spawnv(
os.P_NOWAIT, sys.executable, [sys.executable] + argv os.P_NOWAIT, sys.executable, [sys.executable] + argv # type: ignore
) )
# At this point the IOLoop has been closed and finally # At this point the IOLoop has been closed and finally
# blocks will experience errors if we allow the stack to # blocks will experience errors if we allow the stack to

4
lib/tornado_py3/http1connection.py

@ -235,7 +235,7 @@ class HTTP1Connection(httputil.HTTPConnection):
# but do not actually have a body. # but do not actually have a body.
# http://tools.ietf.org/html/rfc7230#section-3.3 # http://tools.ietf.org/html/rfc7230#section-3.3
skip_body = True skip_body = True
if code >= 100 and code < 200: if 100 <= code < 200:
# 1xx responses should never indicate the presence of # 1xx responses should never indicate the presence of
# a body. # a body.
if "Content-Length" in headers or "Transfer-Encoding" in headers: if "Content-Length" in headers or "Transfer-Encoding" in headers:
@ -406,6 +406,8 @@ class HTTP1Connection(httputil.HTTPConnection):
# self._request_start_line.version or # self._request_start_line.version or
# start_line.version? # start_line.version?
self._request_start_line.version == "HTTP/1.1" self._request_start_line.version == "HTTP/1.1"
# Omit payload header field for HEAD request.
and self._request_start_line.method != "HEAD"
# 1xx, 204 and 304 responses have no body (not even a zero-length # 1xx, 204 and 304 responses have no body (not even a zero-length
# body), and so should not have either Content-Length or # body), and so should not have either Content-Length or
# Transfer-Encoding headers. # Transfer-Encoding headers.

8
lib/tornado_py3/httpclient.py

@ -53,7 +53,7 @@ from tornado_py3 import gen, httputil
from tornado_py3.ioloop import IOLoop from tornado_py3.ioloop import IOLoop
from tornado_py3.util import Configurable from tornado_py3.util import Configurable
from typing import Type, Any, Union, Dict, Callable, Optional, cast, Awaitable from typing import Type, Any, Union, Dict, Callable, Optional, cast
class HTTPClient(object): class HTTPClient(object):
@ -251,7 +251,7 @@ class AsyncHTTPClient(Configurable):
request: Union[str, "HTTPRequest"], request: Union[str, "HTTPRequest"],
raise_error: bool = True, raise_error: bool = True,
**kwargs: Any **kwargs: Any
) -> Awaitable["HTTPResponse"]: ) -> "Future[HTTPResponse]":
"""Executes a request, asynchronously returning an `HTTPResponse`. """Executes a request, asynchronously returning an `HTTPResponse`.
The request may be either a string URL or an `HTTPRequest` object. The request may be either a string URL or an `HTTPRequest` object.
@ -506,7 +506,7 @@ class HTTPRequest(object):
""" """
# Note that some of these attributes go through property setters # Note that some of these attributes go through property setters
# defined below. # defined below.
self.headers = headers self.headers = headers # type: ignore
if if_modified_since: if if_modified_since:
self.headers["If-Modified-Since"] = httputil.format_timestamp( self.headers["If-Modified-Since"] = httputil.format_timestamp(
if_modified_since if_modified_since
@ -518,7 +518,7 @@ class HTTPRequest(object):
self.proxy_auth_mode = proxy_auth_mode self.proxy_auth_mode = proxy_auth_mode
self.url = url self.url = url
self.method = method self.method = method
self.body = body self.body = body # type: ignore
self.body_producer = body_producer self.body_producer = body_producer
self.auth_username = auth_username self.auth_username = auth_username
self.auth_password = auth_password self.auth_password = auth_password

6
lib/tornado_py3/httputil.py

@ -387,7 +387,9 @@ class HTTPServerRequest(object):
def cookies(self) -> Dict[str, http.cookies.Morsel]: def cookies(self) -> Dict[str, http.cookies.Morsel]:
"""A dictionary of ``http.cookies.Morsel`` objects.""" """A dictionary of ``http.cookies.Morsel`` objects."""
if not hasattr(self, "_cookies"): if not hasattr(self, "_cookies"):
self._cookies = http.cookies.SimpleCookie() self._cookies = (
http.cookies.SimpleCookie()
) # type: http.cookies.SimpleCookie
if "Cookie" in self.headers: if "Cookie" in self.headers:
try: try:
parsed = parse_cookie(self.headers["Cookie"]) parsed = parse_cookie(self.headers["Cookie"])
@ -667,7 +669,7 @@ class HTTPFile(ObjectDict):
def _parse_request_range( def _parse_request_range(
range_header: str range_header: str,
) -> Optional[Tuple[Optional[int], Optional[int]]]: ) -> Optional[Tuple[Optional[int], Optional[int]]]:
"""Parses a Range header. """Parses a Range header.

8
lib/tornado_py3/ioloop.py

@ -233,13 +233,13 @@ class IOLoop(Configurable):
def current() -> "IOLoop": def current() -> "IOLoop":
pass pass
@typing.overload # noqa: F811 @typing.overload
@staticmethod @staticmethod
def current(instance: bool = True) -> Optional["IOLoop"]: def current(instance: bool = True) -> Optional["IOLoop"]: # noqa: F811
pass pass
@staticmethod # noqa: F811 @staticmethod
def current(instance: bool = True) -> Optional["IOLoop"]: def current(instance: bool = True) -> Optional["IOLoop"]: # noqa: F811
"""Returns the current thread's `IOLoop`. """Returns the current thread's `IOLoop`.
If an `IOLoop` is currently running or has been marked as If an `IOLoop` is currently running or has been marked as

2
lib/tornado_py3/iostream.py

@ -1133,7 +1133,7 @@ class IOStream(BaseIOStream):
del data del data
def connect( def connect(
self: _IOStreamType, address: tuple, server_hostname: Optional[str] = None self: _IOStreamType, address: Any, server_hostname: Optional[str] = None
) -> "Future[_IOStreamType]": ) -> "Future[_IOStreamType]":
"""Connects the socket to a remote address without blocking. """Connects the socket to a remote address without blocking.

2
lib/tornado_py3/netutil.py

@ -387,7 +387,7 @@ def _resolve_addr(
results = [] results = []
for fam, socktype, proto, canonname, address in addrinfo: for fam, socktype, proto, canonname, address in addrinfo:
results.append((fam, address)) results.append((fam, address))
return results return results # type: ignore
class DefaultExecutorResolver(Resolver): class DefaultExecutorResolver(Resolver):

11
lib/tornado_py3/platform/asyncio.py

@ -21,6 +21,7 @@ the same event loop.
import concurrent.futures import concurrent.futures
import functools import functools
import sys
from threading import get_ident from threading import get_ident
from tornado_py3.gen import convert_yielded from tornado_py3.gen import convert_yielded
@ -307,7 +308,15 @@ def to_asyncio_future(tornado_future: asyncio.Future) -> asyncio.Future:
return convert_yielded(tornado_future) return convert_yielded(tornado_future)
class AnyThreadEventLoopPolicy(asyncio.DefaultEventLoopPolicy): # type: ignore if sys.platform == "win32" and hasattr(asyncio, "WindowsSelectorEventLoopPolicy"):
# "Any thread" and "selector" should be orthogonal, but there's not a clean
# interface for composing policies so pick the right base.
_BasePolicy = asyncio.WindowsSelectorEventLoopPolicy # type: ignore
else:
_BasePolicy = asyncio.DefaultEventLoopPolicy
class AnyThreadEventLoopPolicy(_BasePolicy): # type: ignore
"""Event loop policy that allows loop creation on any thread. """Event loop policy that allows loop creation on any thread.
The default `asyncio` event loop policy only automatically creates The default `asyncio` event loop policy only automatically creates

16
lib/tornado_py3/process.py

@ -55,7 +55,7 @@ def cpu_count() -> int:
except NotImplementedError: except NotImplementedError:
pass pass
try: try:
return os.sysconf("SC_NPROCESSORS_CONF") return os.sysconf("SC_NPROCESSORS_CONF") # type: ignore
except (AttributeError, ValueError): except (AttributeError, ValueError):
pass pass
gen_log.error("Could not detect number of processors; assuming 1") gen_log.error("Could not detect number of processors; assuming 1")
@ -110,14 +110,17 @@ def fork_processes(
number between 0 and ``num_processes``. Processes that exit number between 0 and ``num_processes``. Processes that exit
abnormally (due to a signal or non-zero exit status) are restarted abnormally (due to a signal or non-zero exit status) are restarted
with the same id (up to ``max_restarts`` times). In the parent with the same id (up to ``max_restarts`` times). In the parent
process, ``fork_processes`` returns None if all child processes process, ``fork_processes`` calls ``sys.exit(0)`` after all child
have exited normally, but will otherwise only exit by throwing an processes have exited normally.
exception.
max_restarts defaults to 100. max_restarts defaults to 100.
Availability: Unix Availability: Unix
""" """
if sys.platform == "win32":
# The exact form of this condition matters to mypy; it understands
# if but not assert in this context.
raise Exception("fork not available on windows")
if max_restarts is None: if max_restarts is None:
max_restarts = 100 max_restarts = 100
@ -350,7 +353,7 @@ class Subprocess(object):
@classmethod @classmethod
def _try_cleanup_process(cls, pid: int) -> None: def _try_cleanup_process(cls, pid: int) -> None:
try: try:
ret_pid, status = os.waitpid(pid, os.WNOHANG) ret_pid, status = os.waitpid(pid, os.WNOHANG) # type: ignore
except ChildProcessError: except ChildProcessError:
return return
if ret_pid == 0: if ret_pid == 0:
@ -360,6 +363,9 @@ class Subprocess(object):
subproc.io_loop.add_callback_from_signal(subproc._set_returncode, status) subproc.io_loop.add_callback_from_signal(subproc._set_returncode, status)
def _set_returncode(self, status: int) -> None: def _set_returncode(self, status: int) -> None:
if sys.platform == "win32":
self.returncode = -1
else:
if os.WIFSIGNALED(status): if os.WIFSIGNALED(status):
self.returncode = -os.WTERMSIG(status) self.returncode = -os.WTERMSIG(status)
else: else:

8
lib/tornado_py3/routing.py

@ -627,7 +627,13 @@ class PathMatches(Matcher):
if ")" in fragment: if ")" in fragment:
paren_loc = fragment.index(")") paren_loc = fragment.index(")")
if paren_loc >= 0: if paren_loc >= 0:
pieces.append("%s" + fragment[paren_loc + 1 :]) try:
unescaped_fragment = re_unescape(fragment[paren_loc + 1 :])
except ValueError:
# If we can't unescape part of it, we can't
# reverse this url.
return (None, None)
pieces.append("%s" + unescaped_fragment)
else: else:
try: try:
unescaped_fragment = re_unescape(fragment) unescaped_fragment = re_unescape(fragment)

7
lib/tornado_py3/speedups.c

@ -56,7 +56,6 @@ static PyMethodDef methods[] = {
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef speedupsmodule = { static struct PyModuleDef speedupsmodule = {
PyModuleDef_HEAD_INIT, PyModuleDef_HEAD_INIT,
"speedups", "speedups",
@ -69,9 +68,3 @@ PyMODINIT_FUNC
PyInit_speedups(void) { PyInit_speedups(void) {
return PyModule_Create(&speedupsmodule); return PyModule_Create(&speedupsmodule);
} }
#else // Python 2.x
PyMODINIT_FUNC
initspeedups(void) {
Py_InitModule("tornado.speedups", methods);
}
#endif

2
lib/tornado_py3/tcpclient.py

@ -75,7 +75,7 @@ class _Connector(object):
@staticmethod @staticmethod
def split( def split(
addrinfo: List[Tuple] addrinfo: List[Tuple],
) -> Tuple[ ) -> Tuple[
List[Tuple[socket.AddressFamily, Tuple]], List[Tuple[socket.AddressFamily, Tuple]],
List[Tuple[socket.AddressFamily, Tuple]], List[Tuple[socket.AddressFamily, Tuple]],

25
lib/tornado_py3/testing.py

@ -293,7 +293,7 @@ class AsyncTestCase(unittest.TestCase):
self, self,
condition: Optional[Callable[..., bool]] = None, condition: Optional[Callable[..., bool]] = None,
timeout: Optional[float] = None, timeout: Optional[float] = None,
) -> None: ) -> Any:
"""Runs the `.IOLoop` until stop is called or timeout has passed. """Runs the `.IOLoop` until stop is called or timeout has passed.
In the event of a timeout, an exception will be thrown. The In the event of a timeout, an exception will be thrown. The
@ -657,6 +657,7 @@ class ExpectLog(logging.Filter):
logger: Union[logging.Logger, basestring_type], logger: Union[logging.Logger, basestring_type],
regex: str, regex: str,
required: bool = True, required: bool = True,
level: Optional[int] = None,
) -> None: ) -> None:
"""Constructs an ExpectLog context manager. """Constructs an ExpectLog context manager.
@ -666,6 +667,15 @@ class ExpectLog(logging.Filter):
the specified logger that match this regex will be suppressed. the specified logger that match this regex will be suppressed.
:param required: If true, an exception will be raised if the end of :param required: If true, an exception will be raised if the end of
the ``with`` statement is reached without matching any log entries. the ``with`` statement is reached without matching any log entries.
:param level: A constant from the ``logging`` module indicating the
expected log level. If this parameter is provided, only log messages
at this level will be considered to match. Additionally, the
supplied ``logger`` will have its level adjusted if necessary
(for the duration of the ``ExpectLog`` to enable the expected
message.
.. versionchanged:: 6.1
Added the ``level`` parameter.
""" """
if isinstance(logger, basestring_type): if isinstance(logger, basestring_type):
logger = logging.getLogger(logger) logger = logging.getLogger(logger)
@ -674,17 +684,28 @@ class ExpectLog(logging.Filter):
self.required = required self.required = required
self.matched = False self.matched = False
self.logged_stack = False self.logged_stack = False
self.level = level
self.orig_level = None # type: Optional[int]
def filter(self, record: logging.LogRecord) -> bool: def filter(self, record: logging.LogRecord) -> bool:
if record.exc_info: if record.exc_info:
self.logged_stack = True self.logged_stack = True
message = record.getMessage() message = record.getMessage()
if self.regex.match(message): if self.regex.match(message):
if self.level is not None and record.levelno != self.level:
app_log.warning(
"Got expected log message %r at unexpected level (%s vs %s)"
% (message, logging.getLevelName(self.level), record.levelname)
)
return True
self.matched = True self.matched = True
return False return False
return True return True
def __enter__(self) -> "ExpectLog": def __enter__(self) -> "ExpectLog":
if self.level is not None and self.level < self.logger.getEffectiveLevel():
self.orig_level = self.logger.level
self.logger.setLevel(self.level)
self.logger.addFilter(self) self.logger.addFilter(self)
return self return self
@ -694,6 +715,8 @@ class ExpectLog(logging.Filter):
value: Optional[BaseException], value: Optional[BaseException],
tb: Optional[TracebackType], tb: Optional[TracebackType],
) -> None: ) -> None:
if self.orig_level is not None:
self.logger.setLevel(self.orig_level)
self.logger.removeFilter(self) self.logger.removeFilter(self)
if not typ and self.required and not self.matched: if not typ and self.required and not self.matched:
raise Exception("did not get expected log message") raise Exception("did not get expected log message")

66
lib/tornado_py3/web.py

@ -424,14 +424,14 @@ class RequestHandler(object):
def get_argument(self, name: str, default: str, strip: bool = True) -> str: def get_argument(self, name: str, default: str, strip: bool = True) -> str:
pass pass
@overload # noqa: F811 @overload
def get_argument( def get_argument( # noqa: F811
self, name: str, default: _ArgDefaultMarker = _ARG_DEFAULT, strip: bool = True self, name: str, default: _ArgDefaultMarker = _ARG_DEFAULT, strip: bool = True
) -> str: ) -> str:
pass pass
@overload # noqa: F811 @overload
def get_argument( def get_argument( # noqa: F811
self, name: str, default: None, strip: bool = True self, name: str, default: None, strip: bool = True
) -> Optional[str]: ) -> Optional[str]:
pass pass
@ -624,7 +624,9 @@ class RequestHandler(object):
# Don't let us accidentally inject bad stuff # Don't let us accidentally inject bad stuff
raise ValueError("Invalid cookie %r: %r" % (name, value)) raise ValueError("Invalid cookie %r: %r" % (name, value))
if not hasattr(self, "_new_cookie"): if not hasattr(self, "_new_cookie"):
self._new_cookie = http.cookies.SimpleCookie() self._new_cookie = (
http.cookies.SimpleCookie()
) # type: http.cookies.SimpleCookie
if name in self._new_cookie: if name in self._new_cookie:
del self._new_cookie[name] del self._new_cookie[name]
self._new_cookie[name] = value self._new_cookie[name] = value
@ -1070,7 +1072,11 @@ class RequestHandler(object):
self._headers_written = True self._headers_written = True
for transform in self._transforms: for transform in self._transforms:
assert chunk is not None assert chunk is not None
self._status_code, self._headers, chunk = transform.transform_first_chunk( (
self._status_code,
self._headers,
chunk,
) = transform.transform_first_chunk(
self._status_code, self._headers, chunk, include_footers self._status_code, self._headers, chunk, include_footers
) )
# Ignore the chunk and only write the headers for HEAD requests # Ignore the chunk and only write the headers for HEAD requests
@ -1132,13 +1138,11 @@ class RequestHandler(object):
if self.check_etag_header(): if self.check_etag_header():
self._write_buffer = [] self._write_buffer = []
self.set_status(304) self.set_status(304)
if self._status_code in (204, 304) or ( if self._status_code in (204, 304) or (100 <= self._status_code < 200):
self._status_code >= 100 and self._status_code < 200
):
assert not self._write_buffer, ( assert not self._write_buffer, (
"Cannot send body with %s" % self._status_code "Cannot send body with %s" % self._status_code
) )
self._clear_headers_for_304() self._clear_representation_headers()
elif "Content-Length" not in self._headers: elif "Content-Length" not in self._headers:
content_length = sum(len(part) for part in self._write_buffer) content_length = sum(len(part) for part in self._write_buffer)
self.set_header("Content-Length", content_length) self.set_header("Content-Length", content_length)
@ -1782,11 +1786,11 @@ class RequestHandler(object):
args = [value.status_code, self._request_summary()] + list(value.args) args = [value.status_code, self._request_summary()] + list(value.args)
gen_log.warning(format, *args) gen_log.warning(format, *args)
else: else:
app_log.error( # type: ignore app_log.error(
"Uncaught exception %s\n%r", "Uncaught exception %s\n%r",
self._request_summary(), self._request_summary(),
self.request, self.request,
exc_info=(typ, value, tb), exc_info=(typ, value, tb), # type: ignore
) )
def _ui_module(self, name: str, module: Type["UIModule"]) -> Callable[..., str]: def _ui_module(self, name: str, module: Type["UIModule"]) -> Callable[..., str]:
@ -1803,21 +1807,13 @@ class RequestHandler(object):
def _ui_method(self, method: Callable[..., str]) -> Callable[..., str]: def _ui_method(self, method: Callable[..., str]) -> Callable[..., str]:
return lambda *args, **kwargs: method(self, *args, **kwargs) return lambda *args, **kwargs: method(self, *args, **kwargs)
def _clear_headers_for_304(self) -> None: def _clear_representation_headers(self) -> None:
# 304 responses should not contain entity headers (defined in # 304 responses should not contain representation metadata
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.1) # headers (defined in
# https://tools.ietf.org/html/rfc7231#section-3.1)
# not explicitly allowed by # not explicitly allowed by
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5 # https://tools.ietf.org/html/rfc7232#section-4.1
headers = [ headers = ["Content-Encoding", "Content-Language", "Content-Type"]
"Allow",
"Content-Encoding",
"Content-Language",
"Content-Length",
"Content-MD5",
"Content-Range",
"Content-Type",
"Last-Modified",
]
for h in headers: for h in headers:
self.clear_header(h) self.clear_header(h)
@ -1933,8 +1929,8 @@ class _ApplicationRouter(ReversibleRuleRouter):
rule = super(_ApplicationRouter, self).process_rule(rule) rule = super(_ApplicationRouter, self).process_rule(rule)
if isinstance(rule.target, (list, tuple)): if isinstance(rule.target, (list, tuple)):
rule.target = _ApplicationRouter( # type: ignore rule.target = _ApplicationRouter(
self.application, rule.target self.application, rule.target # type: ignore
) )
return rule return rule
@ -2832,12 +2828,12 @@ class StaticFileHandler(RequestHandler):
"""Returns a version string for the resource at the given path. """Returns a version string for the resource at the given path.
This class method may be overridden by subclasses. The This class method may be overridden by subclasses. The
default implementation is a hash of the file's contents. default implementation is a SHA-512 hash of the file's contents.
.. versionadded:: 3.1 .. versionadded:: 3.1
""" """
data = cls.get_content(abspath) data = cls.get_content(abspath)
hasher = hashlib.md5() hasher = hashlib.sha512()
if isinstance(data, bytes): if isinstance(data, bytes):
hasher.update(data) hasher.update(data)
else: else:
@ -3534,9 +3530,13 @@ def _decode_signed_value_v2(
clock: Callable[[], float], clock: Callable[[], float],
) -> Optional[bytes]: ) -> Optional[bytes]:
try: try:
key_version, timestamp_bytes, name_field, value_field, passed_sig = _decode_fields_v2( (
value key_version,
) timestamp_bytes,
name_field,
value_field,
passed_sig,
) = _decode_fields_v2(value)
except ValueError: except ValueError:
return None return None
signed_string = value[: -len(passed_sig)] signed_string = value[: -len(passed_sig)]

2
lib/tornado_py3/websocket.py

@ -280,8 +280,6 @@ class WebSocketHandler(tornado_py3.web.RequestHandler):
self.set_status(426, "Upgrade Required") self.set_status(426, "Upgrade Required")
self.set_header("Sec-WebSocket-Version", "7, 8, 13") self.set_header("Sec-WebSocket-Version", "7, 8, 13")
stream = None
@property @property
def ping_interval(self) -> Optional[float]: def ping_interval(self) -> Optional[float]:
"""The interval for websocket keep-alive pings. """The interval for websocket keep-alive pings.

Loading…
Cancel
Save