Browse Source

Update Tornado_py3 Web Server 6.1.dev1 (18b653c) to 6.0.4 (b4e39e5).

pull/1289/head
JackDandy 5 years ago
parent
commit
a2c17aab35
  1. 3
      CHANGES.md
  2. 4
      lib/tornado/__init__.pyi
  3. 4
      lib/tornado/_locale_data.pyi
  4. 29
      lib/tornado/auth.pyi
  5. 7
      lib/tornado/autoreload.pyi
  6. 5
      lib/tornado/concurrent.pyi
  7. 13
      lib/tornado/curl_httpclient.pyi
  8. 7
      lib/tornado/escape.pyi
  9. 9
      lib/tornado/gen.pyi
  10. 19
      lib/tornado/http1connection.pyi
  11. 28
      lib/tornado/httpclient.pyi
  12. 16
      lib/tornado/httpserver.pyi
  13. 20
      lib/tornado/httputil.pyi
  14. 16
      lib/tornado/ioloop.pyi
  15. 25
      lib/tornado/iostream.pyi
  16. 23
      lib/tornado/locale.pyi
  17. 12
      lib/tornado/locks.pyi
  18. 9
      lib/tornado/log.pyi
  19. 17
      lib/tornado/netutil.pyi
  20. 23
      lib/tornado/options.pyi
  21. 4
      lib/tornado/platform/__init__.pyi
  22. 9
      lib/tornado/platform/asyncio.pyi
  23. 4
      lib/tornado/platform/auto.pyi
  24. 9
      lib/tornado/platform/caresresolver.pyi
  25. 4
      lib/tornado/platform/interface.pyi
  26. 4
      lib/tornado/platform/posix.pyi
  27. 11
      lib/tornado/platform/twisted.pyi
  28. 4
      lib/tornado/platform/windows.pyi
  29. 13
      lib/tornado/process.pyi
  30. 12
      lib/tornado/queues.pyi
  31. 17
      lib/tornado/routing.pyi
  32. 18
      lib/tornado/simple_httpclient.pyi
  33. 4
      lib/tornado/speedups.pyi
  34. 22
      lib/tornado/tcpclient.pyi
  35. 17
      lib/tornado/tcpserver.pyi
  36. 27
      lib/tornado/template.pyi
  37. 26
      lib/tornado/testing.pyi
  38. 6
      lib/tornado/util.pyi
  39. 59
      lib/tornado/web.pyi
  40. 42
      lib/tornado/websocket.pyi
  41. 7
      lib/tornado/wsgi.pyi
  42. 4
      lib/tornado_py3/__init__.py
  43. 61
      lib/tornado_py3/auth.py
  44. 4
      lib/tornado_py3/autoreload.py
  45. 32
      lib/tornado_py3/curl_httpclient.py
  46. 8
      lib/tornado_py3/escape.py
  47. 26
      lib/tornado_py3/http1connection.py
  48. 97
      lib/tornado_py3/httpclient.py
  49. 20
      lib/tornado_py3/httpserver.py
  50. 101
      lib/tornado_py3/httputil.py
  51. 18
      lib/tornado_py3/ioloop.py
  52. 122
      lib/tornado_py3/iostream.py
  53. 39
      lib/tornado_py3/locale.py
  54. 41
      lib/tornado_py3/locks.py
  55. 7
      lib/tornado_py3/log.py
  56. 67
      lib/tornado_py3/netutil.py
  57. 67
      lib/tornado_py3/options.py
  58. 2
      lib/tornado_py3/platform/auto.py
  59. 35
      lib/tornado_py3/platform/twisted.py
  60. 50
      lib/tornado_py3/process.py
  61. 24
      lib/tornado_py3/queues.py
  62. 20
      lib/tornado_py3/routing.py
  63. 14
      lib/tornado_py3/simple_httpclient.py
  64. 7
      lib/tornado_py3/speedups.c
  65. 24
      lib/tornado_py3/tcpclient.py
  66. 20
      lib/tornado_py3/tcpserver.py
  67. 34
      lib/tornado_py3/template.py
  68. 38
      lib/tornado_py3/testing.py
  69. 4
      lib/tornado_py3/util.py
  70. 137
      lib/tornado_py3/web.py
  71. 55
      lib/tornado_py3/websocket.py

3
CHANGES.md

@ -14,7 +14,7 @@
* Update PySocks 1.7.0 (91dcdf0) to 1.7.1 (c2fa43c)
* 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 Tornado_py3 Web Server 6.0.3 (ff985fe) to 6.0.xx (18b653c)
* Update Tornado_py3 Web Server 6.1.dev1 (18b653c) to 6.0.4 (b4e39e5)
* Update urllib3 release 1.25.6 (4a6c288) to 1.25.7 (37ba61a)
* Add Telegram notifier
* Change enable image caching on browse pages
@ -28,6 +28,7 @@
* Fix name_parser_tests
* Fix config/Media Process/Unpack test unrar under py3
* Change remove deprecated `buildNameCache`
* Update Tornado_py3 Web Server 6.0.3 (ff985fe) to 6.1.dev1 (18b653c)
### 0.21.18 (2020-03-04 19:20:00 UTC)

4
lib/tornado/__init__.pyi

@ -1,7 +1,3 @@
# Stubs for tornado_py3 (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from typing import Any
version: str

4
lib/tornado/_locale_data.pyi

@ -1,7 +1,3 @@
# Stubs for tornado_py3._locale_data (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from typing import Any
LOCALE_NAMES: Any

29
lib/tornado/auth.pyi

@ -1,34 +1,33 @@
# Stubs for tornado_py3.auth (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from tornado_py3 import httpclient
from tornado_py3 import escape as escape, httpclient as httpclient
from tornado_py3.httputil import url_concat as url_concat
from tornado_py3.util import unicode_type as unicode_type
from tornado_py3.web import RequestHandler as RequestHandler
from typing import Any, Dict, List, Optional
class AuthError(Exception): ...
class OpenIdMixin:
def authenticate_redirect(self, callback_uri: Optional[str]=..., ax_attrs: List[str]=...) -> None: ...
async def get_authenticated_user(self, http_client: Optional[httpclient.AsyncHTTPClient]=...) -> Dict[str, Any]: ...
def authenticate_redirect(self, callback_uri: str=..., ax_attrs: List[str]=...) -> None: ...
async def get_authenticated_user(self, http_client: httpclient.AsyncHTTPClient=...) -> Dict[str, Any]: ...
def get_auth_http_client(self) -> httpclient.AsyncHTTPClient: ...
class OAuthMixin:
async def authorize_redirect(self, callback_uri: Optional[str]=..., extra_params: Optional[Dict[str, Any]]=..., http_client: Optional[httpclient.AsyncHTTPClient]=...) -> None: ...
async def get_authenticated_user(self, http_client: Optional[httpclient.AsyncHTTPClient]=...) -> Dict[str, Any]: ...
async def authorize_redirect(self, callback_uri: str=..., extra_params: Dict[str, Any]=..., http_client: httpclient.AsyncHTTPClient=...) -> None: ...
async def get_authenticated_user(self, http_client: httpclient.AsyncHTTPClient=...) -> Dict[str, Any]: ...
def get_auth_http_client(self) -> httpclient.AsyncHTTPClient: ...
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[[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: ...
def authorize_redirect(self, redirect_uri: str=..., client_id: str=..., client_secret: str=..., extra_params: Dict[str, Any]=..., scope: str=..., response_type: str=...) -> None: ...
async def oauth2_request(self, url: str, access_token: str=..., post_args: Dict[str, Any]=..., **args: Any) -> Any: ...
def get_auth_http_client(self) -> httpclient.AsyncHTTPClient: ...
class TwitterMixin(OAuthMixin):
async def authenticate_redirect(self, callback_uri: Optional[str]=...) -> None: ...
async def twitter_request(self, path: str, access_token: Dict[str, Any], post_args: Optional[Dict[str, Any]]=..., **args: Any) -> Any: ...
async def authenticate_redirect(self, callback_uri: str=...) -> None: ...
async def twitter_request(self, path: str, access_token: Dict[str, Any], post_args: Dict[str, Any]=..., **args: Any) -> Any: ...
class GoogleOAuth2Mixin(OAuth2Mixin):
async def get_authenticated_user(self, redirect_uri: str, code: str) -> Dict[str, Any]: ...
class FacebookGraphMixin(OAuth2Mixin):
async def get_authenticated_user(self, redirect_uri: str, client_id: str, client_secret: str, code: str, extra_fields: Optional[Dict[str, Any]]=...) -> Optional[Dict[str, Any]]: ...
async def facebook_request(self, path: str, access_token: Optional[str]=..., post_args: Optional[Dict[str, Any]]=..., **args: Any) -> Any: ...
async def get_authenticated_user(self, redirect_uri: str, client_id: str, client_secret: str, code: str, extra_fields: Dict[str, Any]=...) -> Optional[Dict[str, Any]]: ...
async def facebook_request(self, path: str, access_token: str=..., post_args: Dict[str, Any]=..., **args: Any) -> Any: ...

7
lib/tornado/autoreload.pyi

@ -1,7 +1,6 @@
# Stubs for tornado_py3.autoreload (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from tornado_py3 import ioloop as ioloop, process as process
from tornado_py3.log import gen_log as gen_log
from tornado_py3.util import exec_in as exec_in
from typing import Callable
def start(check_time: int=...) -> None: ...

5
lib/tornado/concurrent.pyi

@ -1,10 +1,7 @@
# Stubs for tornado_py3.concurrent (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import asyncio
import types
from concurrent import futures
from tornado_py3.log import app_log as app_log
from typing import Any, Callable, Optional, Tuple, Union
class ReturnValueIgnoredError(Exception): ...

13
lib/tornado/curl_httpclient.pyi

@ -1,14 +1,13 @@
# Stubs for tornado_py3.curl_httpclient (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from tornado_py3.httpclient import AsyncHTTPClient, HTTPError, HTTPRequest, HTTPResponse
from typing import Any, Callable, Dict, Optional
from tornado_py3 import httputil as httputil, ioloop as ioloop
from tornado_py3.escape import native_str as native_str, utf8 as utf8
from tornado_py3.httpclient import AsyncHTTPClient as AsyncHTTPClient, HTTPError as HTTPError, HTTPRequest as HTTPRequest, HTTPResponse as HTTPResponse, main as main
from tornado_py3.log import app_log as app_log
from typing import Any, Callable, Dict
curl_log: Any
class CurlAsyncHTTPClient(AsyncHTTPClient):
def initialize(self, max_clients: int=..., defaults: Optional[Dict[str, Any]]=...) -> None: ...
def initialize(self, max_clients: int=..., defaults: Dict[str, Any]=...) -> None: ...
def close(self) -> None: ...
def fetch_impl(self, request: HTTPRequest, callback: Callable[[HTTPResponse], None]) -> None: ...
def handle_callback_exception(self, callback: Any) -> None: ...

7
lib/tornado/escape.pyi

@ -1,7 +1,4 @@
# Stubs for tornado_py3.escape (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from tornado_py3.util import unicode_type as unicode_type
from typing import Any, Callable, Dict, List, Union
def xhtml_escape(value: Union[str, bytes]) -> str: ...
@ -11,7 +8,7 @@ def json_decode(value: Union[str, bytes]) -> Any: ...
def squeeze(value: str) -> str: ...
def url_escape(value: Union[str, bytes], plus: bool=...) -> str: ...
def url_unescape(value: Union[str, bytes], encoding: None, plus: bool=...) -> bytes: ...
def parse_qs_bytes(qs: Union[str, bytes], keep_blank_values: bool=..., strict_parsing: bool=...) -> Dict[str, List[bytes]]: ...
def parse_qs_bytes(qs: str, keep_blank_values: bool=..., strict_parsing: bool=...) -> Dict[str, List[bytes]]: ...
def utf8(value: bytes) -> bytes: ...
def to_unicode(value: str) -> str: ...
native_str = to_unicode

9
lib/tornado/gen.pyi

@ -1,12 +1,11 @@
# Stubs for tornado_py3.gen (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import datetime
import types
import typing
from collections.abc import Generator
from tornado_py3.concurrent import Future
from tornado_py3.concurrent import Future as Future, chain_future as chain_future, future_add_done_callback as future_add_done_callback, future_set_exc_info as future_set_exc_info, future_set_result_unless_cancelled as future_set_result_unless_cancelled, is_future as is_future
from tornado_py3.ioloop import IOLoop as IOLoop
from tornado_py3.log import app_log as app_log
from tornado_py3.util import TimeoutError as TimeoutError
from typing import Any, Callable, Dict, List, Tuple, Type, Union
class KeyReuseError(Exception): ...

19
lib/tornado/http1connection.pyi

@ -1,11 +1,10 @@
# Stubs for tornado_py3.http1connection (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import logging
import types
from tornado_py3 import httputil, iostream
from tornado_py3.concurrent import Future
from tornado_py3 import gen as gen, httputil as httputil, iostream as iostream
from tornado_py3.concurrent import Future as Future, future_add_done_callback as future_add_done_callback, future_set_result_unless_cancelled as future_set_result_unless_cancelled
from tornado_py3.escape import native_str as native_str, utf8 as utf8
from tornado_py3.log import app_log as app_log, gen_log as gen_log
from tornado_py3.util import GzipDecompressor as GzipDecompressor
from typing import Any, Awaitable, Callable, Optional, Type, Union
class _QuietException(Exception):
@ -25,7 +24,7 @@ class HTTP1ConnectionParameters:
max_body_size: Any = ...
body_timeout: Any = ...
decompress: Any = ...
def __init__(self, no_keep_alive: bool=..., chunk_size: Optional[int]=..., max_header_size: Optional[int]=..., header_timeout: Optional[float]=..., max_body_size: Optional[int]=..., body_timeout: Optional[float]=..., decompress: bool=...) -> None: ...
def __init__(self, no_keep_alive: bool=..., chunk_size: int=..., max_header_size: int=..., header_timeout: float=..., max_body_size: int=..., body_timeout: float=..., decompress: bool=...) -> None: ...
class HTTP1Connection(httputil.HTTPConnection):
is_client: Any = ...
@ -33,14 +32,14 @@ class HTTP1Connection(httputil.HTTPConnection):
params: Any = ...
context: Any = ...
no_keep_alive: Any = ...
def __init__(self, stream: iostream.IOStream, is_client: bool, params: Optional[HTTP1ConnectionParameters]=..., context: Optional[object]=...) -> None: ...
def __init__(self, stream: iostream.IOStream, is_client: bool, params: HTTP1ConnectionParameters=..., context: object=...) -> None: ...
def read_response(self, delegate: httputil.HTTPMessageDelegate) -> Awaitable[bool]: ...
def set_close_callback(self, callback: Optional[Callable[[], None]]) -> None: ...
def close(self) -> None: ...
def detach(self) -> iostream.IOStream: ...
def set_body_timeout(self, timeout: float) -> None: ...
def set_max_body_size(self, max_body_size: int) -> None: ...
def write_headers(self, start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine], headers: httputil.HTTPHeaders, chunk: Optional[bytes]=...) -> Future[None]: ...
def write_headers(self, start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine], headers: httputil.HTTPHeaders, chunk: bytes=...) -> Future[None]: ...
def write(self, chunk: bytes) -> Future[None]: ...
def finish(self) -> None: ...
@ -55,6 +54,6 @@ class HTTP1ServerConnection:
stream: Any = ...
params: Any = ...
context: Any = ...
def __init__(self, stream: iostream.IOStream, params: Optional[HTTP1ConnectionParameters]=..., context: Optional[object]=...) -> None: ...
def __init__(self, stream: iostream.IOStream, params: HTTP1ConnectionParameters=..., context: object=...) -> None: ...
async def close(self) -> None: ...
def start_serving(self, delegate: httputil.HTTPServerConnectionDelegate) -> None: ...

28
lib/tornado/httpclient.pyi

@ -1,17 +1,15 @@
# Stubs for tornado_py3.httpclient (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import datetime
import ssl
from io import BytesIO
from tornado_py3 import httputil
from tornado_py3.concurrent import Future
from tornado_py3.util import Configurable
from typing import Any, Callable, Dict, Optional, Type, Union
from tornado_py3 import gen as gen, httputil as httputil
from tornado_py3.concurrent import Future as Future, future_set_exception_unless_cancelled as future_set_exception_unless_cancelled, future_set_result_unless_cancelled as future_set_result_unless_cancelled
from tornado_py3.escape import native_str as native_str, utf8 as utf8
from tornado_py3.ioloop import IOLoop as IOLoop
from tornado_py3.util import Configurable as Configurable
from typing import Any, Awaitable, Callable, Dict, Optional, Type, Union
class HTTPClient:
def __init__(self, async_client_class: Optional[Type[AsyncHTTPClient]]=..., **kwargs: Any) -> None: ...
def __init__(self, async_client_class: Type[AsyncHTTPClient]=..., **kwargs: Any) -> None: ...
def __del__(self) -> None: ...
def close(self) -> None: ...
def fetch(self, request: Union[HTTPRequest, str], **kwargs: Any) -> HTTPResponse: ...
@ -24,15 +22,14 @@ class AsyncHTTPClient(Configurable):
def __new__(cls: Any, force_instance: bool=..., **kwargs: Any) -> AsyncHTTPClient: ...
io_loop: Any = ...
defaults: Any = ...
def initialize(self, defaults: Optional[Dict[str, Any]]=...) -> None: ...
def initialize(self, defaults: Dict[str, Any]=...) -> None: ...
def close(self) -> None: ...
def fetch(self, request: Union[str, HTTPRequest], raise_error: bool=..., **kwargs: Any) -> Future[HTTPResponse]: ...
def fetch(self, request: Union[str, HTTPRequest], raise_error: bool=..., **kwargs: Any) -> Awaitable[HTTPResponse]: ...
def fetch_impl(self, request: HTTPRequest, callback: Callable[[HTTPResponse], None]) -> None: ...
@classmethod
def configure(cls: Any, impl: Union[None, str, Type[Configurable]], **kwargs: Any) -> None: ...
class HTTPRequest:
headers: Any = ...
proxy_host: Any = ...
proxy_port: Any = ...
proxy_username: Any = ...
@ -40,7 +37,6 @@ class HTTPRequest:
proxy_auth_mode: Any = ...
url: Any = ...
method: Any = ...
body: Any = ...
body_producer: Any = ...
auth_username: Any = ...
auth_password: Any = ...
@ -64,7 +60,7 @@ class HTTPRequest:
ssl_options: Any = ...
expect_100_continue: Any = ...
start_time: Any = ...
def __init__(self, url: str, method: str=..., headers: Optional[Union[Dict[str, str], httputil.HTTPHeaders]]=..., body: Optional[Union[bytes, str]]=..., auth_username: Optional[str]=..., auth_password: Optional[str]=..., auth_mode: Optional[str]=..., connect_timeout: Optional[float]=..., request_timeout: Optional[float]=..., if_modified_since: Optional[Union[float, datetime.datetime]]=..., follow_redirects: Optional[bool]=..., max_redirects: Optional[int]=..., user_agent: Optional[str]=..., use_gzip: Optional[bool]=..., network_interface: Optional[str]=..., streaming_callback: Optional[Callable[[bytes], None]]=..., header_callback: Optional[Callable[[str], None]]=..., prepare_curl_callback: Optional[Callable[[Any], None]]=..., proxy_host: Optional[str]=..., proxy_port: Optional[int]=..., proxy_username: Optional[str]=..., proxy_password: Optional[str]=..., proxy_auth_mode: Optional[str]=..., allow_nonstandard_methods: Optional[bool]=..., validate_cert: Optional[bool]=..., ca_certs: Optional[str]=..., allow_ipv6: Optional[bool]=..., client_key: Optional[str]=..., client_cert: Optional[str]=..., body_producer: Optional[Callable[[Callable[[bytes], None]], Future[None]]]=..., expect_100_continue: bool=..., decompress_response: Optional[bool]=..., ssl_options: Optional[Union[Dict[str, Any], ssl.SSLContext]]=...) -> None: ...
def __init__(self, url: str, method: str=..., headers: Union[Dict[str, str], httputil.HTTPHeaders]=..., body: Union[bytes, str]=..., auth_username: str=..., auth_password: str=..., auth_mode: str=..., connect_timeout: float=..., request_timeout: float=..., if_modified_since: Union[float, datetime.datetime]=..., follow_redirects: bool=..., max_redirects: int=..., user_agent: str=..., use_gzip: bool=..., network_interface: str=..., streaming_callback: Callable[[bytes], None]=..., header_callback: Callable[[str], None]=..., prepare_curl_callback: Callable[[Any], None]=..., proxy_host: str=..., proxy_port: int=..., proxy_username: str=..., proxy_password: str=..., proxy_auth_mode: str=..., allow_nonstandard_methods: bool=..., validate_cert: bool=..., ca_certs: str=..., allow_ipv6: bool=..., client_key: str=..., client_cert: str=..., body_producer: Callable[[Callable[[bytes], None]], Future[None]]=..., expect_100_continue: bool=..., decompress_response: bool=..., ssl_options: Union[Dict[str, Any], ssl.SSLContext]=...) -> None: ...
@property
def headers(self) -> httputil.HTTPHeaders: ...
@headers.setter
@ -85,7 +81,7 @@ class HTTPResponse:
start_time: Any = ...
request_time: Any = ...
time_info: Any = ...
def __init__(self, request: HTTPRequest, code: int, headers: Optional[httputil.HTTPHeaders]=..., buffer: Optional[BytesIO]=..., effective_url: Optional[str]=..., error: Optional[BaseException]=..., request_time: Optional[float]=..., time_info: Optional[Dict[str, float]]=..., reason: Optional[str]=..., start_time: Optional[float]=...) -> None: ...
def __init__(self, request: HTTPRequest, code: int, headers: httputil.HTTPHeaders=..., buffer: BytesIO=..., effective_url: str=..., error: BaseException=..., request_time: float=..., time_info: Dict[str, float]=..., reason: str=..., start_time: float=...) -> None: ...
@property
def body(self) -> bytes: ...
def rethrow(self) -> None: ...
@ -94,7 +90,7 @@ class HTTPClientError(Exception):
code: Any = ...
message: Any = ...
response: Any = ...
def __init__(self, code: int, message: Optional[str]=..., response: Optional[HTTPResponse]=...) -> None: ...
def __init__(self, code: int, message: str=..., response: HTTPResponse=...) -> None: ...
HTTPError = HTTPClientError
class _RequestProxy:

16
lib/tornado/httpserver.pyi

