Skip to content

Commit

Permalink
Merge branch 'master' into aiohttptestcase
Browse files Browse the repository at this point in the history
  • Loading branch information
WisdomPill committed Oct 21, 2020
2 parents e33f705 + d321923 commit 0de17e9
Show file tree
Hide file tree
Showing 37 changed files with 259 additions and 214 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/autosquash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.repository == 'aio-libs/aiohttp' }} # not awailable for forks, skip the workflow
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- id: generate_token
uses: tibdex/github-app-token@v1
with:
Expand Down
1 change: 1 addition & 0 deletions CHANGES/4850.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't ceil timeouts that are smaller than 5 seconds.
1 change: 1 addition & 0 deletions CHANGES/4972.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix inconsistency between Python and C http request parsers in parsing pct-encoded URL.
1 change: 1 addition & 0 deletions CHANGES/5075.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Multidict > 5 is now supported
1 change: 1 addition & 0 deletions CHANGES/5084.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add aiohttp-sse-client library to third party usage list.
1 change: 1 addition & 0 deletions CHANGES/5086.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix type hint on BaseRunner.addresses (from List[str] to List[Any])
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ Sergey Ninua
Sergey Skripnick
Serhii Charykov
Serhii Kostel
Serhiy Storchaka
Simon Kennedy
Sin-Woo Bang
Stanislas Plum
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/_http_parser.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ cdef _parse_url(char* buf_data, size_t length):