@ -1,11 +1,9 @@
# Stubs for tornado_py3.httpserver (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import ssl
from tornado_py3 import httputil, iostream
from tornado_py3.tcpserver import TCPServer
from tornado_py3.util import Configurable
from tornado_py3 import httputil as httputil, iostream as iostream, netutil as netutil
from tornado_py3.escape import native_str as native_str
from tornado_py3.http1connection import HTTP1ConnectionParameters as HTTP1ConnectionParameters, HTTP1ServerConnection as HTTP1ServerConnection
from tornado_py3.tcpserver import TCPServer as TCPServer
from tornado_py3.util import Configurable as Configurable
from typing import Any, Awaitable, Callable, Dict, List, Optional, Tuple, Type, Union
class HTTPServer(TCPServer, Configurable, httputil.HTTPServerConnectionDelegate):
@ -15,7 +13,7 @@ class HTTPServer(TCPServer, Configurable, httputil.HTTPServerConnectionDelegate)
protocol: Any = ...
conn_params: Any = ...
trusted_downstream: Any = ...
def initialize(self, request_callback: Union[httputil.HTTPServerConnectionDelegate, Callable[[httputil.HTTPServerRequest], None]], no_keep_alive: bool=..., xheaders: bool=..., ssl_options: Optional[Union[Dict[str, Any], ssl.SSLContext]]=..., protocol: Optional[str]=..., decompress_request: bool=..., chunk_size: Optional[int]=..., max_header_size: Optional[int]=..., idle_connection_timeout: Optional[float]=..., body_timeout: Optional[float]=..., max_body_size: Optional[int]=..., max_buffer_size: Optional[int]=..., trusted_downstream: Optional[List[str]]=...) -> None: ...
def initialize(self, request_callback: Union[httputil.HTTPServerConnectionDelegate, Callable[[httputil.HTTPServerRequest], None]], no_keep_alive: bool=..., xheaders: bool=..., ssl_options: Union[Dict[str, Any], ssl.SSLContext]=..., protocol: str=..., decompress_request: bool=..., chunk_size: int=..., max_header_size: int=..., idle_connection_timeout: float=..., body_timeout: float=..., max_body_size: int=..., max_buffer_size: int=..., trusted_downstream: List[str]=...) -> None: ...
@classmethod
def configurable_base(cls: Any) -> Type[Configurable]: ...
@classmethod
@ -42,7 +40,7 @@ class _HTTPRequestContext:
remote_ip: Any = ...
protocol: Any = ...
trusted_downstream: Any = ...
def __init__(self, stream: iostream.IOStream, address: Tuple, protocol: Optional[str], trusted_downstream: Optional[List[str]]=...) -> None: ...
def __init__(self, stream: iostream.IOStream, address: Tuple, protocol: Optional[str], trusted_downstream: List[str]=...) -> None: ...
class _ProxyAdapter(httputil.HTTPMessageDelegate):
connection: Any = ...

20
lib/tornado/httputil.pyi

@ -1,7 +1,3 @@
# Stubs for tornado_py3.httputil (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import collections
import datetime
import http.cookies
@ -10,9 +6,17 @@ import typing
import unittest
from asyncio import Future
from collections import namedtuple
from tornado_py3.util import ObjectDict
from tornado_py3.escape import native_str as native_str, parse_qs_bytes as parse_qs_bytes, utf8 as utf8
from tornado_py3.log import gen_log as gen_log
from tornado_py3.util import ObjectDict as ObjectDict, unicode_type as unicode_type
from typing import Any, AnyStr, Awaitable, Dict, Iterable, Iterator, List, Mapping, Optional, Tuple, Union
class _NormalizedHeaderCache(dict):
size: Any = ...
queue: Any = ...
def __init__(self, size: int) -> None: ...
def __missing__(self, key: str) -> str: ...
class HTTPHeaders(collections.abc.MutableMapping):
def __init__(self, __arg: Mapping[str, List[str]]) -> None: ...
def __init__(self, __arg: Mapping[str, str]) -> None: ...
@ -52,7 +56,7 @@ class HTTPServerRequest:
arguments: Any = ...
query_arguments: Any = ...
body_arguments: Any = ...
def __init__(self, method: Optional[str]=..., uri: Optional[str]=..., version: str=..., headers: Optional[HTTPHeaders]=..., body: Optional[bytes]=..., host: Optional[str]=..., files: Optional[Dict[str, List[HTTPFile]]]=..., connection: Optional[HTTPConnection]=..., start_line: Optional[RequestStartLine]=..., server_connection: Optional[object]=...) -> None: ...
def __init__(self, method: str=..., uri: str=..., version: str=..., headers: HTTPHeaders=..., body: bytes=..., host: str=..., files: Dict[str, List[HTTPFile]]=..., connection: HTTPConnection=..., start_line: RequestStartLine=..., server_connection: object=...) -> None: ...
@property
def cookies(self) -> Dict[str, http.cookies.Morsel]: ...
def full_url(self) -> str: ...
@ -73,7 +77,7 @@ class HTTPMessageDelegate:
def on_connection_close(self) -> None: ...
class HTTPConnection:
def write_headers(self, start_line: Union[RequestStartLine, ResponseStartLine], headers: HTTPHeaders, chunk: Optional[bytes]=...) -> Future[None]: ...
def write_headers(self, start_line: Union[RequestStartLine, ResponseStartLine], headers: HTTPHeaders, chunk: bytes=...) -> Future[None]: ...
def write(self, chunk: bytes) -> Future[None]: ...
def finish(self) -> None: ...
@ -81,7 +85,7 @@ def url_concat(url: str, args: Union[None, Dict[str, str], List[Tuple[str, str]]
class HTTPFile(ObjectDict): ...
def parse_body_arguments(content_type: str, body: bytes, arguments: Dict[str, List[bytes]], files: Dict[str, List[HTTPFile]], headers: Optional[HTTPHeaders]=...) -> None: ...
def parse_body_arguments(content_type: str, body: bytes, arguments: Dict[str, List[bytes]], files: Dict[str, List[HTTPFile]], headers: HTTPHeaders=...) -> None: ...
def parse_multipart_form_data(boundary: bytes, data: bytes, arguments: Dict[str, List[bytes]], files: Dict[str, List[HTTPFile]]) -> None: ...
def format_timestamp(ts: Union[int, float, tuple, time.struct_time, datetime.datetime]) -> str: ...

16
lib/tornado/ioloop.pyi

@ -1,14 +1,10 @@
# Stubs for tornado_py3.ioloop (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import concurrent.futures
import datetime
from tornado_py3.concurrent import Future
from tornado_py3.util import Configurable
from tornado_py3.concurrent import Future as Future, chain_future as chain_future, future_add_done_callback as future_add_done_callback, future_set_exc_info as future_set_exc_info, is_future as is_future
from tornado_py3.log import app_log as app_log
from tornado_py3.util import Configurable as Configurable, TimeoutError as TimeoutError, import_object as import_object
from typing import Any, Awaitable, Callable, Optional, Tuple, Type, Union
Protocol = object
from typing_extensions import Protocol as Protocol
class _Selectable:
def fileno(self) -> int: ...
@ -39,7 +35,7 @@ class IOLoop(Configurable):
def configurable_base(cls: Any) -> Type[Configurable]: ...
@classmethod
def configurable_default(cls: Any) -> Type[Configurable]: ...
def initialize(self, make_current: Optional[bool]=...) -> None: ...
def initialize(self, make_current: bool=...) -> None: ...
def close(self, all_fds: bool=...) -> None: ...
def add_handler(self, fd: int, handler: Callable[[int, int], None], events: int) -> None: ...
def add_handler(self, fd: _S, handler: Callable[[_S, int], None], events: int) -> None: ...
@ -48,7 +44,7 @@ class IOLoop(Configurable):
def remove_handler(self, fd: Union[int, _Selectable]) -> None: ...
def start(self) -> None: ...
def stop(self) -> None: ...
def run_sync(self, func: Callable, timeout: Optional[float]=...) -> Any: ...
def run_sync(self, func: Callable, timeout: float=...) -> Any: ...
def time(self) -> float: ...
def add_timeout(self, deadline: Union[float, datetime.timedelta], callback: Callable[..., None], *args: Any, **kwargs: Any) -> object: ...
def call_later(self, delay: float, callback: Callable[..., None], *args: Any, **kwargs: Any) -> object: ...

25
lib/tornado/iostream.pyi

@ -1,17 +1,16 @@
# Stubs for tornado_py3.iostream (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import socket
import ssl
from tornado_py3 import ioloop
from tornado_py3.concurrent import Future
from tornado_py3 import ioloop as ioloop
from tornado_py3.concurrent import Future as Future, future_set_result_unless_cancelled as future_set_result_unless_cancelled
from tornado_py3.log import gen_log as gen_log
from tornado_py3.netutil import ssl_wrap_socket as ssl_wrap_socket
from tornado_py3.util import errno_from_exception as errno_from_exception
from types import TracebackType
from typing import Any, Awaitable, Callable, Dict, Optional, Tuple, Type, Union
class StreamClosedError(IOError):
real_error: Any = ...
def __init__(self, real_error: Optional[BaseException]=...) -> None: ...
def __init__(self, real_error: BaseException=...) -> None: ...
class UnsatisfiableReadError(Exception): ...
class StreamBufferFullError(Exception): ...
@ -29,14 +28,14 @@ class BaseIOStream:
read_chunk_size: Any = ...
max_write_buffer_size: Any = ...
error: Any = ...
def __init__(self, max_buffer_size: Optional[int]=..., read_chunk_size: Optional[int]=..., max_write_buffer_size: Optional[int]=...) -> None: ...
def __init__(self, max_buffer_size: int=..., read_chunk_size: int=..., max_write_buffer_size: int=...) -> None: ...
def fileno(self) -> Union[int, ioloop._Selectable]: ...
def close_fd(self) -> None: ...
def write_to_fd(self, data: memoryview) -> int: ...
def read_from_fd(self, buf: Union[bytearray, memoryview]) -> Optional[int]: ...
def get_fd_error(self) -> Optional[Exception]: ...
def read_until_regex(self, regex: bytes, max_bytes: Optional[int]=...) -> Awaitable[bytes]: ...
def read_until(self, delimiter: bytes, max_bytes: Optional[int]=...) -> Awaitable[bytes]: ...
def read_until_regex(self, regex: bytes, max_bytes: int=...) -> Awaitable[bytes]: ...
def read_until(self, delimiter: bytes, max_bytes: int=...) -> Awaitable[bytes]: ...
def read_bytes(self, num_bytes: int, partial: bool=...) -> Awaitable[bytes]: ...
def read_into(self, buf: bytearray, partial: bool=...) -> Awaitable[int]: ...
def read_until_close(self) -> Awaitable[bytes]: ...
@ -56,8 +55,8 @@ class IOStream(BaseIOStream):
def get_fd_error(self) -> Optional[Exception]: ...
def read_from_fd(self, buf: Union[bytearray, memoryview]) -> Optional[int]: ...
def write_to_fd(self, data: memoryview) -> int: ...
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 connect(self, address: tuple, server_hostname: str=...) -> Future[_IOStreamType]: ...
def start_tls(self, server_side: bool, ssl_options: Union[Dict[str, Any], ssl.SSLContext]=..., server_hostname: str=...) -> Awaitable[SSLIOStream]: ...
def set_nodelay(self, value: bool) -> None: ...
class SSLIOStream(IOStream):
@ -65,7 +64,7 @@ class SSLIOStream(IOStream):
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def reading(self) -> bool: ...
def writing(self) -> bool: ...
def connect(self, address: Tuple, server_hostname: Optional[str]=...) -> Future[SSLIOStream]: ...
def connect(self, address: Tuple, server_hostname: str=...) -> Future[SSLIOStream]: ...
def wait_for_handshake(self) -> Future[SSLIOStream]: ...
def write_to_fd(self, data: memoryview) -> int: ...
def read_from_fd(self, buf: Union[bytearray, memoryview]) -> Optional[int]: ...

23
lib/tornado/locale.pyi

@ -1,16 +1,15 @@
# Stubs for tornado_py3.locale (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import datetime
import gettext
from typing import Any, Dict, Iterable, Optional, Union
from tornado_py3 import escape as escape
from tornado_py3._locale_data import LOCALE_NAMES as LOCALE_NAMES
from tornado_py3.log import gen_log as gen_log
from typing import Any, Dict, Iterable, Union
CONTEXT_SEPARATOR: str
def get(*locale_codes: str) -> Locale: ...
def set_default_locale(code: str) -> None: ...
def load_translations(directory: str, encoding: Optional[str]=...) -> None: ...
def load_translations(directory: str, encoding: str=...) -> None: ...
def load_gettext_translations(directory: str, domain: str) -> None: ...
def get_supported_locales() -> Iterable[str]: ...
@ -23,8 +22,8 @@ class Locale:
name: Any = ...
rtl: bool = ...
def __init__(self, code: str) -> None: ...
def translate(self, message: str, plural_message: Optional[str]=..., count: Optional[int]=...) -> str: ...
def pgettext(self, context: str, message: str, plural_message: Optional[str]=..., count: Optional[int]=...) -> str: ...
def translate(self, message: str, plural_message: str=..., count: int=...) -> str: ...
def pgettext(self, context: str, message: str, plural_message: str=..., count: int=...) -> str: ...
def format_date(self, date: Union[int, float, datetime.datetime], gmt_offset: int=..., relative: bool=..., shorter: bool=..., full_format: bool=...) -> str: ...
def format_day(self, date: datetime.datetime, gmt_offset: int=..., dow: bool=...) -> bool: ...
def list(self, parts: Any) -> str: ...
@ -33,12 +32,12 @@ class Locale:
class CSVLocale(Locale):
translations: Any = ...
def __init__(self, code: str, translations: Dict[str, Dict[str, str]]) -> None: ...
def translate(self, message: str, plural_message: Optional[str]=..., count: Optional[int]=...) -> str: ...
def pgettext(self, context: str, message: str, plural_message: Optional[str]=..., count: Optional[int]=...) -> str: ...
def translate(self, message: str, plural_message: str=..., count: int=...) -> str: ...
def pgettext(self, context: str, message: str, plural_message: str=..., count: int=...) -> str: ...
class GettextLocale(Locale):
ngettext: Any = ...
gettext: Any = ...
def __init__(self, code: str, translations: gettext.NullTranslations) -> None: ...
def translate(self, message: str, plural_message: Optional[str]=..., count: Optional[int]=...) -> str: ...
def pgettext(self, context: str, message: str, plural_message: Optional[str]=..., count: Optional[int]=...) -> str: ...
def translate(self, message: str, plural_message: str=..., count: int=...) -> str: ...
def pgettext(self, context: str, message: str, plural_message: str=..., count: int=...) -> str: ...

12
lib/tornado/locks.pyi

@ -1,7 +1,3 @@
# Stubs for tornado_py3.locks (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import datetime
import types
from typing import Any, Awaitable, Optional, Type, Union
@ -12,7 +8,7 @@ class _TimeoutGarbageCollector:
class Condition(_TimeoutGarbageCollector):
io_loop: Any = ...
def __init__(self) -> None: ...
def wait(self, timeout: Optional[Union[float, datetime.timedelta]]=...) -> Awaitable[bool]: ...
def wait(self, timeout: Union[float, datetime.timedelta]=...) -> Awaitable[bool]: ...
def notify(self, n: int=...) -> None: ...
def notify_all(self) -> None: ...
@ -21,7 +17,7 @@ class Event:
def is_set(self) -> bool: ...
def set(self) -> None: ...
def clear(self) -> None: ...
def wait(self, timeout: Optional[Union[float, datetime.timedelta]]=...) -> Awaitable[None]: ...
def wait(self, timeout: Union[float, datetime.timedelta]=...) -> Awaitable[None]: ...
class _ReleasingContextManager:
def __init__(self, obj: Any) -> None: ...
@ -31,7 +27,7 @@ class _ReleasingContextManager:
class Semaphore(_TimeoutGarbageCollector):
def __init__(self, value: int=...) -> None: ...
def release(self) -> None: ...
def acquire(self, timeout: Optional[Union[float, datetime.timedelta]]=...) -> Awaitable[_ReleasingContextManager]: ...
def acquire(self, timeout: Union[float, datetime.timedelta]=...) -> Awaitable[_ReleasingContextManager]: ...
def __enter__(self) -> None: ...
def __exit__(self, typ: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[types.TracebackType]) -> None: ...
async def __aenter__(self) -> None: ...
@ -43,7 +39,7 @@ class BoundedSemaphore(Semaphore):
class Lock:
def __init__(self) -> None: ...
def acquire(self, timeout: Optional[Union[float, datetime.timedelta]]=...) -> Awaitable[_ReleasingContextManager]: ...
def acquire(self, timeout: Union[float, datetime.timedelta]=...) -> Awaitable[_ReleasingContextManager]: ...
def release(self) -> None: ...
def __enter__(self) -> None: ...
def __exit__(self, typ: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[types.TracebackType]) -> None: ...

9
lib/tornado/log.pyi

@ -1,9 +1,6 @@
# Stubs for tornado_py3.log (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import logging.handlers
from typing import Any, Dict, Optional
from tornado_py3.util import basestring_type as basestring_type, unicode_type as unicode_type
from typing import Any, Dict
access_log: Any
app_log: Any
@ -16,5 +13,5 @@ class LogFormatter(logging.Formatter):
def __init__(self, fmt: str=..., datefmt: str=..., style: str=..., color: bool=..., colors: Dict[int, int]=...) -> None: ...
def format(self, record: Any) -> str: ...
def enable_pretty_logging(options: Any=..., logger: Optional[logging.Logger]=...) -> None: ...
def enable_pretty_logging(options: Any=..., logger: logging.Logger=...) -> None: ...
def define_logging_options(options: Any=...) -> None: ...

17
lib/tornado/netutil.pyi

@ -1,14 +1,13 @@
# Stubs for tornado_py3.netutil (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import concurrent.futures
import socket
import ssl
from tornado_py3.util import Configurable
from typing import Any, Awaitable, Callable, Dict, List, Optional, Tuple, Type, Union
from tornado_py3.concurrent import dummy_executor as dummy_executor, run_on_executor as run_on_executor
from tornado_py3.ioloop import IOLoop as IOLoop
from tornado_py3.platform.auto import set_close_exec as set_close_exec
from tornado_py3.util import Configurable as Configurable, errno_from_exception as errno_from_exception
from typing import Any, Awaitable, Callable, Dict, List, Tuple, Type, Union
def bind_sockets(port: int, address: Optional[str]=..., family: socket.AddressFamily=..., backlog: int=..., flags: Optional[int]=..., reuse_port: bool=...) -> List[socket.socket]: ...
def bind_sockets(port: int, address: str=..., family: socket.AddressFamily=..., backlog: int=..., flags: int=..., reuse_port: bool=...) -> List[socket.socket]: ...
def bind_unix_socket(file: str, mode: int=..., backlog: int=...) -> socket.socket: ...
def add_accept_handler(sock: socket.socket, callback: Callable[[socket.socket, Any], None]) -> Callable[[], None]: ...
def is_valid_ip(ip: str) -> bool: ...
@ -28,7 +27,7 @@ class ExecutorResolver(Resolver):
io_loop: Any = ...
executor: Any = ...
close_executor: Any = ...
def initialize(self, executor: Optional[concurrent.futures.Executor]=..., close_executor: bool=...) -> None: ...
def initialize(self, executor: concurrent.futures.Executor=..., close_executor: bool=...) -> None: ...
def close(self) -> None: ...
def resolve(self, host: str, port: int, family: socket.AddressFamily=...) -> List[Tuple[int, Any]]: ...
@ -46,4 +45,4 @@ class OverrideResolver(Resolver):
def resolve(self, host: str, port: int, family: socket.AddressFamily=...) -> Awaitable[List[Tuple[int, Any]]]: ...
def ssl_options_to_context(ssl_options: Union[Dict[str, Any], ssl.SSLContext]) -> ssl.SSLContext: ...
def ssl_wrap_socket(socket: socket.socket, ssl_options: Union[Dict[str, Any], ssl.SSLContext], server_hostname: Optional[str]=..., **kwargs: Any) -> ssl.SSLSocket: ...
def ssl_wrap_socket(socket: socket.socket, ssl_options: Union[Dict[str, Any], ssl.SSLContext], server_hostname: str=..., **kwargs: Any) -> ssl.SSLSocket: ...

23
lib/tornado/options.pyi

@ -1,8 +1,7 @@
# Stubs for tornado_py3.options (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Set, TextIO, Tuple
from tornado_py3.escape import native_str as native_str
from tornado_py3.log import define_logging_options as define_logging_options
from tornado_py3.util import basestring_type as basestring_type, exec_in as exec_in
from typing import Any, Callable, Dict, Iterable, Iterator, List, Set, TextIO, Tuple
class Error(Exception): ...
@ -18,10 +17,10 @@ class OptionParser:
def groups(self) -> Set[str]: ...
def group_dict(self, group: str) -> Dict[str, Any]: ...
def as_dict(self) -> Dict[str, Any]: ...
def define(self, name: str, default: Any=..., type: Optional[type]=..., help: Optional[str]=..., metavar: Optional[str]=..., multiple: bool=..., group: Optional[str]=..., callback: Optional[Callable[[Any], None]]=...) -> None: ...
def parse_command_line(self, args: Optional[List[str]]=..., final: bool=...) -> List[str]: ...
def define(self, name: str, default: Any=..., type: type=..., help: str=..., metavar: str=..., multiple: bool=..., group: str=..., callback: Callable[[Any], None]=...) -> None: ...
def parse_command_line(self, args: List[str]=..., final: bool=...) -> List[str]: ...
def parse_config_file(self, path: str, final: bool=...) -> None: ...
def print_help(self, file: Optional[TextIO]=...) -> None: ...
def print_help(self, file: TextIO=...) -> None: ...
def add_parse_callback(self, callback: Callable[[], None]) -> None: ...
def run_parse_callbacks(self) -> None: ...
def mockable(self) -> _Mockable: ...
@ -43,15 +42,15 @@ class _Option:
group_name: Any = ...
callback: Any = ...
default: Any = ...
def __init__(self, name: str, default: Any=..., type: Optional[type]=..., help: Optional[str]=..., metavar: Optional[str]=..., multiple: bool=..., file_name: Optional[str]=..., group_name: Optional[str]=..., callback: Optional[Callable[[Any], None]]=...) -> None: ...
def __init__(self, name: str, default: Any=..., type: type=..., help: str=..., metavar: str=..., multiple: bool=..., file_name: str=..., group_name: str=..., callback: Callable[[Any], None]=...) -> None: ...
def value(self) -> Any: ...
def parse(self, value: str) -> Any: ...
def set(self, value: Any) -> None: ...
options: Any
def define(name: str, default: Any=..., type: Optional[type]=..., help: Optional[str]=..., metavar: Optional[str]=..., multiple: bool=..., group: Optional[str]=..., callback: Optional[Callable[[Any], None]]=...) -> None: ...
def parse_command_line(args: Optional[List[str]]=..., final: bool=...) -> List[str]: ...
def define(name: str, default: Any=..., type: type=..., help: str=..., metavar: str=..., multiple: bool=..., group: str=..., callback: Callable[[Any], None]=...) -> None: ...
def parse_command_line(args: List[str]=..., final: bool=...) -> List[str]: ...
def parse_config_file(path: str, final: bool=...) -> None: ...
def print_help(file: Optional[TextIO]=...) -> None: ...
def print_help(file: TextIO=...) -> None: ...
def add_parse_callback(callback: Callable[[], None]) -> None: ...

4
lib/tornado/platform/__init__.pyi

@ -1,4 +0,0 @@
# Stubs for tornado_py3.platform (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.

9
lib/tornado/platform/asyncio.pyi

@ -1,10 +1,7 @@
# Stubs for tornado_py3.platform.asyncio (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import asyncio
import concurrent.futures
from tornado_py3.ioloop import IOLoop, _Selectable
from tornado_py3.gen import convert_yielded as convert_yielded
from tornado_py3.ioloop import IOLoop as IOLoop, _Selectable
from typing import Any, Awaitable, Callable, Optional, Union
class BaseAsyncIOLoop(IOLoop):
@ -41,5 +38,5 @@ class AsyncIOLoop(BaseAsyncIOLoop):
def to_tornado_future(asyncio_future: asyncio.Future) -> asyncio.Future: ...
def to_asyncio_future(tornado_future: asyncio.Future) -> asyncio.Future: ...
class AnyThreadEventLoopPolicy(asyncio.DefaultEventLoopPolicy):
class AnyThreadEventLoopPolicy(_BasePolicy):
def get_event_loop(self) -> asyncio.AbstractEventLoop: ...

4
lib/tornado/platform/auto.pyi

@ -1,5 +1 @@
# Stubs for tornado_py3.platform.auto (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from .interface import *

9
lib/tornado/platform/caresresolver.pyi

@ -1,8 +1,7 @@
# Stubs for tornado_py3.platform.caresresolver (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from tornado_py3.netutil import Resolver
from tornado_py3 import gen as gen
from tornado_py3.concurrent import Future as Future
from tornado_py3.ioloop import IOLoop as IOLoop
from tornado_py3.netutil import Resolver as Resolver, is_valid_ip as is_valid_ip
from typing import Any, Generator, List, Tuple
class CaresResolver(Resolver):

4
lib/tornado/platform/interface.pyi

@ -1,5 +1 @@
# Stubs for tornado_py3.platform.interface (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
def set_close_exec(fd: int) -> None: ...

4
lib/tornado/platform/posix.pyi

@ -1,5 +1 @@
# Stubs for tornado_py3.platform.posix (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
def set_close_exec(fd: int) -> None: ...

11
lib/tornado/platform/twisted.pyi

@ -1,8 +1,7 @@
# Stubs for tornado_py3.platform.twisted (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from tornado_py3.netutil import Resolver
from tornado_py3 import gen as gen
from tornado_py3.concurrent import Future as Future, future_set_exc_info as future_set_exc_info
from tornado_py3.escape import utf8 as utf8
from tornado_py3.netutil import Resolver as Resolver
from typing import Any, Generator, List, Tuple
class TwistedResolver(Resolver):
@ -10,5 +9,3 @@ class TwistedResolver(Resolver):
resolver: Any = ...
def initialize(self) -> None: ...
def resolve(self, host: str, port: int, family: int=...) -> Generator[Any, Any, List[Tuple[int, Any]]]: ...
def install() -> None: ...

4
lib/tornado/platform/windows.pyi

@ -1,7 +1,3 @@
# Stubs for tornado_py3.platform.windows (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from typing import Any
SetHandleInformation: Any

13
lib/tornado/process.pyi

@ -1,15 +1,16 @@
# Stubs for tornado_py3.process (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import subprocess
from tornado_py3.concurrent import Future
from tornado_py3 import ioloop as ioloop
from tornado_py3.concurrent import Future as Future, future_set_exception_unless_cancelled as future_set_exception_unless_cancelled, future_set_result_unless_cancelled as future_set_result_unless_cancelled
from tornado_py3.iostream import PipeIOStream as PipeIOStream
from tornado_py3.log import gen_log as gen_log
from tornado_py3.platform.auto import set_close_exec as set_close_exec
from tornado_py3.util import errno_from_exception as errno_from_exception
from typing import Any, Callable, Optional
CalledProcessError = subprocess.CalledProcessError
def cpu_count() -> int: ...
def fork_processes(num_processes: Optional[int], max_restarts: Optional[int]=...) -> int: ...
def fork_processes(num_processes: Optional[int], max_restarts: int=...) -> int: ...
def task_id() -> Optional[int]: ...
class Subprocess:

12
lib/tornado/queues.pyi

@ -1,10 +1,6 @@
# Stubs for tornado_py3.queues (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import datetime
from tornado_py3.concurrent import Future
from typing import Any, Awaitable, Optional, Union
from typing import Any, Awaitable, Union
class QueueEmpty(Exception): ...
class QueueFull(Exception): ...
@ -21,12 +17,12 @@ class Queue:
def qsize(self) -> int: ...
def empty(self) -> bool: ...
def full(self) -> bool: ...
def put(self, item: _T, timeout: Optional[Union[float, datetime.timedelta]]=...) -> Future[None]: ...
def put(self, item: _T, timeout: Union[float, datetime.timedelta]=...) -> Future[None]: ...
def put_nowait(self, item: _T) -> None: ...
def get(self, timeout: Optional[Union[float, datetime.timedelta]]=...) -> Awaitable[_T]: ...
def get(self, timeout: Union[float, datetime.timedelta]=...) -> Awaitable[_T]: ...
def get_nowait(self) -> _T: ...
def task_done(self) -> None: ...
def join(self, timeout: Optional[Union[float, datetime.timedelta]]=...) -> Awaitable[None]: ...
def join(self, timeout: Union[float, datetime.timedelta]=...) -> Awaitable[None]: ...
def __aiter__(self) -> _QueueIterator[_T]: ...
class PriorityQueue(Queue): ...

17
lib/tornado/routing.pyi

@ -1,8 +1,7 @@
# Stubs for tornado_py3.routing (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from tornado_py3 import httputil
from tornado_py3 import httputil as httputil
from tornado_py3.escape import url_escape as url_escape, url_unescape as url_unescape, utf8 as utf8
from tornado_py3.log import app_log as app_log
from tornado_py3.util import basestring_type as basestring_type, import_object as import_object, re_unescape as re_unescape, unicode_type as unicode_type
from typing import Any, Awaitable, Dict, Optional, Pattern, Union
class Router(httputil.HTTPServerConnectionDelegate):
@ -30,7 +29,7 @@ class _DefaultMessageDelegate(httputil.HTTPMessageDelegate):
class RuleRouter(Router):
rules: Any = ...
def __init__(self, rules: Optional[_RuleList]=...) -> None: ...
def __init__(self, rules: _RuleList=...) -> None: ...
def add_rules(self, rules: _RuleList) -> None: ...
def process_rule(self, rule: Rule) -> Rule: ...
def find_handler(self, request: httputil.HTTPServerRequest, **kwargs: Any) -> Optional[httputil.HTTPMessageDelegate]: ...
@ -38,7 +37,7 @@ class RuleRouter(Router):
class ReversibleRuleRouter(ReversibleRouter, RuleRouter):
named_rules: Any = ...
def __init__(self, rules: Optional[_RuleList]=...) -> None: ...
def __init__(self, rules: _RuleList=...) -> None: ...
def process_rule(self, rule: Rule) -> Rule: ...
def reverse_url(self, name: str, *args: Any) -> Optional[str]: ...
@ -47,7 +46,7 @@ class Rule:
target: Any = ...
target_kwargs: Any = ...
name: Any = ...
def __init__(self, matcher: Matcher, target: Any, target_kwargs: Optional[Dict[str, Any]]=..., name: Optional[str]=...) -> None: ...
def __init__(self, matcher: Matcher, target: Any, target_kwargs: Dict[str, Any]=..., name: str=...) -> None: ...
def reverse(self, *args: Any) -> Optional[str]: ...
class Matcher:
@ -78,4 +77,4 @@ class URLSpec(Rule):
regex: Any = ...
handler_class: Any = ...
kwargs: Any = ...
def __init__(self, pattern: Union[str, Pattern], handler: Any, kwargs: Optional[Dict[str, Any]]=..., name: Optional[str]=...) -> None: ...
def __init__(self, pattern: Union[str, Pattern], handler: Any, kwargs: Dict[str, Any]=..., name: str=...) -> None: ...

18
lib/tornado/simple_httpclient.pyi

@ -1,11 +1,11 @@
# Stubs for tornado_py3.simple_httpclient (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from tornado_py3 import httputil
from tornado_py3.httpclient import AsyncHTTPClient, HTTPError, HTTPRequest, HTTPResponse
from tornado_py3.netutil import Resolver
from tornado_py3.tcpclient import TCPClient
from tornado_py3 import gen as gen, httputil as httputil
from tornado_py3.http1connection import HTTP1Connection as HTTP1Connection, HTTP1ConnectionParameters as HTTP1ConnectionParameters
from tornado_py3.httpclient import AsyncHTTPClient as AsyncHTTPClient, HTTPError as HTTPError, HTTPRequest as HTTPRequest, HTTPResponse as HTTPResponse, main as main
from tornado_py3.ioloop import IOLoop as IOLoop
from tornado_py3.iostream import IOStream as IOStream, StreamClosedError as StreamClosedError
from tornado_py3.log import gen_log as gen_log
from tornado_py3.netutil import OverrideResolver as OverrideResolver, Resolver as Resolver, is_valid_ip as is_valid_ip
from tornado_py3.tcpclient import TCPClient as TCPClient
from typing import Any, Callable, Dict, Optional, Union
class HTTPTimeoutError(HTTPError):
@ -25,7 +25,7 @@ class SimpleAsyncHTTPClient(AsyncHTTPClient):
resolver: Any = ...
own_resolver: bool = ...
tcp_client: Any = ...
def initialize(self, max_clients: int=..., hostname_mapping: Optional[Dict[str, str]]=..., max_buffer_size: int=..., resolver: Optional[Resolver]=..., defaults: Optional[Dict[str, Any]]=..., max_header_size: Optional[int]=..., max_body_size: Optional[int]=...) -> None: ...
def initialize(self, max_clients: int=..., hostname_mapping: Dict[str, str]=..., max_buffer_size: int=..., resolver: Resolver=..., defaults: Dict[str, Any]=..., max_header_size: int=..., max_body_size: int=...) -> None: ...
def close(self) -> None: ...
def fetch_impl(self, request: HTTPRequest, callback: Callable[[HTTPResponse], None]) -> None: ...

4
lib/tornado/speedups.pyi

@ -1,5 +1 @@
# Stubs for tornado_py3.speedups (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
def websocket_mask(mask: bytes, data: bytes) -> bytes: ...

22
lib/tornado/tcpclient.pyi

@ -1,14 +1,14 @@
# Stubs for tornado_py3.tcpclient (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import datetime
import socket
import ssl
from tornado_py3.concurrent import Future
from tornado_py3.iostream import IOStream
from tornado_py3.netutil import Resolver
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union
from tornado_py3 import gen as gen
from tornado_py3.concurrent import Future as Future, future_add_done_callback as future_add_done_callback
from tornado_py3.gen import TimeoutError as TimeoutError
from tornado_py3.ioloop import IOLoop as IOLoop
from tornado_py3.iostream import IOStream as IOStream
from tornado_py3.netutil import Resolver as Resolver
from tornado_py3.platform.auto import set_close_exec as set_close_exec
from typing import Any, Callable, Dict, Iterator, List, Tuple, Union
class _Connector:
io_loop: Any = ...
@ -22,7 +22,7 @@ class _Connector:
def __init__(self, addrinfo: List[Tuple], connect: Callable[[socket.AddressFamily, Tuple], Tuple[IOStream, Future[IOStream]]]) -> None: ...
@staticmethod
def split(addrinfo: List[Tuple]) -> Tuple[List[Tuple[socket.AddressFamily, Tuple]], List[Tuple[socket.AddressFamily, Tuple]]]: ...
def start(self, timeout: float=..., connect_timeout: Optional[Union[float, datetime.timedelta]]=...) -> Future[Tuple[socket.AddressFamily, Any, IOStream]]: ...
def start(self, timeout: float=..., connect_timeout: Union[float, datetime.timedelta]=...) -> Future[Tuple[socket.AddressFamily, Any, IOStream]]: ...
def try_connect(self, addrs: Iterator[Tuple[socket.AddressFamily, Tuple]]) -> None: ...
def on_connect_done(self, addrs: Iterator[Tuple[socket.AddressFamily, Tuple]], af: socket.AddressFamily, addr: Tuple, future: Future[IOStream]) -> None: ...
def set_timeout(self, timeout: float) -> None: ...
@ -35,6 +35,6 @@ class _Connector:
class TCPClient:
resolver: Any = ...
def __init__(self, resolver: Optional[Resolver]=...) -> None: ...
def __init__(self, resolver: Resolver=...) -> None: ...
def close(self) -> None: ...
async def connect(self, host: str, port: int, af: socket.AddressFamily=..., ssl_options: Optional[Union[Dict[str, Any], ssl.SSLContext]]=..., max_buffer_size: Optional[int]=..., source_ip: Optional[str]=..., source_port: Optional[int]=..., timeout: Optional[Union[float, datetime.timedelta]]=...) -> IOStream: ...
async def connect(self, host: str, port: int, af: socket.AddressFamily=..., ssl_options: Union[Dict[str, Any], ssl.SSLContext]=..., max_buffer_size: int=..., source_ip: str=..., source_port: int=..., timeout: Union[float, datetime.timedelta]=...) -> IOStream: ...

17
lib/tornado/tcpserver.pyi

@ -1,21 +1,22 @@
# Stubs for tornado_py3.tcpserver (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import socket
import ssl
from tornado_py3.iostream import IOStream
from tornado_py3 import gen as gen, process as process
from tornado_py3.ioloop import IOLoop as IOLoop
from tornado_py3.iostream import IOStream as IOStream, SSLIOStream as SSLIOStream
from tornado_py3.log import app_log as app_log
from tornado_py3.netutil import add_accept_handler as add_accept_handler, bind_sockets as bind_sockets, ssl_wrap_socket as ssl_wrap_socket
from tornado_py3.util import errno_from_exception as errno_from_exception
from typing import Any, Awaitable, Dict, Iterable, Optional, Union
class TCPServer:
ssl_options: Any = ...
max_buffer_size: Any = ...
read_chunk_size: Any = ...
def __init__(self, ssl_options: Optional[Union[Dict[str, Any], ssl.SSLContext]]=..., max_buffer_size: Optional[int]=..., read_chunk_size: Optional[int]=...) -> None: ...
def __init__(self, ssl_options: Union[Dict[str, Any], ssl.SSLContext]=..., max_buffer_size: int=..., read_chunk_size: int=...) -> None: ...
def listen(self, port: int, address: str=...) -> None: ...
def add_sockets(self, sockets: Iterable[socket.socket]) -> None: ...
def add_socket(self, socket: socket.socket) -> None: ...
def bind(self, port: int, address: Optional[str]=..., family: socket.AddressFamily=..., backlog: int=..., reuse_port: bool=...) -> None: ...
def start(self, num_processes: Optional[int]=..., max_restarts: Optional[int]=...) -> None: ...
def bind(self, port: int, address: str=..., family: socket.AddressFamily=..., backlog: int=..., reuse_port: bool=...) -> None: ...
def start(self, num_processes: Optional[int]=..., max_restarts: int=...) -> None: ...
def stop(self) -> None: ...
def handle_stream(self, stream: IOStream, address: tuple) -> Optional[Awaitable[None]]: ...

27
lib/tornado/template.pyi

@ -1,7 +1,6 @@
# Stubs for tornado_py3.template (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from tornado_py3 import escape as escape
from tornado_py3.log import app_log as app_log
from tornado_py3.util import ObjectDict as ObjectDict, exec_in as exec_in, unicode_type as unicode_type
from typing import Any, ContextManager, Dict, Iterable, List, Optional, TextIO, Union
class _UnsetMarker: ...
@ -16,7 +15,7 @@ class Template:
code: Any = ...
loader: Any = ...
compiled: Any = ...
def __init__(self, template_string: Union[str, bytes], name: str=..., loader: Optional[BaseLoader]=..., compress_whitespace: Union[bool, _UnsetMarker]=..., autoescape: Optional[Union[str, _UnsetMarker]]=..., whitespace: Optional[str]=...) -> None: ...
def __init__(self, template_string: Union[str, bytes], name: str=..., loader: BaseLoader=..., compress_whitespace: Union[bool, _UnsetMarker]=..., autoescape: Union[str, _UnsetMarker]=..., whitespace: str=...) -> None: ...
def generate(self, **kwargs: Any) -> bytes: ...
class BaseLoader:
@ -25,20 +24,20 @@ class BaseLoader:
whitespace: Any = ...
templates: Any = ...
lock: Any = ...
def __init__(self, autoescape: str=..., namespace: Optional[Dict[str, Any]]=..., whitespace: Optional[str]=...) -> None: ...
def __init__(self, autoescape: str=..., namespace: Dict[str, Any]=..., whitespace: str=...) -> None: ...
def reset(self) -> None: ...
def resolve_path(self, name: str, parent_path: Optional[str]=...) -> str: ...
def load(self, name: str, parent_path: Optional[str]=...) -> Template: ...
def resolve_path(self, name: str, parent_path: str=...) -> str: ...
def load(self, name: str, parent_path: str=...) -> Template: ...
class Loader(BaseLoader):
root: Any = ...
def __init__(self, root_directory: str, **kwargs: Any) -> None: ...
def resolve_path(self, name: str, parent_path: Optional[str]=...) -> str: ...
def resolve_path(self, name: str, parent_path: str=...) -> str: ...
class DictLoader(BaseLoader):
dict: Any = ...
def __init__(self, dict: Dict[str, str], **kwargs: Any) -> None: ...
def resolve_path(self, name: str, parent_path: Optional[str]=...) -> str: ...
def resolve_path(self, name: str, parent_path: str=...) -> str: ...
class _Node:
def each_child(self) -> Iterable[_Node]: ...
@ -130,7 +129,7 @@ class ParseError(Exception):
message: Any = ...
filename: Any = ...
lineno: Any = ...
def __init__(self, message: str, filename: Optional[str]=..., lineno: int=...) -> None: ...
def __init__(self, message: str, filename: str=..., lineno: int=...) -> None: ...
class _CodeWriter:
file: Any = ...
@ -143,7 +142,7 @@ class _CodeWriter:
def indent_size(self) -> int: ...
def indent(self) -> ContextManager: ...
def include(self, template: Template, line: int) -> ContextManager: ...
def write_line(self, line: str, line_number: int, indent: Optional[int]=...) -> None: ...
def write_line(self, line: str, line_number: int, indent: int=...) -> None: ...
class _TemplateReader:
name: Any = ...
@ -152,8 +151,8 @@ class _TemplateReader:
line: int = ...
pos: int = ...
def __init__(self, name: str, text: str, whitespace: str) -> None: ...
def find(self, needle: str, start: int=..., end: Optional[int]=...) -> int: ...
def consume(self, count: Optional[int]=...) -> str: ...
def find(self, needle: str, start: int=..., end: int=...) -> int: ...
def consume(self, count: int=...) -> str: ...
def remaining(self) -> int: ...
def __len__(self) -> int: ...
def __getitem__(self, key: Union[int, slice]) -> str: ...

26
lib/tornado/testing.pyi

@ -1,16 +1,16 @@
# Stubs for tornado_py3.testing (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import logging
import socket
import unittest
from collections.abc import Generator
from tornado_py3.httpclient import AsyncHTTPClient, HTTPResponse
from tornado_py3.httpserver import HTTPServer
from tornado_py3.ioloop import IOLoop
from tornado_py3.util import basestring_type
from tornado_py3.web import Application
from tornado_py3 import gen as gen, netutil as netutil
from tornado_py3.httpclient import AsyncHTTPClient as AsyncHTTPClient, HTTPResponse as HTTPResponse
from tornado_py3.httpserver import HTTPServer as HTTPServer
from tornado_py3.ioloop import IOLoop as IOLoop, TimeoutError as TimeoutError
from tornado_py3.log import app_log as app_log
from tornado_py3.platform.asyncio import AsyncIOMainLoop as AsyncIOMainLoop
from tornado_py3.process import Subprocess as Subprocess
from tornado_py3.util import basestring_type as basestring_type, raise_exc_info as raise_exc_info
from tornado_py3.web import Application as Application
from types import TracebackType
from typing import Any, Callable, Coroutine, Dict, Optional, Tuple, Type, Union
@ -29,9 +29,9 @@ class AsyncTestCase(unittest.TestCase):
def setUp(self) -> None: ...
def tearDown(self) -> None: ...
def get_new_ioloop(self) -> IOLoop: ...
def run(self, result: Optional[unittest.TestResult]=...) -> Optional[unittest.TestResult]: ...
def run(self, result: unittest.TestResult=...) -> unittest.TestCase: ...
def stop(self, _arg: Any=..., **kwargs: Any) -> None: ...
def wait(self, condition: Optional[Callable[..., bool]]=..., timeout: Optional[float]=...) -> Any: ...
def wait(self, condition: Callable[..., bool]=..., timeout: float=...) -> None: ...
class AsyncHTTPTestCase(AsyncTestCase):
http_client: Any = ...
@ -55,7 +55,7 @@ class AsyncHTTPSTestCase(AsyncHTTPTestCase):
def default_ssl_options() -> Dict[str, Any]: ...
def get_protocol(self) -> str: ...
def gen_test(*, timeout: Optional[float]=...) -> Callable[[Callable[..., Union[Generator, Coroutine]]], Callable[..., None]]: ...
def gen_test(*, timeout: float=...) -> Callable[[Callable[..., Union[Generator, Coroutine]]], Callable[..., None]]: ...
class ExpectLog(logging.Filter):
logger: Any = ...
@ -63,7 +63,7 @@ class ExpectLog(logging.Filter):
required: Any = ...
matched: bool = ...
logged_stack: bool = ...
def __init__(self, logger: Union[logging.Logger, basestring_type], regex: str, required: bool=..., level: Optional[int] = None) -> None: ...
def __init__(self, logger: Union[logging.Logger, basestring_type], regex: str, required: bool=...) -> None: ...
def filter(self, record: logging.LogRecord) -> bool: ...
def __enter__(self) -> ExpectLog: ...
def __exit__(self, typ: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[TracebackType]) -> None: ...

6
lib/tornado/util.pyi

@ -1,7 +1,3 @@
# Stubs for tornado_py3.util (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import datetime
import typing
import unittest
@ -27,7 +23,7 @@ class GzipDecompressor:
def flush(self) -> bytes: ...
def import_object(name: str) -> Any: ...
def exec_in(code: Any, glob: Dict[str, Any], loc: Optional[Optional[Mapping[str, Any]]]=...) -> None: ...
def exec_in(code: Any, glob: Dict[str, Any], loc: Mapping[str, Any]=...) -> None: ...
def raise_exc_info(exc_info: Tuple[Optional[type], Optional[BaseException], Optional[TracebackType]]) -> typing.NoReturn: ...
def errno_from_exception(e: BaseException) -> Optional[int]: ...
def re_unescape(s: str) -> str: ...

59
lib/tornado/web.pyi

@ -1,14 +1,13 @@
# Stubs for tornado_py3.web (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import datetime
import http.cookies
import tornado_py3.locale
from tornado_py3 import httputil, iostream, template
from tornado_py3.concurrent import Future
from tornado_py3.httpserver import HTTPServer
from tornado_py3.routing import ReversibleRouter, ReversibleRuleRouter, Rule, URLSpec, _RuleList
from tornado_py3 import escape as escape, gen as gen, httputil as httputil, iostream as iostream, locale as locale, template as template
from tornado_py3.concurrent import Future as Future, future_set_result_unless_cancelled as future_set_result_unless_cancelled
from tornado_py3.escape import utf8 as utf8
from tornado_py3.httpserver import HTTPServer as HTTPServer
from tornado_py3.log import access_log as access_log, app_log as app_log, gen_log as gen_log
from tornado_py3.routing import AnyMatches as AnyMatches, DefaultHostMatches as DefaultHostMatches, HostMatches as HostMatches, ReversibleRouter as ReversibleRouter, ReversibleRuleRouter as ReversibleRuleRouter, Rule as Rule, URLSpec as URLSpec, _RuleList
from tornado_py3.util import ObjectDict as ObjectDict, unicode_type as unicode_type
from types import TracebackType
from typing import Any, Awaitable, Callable, Dict, Generator, Iterable, List, Optional, Tuple, Type, Union
@ -43,7 +42,7 @@ class RequestHandler:
def on_connection_close(self) -> None: ...
def clear(self) -> None: ...
def set_default_headers(self) -> None: ...
def set_status(self, status_code: int, reason: Optional[str]=...) -> None: ...
def set_status(self, status_code: int, reason: str=...) -> None: ...
def get_status(self) -> int: ...
def set_header(self, name: str, value: _HeaderTypes) -> None: ...
def add_header(self, name: str, value: _HeaderTypes) -> None: ...
@ -57,18 +56,18 @@ class RequestHandler:
def get_body_arguments(self, name: str, strip: bool=...) -> List[str]: ...
def get_query_argument(self, name: str, default: Union[None, str, _ArgDefaultMarker]=..., strip: bool=...) -> Optional[str]: ...
def get_query_arguments(self, name: str, strip: bool=...) -> List[str]: ...
def decode_argument(self, value: bytes, name: Optional[str]=...) -> str: ...
def decode_argument(self, value: bytes, name: str=...) -> str: ...
@property
def cookies(self) -> Dict[str, http.cookies.Morsel]: ...
def get_cookie(self, name: str, default: Optional[str]=...) -> Optional[str]: ...
def set_cookie(self, name: str, value: Union[str, bytes], domain: Optional[str]=..., expires: Optional[Union[float, Tuple, datetime.datetime]]=..., path: str=..., expires_days: Optional[int]=..., **kwargs: Any) -> None: ...
def clear_cookie(self, name: str, path: str=..., domain: Optional[str]=...) -> None: ...
def clear_all_cookies(self, path: str=..., domain: Optional[str]=...) -> None: ...
def set_secure_cookie(self, name: str, value: Union[str, bytes], expires_days: Optional[int]=..., version: Optional[int]=..., **kwargs: Any) -> None: ...
def create_signed_value(self, name: str, value: Union[str, bytes], version: Optional[int]=...) -> bytes: ...
def get_secure_cookie(self, name: str, value: Optional[str]=..., max_age_days: int=..., min_version: Optional[int]=...) -> Optional[bytes]: ...
def get_secure_cookie_key_version(self, name: str, value: Optional[str]=...) -> Optional[int]: ...
def redirect(self, url: str, permanent: bool=..., status: Optional[int]=...) -> None: ...
def get_cookie(self, name: str, default: str=...) -> Optional[str]: ...
def set_cookie(self, name: str, value: Union[str, bytes], domain: str=..., expires: Union[float, Tuple, datetime.datetime]=..., path: str=..., expires_days: int=..., **kwargs: Any) -> None: ...
def clear_cookie(self, name: str, path: str=..., domain: str=...) -> None: ...
def clear_all_cookies(self, path: str=..., domain: str=...) -> None: ...
def set_secure_cookie(self, name: str, value: Union[str, bytes], expires_days: int=..., version: int=..., **kwargs: Any) -> None: ...
def create_signed_value(self, name: str, value: Union[str, bytes], version: int=...) -> bytes: ...
def get_secure_cookie(self, name: str, value: str=..., max_age_days: int=..., min_version: int=...) -> Optional[bytes]: ...
def get_secure_cookie_key_version(self, name: str, value: str=...) -> Optional[int]: ...
def redirect(self, url: str, permanent: bool=..., status: int=...) -> None: ...
def write(self, chunk: Union[str, bytes, dict]) -> None: ...
def render(self, template_name: str, **kwargs: Any) -> Future[None]: ...
def render_linked_js(self, js_files: Iterable[str]) -> str: ...
@ -79,7 +78,7 @@ class RequestHandler:
def get_template_namespace(self) -> Dict[str, Any]: ...
def create_template_loader(self, template_path: str) -> template.BaseLoader: ...
def flush(self, include_footers: bool=...) -> Future[None]: ...
def finish(self, chunk: Optional[Union[str, bytes, dict]]=...) -> Future[None]: ...
def finish(self, chunk: Union[str, bytes, dict]=...) -> Future[None]: ...
def detach(self) -> iostream.IOStream: ...
def send_error(self, status_code: int=..., **kwargs: Any) -> None: ...
def write_error(self, status_code: int, **kwargs: Any) -> None: ...
@ -100,7 +99,7 @@ class RequestHandler:
def xsrf_token(self) -> bytes: ...
def check_xsrf_cookie(self) -> None: ...
def xsrf_form_html(self) -> str: ...
def static_url(self, path: str, include_host: Optional[bool]=..., **kwargs: Any) -> str: ...
def static_url(self, path: str, include_host: bool=..., **kwargs: Any) -> str: ...
def require_setting(self, name: str, feature: str=...) -> None: ...
def reverse_url(self, name: str, *args: Any) -> str: ...
def compute_etag(self) -> Optional[str]: ...
@ -115,7 +114,7 @@ def addslash(method: Callable[..., Optional[Awaitable[None]]]) -> Callable[...,
class _ApplicationRouter(ReversibleRuleRouter):
application: Any = ...
def __init__(self, application: Application, rules: Optional[_RuleList]=...) -> None: ...
def __init__(self, application: Application, rules: _RuleList=...) -> None: ...
def process_rule(self, rule: Rule) -> Rule: ...
def get_target_delegate(self, target: Any, request: httputil.HTTPServerRequest, **target_params: Any) -> Optional[httputil.HTTPMessageDelegate]: ...
@ -127,13 +126,13 @@ class Application(ReversibleRouter):
ui_methods: Any = ...
wildcard_router: Any = ...
default_router: Any = ...
def __init__(self, handlers: Optional[_RuleList]=..., default_host: Optional[str]=..., transforms: Optional[List[Type[OutputTransform]]]=..., **settings: Any) -> None: ...
def __init__(self, handlers: _RuleList=..., default_host: str=..., transforms: List[Type[OutputTransform]]=..., **settings: Any) -> None: ...
def listen(self, port: int, address: str=..., **kwargs: Any) -> HTTPServer: ...
def add_handlers(self, host_pattern: str, host_handlers: _RuleList) -> None: ...
def add_transform(self, transform_class: Type[OutputTransform]) -> None: ...
def __call__(self, request: httputil.HTTPServerRequest) -> Optional[Awaitable[None]]: ...
def find_handler(self, request: httputil.HTTPServerRequest, **kwargs: Any) -> _HandlerDelegate: ...
def get_handler_delegate(self, request: httputil.HTTPServerRequest, target_class: Type[RequestHandler], target_kwargs: Optional[Dict[str, Any]]=..., path_args: Optional[List[bytes]]=..., path_kwargs: Optional[Dict[str, bytes]]=...) -> _HandlerDelegate: ...
def get_handler_delegate(self, request: httputil.HTTPServerRequest, target_class: Type[RequestHandler], target_kwargs: Dict[str, Any]=..., path_args: List[bytes]=..., path_kwargs: Dict[str, bytes]=...) -> _HandlerDelegate: ...
def reverse_url(self, name: str, *args: Any) -> str: ...
def log_request(self, handler: RequestHandler) -> None: ...
@ -160,7 +159,7 @@ class HTTPError(Exception):
log_message: Any = ...
args: Any = ...
reason: Any = ...
def __init__(self, status_code: int=..., log_message: Optional[str]=..., *args: Any, **kwargs: Any) -> None: ...
def __init__(self, status_code: int=..., log_message: str=..., *args: Any, **kwargs: Any) -> None: ...
class Finish(Exception): ...
@ -175,13 +174,13 @@ class ErrorHandler(RequestHandler):
class RedirectHandler(RequestHandler):
def initialize(self, url: str, permanent: bool=...) -> None: ...
def get(self, *args: Any, **kwargs: Any) -> None: ...
def get(self, *args: Any) -> None: ...
class StaticFileHandler(RequestHandler):
CACHE_MAX_AGE: Any = ...
root: Any = ...
default_filename: Any = ...
def initialize(self, path: str, default_filename: Optional[str]=...) -> None: ...
def initialize(self, path: str, default_filename: str=...) -> None: ...
@classmethod
def reset(cls: Any) -> None: ...
def head(self, path: str) -> Awaitable[None]: ...
@ -196,7 +195,7 @@ class StaticFileHandler(RequestHandler):
def get_absolute_path(cls: Any, root: str, path: str) -> str: ...
def validate_absolute_path(self, root: str, absolute_path: str) -> Optional[str]: ...
@classmethod
def get_content(cls: Any, abspath: str, start: Optional[int]=..., end: Optional[int]=...) -> Generator[bytes, None, None]: ...
def get_content(cls: Any, abspath: str, start: int=..., end: int=...) -> Generator[bytes, None, None]: ...
@classmethod
def get_content_version(cls: Any, abspath: str) -> str: ...
def get_content_size(self) -> int: ...
@ -270,7 +269,7 @@ class _UIModuleNamespace:
def __getitem__(self, key: str) -> Callable[..., str]: ...
def __getattr__(self, key: str) -> Callable[..., str]: ...
def create_signed_value(secret: _CookieSecretTypes, name: str, value: Union[str, bytes], version: Optional[int]=..., clock: Optional[Callable[[], float]]=..., key_version: Optional[int]=...) -> bytes: ...
def decode_signed_value(secret: _CookieSecretTypes, name: str, value: Union[None, str, bytes], max_age_days: int=..., clock: Optional[Callable[[], float]]=..., min_version: Optional[int]=...) -> Optional[bytes]: ...
def create_signed_value(secret: _CookieSecretTypes, name: str, value: Union[str, bytes], version: int=..., clock: Callable[[], float]=..., key_version: int=...) -> bytes: ...
def decode_signed_value(secret: _CookieSecretTypes, name: str, value: Union[None, str, bytes], max_age_days: int=..., clock: Callable[[], float]=..., min_version: int=...) -> Optional[bytes]: ...
def get_signature_key_version(value: Union[str, bytes]) -> Optional[int]: ...
def is_absolute(path: str) -> bool: ...

42
lib/tornado/websocket.pyi

@ -1,14 +1,16 @@
# Stubs for tornado_py3.websocket (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
import abc
import tornado_py3.web
from tornado_py3 import httpclient, httputil, simple_httpclient
from tornado_py3.concurrent import Future
from tornado_py3.iostream import IOStream
from tornado_py3 import gen as gen, httpclient as httpclient, httputil as httputil, simple_httpclient as simple_httpclient
from tornado_py3.concurrent import Future as Future, future_set_result_unless_cancelled as future_set_result_unless_cancelled
from tornado_py3.escape import native_str as native_str, to_unicode as to_unicode, utf8 as utf8
from tornado_py3.ioloop import IOLoop as IOLoop, PeriodicCallback as PeriodicCallback
from tornado_py3.iostream import IOStream as IOStream, StreamClosedError as StreamClosedError
from tornado_py3.log import app_log as app_log, gen_log as gen_log
from tornado_py3.queues import Queue as Queue
from tornado_py3.tcpclient import TCPClient as TCPClient
from types import TracebackType
from typing import Any, Awaitable, Callable, Dict, List, Optional, Type, Union
from typing_extensions import Protocol as Protocol
class _Compressor:
def compress(self, data: bytes) -> bytes: ...
@ -19,7 +21,7 @@ class _Decompressor:
def decompress(self, data: bytes, max_length: int) -> bytes: ...
class _WebSocketDelegate:
def on_ws_connection_close(self, close_code: Optional[int]=..., close_reason: Optional[str]=...) -> None: ...
def on_ws_connection_close(self, close_code: int=..., close_reason: str=...) -> None: ...
def on_message(self, message: Union[str, bytes]) -> Optional[Awaitable[None]]: ...
def on_ping(self, data: bytes) -> None: ...
def on_pong(self, data: bytes) -> None: ...
@ -34,7 +36,7 @@ class _WebSocketParams:
ping_timeout: Any = ...
max_message_size: Any = ...
compression_options: Any = ...
def __init__(self, ping_interval: Optional[float]=..., ping_timeout: Optional[float]=..., max_message_size: int=..., compression_options: Optional[Dict[str, Any]]=...) -> None: ...
def __init__(self, ping_interval: float=..., ping_timeout: float=..., max_message_size: int=..., compression_options: Dict[str, Any]=...) -> None: ...
class WebSocketHandler(tornado_py3.web.RequestHandler):
ws_connection: Any = ...
@ -62,11 +64,11 @@ class WebSocketHandler(tornado_py3.web.RequestHandler):
def on_pong(self, data: bytes) -> None: ...
def on_ping(self, data: bytes) -> None: ...
def on_close(self) -> None: ...
def close(self, code: Optional[int]=..., reason: Optional[str]=...) -> None: ...
def close(self, code: int=..., reason: str=...) -> None: ...
def check_origin(self, origin: str) -> bool: ...
def set_nodelay(self, value: bool) -> None: ...
def on_connection_close(self) -> None: ...
def on_ws_connection_close(self, close_code: Optional[int]=..., close_reason: Optional[str]=...) -> None: ...
def on_ws_connection_close(self, close_code: int=..., close_reason: str=...) -> None: ...
def send_error(self, *args: Any, **kwargs: Any) -> None: ...
def get_websocket_protocol(self) -> Optional[WebSocketProtocol]: ...
@ -78,7 +80,7 @@ class WebSocketProtocol(abc.ABC, metaclass=abc.ABCMeta):
def __init__(self, handler: _WebSocketDelegate) -> None: ...
def on_connection_close(self) -> None: ...
@abc.abstractmethod
def close(self, code: Optional[int]=..., reason: Optional[str]=...) -> None: ...
def close(self, code: int=..., reason: str=...) -> None: ...
@abc.abstractmethod
def is_closing(self) -> bool: ...
@abc.abstractmethod
@ -96,11 +98,11 @@ class WebSocketProtocol(abc.ABC, metaclass=abc.ABCMeta):
def set_nodelay(self, x: bool) -> None: ...
class _PerMessageDeflateCompressor:
def __init__(self, persistent: bool, max_wbits: Optional[int], compression_options: Optional[Dict[str, Any]]=...) -> None: ...
def __init__(self, persistent: bool, max_wbits: Optional[int], compression_options: Dict[str, Any]=...) -> None: ...
def compress(self, data: bytes) -> bytes: ...
class _PerMessageDeflateDecompressor:
def __init__(self, persistent: bool, max_wbits: Optional[int], max_message_size: int, compression_options: Optional[Dict[str, Any]]=...) -> None: ...
def __init__(self, persistent: bool, max_wbits: Optional[int], max_message_size: int, compression_options: Dict[str, Any]=...) -> None: ...
def decompress(self, data: bytes) -> bytes: ...
class WebSocketProtocol13(WebSocketProtocol):
@ -129,7 +131,7 @@ class WebSocketProtocol13(WebSocketProtocol):
def write_message(self, message: Union[str, bytes], binary: bool=...) -> Future[None]: ...
def write_ping(self, data: bytes) -> None: ...
server_terminated: bool = ...
def close(self, code: Optional[int]=..., reason: Optional[str]=...) -> None: ...
def close(self, code: int=..., reason: str=...) -> None: ...
def is_closing(self) -> bool: ...
@property
def ping_interval(self) -> Optional[float]: ...
@ -148,15 +150,15 @@ class WebSocketClientConnection(simple_httpclient._HTTPConnection):
close_reason: Any = ...
params: Any = ...
tcp_client: Any = ...
def __init__(self, request: httpclient.HTTPRequest, on_message_callback: Optional[Callable[[Union[None, str, bytes]], None]]=..., compression_options: Optional[Dict[str, Any]]=..., ping_interval: Optional[float]=..., ping_timeout: Optional[float]=..., max_message_size: int=..., subprotocols: Optional[List[str]]=...) -> None: ...
def close(self, code: Optional[int]=..., reason: Optional[str]=...) -> None: ...
def __init__(self, request: httpclient.HTTPRequest, on_message_callback: Callable[[Union[None, str, bytes]], None]=..., compression_options: Dict[str, Any]=..., ping_interval: float=..., ping_timeout: float=..., max_message_size: int=..., subprotocols: Optional[List[str]]=...) -> None: ...
def close(self, code: int=..., reason: str=...) -> None: ...
def on_connection_close(self) -> None: ...
def on_ws_connection_close(self, close_code: Optional[int]=..., close_reason: Optional[str]=...) -> None: ...
def on_ws_connection_close(self, close_code: int=..., close_reason: str=...) -> None: ...
headers: Any = ...
final_callback: Any = ...
async def headers_received(self, start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine], headers: httputil.HTTPHeaders) -> None: ...
def write_message(self, message: Union[str, bytes], binary: bool=...) -> Future[None]: ...
def read_message(self, callback: Optional[Callable[[Future[Union[None, str, bytes]]], None]]=...) -> Awaitable[Union[None, str, bytes]]: ...
def read_message(self, callback: Callable[[Future[Union[None, str, bytes]]], None]=...) -> Awaitable[Union[None, str, bytes]]: ...
def on_message(self, message: Union[str, bytes]) -> Optional[Awaitable[None]]: ...
def ping(self, data: bytes=...) -> None: ...
def on_pong(self, data: bytes) -> None: ...
@ -166,4 +168,4 @@ class WebSocketClientConnection(simple_httpclient._HTTPConnection):
def selected_subprotocol(self) -> Optional[str]: ...
def log_exception(self, typ: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[TracebackType]) -> None: ...
def websocket_connect(url: Union[str, httpclient.HTTPRequest], callback: Optional[Callable[[Future[WebSocketClientConnection]], None]]=..., connect_timeout: Optional[float]=..., on_message_callback: Optional[Callable[[Union[None, str, bytes]], None]]=..., compression_options: Optional[Dict[str, Any]]=..., ping_interval: Optional[float]=..., ping_timeout: Optional[float]=..., max_message_size: int=..., subprotocols: Optional[List[str]]=...) -> Awaitable[WebSocketClientConnection]: ...
def websocket_connect(url: Union[str, httpclient.HTTPRequest], callback: Callable[[Future[WebSocketClientConnection]], None]=..., connect_timeout: float=..., on_message_callback: Callable[[Union[None, str, bytes]], None]=..., compression_options: Dict[str, Any]=..., ping_interval: float=..., ping_timeout: float=..., max_message_size: int=..., subprotocols: List[str]=...) -> Awaitable[WebSocketClientConnection]: ...

7
lib/tornado/wsgi.pyi

@ -1,8 +1,5 @@
# Stubs for tornado_py3.wsgi (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from tornado_py3 import httputil
from tornado_py3 import escape as escape, httputil as httputil
from tornado_py3.log import access_log as access_log
from typing import Any, Dict, Text
from wsgiref.types import WSGIApplication as WSGIAppType

4
lib/tornado_py3/__init__.py

@ -22,5 +22,5 @@
# is zero for an official release, positive for a development branch,
# or negative for a release candidate or beta (after the base version
# number has been incremented)
version = "6.1.dev1"
version_info = (6, 1, 0, -100)
version = "6.0.4"
version_info = (6, 0, 4, 0)

61
lib/tornado_py3/auth.py

@ -87,7 +87,7 @@ class OpenIdMixin(object):
def authenticate_redirect(
self,
callback_uri: Optional[str] = None,
callback_uri: str = None,
ax_attrs: List[str] = ["name", "email", "language", "username"],
) -> None:
"""Redirects to the authentication URL for this service.
@ -114,7 +114,7 @@ class OpenIdMixin(object):
handler.redirect(endpoint + "?" + urllib.parse.urlencode(args))
async def get_authenticated_user(
self, http_client: Optional[httpclient.AsyncHTTPClient] = None
self, http_client: httpclient.AsyncHTTPClient = None
) -> Dict[str, Any]:
"""Fetches the authenticated user data upon redirect.
@ -146,10 +146,7 @@ class OpenIdMixin(object):
return self._on_authentication_verified(resp)
def _openid_args(
self,
callback_uri: str,
ax_attrs: Iterable[str] = [],
oauth_scope: Optional[str] = None,
self, callback_uri: str, ax_attrs: Iterable[str] = [], oauth_scope: str = None
) -> Dict[str, str]:
handler = cast(RequestHandler, self)
url = urllib.parse.urljoin(handler.request.full_url(), callback_uri)
@ -204,7 +201,7 @@ class OpenIdMixin(object):
) -> Dict[str, Any]:
handler = cast(RequestHandler, self)
if b"is_valid:true" not in response.body:
raise AuthError("Invalid OpenID response: %r" % response.body)
raise AuthError("Invalid OpenID response: %s" % response.body)
# Make sure we got back at least an email from attribute exchange
ax_ns = None
@ -289,9 +286,9 @@ class OAuthMixin(object):
async def authorize_redirect(
self,
callback_uri: Optional[str] = None,
extra_params: Optional[Dict[str, Any]] = None,
http_client: Optional[httpclient.AsyncHTTPClient] = None,
callback_uri: str = None,
extra_params: Dict[str, Any] = None,
http_client: httpclient.AsyncHTTPClient = None,
) -> None:
"""Redirects the user to obtain OAuth authorization for this service.
@ -337,7 +334,7 @@ class OAuthMixin(object):
self._on_request_token(url, callback_uri, response)
async def get_authenticated_user(
self, http_client: Optional[httpclient.AsyncHTTPClient] = None
self, http_client: httpclient.AsyncHTTPClient = None
) -> Dict[str, Any]:
"""Gets the OAuth authorized user and access token.
@ -383,9 +380,7 @@ class OAuthMixin(object):
return user
def _oauth_request_token_url(
self,
callback_uri: Optional[str] = None,
extra_params: Optional[Dict[str, Any]] = None,
self, callback_uri: str = None, extra_params: Dict[str, Any] = None
) -> str:
handler = cast(RequestHandler, self)
consumer_token = self._oauth_consumer_token()
@ -552,11 +547,11 @@ class OAuth2Mixin(object):
def authorize_redirect(
self,
redirect_uri: Optional[str] = None,
client_id: Optional[str] = None,
client_secret: Optional[str] = None,
extra_params: Optional[Dict[str, Any]] = None,
scope: Optional[List[str]] = None,
redirect_uri: str = None,
client_id: str = None,
client_secret: str = None,
extra_params: Dict[str, Any] = None,
scope: str = None,
response_type: str = "code",
) -> None:
"""Redirects the user to obtain OAuth authorization for this service.
@ -587,11 +582,11 @@ class OAuth2Mixin(object):
def _oauth_request_token_url(
self,
redirect_uri: Optional[str] = None,
client_id: Optional[str] = None,
client_secret: Optional[str] = None,
code: Optional[str] = None,
extra_params: Optional[Dict[str, Any]] = None,
redirect_uri: str = None,
client_id: str = None,
client_secret: str = None,
code: str = None,
extra_params: Dict[str, Any] = None,
) -> str:
url = self._OAUTH_ACCESS_TOKEN_URL # type: ignore
args = {} # type: Dict[str, str]
@ -610,8 +605,8 @@ class OAuth2Mixin(object):
async def oauth2_request(
self,
url: str,
access_token: Optional[str] = None,
post_args: Optional[Dict[str, Any]] = None,
access_token: str = None,
post_args: Dict[str, Any] = None,
**args: Any
) -> Any:
"""Fetches the given URL auth an OAuth2 access token.
@ -714,7 +709,7 @@ class TwitterMixin(OAuthMixin):
_OAUTH_NO_CALLBACKS = False
_TWITTER_BASE_URL = "https://api.twitter.com/1.1"
async def authenticate_redirect(self, callback_uri: Optional[str] = None) -> None:
async def authenticate_redirect(self, callback_uri: str = None) -> None:
"""Just like `~OAuthMixin.authorize_redirect`, but
auto-redirects if authorized.
@ -740,7 +735,7 @@ class TwitterMixin(OAuthMixin):
self,
path: str,
access_token: Dict[str, Any],
post_args: Optional[Dict[str, Any]] = None,
post_args: Dict[str, Any] = None,
**args: Any
) -> Any:
"""Fetches the given API path, e.g., ``statuses/user_timeline/btaylor``
@ -935,7 +930,7 @@ class FacebookGraphMixin(OAuth2Mixin):
client_id: str,
client_secret: str,
code: str,
extra_fields: Optional[Dict[str, Any]] = None,
extra_fields: Dict[str, Any] = None,
) -> Optional[Dict[str, Any]]:
"""Handles the login for the Facebook user, returning a user object.
@ -1039,8 +1034,8 @@ class FacebookGraphMixin(OAuth2Mixin):
async def facebook_request(
self,
path: str,
access_token: Optional[str] = None,
post_args: Optional[Dict[str, Any]] = None,
access_token: str = None,
post_args: Dict[str, Any] = None,
**args: Any
) -> Any:
"""Fetches the given relative API path, e.g., "/btaylor/picture"
@ -1104,7 +1099,7 @@ def _oauth_signature(
method: str,
url: str,
parameters: Dict[str, Any] = {},
token: Optional[Dict[str, Any]] = None,
token: Dict[str, Any] = None,
) -> bytes:
"""Calculates the HMAC-SHA1 OAuth signature for the given request.
@ -1137,7 +1132,7 @@ def _oauth10a_signature(
method: str,
url: str,
parameters: Dict[str, Any] = {},
token: Optional[Dict[str, Any]] = None,
token: Dict[str, Any] = None,
) -> bytes:
"""Calculates the HMAC-SHA1 OAuth 1.0a signature for the given request.