return URL_build(scheme=schema,
user=user, password=password, host=host, port=port,
path=path, query=query, fragment=fragment)
path=path, query_string=query, fragment=fragment, encoded=True)
else:
raise InvalidURLError("invalid url {!r}".format(buf_data))
finally:
Expand Down
4 changes: 2 additions & 2 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ async def _request(
data: Any=None,
json: Any=None,
cookies: Optional[LooseCookies]=None,
headers: LooseHeaders=None,
headers: Optional[LooseHeaders]=None,
skip_auto_headers: Optional[Iterable[str]]=None,
auth: Optional[BasicAuth]=None,
allow_redirects: bool=True,
Expand Down Expand Up @@ -1089,7 +1089,7 @@ def request(
params: Optional[Mapping[str, str]]=None,
data: Any=None,
json: Any=None,
headers: LooseHeaders=None,
headers: Optional[LooseHeaders]=None,
skip_auto_headers: Optional[Iterable[str]]=None,
auth: Optional[BasicAuth]=None,
allow_redirects: bool=True,
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/client_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def set_parser(self, parser: Any, payload: Any) -> None:
data, self._tail = self._tail, b''
self.data_received(data)

def set_response_params(self, *, timer: BaseTimerContext=None,
def set_response_params(self, *, timer: Optional[BaseTimerContext]=None,
skip_payload: bool=False,
read_until_eof: bool=False,
auto_decompress: bool=True,
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ async def text(self,

return self._body.decode(encoding, errors=errors) # type: ignore

async def json(self, *, encoding: str=None,
async def json(self, *, encoding: Optional[str]=None,
loads: JSONDecoder=DEFAULT_JSON_DECODER,
content_type: Optional[str]='application/json') -> Any:
"""Read and decodes JSON response."""
Expand Down
24 changes: 16 additions & 8 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,18 +515,20 @@ def _weakref_handle(info): # type: ignore
getattr(ob, name)()


def weakref_handle(ob, name, timeout, loop, ceil_timeout=True): # type: ignore
def weakref_handle(ob, name, timeout, loop): # type: ignore
if timeout is not None and timeout > 0:
when = loop.time() + timeout
if ceil_timeout:
if timeout >= 5:
when = ceil(when)

return loop.call_at(when, _weakref_handle, (weakref.ref(ob), name))


def call_later(cb, timeout, loop): # type: ignore
if timeout is not None and timeout > 0:
when = ceil(loop.time() + timeout)
when = loop.time() + timeout
if timeout > 5:
when = ceil(when)
return loop.call_at(when, cb)


Expand All @@ -548,9 +550,12 @@ def close(self) -> None:
self._callbacks.clear()

def start(self) -> Optional[asyncio.Handle]:
if self._timeout is not None and self._timeout > 0:
at = ceil(self._loop.time() + self._timeout)
return self._loop.call_at(at, self.__call__)
timeout = self._timeout
if timeout is not None and timeout > 0:
when = self._loop.time() + timeout
if timeout >= 5:
when = ceil(when)
return self._loop.call_at(when, self.__call__)
else:
return None

Expand Down Expand Up @@ -626,10 +631,13 @@ def timeout(self) -> None:


def ceil_timeout(delay: Optional[float]) -> async_timeout.Timeout:
if delay is not None:
if delay is not None and delay > 0:
loop = get_running_loop()
now = loop.time()
return async_timeout.timeout_at(ceil(now + delay))
when = now + delay
if delay > 5:
when = ceil(when)
return async_timeout.timeout_at(when)
else:
return async_timeout.timeout(None)

Expand Down
29 changes: 1 addition & 28 deletions aiohttp/tcp_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
from contextlib import suppress
from typing import Optional # noqa

__all__ = ('tcp_keepalive', 'tcp_nodelay', 'tcp_cork')


if hasattr(socket, 'TCP_CORK'): # pragma: no cover
CORK = socket.TCP_CORK # type: Optional[int]
elif hasattr(socket, 'TCP_NOPUSH'): # pragma: no cover
CORK = socket.TCP_NOPUSH # type: ignore
else: # pragma: no cover
CORK = None
__all__ = ('tcp_keepalive', 'tcp_nodelay')


if hasattr(socket, 'SO_KEEPALIVE'):
Expand Down Expand Up @@ -42,22 +34,3 @@ def tcp_nodelay(transport: asyncio.Transport, value: bool) -> None:
with suppress(OSError):
sock.setsockopt(
socket.IPPROTO_TCP, socket.TCP_NODELAY, value)


def tcp_cork(transport: asyncio.Transport, value: bool) -> None:
sock = transport.get_extra_info('socket')

if CORK is None:
return

if sock is None:
return

if sock.family not in (socket.AF_INET, socket.AF_INET6):
return

value = bool(value)

with suppress(OSError):
sock.setsockopt(
socket.IPPROTO_TCP, CORK, value)
4 changes: 2 additions & 2 deletions aiohttp/tracing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from types import SimpleNamespace
from typing import TYPE_CHECKING, Awaitable, Type, TypeVar
from typing import TYPE_CHECKING, Awaitable, Optional, Type, TypeVar

import attr
from multidict import CIMultiDict # noqa
Expand Down Expand Up @@ -92,7 +92,7 @@ def __init__(

def trace_config_ctx(
self,
trace_request_ctx: SimpleNamespace=None
trace_request_ctx: Optional[SimpleNamespace]=None
) -> SimpleNamespace: # noqa
""" Return a new trace_config_ctx instance """
return self._trace_config_ctx_factory(
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Application(MutableMapping[str, Any]):
def __init__(self, *,
logger: logging.Logger=web_logger,
middlewares: Iterable[_Middleware]=(),
handler_args: Mapping[str, Any]=None,
handler_args: Optional[Mapping[str, Any]]=None,
client_max_size: int=1024**2,
debug: Any=... # mypy doesn't support ellipsis
) -> None:
Expand Down
8 changes: 4 additions & 4 deletions aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def __init__(self, *,
content_type: Optional[str]=None,
charset: Optional[str]=None,
zlib_executor_size: Optional[int]=None,
zlib_executor: Executor=None) -> None:
zlib_executor: Optional[Executor]=None) -> None:
if body is not None and text is not None:
raise ValueError("body and text are not allowed together")

Expand Down Expand Up @@ -716,11 +716,11 @@ async def _do_start_compression(self, coding: ContentCoding) -> None:


def json_response(data: Any=sentinel, *,
text: str=None,
body: bytes=None,
text: Optional[str]=None,
body: Optional[bytes]=None,
status: int=200,
reason: Optional[str]=None,
headers: LooseHeaders=None,
headers: Optional[LooseHeaders]=None,
content_type: str='application/json',
dumps: JSONEncoder=json.dumps) -> Response:
if data is not sentinel:
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_routedef.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __repr__(self) -> str:
def register(self, router: UrlDispatcher) -> List[AbstractRoute]:
resource = router.add_static(self.prefix, self.path, **self.kwargs)
routes = resource.get_info().get('routes', {})
return routes.values()
return list(routes.values())


def route(method: str, path: str, handler: _HandlerType,
Expand Down
6 changes: 3 additions & 3 deletions aiohttp/web_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class TCPSite(BaseSite):
__slots__ = ('_host', '_port', '_reuse_address', '_reuse_port')

def __init__(self, runner: 'BaseRunner',
host: str=None, port: int=None, *,
host: Optional[str]=None, port: Optional[int]=None, *,
shutdown_timeout: float=60.0,
ssl_context: Optional[SSLContext]=None,
backlog: int=128, reuse_address: Optional[bool]=None,
Expand Down Expand Up @@ -209,8 +209,8 @@ def server(self) -> Optional[Server]:
return self._server

@property
def addresses(self) -> List[str]:
ret = [] # type: List[str]
def addresses(self) -> List[Any]:
ret = [] # type: List[Any]
for site in self._sites:
server = site._server
if server is not None:
Expand Down

0 comments on commit 0de17e9

Please sign in to comment.