4
lib/tornado_py3/autoreload.py

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

32
lib/tornado_py3/curl_httpclient.py

@ -18,7 +18,7 @@
import collections
import functools
import logging
import pycurl
import pycurl # type: ignore
import threading
import time
from io import BytesIO
@ -36,22 +36,21 @@ from tornado_py3.httpclient import (
)
from tornado_py3.log import app_log
from typing import Dict, Any, Callable, Union, Tuple, Optional
from typing import Dict, Any, Callable, Union
import typing
if typing.TYPE_CHECKING:
from typing import Deque # noqa: F401
from typing import Deque, Tuple, Optional # noqa: F401
curl_log = logging.getLogger("tornado.curl_httpclient")
class CurlAsyncHTTPClient(AsyncHTTPClient):
def initialize( # type: ignore
self, max_clients: int = 10, defaults: Optional[Dict[str, Any]] = None
self, max_clients: int = 10, defaults: Dict[str, Any] = None
) -> None:
super(CurlAsyncHTTPClient, self).initialize(defaults=defaults)
# Typeshed is incomplete for CurlMulti, so just use Any for now.
self._multi = pycurl.CurlMulti() # type: Any
self._multi = pycurl.CurlMulti()
self._multi.setopt(pycurl.M_TIMERFUNCTION, self._set_timeout)
self._multi.setopt(pycurl.M_SOCKETFUNCTION, self._handle_socket)
self._curls = [self._curl_create() for i in range(max_clients)]
@ -220,8 +219,7 @@ class CurlAsyncHTTPClient(AsyncHTTPClient):
started += 1
curl = self._free_list.pop()
(request, callback, queue_start_time) = self._requests.popleft()
# TODO: Don't smuggle extra data on an attribute of the Curl object.
curl.info = { # type: ignore
curl.info = {
"headers": httputil.HTTPHeaders(),
"buffer": BytesIO(),
"request": request,
@ -232,10 +230,7 @@ class CurlAsyncHTTPClient(AsyncHTTPClient):
}
try:
self._curl_setup_request(
curl,
request,
curl.info["buffer"], # type: ignore
curl.info["headers"], # type: ignore
curl, request, curl.info["buffer"], curl.info["headers"]
)
except Exception as e:
# If there was an error in setup, pass it on
@ -255,13 +250,10 @@ class CurlAsyncHTTPClient(AsyncHTTPClient):
break
def _finish(
self,
curl: pycurl.Curl,
curl_error: Optional[int] = None,
curl_message: Optional[str] = None,
self, curl: pycurl.Curl, curl_error: int = None, curl_message: str = None
) -> None:
info = curl.info # type: ignore
curl.info = None # type: ignore
info = curl.info
curl.info = None
self._multi.remove_handle(curl)
self._free_list.append(curl)
buffer = info["buffer"]
@ -386,7 +378,7 @@ class CurlAsyncHTTPClient(AsyncHTTPClient):
if request.decompress_response:
curl.setopt(pycurl.ENCODING, "gzip,deflate")
else:
curl.setopt(pycurl.ENCODING, None)
curl.setopt(pycurl.ENCODING, "none")
if request.proxy_host and request.proxy_port:
curl.setopt(pycurl.PROXY, request.proxy_host)
curl.setopt(pycurl.PROXYPORT, request.proxy_port)
@ -477,7 +469,7 @@ class CurlAsyncHTTPClient(AsyncHTTPClient):
request_buffer = BytesIO(utf8(request.body or ""))
def ioctl(cmd: int) -> None:
if cmd == curl.IOCMD_RESTARTREAD: # type: ignore
if cmd == curl.IOCMD_RESTARTREAD:
request_buffer.seek(0)
curl.setopt(pycurl.READFUNCTION, request_buffer.read)

8
lib/tornado_py3/escape.py

@ -145,10 +145,10 @@ def url_unescape( # noqa: F811
def parse_qs_bytes(
qs: Union[str, bytes], keep_blank_values: bool = False, strict_parsing: bool = False
qs: str, keep_blank_values: bool = False, strict_parsing: bool = False
) -> Dict[str, List[bytes]]:
"""Parses a query string like urlparse.parse_qs,
but takes bytes and returns the values as byte strings.
"""Parses a query string like urlparse.parse_qs, but returns the
values as byte strings.
Keys still become type str (interpreted as latin1 in python3!)
because it's too painful to keep them as byte strings in
@ -156,8 +156,6 @@ def parse_qs_bytes(
"""
# This is gross, but python3 doesn't give us another way.
# Latin1 is the universal donor of character encodings.
if isinstance(qs, bytes):
qs = qs.decode("latin1")
result = urllib.parse.parse_qs(
qs, keep_blank_values, strict_parsing, encoding="latin1", errors="strict"
)

26
lib/tornado_py3/http1connection.py

@ -75,11 +75,11 @@ class HTTP1ConnectionParameters(object):
def __init__(
self,
no_keep_alive: bool = False,
chunk_size: Optional[int] = None,
max_header_size: Optional[int] = None,
header_timeout: Optional[float] = None,
max_body_size: Optional[int] = None,
body_timeout: Optional[float] = None,
chunk_size: int = None,
max_header_size: int = None,
header_timeout: float = None,
max_body_size: int = None,
body_timeout: float = None,
decompress: bool = False,
) -> None:
"""
@ -113,8 +113,8 @@ class HTTP1Connection(httputil.HTTPConnection):
self,
stream: iostream.IOStream,
is_client: bool,
params: Optional[HTTP1ConnectionParameters] = None,
context: Optional[object] = None,
params: HTTP1ConnectionParameters = None,
context: object = None,
) -> None:
"""
:arg stream: an `.IOStream`
@ -235,7 +235,7 @@ class HTTP1Connection(httputil.HTTPConnection):
# but do not actually have a body.
# http://tools.ietf.org/html/rfc7230#section-3.3
skip_body = True
if 100 <= code < 200:
if code >= 100 and code < 200:
# 1xx responses should never indicate the presence of
# a body.
if "Content-Length" in headers or "Transfer-Encoding" in headers:
@ -317,7 +317,7 @@ class HTTP1Connection(httputil.HTTPConnection):
Note that this callback is slightly different from
`.HTTPMessageDelegate.on_connection_close`: The
`.HTTPMessageDelegate` method is called when the connection is
closed while receiving a message. This callback is used when
closed while recieving a message. This callback is used when
there is not an active delegate (for example, on the server
side this callback is used if the client closes the connection
after sending its request but before receiving all the
@ -377,7 +377,7 @@ class HTTP1Connection(httputil.HTTPConnection):
self,
start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine],
headers: httputil.HTTPHeaders,
chunk: Optional[bytes] = None,
chunk: bytes = None,
) -> "Future[None]":
"""Implements `.HTTPConnection.write_headers`."""
lines = []
@ -406,8 +406,6 @@ class HTTP1Connection(httputil.HTTPConnection):
# self._request_start_line.version or
# start_line.version?
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
# body), and so should not have either Content-Length or
# Transfer-Encoding headers.
@ -767,8 +765,8 @@ class HTTP1ServerConnection(object):
def __init__(
self,
stream: iostream.IOStream,
params: Optional[HTTP1ConnectionParameters] = None,
context: Optional[object] = None,
params: HTTP1ConnectionParameters = None,
context: object = None,
) -> None:
"""
:arg stream: an `.IOStream`

97
lib/tornado_py3/httpclient.py

@ -53,7 +53,7 @@ from tornado_py3 import gen, httputil
from tornado_py3.ioloop import IOLoop
from tornado_py3.util import Configurable
from typing import Type, Any, Union, Dict, Callable, Optional, cast
from typing import Type, Any, Union, Dict, Callable, Optional, cast, Awaitable
class HTTPClient(object):
@ -87,9 +87,7 @@ class HTTPClient(object):
"""
def __init__(
self,
async_client_class: "Optional[Type[AsyncHTTPClient]]" = None,
**kwargs: Any
self, async_client_class: Type["AsyncHTTPClient"] = None, **kwargs: Any
) -> None:
# Initialize self._closed at the beginning of the constructor
# so that an exception raised here doesn't lead to confusing
@ -213,7 +211,7 @@ class AsyncHTTPClient(Configurable):
instance_cache[instance.io_loop] = instance
return instance
def initialize(self, defaults: Optional[Dict[str, Any]] = None) -> None:
def initialize(self, defaults: Dict[str, Any] = None) -> None:
self.io_loop = IOLoop.current()
self.defaults = dict(HTTPRequest._DEFAULTS)
if defaults is not None:
@ -251,7 +249,7 @@ class AsyncHTTPClient(Configurable):
request: Union[str, "HTTPRequest"],
raise_error: bool = True,
**kwargs: Any
) -> "Future[HTTPResponse]":
) -> Awaitable["HTTPResponse"]:
"""Executes a request, asynchronously returning an `HTTPResponse`.
The request may be either a string URL or an `HTTPRequest` object.
@ -359,39 +357,37 @@ class HTTPRequest(object):
self,
url: str,
method: str = "GET",
headers: Optional[Union[Dict[str, str], httputil.HTTPHeaders]] = None,
body: Optional[Union[bytes, str]] = None,
auth_username: Optional[str] = None,
auth_password: Optional[str] = None,
auth_mode: Optional[str] = None,
connect_timeout: Optional[float] = None,
request_timeout: Optional[float] = None,
if_modified_since: Optional[Union[float, datetime.datetime]] = None,
follow_redirects: Optional[bool] = None,
max_redirects: Optional[int] = None,
user_agent: Optional[str] = None,
use_gzip: Optional[bool] = None,
network_interface: Optional[str] = None,
streaming_callback: Optional[Callable[[bytes], None]] = None,
header_callback: Optional[Callable[[str], None]] = None,
prepare_curl_callback: Optional[Callable[[Any], None]] = None,
proxy_host: Optional[str] = None,
proxy_port: Optional[int] = None,
proxy_username: Optional[str] = None,
proxy_password: Optional[str] = None,
proxy_auth_mode: Optional[str] = None,
allow_nonstandard_methods: Optional[bool] = None,
validate_cert: Optional[bool] = None,
ca_certs: Optional[str] = None,
allow_ipv6: Optional[bool] = None,
client_key: Optional[str] = None,
client_cert: Optional[str] = None,
body_producer: Optional[
Callable[[Callable[[bytes], None]], "Future[None]"]
] = None,
headers: Union[Dict[str, str], httputil.HTTPHeaders] = None,
body: Union[bytes, str] = None,
auth_username: str = None,
auth_password: str = None,
auth_mode: str = None,
connect_timeout: float = None,
request_timeout: float = None,
if_modified_since: Union[float, datetime.datetime] = None,
follow_redirects: bool = None,
max_redirects: int = None,
user_agent: str = None,
use_gzip: bool = None,
network_interface: str = None,
streaming_callback: Callable[[bytes], None] = None,
header_callback: Callable[[str], None] = None,
prepare_curl_callback: Callable[[Any], None] = None,
proxy_host: str = None,
proxy_port: int = None,
proxy_username: str = None,
proxy_password: str = None,
proxy_auth_mode: str = None,
allow_nonstandard_methods: bool = None,
validate_cert: bool = None,
ca_certs: str = None,
allow_ipv6: bool = None,
client_key: str = None,
client_cert: str = None,
body_producer: Callable[[Callable[[bytes], None]], "Future[None]"] = None,
expect_100_continue: bool = False,
decompress_response: Optional[bool] = None,
ssl_options: Optional[Union[Dict[str, Any], ssl.SSLContext]] = None,
decompress_response: bool = None,
ssl_options: Union[Dict[str, Any], ssl.SSLContext] = None,
) -> None:
r"""All parameters except ``url`` are optional.
@ -506,7 +502,7 @@ class HTTPRequest(object):
"""
# Note that some of these attributes go through property setters
# defined below.
self.headers = headers # type: ignore
self.headers = headers
if if_modified_since:
self.headers["If-Modified-Since"] = httputil.format_timestamp(
if_modified_since
@ -518,7 +514,7 @@ class HTTPRequest(object):
self.proxy_auth_mode = proxy_auth_mode
self.url = url
self.method = method
self.body = body # type: ignore
self.body = body
self.body_producer = body_producer
self.auth_username = auth_username
self.auth_password = auth_password
@ -628,14 +624,14 @@ class HTTPResponse(object):
self,
request: HTTPRequest,
code: int,
headers: Optional[httputil.HTTPHeaders] = None,
buffer: Optional[BytesIO] = None,
effective_url: Optional[str] = None,
error: Optional[BaseException] = None,
request_time: Optional[float] = None,
time_info: Optional[Dict[str, float]] = None,
reason: Optional[str] = None,
start_time: Optional[float] = None,
headers: httputil.HTTPHeaders = None,
buffer: BytesIO = None,
effective_url: str = None,
error: BaseException = None,
request_time: float = None,
time_info: Dict[str, float] = None,
reason: str = None,
start_time: float = None,
) -> None:
if isinstance(request, _RequestProxy):
self.request = request.request
@ -707,10 +703,7 @@ class HTTPClientError(Exception):
"""
def __init__(
self,
code: int,
message: Optional[str] = None,
response: Optional[HTTPResponse] = None,
self, code: int, message: str = None, response: HTTPResponse = None
) -> None:
self.code = code
self.message = message or httputil.responses.get(code, "Unknown")

20
lib/tornado_py3/httpserver.py

@ -157,16 +157,16 @@ class HTTPServer(TCPServer, Configurable, httputil.HTTPServerConnectionDelegate)
],
no_keep_alive: bool = False,
xheaders: bool = False,
ssl_options: Optional[Union[Dict[str, Any], ssl.SSLContext]] = None,
protocol: Optional[str] = None,
ssl_options: Union[Dict[str, Any], ssl.SSLContext] = None,
protocol: str = None,
decompress_request: bool = False,
chunk_size: Optional[int] = None,
max_header_size: Optional[int] = None,
idle_connection_timeout: Optional[float] = None,
body_timeout: Optional[float] = None,
max_body_size: Optional[int] = None,
max_buffer_size: Optional[int] = None,
trusted_downstream: Optional[List[str]] = None,
chunk_size: int = None,
max_header_size: int = None,
idle_connection_timeout: float = None,
body_timeout: float = None,
max_body_size: int = None,
max_buffer_size: int = None,
trusted_downstream: List[str] = None,
) -> None:
# This method's signature is not extracted with autodoc
# because we want its arguments to appear on the class
@ -289,7 +289,7 @@ class _HTTPRequestContext(object):
stream: iostream.IOStream,
address: Tuple,
protocol: Optional[str],
trusted_downstream: Optional[List[str]] = None,
trusted_downstream: List[str] = None,
) -> None:
self.address = address
# Save the socket's address family now so we know how to

101
lib/tornado_py3/httputil.py

@ -24,7 +24,6 @@ import collections
import copy
import datetime
import email.utils
from functools import lru_cache
from http.client import responses
import http.cookies
import re
@ -63,14 +62,42 @@ if typing.TYPE_CHECKING:
import unittest # noqa: F401
@lru_cache(1000)
def _normalize_header(name: str) -> str:
"""Map a header name to Http-Header-Case.
# RFC 7230 section 3.5: a recipient MAY recognize a single LF as a line
# terminator and ignore any preceding CR.
_CRLF_RE = re.compile(r"\r?\n")
>>> _normalize_header("coNtent-TYPE")
class _NormalizedHeaderCache(dict):
"""Dynamic cached mapping of header names to Http-Header-Case.
Implemented as a dict subclass so that cache hits are as fast as a
normal dict lookup, without the overhead of a python function
call.
>>> normalized_headers = _NormalizedHeaderCache(10)
>>> normalized_headers["coNtent-TYPE"]
'Content-Type'
"""
return "-".join([w.capitalize() for w in name.split("-")])
def __init__(self, size: int) -> None:
super(_NormalizedHeaderCache, self).__init__()
self.size = size
self.queue = collections.deque() # type: Deque[str]
def __missing__(self, key: str) -> str:
normalized = "-".join([w.capitalize() for w in key.split("-")])
self[key] = normalized
self.queue.append(key)
if len(self.queue) > self.size:
# Limit the size of the cache. LRU would be better, but this
# simpler approach should be fine. In Python 2.7+ we could
# use OrderedDict (or in 3.2+, @functools.lru_cache).
old_key = self.queue.popleft()
del self[old_key]
return normalized
_normalized_headers = _NormalizedHeaderCache(1000)
class HTTPHeaders(collections.abc.MutableMapping):
@ -121,7 +148,7 @@ class HTTPHeaders(collections.abc.MutableMapping):
def __init__(self, *args: typing.Any, **kwargs: str) -> None: # noqa: F811
self._dict = {} # type: typing.Dict[str, str]
self._as_list = {} # type: typing.Dict[str, typing.List[str]]
self._last_key = None # type: Optional[str]
self._last_key = None
if len(args) == 1 and len(kwargs) == 0 and isinstance(args[0], HTTPHeaders):
# Copy constructor
for k, v in args[0].get_all():
@ -134,7 +161,7 @@ class HTTPHeaders(collections.abc.MutableMapping):
def add(self, name: str, value: str) -> None:
"""Adds a new value for the given key."""
norm_name = _normalize_header(name)
norm_name = _normalized_headers[name]
self._last_key = norm_name
if norm_name in self:
self._dict[norm_name] = (
@ -146,7 +173,7 @@ class HTTPHeaders(collections.abc.MutableMapping):
def get_list(self, name: str) -> List[str]:
"""Returns all values for the given header as a list."""
norm_name = _normalize_header(name)
norm_name = _normalized_headers[name]
return self._as_list.get(norm_name, [])
def get_all(self) -> Iterable[Tuple[str, str]]:
@ -196,11 +223,7 @@ class HTTPHeaders(collections.abc.MutableMapping):
"""
h = cls()
# RFC 7230 section 3.5: a recipient MAY recognize a single LF as a line
# terminator and ignore any preceding CR.
for line in headers.split("\n"):
if line.endswith("\r"):
line = line[:-1]
for line in _CRLF_RE.split(headers):
if line:
h.parse_line(line)
return h
@ -208,15 +231,15 @@ class HTTPHeaders(collections.abc.MutableMapping):
# MutableMapping abstract method implementations.
def __setitem__(self, name: str, value: str) -> None:
norm_name = _normalize_header(name)
norm_name = _normalized_headers[name]
self._dict[norm_name] = value
self._as_list[norm_name] = [value]
def __getitem__(self, name: str) -> str:
return self._dict[_normalize_header(name)]
return self._dict[_normalized_headers[name]]
def __delitem__(self, name: str) -> None:
norm_name = _normalize_header(name)
norm_name = _normalized_headers[name]
del self._dict[norm_name]
del self._as_list[norm_name]
@ -345,16 +368,16 @@ class HTTPServerRequest(object):
def __init__(
self,
method: Optional[str] = None,
uri: Optional[str] = None,
method: str = None,
uri: str = None,
version: str = "HTTP/1.0",
headers: Optional[HTTPHeaders] = None,
body: Optional[bytes] = None,
host: Optional[str] = None,
files: Optional[Dict[str, List["HTTPFile"]]] = None,
connection: Optional["HTTPConnection"] = None,
start_line: Optional["RequestStartLine"] = None,
server_connection: Optional[object] = None,
headers: HTTPHeaders = None,
body: bytes = None,
host: str = None,
files: Dict[str, List["HTTPFile"]] = None,
connection: "HTTPConnection" = None,
start_line: "RequestStartLine" = None,
server_connection: object = None,
) -> None:
if start_line is not None:
method, uri, version = start_line
@ -387,9 +410,7 @@ class HTTPServerRequest(object):
def cookies(self) -> Dict[str, http.cookies.Morsel]:
"""A dictionary of ``http.cookies.Morsel`` objects."""
if not hasattr(self, "_cookies"):
self._cookies = (
http.cookies.SimpleCookie()
) # type: http.cookies.SimpleCookie
self._cookies = http.cookies.SimpleCookie()
if "Cookie" in self.headers:
try:
parsed = parse_cookie(self.headers["Cookie"])
@ -570,7 +591,7 @@ class HTTPConnection(object):
self,
start_line: Union["RequestStartLine", "ResponseStartLine"],
headers: HTTPHeaders,
chunk: Optional[bytes] = None,
chunk: bytes = None,
) -> "Future[None]":
"""Write an HTTP header block.
@ -746,7 +767,7 @@ def parse_body_arguments(
body: bytes,
arguments: Dict[str, List[bytes]],
files: Dict[str, List[HTTPFile]],
headers: Optional[HTTPHeaders] = None,
headers: HTTPHeaders = None,
) -> None:
"""Parses a form request body.
@ -763,8 +784,7 @@ def parse_body_arguments(
)
return
try:
# real charset decoding will happen in RequestHandler.decode_argument()
uri_arguments = parse_qs_bytes(body, keep_blank_values=True)
uri_arguments = parse_qs_bytes(native_str(body), keep_blank_values=True)
except Exception as e:
gen_log.warning("Invalid x-www-form-urlencoded body: %s", e)
uri_arguments = {}
@ -876,9 +896,6 @@ RequestStartLine = collections.namedtuple(
)
_http_version_re = re.compile(r"^HTTP/1\.[0-9]$")
def parse_request_start_line(line: str) -> RequestStartLine:
"""Returns a (method, path, version) tuple for an HTTP 1.x request line.
@ -893,7 +910,7 @@ def parse_request_start_line(line: str) -> RequestStartLine:
# https://tools.ietf.org/html/rfc7230#section-3.1.1
# invalid request-line SHOULD respond with a 400 (Bad Request)
raise HTTPInputError("Malformed HTTP request line")
if not _http_version_re.match(version):
if not re.match(r"^HTTP/1\.[0-9]$", version):
raise HTTPInputError(
"Malformed HTTP version in HTTP Request-Line: %r" % version
)
@ -905,9 +922,6 @@ ResponseStartLine = collections.namedtuple(
)
_http_response_line_re = re.compile(r"(HTTP/1.[0-9]) ([0-9]+) ([^\r]*)")
def parse_response_start_line(line: str) -> ResponseStartLine:
"""Returns a (version, code, reason) tuple for an HTTP 1.x response line.
@ -917,7 +931,7 @@ def parse_response_start_line(line: str) -> ResponseStartLine:
ResponseStartLine(version='HTTP/1.1', code=200, reason='OK')
"""
line = native_str(line)
match = _http_response_line_re.match(line)
match = re.match("(HTTP/1.[0-9]) ([0-9]+) ([^\r]*)", line)
if not match:
raise HTTPInputError("Error parsing response start line")
return ResponseStartLine(match.group(1), int(match.group(2)), match.group(3))
@ -1022,9 +1036,6 @@ def doctests():
return doctest.DocTestSuite()
_netloc_re = re.compile(r"^(.+):(\d+)$")
def split_host_and_port(netloc: str) -> Tuple[str, Optional[int]]:
"""Returns ``(host, port)`` tuple from ``netloc``.
@ -1032,7 +1043,7 @@ def split_host_and_port(netloc: str) -> Tuple[str, Optional[int]]:
.. versionadded:: 4.1
"""
match = _netloc_re.match(netloc)
match = re.match(r"^(.+):(\d+)$", netloc)
if match:
host = match.group(1)
port = int(match.group(2)) # type: Optional[int]

18
lib/tornado_py3/ioloop.py

@ -90,7 +90,7 @@ class IOLoop(Configurable):
import socket
import tornado.ioloop
from tornado.iostream import IOStream
from tornado_py3.iostream import IOStream
async def handle_connection(connection, address):
stream = IOStream(connection)
@ -101,7 +101,9 @@ class IOLoop(Configurable):
while True:
try:
connection, address = sock.accept()
except BlockingIOError:
except socket.error as e:
if e.args[0] not in (errno.EWOULDBLOCK, errno.EAGAIN):
raise
return
connection.setblocking(0)
io_loop = tornado.ioloop.IOLoop.current()
@ -233,13 +235,13 @@ class IOLoop(Configurable):
def current() -> "IOLoop":
pass
@typing.overload
@typing.overload # noqa: F811
@staticmethod
def current(instance: bool = True) -> Optional["IOLoop"]: # noqa: F811
def current(instance: bool = True) -> Optional["IOLoop"]:
pass
@staticmethod
def current(instance: bool = True) -> Optional["IOLoop"]: # noqa: F811
@staticmethod # noqa: F811
def current(instance: bool = True) -> Optional["IOLoop"]:
"""Returns the current thread's `IOLoop`.
If an `IOLoop` is currently running or has been marked as
@ -327,7 +329,7 @@ class IOLoop(Configurable):
return AsyncIOLoop
def initialize(self, make_current: Optional[bool] = None) -> None:
def initialize(self, make_current: bool = None) -> None:
if make_current is None:
if IOLoop.current(instance=False) is None:
self.make_current()
@ -455,7 +457,7 @@ class IOLoop(Configurable):
"""
raise NotImplementedError()
def run_sync(self, func: Callable, timeout: Optional[float] = None) -> Any:
def run_sync(self, func: Callable, timeout: float = None) -> Any:
"""Starts the `IOLoop`, runs the given function, and stops the loop.
The function must return either an awaitable object or

122
lib/tornado_py3/iostream.py

@ -64,6 +64,14 @@ try:
except ImportError:
_set_nonblocking = None # type: ignore
# These errnos indicate that a non-blocking operation must be retried
# at a later time. On most platforms they're the same value, but on
# some they differ.
_ERRNO_WOULDBLOCK = (errno.EWOULDBLOCK, errno.EAGAIN)
if hasattr(errno, "WSAEWOULDBLOCK"):
_ERRNO_WOULDBLOCK += (errno.WSAEWOULDBLOCK,) # type: ignore
# These errnos indicate that a connection has been abruptly terminated.
# They should be caught and handled less noisily than other errors.
_ERRNO_CONNRESET = (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE, errno.ETIMEDOUT)
@ -83,6 +91,12 @@ if sys.platform == "darwin":
# instead of an unexpected error.
_ERRNO_CONNRESET += (errno.EPROTOTYPE,) # type: ignore
# More non-portable errnos:
_ERRNO_INPROGRESS = (errno.EINPROGRESS,)
if hasattr(errno, "WSAEINPROGRESS"):
_ERRNO_INPROGRESS += (errno.WSAEINPROGRESS,) # type: ignore
_WINDOWS = sys.platform.startswith("win")
@ -100,7 +114,7 @@ class StreamClosedError(IOError):
Added the ``real_error`` attribute.
"""
def __init__(self, real_error: Optional[BaseException] = None) -> None:
def __init__(self, real_error: BaseException = None) -> None:
super(StreamClosedError, self).__init__("Stream is closed")
self.real_error = real_error
@ -232,9 +246,9 @@ class BaseIOStream(object):
def __init__(
self,
max_buffer_size: Optional[int] = None,
read_chunk_size: Optional[int] = None,
max_write_buffer_size: Optional[int] = None,
max_buffer_size: int = None,
read_chunk_size: int = None,
max_write_buffer_size: int = None,
) -> None:
"""`BaseIOStream` constructor.
@ -332,9 +346,7 @@ class BaseIOStream(object):
"""
return None
def read_until_regex(
self, regex: bytes, max_bytes: Optional[int] = None
) -> Awaitable[bytes]:
def read_until_regex(self, regex: bytes, max_bytes: int = None) -> Awaitable[bytes]:
"""Asynchronously read until we have matched the given regex.
The result includes the data that matches the regex and anything
@ -371,9 +383,7 @@ class BaseIOStream(object):
raise
return future
def read_until(
self, delimiter: bytes, max_bytes: Optional[int] = None
) -> Awaitable[bytes]:
def read_until(self, delimiter: bytes, max_bytes: int = None) -> Awaitable[bytes]:
"""Asynchronously read until we have found the given delimiter.
The result includes all the data read including the delimiter.
@ -599,6 +609,15 @@ class BaseIOStream(object):
if self._read_until_close:
self._read_until_close = False
self._finish_read(self._read_buffer_size, False)
elif self._read_future is not None:
# resolve reads that are pending and ready to complete
try:
pos = self._find_read_pos()
except UnsatisfiableReadError:
pass
else:
if pos is not None:
self._read_from_buffer(pos)
if self._state is not None:
self.io_loop.remove_handler(self.fileno())
self._state = None
@ -786,8 +805,25 @@ class BaseIOStream(object):
self._read_from_buffer(pos)
def _start_read(self) -> Future:
self._check_closed() # Before reading, check that stream is not closed.
assert self._read_future is None, "Already reading"
if self._read_future is not None:
# It is an error to start a read while a prior read is unresolved.
# However, if the prior read is unresolved because the stream was
# closed without satisfying it, it's better to raise
# StreamClosedError instead of AssertionError. In particular, this
# situation occurs in harmless situations in http1connection.py and
# an AssertionError would be logged noisily.
#
# On the other hand, it is legal to start a new read while the
# stream is closed, in case the read can be satisfied from the
# read buffer. So we only want to check the closed status of the
# stream if we need to decide what kind of error to raise for
# "already reading".
#
# These conditions have proven difficult to test; we have no
# unittests that reliably verify this behavior so be careful
# when making changes here. See #2651 and #2719.
self._check_closed()
assert self._read_future is None, "Already reading"
self._read_future = Future()
return self._read_future
@ -847,6 +883,8 @@ class BaseIOStream(object):
buf = bytearray(self.read_chunk_size)
bytes_read = self.read_from_fd(buf)
except (socket.error, IOError, OSError) as e:
if errno_from_exception(e) == errno.EINTR:
continue
# ssl.SSLError is a subclass of socket.error
if self._is_connreset(e):
# Treat ECONNRESET as a connection close rather than
@ -954,16 +992,17 @@ class BaseIOStream(object):
break
self._write_buffer.advance(num_bytes)
self._total_write_done_index += num_bytes
except BlockingIOError:
break
except (socket.error, IOError, OSError) as e:
if not self._is_connreset(e):
# Broken pipe errors are usually caused by connection
# reset, and its better to not log EPIPE errors to
# minimize log spam
gen_log.warning("Write error on %s: %s", self.fileno(), e)
self.close(exc_info=e)
return
if e.args[0] in _ERRNO_WOULDBLOCK:
break
else:
if not self._is_connreset(e):
# Broken pipe errors are usually caused by connection
# reset, and its better to not log EPIPE errors to
# minimize log spam
gen_log.warning("Write error on %s: %s", self.fileno(), e)
self.close(exc_info=e)
return
while self._write_futures:
index, future = self._write_futures[0]
@ -1119,8 +1158,11 @@ class IOStream(BaseIOStream):
def read_from_fd(self, buf: Union[bytearray, memoryview]) -> Optional[int]:
try:
return self.socket.recv_into(buf, len(buf))
except BlockingIOError:
return None
except socket.error as e:
if e.args[0] in _ERRNO_WOULDBLOCK:
return None
else:
raise
finally:
del buf
@ -1133,7 +1175,7 @@ class IOStream(BaseIOStream):
del data
def connect(
self: _IOStreamType, address: Any, server_hostname: Optional[str] = None
self: _IOStreamType, address: tuple, server_hostname: str = None
) -> "Future[_IOStreamType]":
"""Connects the socket to a remote address without blocking.
@ -1184,27 +1226,32 @@ class IOStream(BaseIOStream):
self._connect_future = typing.cast("Future[IOStream]", future)
try:
self.socket.connect(address)
except BlockingIOError:
except socket.error as e:
# In non-blocking mode we expect connect() to raise an
# exception with EINPROGRESS or EWOULDBLOCK.
pass
except socket.error as e:
#
# On freebsd, other errors such as ECONNREFUSED may be
# returned immediately when attempting to connect to
# localhost, so handle them the same way as an error
# reported later in _handle_connect.
if future is None:
gen_log.warning("Connect error on fd %s: %s", self.socket.fileno(), e)
self.close(exc_info=e)
return future
if (
errno_from_exception(e) not in _ERRNO_INPROGRESS
and errno_from_exception(e) not in _ERRNO_WOULDBLOCK
):
if future is None:
gen_log.warning(
"Connect error on fd %s: %s", self.socket.fileno(), e
)
self.close(exc_info=e)
return future
self._add_io_state(self.io_loop.WRITE)
return future
def start_tls(
self,
server_side: bool,
ssl_options: Optional[Union[Dict[str, Any], ssl.SSLContext]] = None,
server_hostname: Optional[str] = None,
ssl_options: Union[Dict[str, Any], ssl.SSLContext] = None,
server_hostname: str = None,
) -> Awaitable["SSLIOStream"]:
"""Convert this `IOStream` to an `SSLIOStream`.
@ -1461,7 +1508,7 @@ class SSLIOStream(IOStream):
super(SSLIOStream, self)._handle_write()
def connect(
self, address: Tuple, server_hostname: Optional[str] = None
self, address: Tuple, server_hostname: str = None
) -> "Future[SSLIOStream]":
self._server_hostname = server_hostname
# Ignore the result of connect(). If it fails,
@ -1572,8 +1619,11 @@ class SSLIOStream(IOStream):
return None
else:
raise
except BlockingIOError:
return None
except socket.error as e:
if e.args[0] in _ERRNO_WOULDBLOCK:
return None
else:
raise
finally:
del buf

39
lib/tornado_py3/locale.py

@ -51,7 +51,7 @@ from tornado_py3.log import gen_log
from tornado_py3._locale_data import LOCALE_NAMES
from typing import Iterable, Any, Union, Dict, Optional
from typing import Iterable, Any, Union, Dict
_default_locale = "en_US"
_translations = {} # type: Dict[str, Any]
@ -88,7 +88,7 @@ def set_default_locale(code: str) -> None:
_supported_locales = frozenset(list(_translations.keys()) + [_default_locale])
def load_translations(directory: str, encoding: Optional[str] = None) -> None:
def load_translations(directory: str, encoding: str = None) -> None:
"""Loads translations from CSV files in a directory.
Translations are strings with optional Python-style named placeholders
@ -196,6 +196,8 @@ def load_gettext_translations(directory: str, domain: str) -> None:
msgfmt mydomain.po -o {directory}/pt_BR/LC_MESSAGES/mydomain.mo
"""
import gettext
global _translations
global _supported_locales
global _use_gettext
@ -304,10 +306,7 @@ class Locale(object):
]
def translate(
self,
message: str,
plural_message: Optional[str] = None,
count: Optional[int] = None,
self, message: str, plural_message: str = None, count: int = None
) -> str:
"""Returns the translation for the given message for this locale.
@ -319,11 +318,7 @@ class Locale(object):
raise NotImplementedError()
def pgettext(
self,
context: str,
message: str,
plural_message: Optional[str] = None,
count: Optional[int] = None,
self, context: str, message: str, plural_message: str = None, count: int = None
) -> str:
raise NotImplementedError()
@ -486,10 +481,7 @@ class CSVLocale(Locale):
super(CSVLocale, self).__init__(code)
def translate(
self,
message: str,
plural_message: Optional[str] = None,
count: Optional[int] = None,
self, message: str, plural_message: str = None, count: int = None
) -> str:
if plural_message is not None:
assert count is not None
@ -503,11 +495,7 @@ class CSVLocale(Locale):
return message_dict.get(message, message)
def pgettext(
self,
context: str,
message: str,
plural_message: Optional[str] = None,
count: Optional[int] = None,
self, context: str, message: str, plural_message: str = None, count: int = None
) -> str:
if self.translations:
gen_log.warning("pgettext is not supported by CSVLocale")
@ -525,10 +513,7 @@ class GettextLocale(Locale):
super(GettextLocale, self).__init__(code)
def translate(
self,
message: str,
plural_message: Optional[str] = None,
count: Optional[int] = None,
self, message: str, plural_message: str = None, count: int = None
) -> str:
if plural_message is not None:
assert count is not None
@ -537,11 +522,7 @@ class GettextLocale(Locale):
return self.gettext(message)
def pgettext(
self,
context: str,
message: str,
plural_message: Optional[str] = None,
count: Optional[int] = None,
self, context: str, message: str, plural_message: str = None, count: int = None
) -> str:
"""Allows to set context for translation, accepts plural forms.

41
lib/tornado_py3/locks.py

@ -13,6 +13,7 @@
# under the License.
import collections
from concurrent.futures import CancelledError
import datetime
import types
@ -60,9 +61,9 @@ class Condition(_TimeoutGarbageCollector):
.. testcode::
from tornado import gen
from tornado.ioloop import IOLoop
from tornado.locks import Condition
from tornado_py3 import gen
from tornado_py3.ioloop import IOLoop
from tornado_py3.locks import Condition
condition = Condition()
@ -120,9 +121,7 @@ class Condition(_TimeoutGarbageCollector):
result += " waiters[%s]" % len(self._waiters)
return result + ">"
def wait(
self, timeout: Optional[Union[float, datetime.timedelta]] = None
) -> Awaitable[bool]:
def wait(self, timeout: Union[float, datetime.timedelta] = None) -> Awaitable[bool]:
"""Wait for `.notify`.
Returns a `.Future` that resolves ``True`` if the condition is notified,
@ -169,9 +168,9 @@ class Event(object):
.. testcode::
from tornado import gen
from tornado.ioloop import IOLoop
from tornado.locks import Event
from tornado_py3 import gen
from tornado_py3.ioloop import IOLoop
from tornado_py3.locks import Event
event = Event()
@ -232,9 +231,7 @@ class Event(object):
"""
self._value = False
def wait(
self, timeout: Optional[Union[float, datetime.timedelta]] = None
) -> Awaitable[None]:
def wait(self, timeout: Union[float, datetime.timedelta] = None) -> Awaitable[None]:
"""Block until the internal flag is true.
Returns an awaitable, which raises `tornado.util.TimeoutError` after a
@ -249,7 +246,9 @@ class Event(object):
if timeout is None:
return fut
else:
timeout_fut = gen.with_timeout(timeout, fut)
timeout_fut = gen.with_timeout(
timeout, fut, quiet_exceptions=(CancelledError,)
)
# This is a slightly clumsy workaround for the fact that
# gen.with_timeout doesn't cancel its futures. Cancelling
# fut will remove it from the waiters list.
@ -298,9 +297,9 @@ class Semaphore(_TimeoutGarbageCollector):
from collections import deque
from tornado import gen
from tornado.ioloop import IOLoop
from tornado.concurrent import Future
from tornado_py3 import gen
from tornado_py3.ioloop import IOLoop
from tornado_py3.concurrent import Future
# Ensure reliable doctest output: resolve Futures one at a time.
futures_q = deque([Future() for _ in range(3)])
@ -319,9 +318,9 @@ class Semaphore(_TimeoutGarbageCollector):
.. testcode:: semaphore
from tornado import gen
from tornado.ioloop import IOLoop
from tornado.locks import Semaphore
from tornado_py3 import gen
from tornado_py3.ioloop import IOLoop
from tornado_py3.locks import Semaphore
sem = Semaphore(2)
@ -413,7 +412,7 @@ class Semaphore(_TimeoutGarbageCollector):
break
def acquire(
self, timeout: Optional[Union[float, datetime.timedelta]] = None
self, timeout: Union[float, datetime.timedelta] = None
) -> Awaitable[_ReleasingContextManager]:
"""Decrement the counter. Returns an awaitable.
@ -527,7 +526,7 @@ class Lock(object):
return "<%s _block=%s>" % (self.__class__.__name__, self._block)
def acquire(
self, timeout: Optional[Union[float, datetime.timedelta]] = None
self, timeout: Union[float, datetime.timedelta] = None
) -> Awaitable[_ReleasingContextManager]:
"""Attempt to lock. Returns an awaitable.

7
lib/tornado_py3/log.py

@ -44,7 +44,7 @@ try:
except ImportError:
curses = None # type: ignore
from typing import Dict, Any, cast, Optional
from typing import Dict, Any, cast
# Logger objects for internal tornado use
access_log = logging.getLogger("tornado.access")
@ -110,7 +110,6 @@ class LogFormatter(logging.Formatter):
logging.INFO: 2, # Green
logging.WARNING: 3, # Yellow
logging.ERROR: 1, # Red
logging.CRITICAL: 5, # Magenta
}
def __init__(
@ -208,9 +207,7 @@ class LogFormatter(logging.Formatter):
return formatted.replace("\n", "\n ")
def enable_pretty_logging(
options: Any = None, logger: Optional[logging.Logger] = None
) -> None:
def enable_pretty_logging(options: Any = None, logger: logging.Logger = None) -> None:
"""Turns on formatted logging output as configured.
This is called automatically by `tornado.options.parse_command_line`

67
lib/tornado_py3/netutil.py

@ -28,7 +28,11 @@ from tornado_py3.ioloop import IOLoop
from tornado_py3.platform.auto import set_close_exec
from tornado_py3.util import Configurable, errno_from_exception
from typing import List, Callable, Any, Type, Dict, Union, Tuple, Awaitable, Optional
import typing
from typing import List, Callable, Any, Type, Dict, Union, Tuple, Awaitable
if typing.TYPE_CHECKING:
from asyncio import Future # noqa: F401
# Note that the naming of ssl.Purpose is confusing; the purpose
# of a context is to authentiate the opposite side of the connection.
@ -49,16 +53,24 @@ u"foo".encode("idna")
# For undiagnosed reasons, 'latin1' codec may also need to be preloaded.
u"foo".encode("latin1")
# These errnos indicate that a non-blocking operation must be retried
# at a later time. On most platforms they're the same value, but on
# some they differ.
_ERRNO_WOULDBLOCK = (errno.EWOULDBLOCK, errno.EAGAIN)
if hasattr(errno, "WSAEWOULDBLOCK"):
_ERRNO_WOULDBLOCK += (errno.WSAEWOULDBLOCK,) # type: ignore
# Default backlog used when calling sock.listen()
_DEFAULT_BACKLOG = 128
def bind_sockets(
port: int,
address: Optional[str] = None,
address: str = None,
family: socket.AddressFamily = socket.AF_UNSPEC,
backlog: int = _DEFAULT_BACKLOG,
flags: Optional[int] = None,
flags: int = None,
reuse_port: bool = False,
) -> List[socket.socket]:
"""Creates listening sockets bound to the given port and address.
@ -159,29 +171,7 @@ def bind_sockets(
sockaddr = tuple([host, bound_port] + list(sockaddr[2:]))
sock.setblocking(False)
try:
sock.bind(sockaddr)
except OSError as e:
if (
errno_from_exception(e) == errno.EADDRNOTAVAIL
and address == "localhost"
and sockaddr[0] == "::1"
):
# On some systems (most notably docker with default
# configurations), ipv6 is partially disabled:
# socket.has_ipv6 is true, we can create AF_INET6
# sockets, and getaddrinfo("localhost", ...,
# AF_PASSIVE) resolves to ::1, but we get an error
# when binding.
#
# Swallow the error, but only for this specific case.
# If EADDRNOTAVAIL occurs in other situations, it
# might be a real problem like a typo in a
# configuration.
sock.close()
continue
else:
raise
sock.bind(sockaddr)
bound_port = sock.getsockname()[1]
sock.listen(backlog)
sockets.append(sock)
@ -213,8 +203,9 @@ if hasattr(socket, "AF_UNIX"):
sock.setblocking(False)
try:
st = os.stat(file)
except FileNotFoundError:
pass
except OSError as err:
if errno_from_exception(err) != errno.ENOENT:
raise
else:
if stat.S_ISSOCK(st.st_mode):
os.remove(file)
@ -267,15 +258,17 @@ def add_accept_handler(
return
try:
connection, address = sock.accept()
except BlockingIOError:
# EWOULDBLOCK indicates we have accepted every
except socket.error as e:
# _ERRNO_WOULDBLOCK indicate we have accepted every
# connection that is available.
return
except ConnectionAbortedError:
if errno_from_exception(e) in _ERRNO_WOULDBLOCK:
return
# ECONNABORTED indicates that there was a connection
# but it was closed while still in the accept queue.
# (observed on FreeBSD).
continue
if errno_from_exception(e) == errno.ECONNABORTED:
continue
raise
set_close_exec(connection.fileno())
callback(connection, address)
@ -387,7 +380,7 @@ def _resolve_addr(
results = []
for fam, socktype, proto, canonname, address in addrinfo:
results.append((fam, address))
return results # type: ignore
return results
class DefaultExecutorResolver(Resolver):
@ -424,9 +417,7 @@ class ExecutorResolver(Resolver):
"""
def initialize(
self,
executor: Optional[concurrent.futures.Executor] = None,
close_executor: bool = True,
self, executor: concurrent.futures.Executor = None, close_executor: bool = True
) -> None:
self.io_loop = IOLoop.current()
if executor is not None:
@ -600,7 +591,7 @@ def ssl_options_to_context(
def ssl_wrap_socket(
socket: socket.socket,
ssl_options: Union[Dict[str, Any], ssl.SSLContext],
server_hostname: Optional[str] = None,
server_hostname: str = None,
**kwargs: Any
) -> ssl.SSLSocket:
"""Returns an ``ssl.SSLSocket`` wrapping the given socket.

67
lib/tornado_py3/options.py

@ -28,7 +28,7 @@ generally at the top level of a module. The options are then
accessible as attributes of `tornado.options.options`::
# myapp/db.py
from tornado.options import define, options
from tornado_py3.options import define, options
define("mysql_host", default="127.0.0.1:3306", help="Main user DB")
define("memcache_hosts", default="127.0.0.1:11011", multiple=True,
@ -39,7 +39,7 @@ accessible as attributes of `tornado.options.options`::
...
# myapp/server.py
from tornado.options import define, options
from tornado_py3.options import define, options
define("port", default=8080, help="port to listen on")
@ -82,7 +82,7 @@ instances to define isolated sets of options, such as for subcommands.
alone so you can manage it yourself, either pass ``--logging=none``
on the command line or do the following to disable it in code::
from tornado.options import options, parse_command_line
from tornado_py3.options import options, parse_command_line
options.logging = None
parse_command_line()
@ -104,18 +104,11 @@ from tornado_py3.escape import _unicode, native_str
from tornado_py3.log import define_logging_options
from tornado_py3.util import basestring_type, exec_in
from typing import (
Any,
Iterator,
Iterable,
Tuple,
Set,
Dict,
Callable,
List,
TextIO,
Optional,
)
import typing
from typing import Any, Iterator, Iterable, Tuple, Set, Dict, Callable, List, TextIO
if typing.TYPE_CHECKING:
from typing import Optional # noqa: F401
class Error(Exception):
@ -189,7 +182,7 @@ class OptionParser(object):
Useful for copying options into Application settings::
from tornado.options import define, parse_command_line, options
from tornado_py3.options import define, parse_command_line, options
define('template_path', group='application')
define('static_path', group='application')
@ -218,12 +211,12 @@ class OptionParser(object):
self,
name: str,
default: Any = None,
type: Optional[type] = None,
help: Optional[str] = None,
metavar: Optional[str] = None,
type: type = None,
help: str = None,
metavar: str = None,
multiple: bool = False,
group: Optional[str] = None,
callback: Optional[Callable[[Any], None]] = None,
group: str = None,
callback: Callable[[Any], None] = None,
) -> None:
"""Defines a new command line option.
@ -302,7 +295,7 @@ class OptionParser(object):
self._options[normalized] = option
def parse_command_line(
self, args: Optional[List[str]] = None, final: bool = True
self, args: List[str] = None, final: bool = True
) -> List[str]:
"""Parses all options given on the command line (defaults to
`sys.argv`).
@ -424,7 +417,7 @@ class OptionParser(object):
if final:
self.run_parse_callbacks()
def print_help(self, file: Optional[TextIO] = None) -> None:
def print_help(self, file: TextIO = None) -> None:
"""Prints all the command line options to stderr (or another file)."""
if file is None:
file = sys.stderr
@ -525,13 +518,13 @@ class _Option(object):
self,
name: str,
default: Any = None,
type: Optional[type] = None,
help: Optional[str] = None,
metavar: Optional[str] = None,
type: type = None,
help: str = None,
metavar: str = None,
multiple: bool = False,
file_name: Optional[str] = None,
group_name: Optional[str] = None,
callback: Optional[Callable[[Any], None]] = None,
file_name: str = None,
group_name: str = None,
callback: Callable[[Any], None] = None,
) -> None:
if default is None and multiple:
default = []
@ -674,12 +667,12 @@ All defined options are available as attributes on this object.
def define(
name: str,
default: Any = None,
type: Optional[type] = None,
help: Optional[str] = None,
metavar: Optional[str] = None,
type: type = None,
help: str = None,
metavar: str = None,
multiple: bool = False,
group: Optional[str] = None,
callback: Optional[Callable[[Any], None]] = None,
group: str = None,
callback: Callable[[Any], None] = None,
) -> None:
"""Defines an option in the global namespace.
@ -697,9 +690,7 @@ def define(
)
def parse_command_line(
args: Optional[List[str]] = None, final: bool = True
) -> List[str]:
def parse_command_line(args: List[str] = None, final: bool = True) -> List[str]:
"""Parses global options from the command line.
See `OptionParser.parse_command_line`.
@ -715,7 +706,7 @@ def parse_config_file(path: str, final: bool = True) -> None:
return options.parse_config_file(path, final=final)
def print_help(file: Optional[TextIO] = None) -> None:
def print_help(file: TextIO = None) -> None:
"""Prints all the command line options to stderr (or another file).
See `OptionParser.print_help`.

2
lib/tornado_py3/platform/auto.py

@ -19,7 +19,7 @@ For each function or class described in `tornado.platform.interface`,
the appropriate platform-specific implementation exists in this module.
Most code that needs access to this functionality should do e.g.::
from tornado.platform.auto import set_close_exec
from tornado_py3.platform.auto import set_close_exec
"""
import os

35
lib/tornado_py3/platform/twisted.py

@ -1,3 +1,6 @@
# Author: Ovidiu Predescu
# Date: July 2011
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
@ -9,7 +12,13 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Bridges between the Twisted package and Tornado.
"""Bridges between the Twisted reactor and Tornado IOLoop.
This module lets you run applications and libraries written for
Twisted in a Tornado application. It can be used in two modes,
depending on which library's underlying event loop you want to use.
This module has been tested with Twisted versions 11.0.0 and newer.
"""
import socket
@ -104,30 +113,6 @@ class TwistedResolver(Resolver):
return result
def install() -> None:
"""Install ``AsyncioSelectorReactor`` as the default Twisted reactor.
.. deprecated:: 5.1
This function is provided for backwards compatibility; code
that does not require compatibility with older versions of
Tornado should use
``twisted.internet.asyncioreactor.install()`` directly.
.. versionchanged:: 6.0.3
In Tornado 5.x and before, this function installed a reactor
based on the Tornado ``IOLoop``. When that reactor
implementation was removed in Tornado 6.0.0, this function was
removed as well. It was restored in Tornado 6.0.3 using the
``asyncio`` reactor instead.
"""
from twisted.internet.asyncioreactor import install
install()
if hasattr(gen.convert_yielded, "register"):
@gen.convert_yielded.register(Deferred) # type: ignore

50
lib/tornado_py3/process.py

@ -17,6 +17,7 @@
the server into multiple processes and managing subprocesses.
"""
import errno
import os
import multiprocessing
import signal
@ -35,6 +36,7 @@ from tornado_py3 import ioloop
from tornado_py3.iostream import PipeIOStream
from tornado_py3.log import gen_log
from tornado_py3.platform.auto import set_close_exec
from tornado_py3.util import errno_from_exception
import typing
from typing import Tuple, Optional, Any, Callable
@ -55,7 +57,7 @@ def cpu_count() -> int:
except NotImplementedError:
pass
try:
return os.sysconf("SC_NPROCESSORS_CONF") # type: ignore
return os.sysconf("SC_NPROCESSORS_CONF")
except (AttributeError, ValueError):
pass
gen_log.error("Could not detect number of processors; assuming 1")
@ -87,9 +89,7 @@ def _pipe_cloexec() -> Tuple[int, int]:
_task_id = None
def fork_processes(
num_processes: Optional[int], max_restarts: Optional[int] = None
) -> int:
def fork_processes(num_processes: Optional[int], max_restarts: int = None) -> int:
"""Starts multiple worker processes.
If ``num_processes`` is None or <= 0, we detect the number of cores
@ -110,17 +110,12 @@ def fork_processes(
number between 0 and ``num_processes``. Processes that exit
abnormally (due to a signal or non-zero exit status) are restarted
with the same id (up to ``max_restarts`` times). In the parent
process, ``fork_processes`` calls ``sys.exit(0)`` after all child
processes have exited normally.
process, ``fork_processes`` returns None if all child processes
have exited normally, but will otherwise only exit by throwing an
exception.
max_restarts defaults to 100.
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:
max_restarts = 100
@ -149,7 +144,12 @@ def fork_processes(
return id
num_restarts = 0
while children:
pid, status = os.wait()
try:
pid, status = os.wait()
except OSError as e:
if errno_from_exception(e) == errno.EINTR:
continue
raise
if pid not in children:
continue
id = children.pop(pid)
@ -273,8 +273,6 @@ class Subprocess(object):
In many cases a close callback on the stdout or stderr streams
can be used as an alternative to an exit callback if the
signal handler is causing a problem.
Availability: Unix
"""
self._exit_callback = callback
Subprocess.initialize()
@ -296,8 +294,6 @@ class Subprocess(object):
to suppress this behavior and return the exit status without raising.
.. versionadded:: 4.2
Availability: Unix
"""
future = Future() # type: Future[int]
@ -325,8 +321,6 @@ class Subprocess(object):
.. versionchanged:: 5.0
The ``io_loop`` argument (deprecated since version 4.1) has been
removed.
Availability: Unix
"""
if cls._initialized:
return
@ -353,9 +347,10 @@ class Subprocess(object):
@classmethod
def _try_cleanup_process(cls, pid: int) -> None:
try:
ret_pid, status = os.waitpid(pid, os.WNOHANG) # type: ignore
except ChildProcessError:
return
ret_pid, status = os.waitpid(pid, os.WNOHANG)
except OSError as e:
if errno_from_exception(e) == errno.ECHILD:
return
if ret_pid == 0:
return
assert ret_pid == pid
@ -363,14 +358,11 @@ class Subprocess(object):
subproc.io_loop.add_callback_from_signal(subproc._set_returncode, status)
def _set_returncode(self, status: int) -> None:
if sys.platform == "win32":
self.returncode = -1
if os.WIFSIGNALED(status):
self.returncode = -os.WTERMSIG(status)
else:
if os.WIFSIGNALED(status):
self.returncode = -os.WTERMSIG(status)
else:
assert os.WIFEXITED(status)
self.returncode = os.WEXITSTATUS(status)
assert os.WIFEXITED(status)
self.returncode = os.WEXITSTATUS(status)
# We've taken over wait() duty from the subprocess.Popen
# object. If we don't inform it of the process's return code,
# it will log a warning at destruction in python 3.6+.

24
lib/tornado_py3/queues.py

@ -33,11 +33,11 @@ from tornado_py3 import gen, ioloop
from tornado_py3.concurrent import Future, future_set_result_unless_cancelled
from tornado_py3.locks import Event
from typing import Union, TypeVar, Generic, Awaitable, Optional
from typing import Union, TypeVar, Generic, Awaitable
import typing
if typing.TYPE_CHECKING:
from typing import Deque, Tuple, Any # noqa: F401
from typing import Deque, Tuple, List, Any # noqa: F401
_T = TypeVar("_T")
@ -85,9 +85,9 @@ class Queue(Generic[_T]):
.. testcode::
from tornado import gen
from tornado.ioloop import IOLoop
from tornado.queues import Queue
from tornado_py3 import gen
from tornado_py3.ioloop import IOLoop
from tornado_py3.queues import Queue
q = Queue(maxsize=2)
@ -184,7 +184,7 @@ class Queue(Generic[_T]):
return self.qsize() >= self.maxsize
def put(
self, item: _T, timeout: Optional[Union[float, datetime.timedelta]] = None
self, item: _T, timeout: Union[float, datetime.timedelta] = None
) -> "Future[None]":
"""Put an item into the queue, perhaps waiting until there is room.
@ -222,9 +222,7 @@ class Queue(Generic[_T]):
else:
self.__put_internal(item)
def get(
self, timeout: Optional[Union[float, datetime.timedelta]] = None
) -> Awaitable[_T]:
def get(self, timeout: Union[float, datetime.timedelta] = None) -> Awaitable[_T]:
"""Remove and return an item from the queue.
Returns an awaitable which resolves once an item is available, or raises
@ -289,9 +287,7 @@ class Queue(Generic[_T]):
if self._unfinished_tasks == 0:
self._finished.set()
def join(
self, timeout: Optional[Union[float, datetime.timedelta]] = None
) -> Awaitable[None]:
def join(self, timeout: Union[float, datetime.timedelta] = None) -> Awaitable[None]:
"""Block until all items in the queue are processed.
Returns an awaitable, which raises `tornado.util.TimeoutError` after a
@ -353,7 +349,7 @@ class PriorityQueue(Queue):
.. testcode::
from tornado.queues import PriorityQueue
from tornado_py3.queues import PriorityQueue
q = PriorityQueue()
q.put((1, 'medium-priority item'))
@ -386,7 +382,7 @@ class LifoQueue(Queue):
.. testcode::
from tornado.queues import LifoQueue
from tornado_py3.queues import LifoQueue
q = LifoQueue()
q.put(3)

20
lib/tornado_py3/routing.py

@ -300,7 +300,7 @@ _RuleList = List[
class RuleRouter(Router):
"""Rule-based router implementation."""
def __init__(self, rules: Optional[_RuleList] = None) -> None:
def __init__(self, rules: _RuleList = None) -> None:
"""Constructs a router from an ordered list of rules::
RuleRouter([
@ -409,7 +409,7 @@ class ReversibleRuleRouter(ReversibleRouter, RuleRouter):
in a rule's matcher (see `Matcher.reverse`).
"""
def __init__(self, rules: Optional[_RuleList] = None) -> None:
def __init__(self, rules: _RuleList = None) -> None:
self.named_rules = {} # type: Dict[str, Any]
super(ReversibleRuleRouter, self).__init__(rules)
@ -445,8 +445,8 @@ class Rule(object):
self,
matcher: "Matcher",
target: Any,
target_kwargs: Optional[Dict[str, Any]] = None,
name: Optional[str] = None,
target_kwargs: Dict[str, Any] = None,
name: str = None,
) -> None:
"""Constructs a Rule instance.
@ -627,13 +627,7 @@ class PathMatches(Matcher):
if ")" in fragment:
paren_loc = fragment.index(")")
if paren_loc >= 0:
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)
pieces.append("%s" + fragment[paren_loc + 1 :])
else:
try:
unescaped_fragment = re_unescape(fragment)
@ -658,8 +652,8 @@ class URLSpec(Rule):
self,
pattern: Union[str, Pattern],
handler: Any,
kwargs: Optional[Dict[str, Any]] = None,
name: Optional[str] = None,
kwargs: Dict[str, Any] = None,
name: str = None,
) -> None:
"""Parameters:

14
lib/tornado_py3/simple_httpclient.py

@ -89,12 +89,12 @@ class SimpleAsyncHTTPClient(AsyncHTTPClient):
def initialize( # type: ignore
self,
max_clients: int = 10,
hostname_mapping: Optional[Dict[str, str]] = None,
hostname_mapping: Dict[str, str] = None,
max_buffer_size: int = 104857600,
resolver: Optional[Resolver] = None,
defaults: Optional[Dict[str, Any]] = None,
max_header_size: Optional[int] = None,
max_body_size: Optional[int] = None,
resolver: Resolver = None,
defaults: Dict[str, Any] = None,
max_header_size: int = None,
max_body_size: int = None,
) -> None:
"""Creates a AsyncHTTPClient.
@ -226,7 +226,7 @@ class SimpleAsyncHTTPClient(AsyncHTTPClient):
self.io_loop.remove_timeout(timeout_handle)
del self.waiting[key]
def _on_timeout(self, key: object, info: Optional[str] = None) -> None:
def _on_timeout(self, key: object, info: str = None) -> None:
"""Timeout callback of request.
Construct a timeout HTTPResponse when a timeout occurs.
@ -471,7 +471,7 @@ class _HTTPConnection(httputil.HTTPMessageDelegate):
return ssl_ctx
return None
def _on_timeout(self, info: Optional[str] = None) -> None:
def _on_timeout(self, info: str = None) -> None:
"""Timeout callback of _HTTPConnection instance.
Raise a `HTTPTimeoutError` when a timeout occurs.

7
lib/tornado_py3/speedups.c

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

24
lib/tornado_py3/tcpclient.py

@ -30,7 +30,11 @@ from tornado_py3.netutil import Resolver
from tornado_py3.platform.auto import set_close_exec
from tornado_py3.gen import TimeoutError
from typing import Any, Union, Dict, Tuple, List, Callable, Iterator, Optional, Set
import typing
from typing import Any, Union, Dict, Tuple, List, Callable, Iterator
if typing.TYPE_CHECKING:
from typing import Optional, Set # noqa: F401
_INITIAL_CONNECT_TIMEOUT = 0.3
@ -101,7 +105,7 @@ class _Connector(object):
def start(
self,
timeout: float = _INITIAL_CONNECT_TIMEOUT,
connect_timeout: Optional[Union[float, datetime.timedelta]] = None,
connect_timeout: Union[float, datetime.timedelta] = None,
) -> "Future[Tuple[socket.AddressFamily, Any, IOStream]]":
self.try_connect(iter(self.primary_addrs))
self.set_timeout(timeout)
@ -203,7 +207,7 @@ class TCPClient(object):
The ``io_loop`` argument (deprecated since version 4.1) has been removed.
"""
def __init__(self, resolver: Optional[Resolver] = None) -> None:
def __init__(self, resolver: Resolver = None) -> None:
if resolver is not None:
self.resolver = resolver
self._own_resolver = False
@ -220,11 +224,11 @@ class TCPClient(object):
host: str,
port: int,
af: socket.AddressFamily = socket.AF_UNSPEC,
ssl_options: Optional[Union[Dict[str, Any], ssl.SSLContext]] = None,
max_buffer_size: Optional[int] = None,
source_ip: Optional[str] = None,
source_port: Optional[int] = None,
timeout: Optional[Union[float, datetime.timedelta]] = None,
ssl_options: Union[Dict[str, Any], ssl.SSLContext] = None,
max_buffer_size: int = None,
source_ip: str = None,
source_port: int = None,
timeout: Union[float, datetime.timedelta] = None,
) -> IOStream:
"""Connect to the given host and port.
@ -296,8 +300,8 @@ class TCPClient(object):
max_buffer_size: int,
af: socket.AddressFamily,
addr: Tuple,
source_ip: Optional[str] = None,
source_port: Optional[int] = None,
source_ip: str = None,
source_port: int = None,
) -> Tuple[IOStream, "Future[IOStream]"]:
# Always connect in plaintext; we'll convert to ssl if necessary
# after one connection has completed.

20
lib/tornado_py3/tcpserver.py

@ -41,9 +41,9 @@ class TCPServer(object):
To use `TCPServer`, define a subclass which overrides the `handle_stream`
method. For example, a simple echo server could be defined like this::
from tornado.tcpserver import TCPServer
from tornado.iostream import StreamClosedError
from tornado import gen
from tornado_py3.tcpserver import TCPServer
from tornado_py3.iostream import StreamClosedError
from tornado_py3 import gen
class EchoServer(TCPServer):
async def handle_stream(self, stream, address):
@ -107,9 +107,9 @@ class TCPServer(object):
def __init__(
self,
ssl_options: Optional[Union[Dict[str, Any], ssl.SSLContext]] = None,
max_buffer_size: Optional[int] = None,
read_chunk_size: Optional[int] = None,
ssl_options: Union[Dict[str, Any], ssl.SSLContext] = None,
max_buffer_size: int = None,
read_chunk_size: int = None,
) -> None:
self.ssl_options = ssl_options
self._sockets = {} # type: Dict[int, socket.socket]
@ -173,7 +173,7 @@ class TCPServer(object):
def bind(
self,
port: int,
address: Optional[str] = None,
address: str = None,
family: socket.AddressFamily = socket.AF_UNSPEC,
backlog: int = 128,
reuse_port: bool = False,
@ -209,9 +209,7 @@ class TCPServer(object):
else:
self._pending_sockets.extend(sockets)
def start(
self, num_processes: Optional[int] = 1, max_restarts: Optional[int] = None
) -> None:
def start(self, num_processes: Optional[int] = 1, max_restarts: int = None) -> None:
"""Starts this server in the `.IOLoop`.
By default, we run the server in this process and do not fork any
@ -231,8 +229,6 @@ class TCPServer(object):
When using multiple processes, no IOLoops can be created or
referenced until after the call to ``TCPServer.start(n)``.
Values of ``num_processes`` other than 1 are not supported on Windows.
The ``max_restarts`` argument is passed to `.fork_processes`.
.. versionchanged:: 6.0

34
lib/tornado_py3/template.py

@ -262,10 +262,10 @@ class Template(object):
self,
template_string: Union[str, bytes],
name: str = "<string>",
loader: Optional["BaseLoader"] = None,
loader: "BaseLoader" = None,
compress_whitespace: Union[bool, _UnsetMarker] = _UNSET,
autoescape: Optional[Union[str, _UnsetMarker]] = _UNSET,
whitespace: Optional[str] = None,
autoescape: Union[str, _UnsetMarker] = _UNSET,
whitespace: str = None,
) -> None:
"""Construct a Template.
@ -399,8 +399,8 @@ class BaseLoader(object):
def __init__(
self,
autoescape: str = _DEFAULT_AUTOESCAPE,
namespace: Optional[Dict[str, Any]] = None,
whitespace: Optional[str] = None,
namespace: Dict[str, Any] = None,
whitespace: str = None,
) -> None:
"""Construct a template loader.
@ -433,11 +433,11 @@ class BaseLoader(object):
with self.lock:
self.templates = {}
def resolve_path(self, name: str, parent_path: Optional[str] = None) -> str:
def resolve_path(self, name: str, parent_path: str = None) -> str:
"""Converts a possibly-relative path to absolute (used internally)."""
raise NotImplementedError()
def load(self, name: str, parent_path: Optional[str] = None) -> Template:
def load(self, name: str, parent_path: str = None) -> Template:
"""Loads a template."""
name = self.resolve_path(name, parent_path=parent_path)
with self.lock:
@ -457,7 +457,7 @@ class Loader(BaseLoader):
super(Loader, self).__init__(**kwargs)
self.root = os.path.abspath(root_directory)
def resolve_path(self, name: str, parent_path: Optional[str] = None) -> str:
def resolve_path(self, name: str, parent_path: str = None) -> str:
if (
parent_path
and not parent_path.startswith("<")
@ -485,7 +485,7 @@ class DictLoader(BaseLoader):
super(DictLoader, self).__init__(**kwargs)
self.dict = dict
def resolve_path(self, name: str, parent_path: Optional[str] = None) -> str:
def resolve_path(self, name: str, parent_path: str = None) -> str:
if (
parent_path
and not parent_path.startswith("<")
@ -707,9 +707,7 @@ class ParseError(Exception):
Added ``filename`` and ``lineno`` attributes.
"""
def __init__(
self, message: str, filename: Optional[str] = None, lineno: int = 0
) -> None:
def __init__(self, message: str, filename: str = None, lineno: int = 0) -> None:
self.message = message
# The names "filename" and "lineno" are chosen for consistency
# with python SyntaxError.
@ -764,9 +762,7 @@ class _CodeWriter(object):
return IncludeTemplate()
def write_line(
self, line: str, line_number: int, indent: Optional[int] = None
) -> None:
def write_line(self, line: str, line_number: int, indent: int = None) -> None:
if indent is None:
indent = self._indent
line_comment = " # %s:%d" % (self.current_template.name, line_number)
@ -786,7 +782,7 @@ class _TemplateReader(object):
self.line = 1
self.pos = 0
def find(self, needle: str, start: int = 0, end: Optional[int] = None) -> int:
def find(self, needle: str, start: int = 0, end: int = None) -> int:
assert start >= 0, start
pos = self.pos
start += pos
@ -800,7 +796,7 @@ class _TemplateReader(object):
index -= pos
return index
def consume(self, count: Optional[int] = None) -> str:
def consume(self, count: int = None) -> str:
if count is None:
count = len(self.text) - self.pos
newpos = self.pos + count
@ -847,8 +843,8 @@ def _format_code(code: str) -> str:
def _parse(
reader: _TemplateReader,
template: Template,
in_block: Optional[str] = None,
in_loop: Optional[str] = None,
in_block: str = None,
in_loop: str = None,
) -> _ChunkList:
body = _ChunkList([])
while True:

38
lib/tornado_py3/testing.py

@ -260,9 +260,7 @@ class AsyncTestCase(unittest.TestCase):
self.__failure = None
raise_exc_info(failure)
def run(
self, result: Optional[unittest.TestResult] = None
) -> Optional[unittest.TestResult]:
def run(self, result: unittest.TestResult = None) -> unittest.TestCase:
ret = super(AsyncTestCase, self).run(result)
# As a last resort, if an exception escaped super.run() and wasn't
# re-raised in tearDown, raise it here. This will cause the
@ -290,10 +288,8 @@ class AsyncTestCase(unittest.TestCase):
self.__stopped = True
def wait(
self,
condition: Optional[Callable[..., bool]] = None,
timeout: Optional[float] = None,
) -> Any:
self, condition: Callable[..., bool] = None, timeout: float = None
) -> None:
"""Runs the `.IOLoop` until stop is called or timeout has passed.
In the event of a timeout, an exception will be thrown. The
@ -512,7 +508,7 @@ class AsyncHTTPSTestCase(AsyncHTTPTestCase):
@typing.overload
def gen_test(
*, timeout: Optional[float] = None
*, timeout: float = None
) -> Callable[[Callable[..., Union[Generator, "Coroutine"]]], Callable[..., None]]:
pass
@ -523,8 +519,7 @@ def gen_test(func: Callable[..., Union[Generator, "Coroutine"]]) -> Callable[...
def gen_test( # noqa: F811
func: Optional[Callable[..., Union[Generator, "Coroutine"]]] = None,
timeout: Optional[float] = None,
func: Callable[..., Union[Generator, "Coroutine"]] = None, timeout: float = None
) -> Union[
Callable[..., None],
Callable[[Callable[..., Union[Generator, "Coroutine"]]], Callable[..., None]],
@ -657,7 +652,6 @@ class ExpectLog(logging.Filter):
logger: Union[logging.Logger, basestring_type],
regex: str,
required: bool = True,
level: Optional[int] = None,
) -> None:
"""Constructs an ExpectLog context manager.
@ -667,15 +661,6 @@ class ExpectLog(logging.Filter):
the specified logger that match this regex will be suppressed.
:param required: If true, an exception will be raised if the end of
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):
logger = logging.getLogger(logger)
@ -684,28 +669,17 @@ class ExpectLog(logging.Filter):
self.required = required
self.matched = False
self.logged_stack = False
self.level = level
self.orig_level = None # type: Optional[int]
def filter(self, record: logging.LogRecord) -> bool:
if record.exc_info:
self.logged_stack = True
message = record.getMessage()
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
return False
return True
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)
return self
@ -715,8 +689,6 @@ class ExpectLog(logging.Filter):
value: Optional[BaseException],
tb: Optional[TracebackType],
) -> None:
if self.orig_level is not None:
self.logger.setLevel(self.orig_level)
self.logger.removeFilter(self)
if not typ and self.required and not self.matched:
raise Exception("did not get expected log message")

4
lib/tornado_py3/util.py

@ -157,9 +157,7 @@ def import_object(name: str) -> Any:
raise ImportError("No module named %s" % parts[-1])
def exec_in(
code: Any, glob: Dict[str, Any], loc: Optional[Optional[Mapping[str, Any]]] = None
) -> None:
def exec_in(code: Any, glob: Dict[str, Any], loc: Mapping[str, Any] = None) -> None:
if isinstance(code, str):
# exec(string) inherits the caller's future imports; compile
# the string first to prevent that.

137
lib/tornado_py3/web.py

@ -340,7 +340,7 @@ class RequestHandler(object):
"""
pass
def set_status(self, status_code: int, reason: Optional[str] = None) -> None:
def set_status(self, status_code: int, reason: str = None) -> None:
"""Sets the status code for our response.
:arg int status_code: Response status code.
@ -424,14 +424,14 @@ class RequestHandler(object):
def get_argument(self, name: str, default: str, strip: bool = True) -> str:
pass
@overload
def get_argument( # noqa: F811
@overload # noqa: F811
def get_argument(
self, name: str, default: _ArgDefaultMarker = _ARG_DEFAULT, strip: bool = True
) -> str:
pass
@overload
def get_argument( # noqa: F811
@overload # noqa: F811
def get_argument(
self, name: str, default: None, strip: bool = True
) -> Optional[str]:
pass
@ -554,7 +554,7 @@ class RequestHandler(object):
values.append(s)
return values
def decode_argument(self, value: bytes, name: Optional[str] = None) -> str:
def decode_argument(self, value: bytes, name: str = None) -> str:
"""Decodes an argument from the request.
The argument has been percent-decoded and is now a byte string.
@ -580,7 +580,7 @@ class RequestHandler(object):
`self.request.cookies <.httputil.HTTPServerRequest.cookies>`."""
return self.request.cookies
def get_cookie(self, name: str, default: Optional[str] = None) -> Optional[str]:
def get_cookie(self, name: str, default: str = None) -> Optional[str]:
"""Returns the value of the request cookie with the given name.
If the named cookie is not present, returns ``default``.
@ -597,10 +597,10 @@ class RequestHandler(object):
self,
name: str,
value: Union[str, bytes],
domain: Optional[str] = None,
expires: Optional[Union[float, Tuple, datetime.datetime]] = None,
domain: str = None,
expires: Union[float, Tuple, datetime.datetime] = None,
path: str = "/",
expires_days: Optional[int] = None,
expires_days: int = None,
**kwargs: Any
) -> None:
"""Sets an outgoing cookie name/value with the given options.
@ -624,9 +624,7 @@ class RequestHandler(object):
# Don't let us accidentally inject bad stuff
raise ValueError("Invalid cookie %r: %r" % (name, value))
if not hasattr(self, "_new_cookie"):
self._new_cookie = (
http.cookies.SimpleCookie()
) # type: http.cookies.SimpleCookie
self._new_cookie = http.cookies.SimpleCookie()
if name in self._new_cookie:
del self._new_cookie[name]
self._new_cookie[name] = value
@ -650,9 +648,7 @@ class RequestHandler(object):
morsel[k] = v
def clear_cookie(
self, name: str, path: str = "/", domain: Optional[str] = None
) -> None:
def clear_cookie(self, name: str, path: str = "/", domain: str = None) -> None:
"""Deletes the cookie with the given name.
Due to limitations of the cookie protocol, you must pass the same
@ -666,7 +662,7 @@ class RequestHandler(object):
expires = datetime.datetime.utcnow() - datetime.timedelta(days=365)
self.set_cookie(name, value="", path=path, expires=expires, domain=domain)
def clear_all_cookies(self, path: str = "/", domain: Optional[str] = None) -> None:
def clear_all_cookies(self, path: str = "/", domain: str = None) -> None:
"""Deletes all the cookies the user sent with this request.
See `clear_cookie` for more information on the path and domain
@ -686,8 +682,8 @@ class RequestHandler(object):
self,
name: str,
value: Union[str, bytes],
expires_days: Optional[int] = 30,
version: Optional[int] = None,
expires_days: int = 30,
version: int = None,
**kwargs: Any
) -> None:
"""Signs and timestamps a cookie so it cannot be forged.
@ -701,7 +697,6 @@ class RequestHandler(object):
Note that the ``expires_days`` parameter sets the lifetime of the
cookie in the browser, but is independent of the ``max_age_days``
parameter to `get_secure_cookie`.
A value of None limits the lifetime to the current browser session.
Secure cookies may contain arbitrary byte values, not just unicode
strings (unlike regular cookies)
@ -722,7 +717,7 @@ class RequestHandler(object):
)
def create_signed_value(
self, name: str, value: Union[str, bytes], version: Optional[int] = None
self, name: str, value: Union[str, bytes], version: int = None
) -> bytes:
"""Signs and timestamps a string so it cannot be forged.
@ -750,9 +745,9 @@ class RequestHandler(object):
def get_secure_cookie(
self,
name: str,
value: Optional[str] = None,
value: str = None,
max_age_days: int = 31,
min_version: Optional[int] = None,
min_version: int = None,
) -> Optional[bytes]:
"""Returns the given signed cookie if it validates, or None.
@ -780,7 +775,7 @@ class RequestHandler(object):
)
def get_secure_cookie_key_version(
self, name: str, value: Optional[str] = None
self, name: str, value: str = None
) -> Optional[int]:
"""Returns the signing key version of the secure cookie.
@ -793,9 +788,7 @@ class RequestHandler(object):
return None
return get_signature_key_version(value)
def redirect(
self, url: str, permanent: bool = False, status: Optional[int] = None
) -> None:
def redirect(self, url: str, permanent: bool = False, status: int = None) -> None:
"""Sends a redirect to the given (optionally relative) URL.
If the ``status`` argument is specified, that value is used as the
@ -1058,6 +1051,12 @@ class RequestHandler(object):
def flush(self, include_footers: bool = False) -> "Future[None]":
"""Flushes the current output buffer to the network.
The ``callback`` argument, if given, can be used for flow control:
it will be run when all flushed data has been written to the socket.
Note that only one flush callback can be outstanding at a time;
if another flush occurs before the previous flush's callback
has been run, the previous callback will be discarded.
.. versionchanged:: 4.0
Now returns a `.Future` if no callback is given.
@ -1105,7 +1104,7 @@ class RequestHandler(object):
future.set_result(None)
return future
def finish(self, chunk: Optional[Union[str, bytes, dict]] = None) -> "Future[None]":
def finish(self, chunk: Union[str, bytes, dict] = None) -> "Future[None]":
"""Finishes this response, ending the HTTP request.
Passing a ``chunk`` to ``finish()`` is equivalent to passing that
@ -1138,11 +1137,13 @@ class RequestHandler(object):
if self.check_etag_header():
self._write_buffer = []
self.set_status(304)
if self._status_code in (204, 304) or (100 <= self._status_code < 200):
if self._status_code in (204, 304) or (
self._status_code >= 100 and self._status_code < 200
):
assert not self._write_buffer, (
"Cannot send body with %s" % self._status_code
)
self._clear_representation_headers()
self._clear_headers_for_304()
elif "Content-Length" not in self._headers:
content_length = sum(len(part) for part in self._write_buffer)
self.set_header("Content-Length", content_length)
@ -1543,9 +1544,7 @@ class RequestHandler(object):
+ '"/>'
)
def static_url(
self, path: str, include_host: Optional[bool] = None, **kwargs: Any
) -> str:
def static_url(self, path: str, include_host: bool = None, **kwargs: Any) -> str:
"""Returns a static URL for the given relative static file path.
This method requires you set the ``static_path`` setting in your
@ -1786,11 +1785,11 @@ class RequestHandler(object):
args = [value.status_code, self._request_summary()] + list(value.args)
gen_log.warning(format, *args)
else:
app_log.error(
app_log.error( # type: ignore
"Uncaught exception %s\n%r",
self._request_summary(),
self.request,
exc_info=(typ, value, tb), # type: ignore
exc_info=(typ, value, tb),
)
def _ui_module(self, name: str, module: Type["UIModule"]) -> Callable[..., str]:
@ -1807,13 +1806,21 @@ class RequestHandler(object):
def _ui_method(self, method: Callable[..., str]) -> Callable[..., str]:
return lambda *args, **kwargs: method(self, *args, **kwargs)
def _clear_representation_headers(self) -> None:
# 304 responses should not contain representation metadata
# headers (defined in
# https://tools.ietf.org/html/rfc7231#section-3.1)
def _clear_headers_for_304(self) -> None:
# 304 responses should not contain entity headers (defined in
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.1)
# not explicitly allowed by
# https://tools.ietf.org/html/rfc7232#section-4.1
headers = ["Content-Encoding", "Content-Language", "Content-Type"]
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
headers = [
"Allow",
"Content-Encoding",
"Content-Language",
"Content-Length",
"Content-MD5",
"Content-Range",
"Content-Type",
"Last-Modified",
]
for h in headers:
self.clear_header(h)
@ -1918,9 +1925,7 @@ class _ApplicationRouter(ReversibleRuleRouter):
`_ApplicationRouter` instance.
"""
def __init__(
self, application: "Application", rules: Optional[_RuleList] = None
) -> None:
def __init__(self, application: "Application", rules: _RuleList = None) -> None:
assert isinstance(application, Application)
self.application = application
super(_ApplicationRouter, self).__init__(rules)
@ -1929,8 +1934,8 @@ class _ApplicationRouter(ReversibleRuleRouter):
rule = super(_ApplicationRouter, self).process_rule(rule)
if isinstance(rule.target, (list, tuple)):
rule.target = _ApplicationRouter(
self.application, rule.target # type: ignore
rule.target = _ApplicationRouter( # type: ignore
self.application, rule.target
)
return rule
@ -2034,9 +2039,9 @@ class Application(ReversibleRouter):
def __init__(
self,
handlers: Optional[_RuleList] = None,
default_host: Optional[str] = None,
transforms: Optional[List[Type["OutputTransform"]]] = None,
handlers: _RuleList = None,
default_host: str = None,
transforms: List[Type["OutputTransform"]] = None,
**settings: Any
) -> None:
if transforms is None:
@ -2187,9 +2192,9 @@ class Application(ReversibleRouter):
self,
request: httputil.HTTPServerRequest,
target_class: Type[RequestHandler],
target_kwargs: Optional[Dict[str, Any]] = None,
path_args: Optional[List[bytes]] = None,
path_kwargs: Optional[Dict[str, bytes]] = None,
target_kwargs: Dict[str, Any] = None,
path_args: List[bytes] = None,
path_kwargs: Dict[str, bytes] = None,
) -> "_HandlerDelegate":
"""Returns `~.httputil.HTTPMessageDelegate` that can serve a request
for application and `RequestHandler` subclass.
@ -2356,11 +2361,7 @@ class HTTPError(Exception):
"""
def __init__(
self,
status_code: int = 500,
log_message: Optional[str] = None,
*args: Any,
**kwargs: Any
self, status_code: int = 500, log_message: str = None, *args: Any, **kwargs: Any
) -> None:
self.status_code = status_code
self.log_message = log_message
@ -2477,8 +2478,8 @@ class RedirectHandler(RequestHandler):
self._url = url
self._permanent = permanent
def get(self, *args: Any, **kwargs: Any) -> None:
to_url = self._url.format(*args, **kwargs)
def get(self, *args: Any) -> None:
to_url = self._url.format(*args)
if self.request.query_arguments:
# TODO: figure out typing for the next line.
to_url = httputil.url_concat(
@ -2560,7 +2561,7 @@ class StaticFileHandler(RequestHandler):
_static_hashes = {} # type: Dict[str, Optional[str]]
_lock = threading.Lock() # protects _static_hashes
def initialize(self, path: str, default_filename: Optional[str] = None) -> None:
def initialize(self, path: str, default_filename: str = None) -> None:
self.root = path
self.default_filename = default_filename
@ -2786,7 +2787,7 @@ class StaticFileHandler(RequestHandler):
@classmethod
def get_content(
cls, abspath: str, start: Optional[int] = None, end: Optional[int] = None
cls, abspath: str, start: int = None, end: int = None
) -> Generator[bytes, None, None]:
"""Retrieve the content of the requested resource which is located
at the given absolute path.
@ -2828,12 +2829,12 @@ class StaticFileHandler(RequestHandler):
"""Returns a version string for the resource at the given path.
This class method may be overridden by subclasses. The
default implementation is a SHA-512 hash of the file's contents.
default implementation is a hash of the file's contents.
.. versionadded:: 3.1
"""
data = cls.get_content(abspath)
hasher = hashlib.sha512()
hasher = hashlib.md5()
if isinstance(data, bytes):
hasher.update(data)
else:
@ -3350,9 +3351,9 @@ def create_signed_value(
secret: _CookieSecretTypes,
name: str,
value: Union[str, bytes],
version: Optional[int] = None,
clock: Optional[Callable[[], float]] = None,
key_version: Optional[int] = None,
version: int = None,
clock: Callable[[], float] = None,
key_version: int = None,
) -> bytes:
if version is None:
version = DEFAULT_SIGNED_VALUE_VERSION
@ -3441,8 +3442,8 @@ def decode_signed_value(
name: str,
value: Union[None, str, bytes],
max_age_days: int = 31,
clock: Optional[Callable[[], float]] = None,
min_version: Optional[int] = None,
clock: Callable[[], float] = None,
min_version: int = None,
) -> Optional[bytes]:
if clock is None:
clock = time.time

55
lib/tornado_py3/websocket.py

@ -77,7 +77,7 @@ if TYPE_CHECKING:
# the server side and WebSocketClientConnection on the client
# side.
def on_ws_connection_close(
self, close_code: Optional[int] = None, close_reason: Optional[str] = None
self, close_code: int = None, close_reason: str = None
) -> None:
pass
@ -122,10 +122,10 @@ class _DecompressTooLargeError(Exception):
class _WebSocketParams(object):
def __init__(
self,
ping_interval: Optional[float] = None,
ping_timeout: Optional[float] = None,
ping_interval: float = None,
ping_timeout: float = None,
max_message_size: int = _default_max_message_size,
compression_options: Optional[Dict[str, Any]] = None,
compression_options: Dict[str, Any] = None,
) -> None:
self.ping_interval = ping_interval
self.ping_timeout = ping_timeout
@ -280,6 +280,8 @@ class WebSocketHandler(tornado_py3.web.RequestHandler):
self.set_status(426, "Upgrade Required")
self.set_header("Sec-WebSocket-Version", "7, 8, 13")
stream = None
@property
def ping_interval(self) -> Optional[float]:
"""The interval for websocket keep-alive pings.
@ -466,7 +468,7 @@ class WebSocketHandler(tornado_py3.web.RequestHandler):
"""
pass
def close(self, code: Optional[int] = None, reason: Optional[str] = None) -> None:
def close(self, code: int = None, reason: str = None) -> None:
"""Closes this Web Socket.
Once the close handshake is successful the socket will be closed.
@ -569,7 +571,7 @@ class WebSocketHandler(tornado_py3.web.RequestHandler):
self._break_cycles()
def on_ws_connection_close(
self, close_code: Optional[int] = None, close_reason: Optional[str] = None
self, close_code: int = None, close_reason: str = None
) -> None:
self.close_code = close_code
self.close_reason = close_reason
@ -668,7 +670,7 @@ class WebSocketProtocol(abc.ABC):
self.close() # let the subclass cleanup
@abc.abstractmethod
def close(self, code: Optional[int] = None, reason: Optional[str] = None) -> None:
def close(self, code: int = None, reason: str = None) -> None:
raise NotImplementedError()
@abc.abstractmethod
@ -722,7 +724,7 @@ class _PerMessageDeflateCompressor(object):
self,
persistent: bool,
max_wbits: Optional[int],
compression_options: Optional[Dict[str, Any]] = None,
compression_options: Dict[str, Any] = None,
) -> None:
if max_wbits is None:
max_wbits = zlib.MAX_WBITS
@ -771,7 +773,7 @@ class _PerMessageDeflateDecompressor(object):
persistent: bool,
max_wbits: Optional[int],
max_message_size: int,
compression_options: Optional[Dict[str, Any]] = None,
compression_options: Dict[str, Any] = None,
) -> None:
self._max_message_size = max_message_size
if max_wbits is None:
@ -994,7 +996,7 @@ class WebSocketProtocol13(WebSocketProtocol):
self,
side: str,
agreed_parameters: Dict[str, Any],
compression_options: Optional[Dict[str, Any]] = None,
compression_options: Dict[str, Any] = None,
) -> Dict[str, Any]:
"""Converts a websocket agreed_parameters set to keyword arguments
for our compressor objects.
@ -1014,7 +1016,7 @@ class WebSocketProtocol13(WebSocketProtocol):
self,
side: str,
agreed_parameters: Dict[str, Any],
compression_options: Optional[Dict[str, Any]] = None,
compression_options: Dict[str, Any] = None,
) -> None:
# TODO: handle invalid parameters gracefully
allowed_keys = set(
@ -1257,7 +1259,7 @@ class WebSocketProtocol13(WebSocketProtocol):
self._abort()
return None
def close(self, code: Optional[int] = None, reason: Optional[str] = None) -> None:
def close(self, code: int = None, reason: str = None) -> None:
"""Closes the WebSocket connection."""
if not self.server_terminated:
if not self.stream.closed():
@ -1363,10 +1365,10 @@ class WebSocketClientConnection(simple_httpclient._HTTPConnection):
def __init__(
self,
request: httpclient.HTTPRequest,
on_message_callback: Optional[Callable[[Union[None, str, bytes]], None]] = None,
compression_options: Optional[Dict[str, Any]] = None,
ping_interval: Optional[float] = None,
ping_timeout: Optional[float] = None,
on_message_callback: Callable[[Union[None, str, bytes]], None] = None,
compression_options: Dict[str, Any] = None,
ping_interval: float = None,
ping_timeout: float = None,
max_message_size: int = _default_max_message_size,
subprotocols: Optional[List[str]] = [],
) -> None:
@ -1418,7 +1420,7 @@ class WebSocketClientConnection(simple_httpclient._HTTPConnection):
104857600,
)
def close(self, code: Optional[int] = None, reason: Optional[str] = None) -> None:
def close(self, code: int = None, reason: str = None) -> None:
"""Closes the websocket connection.
``code`` and ``reason`` are documented under
@ -1442,7 +1444,7 @@ class WebSocketClientConnection(simple_httpclient._HTTPConnection):
super(WebSocketClientConnection, self).on_connection_close()
def on_ws_connection_close(
self, close_code: Optional[int] = None, close_reason: Optional[str] = None
self, close_code: int = None, close_reason: str = None
) -> None:
self.close_code = close_code
self.close_reason = close_reason
@ -1504,8 +1506,7 @@ class WebSocketClientConnection(simple_httpclient._HTTPConnection):
return self.protocol.write_message(message, binary=binary)
def read_message(
self,
callback: Optional[Callable[["Future[Union[None, str, bytes]]"], None]] = None,
self, callback: Callable[["Future[Union[None, str, bytes]]"], None] = None
) -> Awaitable[Union[None, str, bytes]]:
"""Reads a message from the WebSocket server.
@ -1584,14 +1585,14 @@ class WebSocketClientConnection(simple_httpclient._HTTPConnection):
def websocket_connect(
url: Union[str, httpclient.HTTPRequest],
callback: Optional[Callable[["Future[WebSocketClientConnection]"], None]] = None,
connect_timeout: Optional[float] = None,
on_message_callback: Optional[Callable[[Union[None, str, bytes]], None]] = None,
compression_options: Optional[Dict[str, Any]] = None,
ping_interval: Optional[float] = None,
ping_timeout: Optional[float] = None,
callback: Callable[["Future[WebSocketClientConnection]"], None] = None,
connect_timeout: float = None,
on_message_callback: Callable[[Union[None, str, bytes]], None] = None,
compression_options: Dict[str, Any] = None,
ping_interval: float = None,
ping_timeout: float = None,
max_message_size: int = _default_max_message_size,
subprotocols: Optional[List[str]] = None,
subprotocols: List[str] = None,
) -> "Awaitable[WebSocketClientConnection]":
"""Client-side websocket support.

Loading…
Cancel
Save