Skip to content

Commit

Permalink
Merge branch 'master' into misc/app-configure-timeout-ceil-threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Dec 6, 2021
2 parents dc18609 + 674948f commit 5c6c3fd
Show file tree
Hide file tree
Showing 21 changed files with 165 additions and 54 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
with:
python-version: 3.8
- name: Cache PyPI
uses: actions/[email protected].6
uses: actions/[email protected].7
with:
key: pip-lint-${{ hashFiles('requirements/*.txt') }}
path: ~/.cache/pip
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
twine check --strict dist/*
- name: Making sure that CONTRIBUTORS.txt remains sorted
run: |
LC_ALL=C sort -c CONTRIBUTORS.txt
LC_ALL=C sort --check --ignore-case CONTRIBUTORS.txt
gen_llhttp:
name: Generate llhttp sources
Expand All @@ -87,7 +87,7 @@ jobs:
with:
submodules: true
- name: Cache llhttp generated files
uses: actions/cache@v2
uses: actions/cache@v2.1.7
id: cache
with:
key: llhttp-${{ hashFiles('vendor/llhttp/package.json', 'vendor/llhttp/src/**/*') }}
Expand Down Expand Up @@ -146,7 +146,7 @@ jobs:
run: |
echo "::set-output name=dir::$(pip cache dir)" # - name: Cache
- name: Cache PyPI
uses: actions/[email protected].6
uses: actions/[email protected].7
with:
key: pip-ci-${{ runner.os }}-${{ matrix.pyver }}-${{ matrix.no-extensions }}-${{ hashFiles('requirements/*.txt') }}
path: ${{ steps.pip-cache.outputs.dir }}
Expand Down Expand Up @@ -183,16 +183,18 @@ jobs:
fail_ci_if_error: false

check: # This job does nothing and is only used for the branch protection
if: always()

needs:
- test

runs-on: ubuntu-latest

steps:
- name: Report success of the test matrix
run: >-
print("All's good")
shell: python
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}

pre-deploy:
name: Pre-Deploy
Expand Down Expand Up @@ -291,7 +293,7 @@ jobs:
run: |
make cythonize
- name: Build wheels
uses: pypa/cibuildwheel@v2.2.2
uses: pypa/cibuildwheel@v2.3.0
env:
CIBW_ARCHS_MACOS: x86_64 arm64 universal2
- uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -324,7 +326,7 @@ jobs:
run: |
tree dist
- name: Make Release
uses: aio-libs/create-release@v1.2.3
uses: aio-libs/create-release@v1.3.1
with:
changes_file: CHANGES.rst
name: aiohttp
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/post-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
- name: Cache PyPI
uses: actions/[email protected].6
uses: actions/[email protected].7
with:
key: post-update-${{ hashFiles('requirements/*.txt') }}
path: ~/.cache/pip
Expand Down
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: '21.10b0'
rev: '21.11b1'
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.6+
Expand All @@ -49,6 +49,7 @@ repos:
^requirements/constraints[.]txt$
- id: trailing-whitespace
- id: file-contents-sorter
args: ['--ignore-case']
files: |
CONTRIBUTORS.txt|
docs/spelling_wordlist.txt|
Expand All @@ -71,7 +72,7 @@ repos:
- id: detect-private-key
exclude: ^examples/
- repo: https://github.com/asottile/pyupgrade
rev: 'v2.29.0'
rev: 'v2.29.1'
hooks:
- id: pyupgrade
args: ['--py36-plus']
Expand Down
1 change: 1 addition & 0 deletions CHANGES/4137.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added clarification on configuring the app object with settings such as a db connection.
1 change: 1 addition & 0 deletions CHANGES/5704.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A new argument ``client_max_size`` was added to ``BaseRequest.clone`` method to allow overriding the request body size -- :user:`anesabml`.
1 change: 1 addition & 0 deletions CHANGES/6345.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use str.partition() instead of .split() with a limit and a check.
3 changes: 3 additions & 0 deletions CHANGES/6369.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed the CI check used in the branch protection to gate merging PR, now
broken pull requests from ``Dependabot`` and others are not auto-merged
silently anymore -- :user:`webknjaz`.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ Willem de Groot
William Grzybowski
William S.
Wilson Ong
wouter bolsterlee
Yang Zhou
Yannick Koechlin
Yannick Péroux
Expand Down
14 changes: 3 additions & 11 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,23 +322,15 @@ def parse_mimetype(mimetype: str) -> MimeType:
for item in parts[1:]:
if not item:
continue
key, value = cast(
Tuple[str, str], item.split("=", 1) if "=" in item else (item, "")
)
key, _, value = item.partition("=")
params.add(key.lower().strip(), value.strip(' "'))

fulltype = parts[0].strip().lower()
if fulltype == "*":
fulltype = "*/*"

mtype, stype = (
cast(Tuple[str, str], fulltype.split("/", 1))
if "/" in fulltype
else (fulltype, "")
)
stype, suffix = (
cast(Tuple[str, str], stype.split("+", 1)) if "+" in stype else (stype, "")
)
mtype, _, stype = fulltype.partition("/")
stype, _, suffix = stype.partition("+")

return MimeType(
type=mtype, subtype=stype, suffix=suffix, parameters=MultiDictProxy(params)
Expand Down
11 changes: 10 additions & 1 deletion aiohttp/web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def clone(
scheme: Union[str, _SENTINEL] = sentinel,
host: Union[str, _SENTINEL] = sentinel,
remote: Union[str, _SENTINEL] = sentinel,
client_max_size: Union[int, _SENTINEL] = sentinel,
) -> "BaseRequest":
"""Clone itself with replacement some attributes.
Expand Down Expand Up @@ -239,6 +240,8 @@ def clone(
kwargs["host"] = host
if remote is not sentinel:
kwargs["remote"] = remote
if client_max_size is sentinel:
client_max_size = self._client_max_size

return self.__class__(
message,
Expand All @@ -247,7 +250,7 @@ def clone(
self._payload_writer,
self._task,
self._loop,
client_max_size=self._client_max_size,
client_max_size=client_max_size,
state=self._state.copy(),
**kwargs,
)
Expand All @@ -270,6 +273,10 @@ def transport(self) -> Optional[asyncio.Transport]:
def writer(self) -> AbstractStreamWriter:
return self._payload_writer

@property
def client_max_size(self) -> int:
return self._client_max_size

@reify
def rel_url(self) -> URL:
return self._rel_url
Expand Down Expand Up @@ -852,6 +859,7 @@ def clone(
scheme: Union[str, _SENTINEL] = sentinel,
host: Union[str, _SENTINEL] = sentinel,
remote: Union[str, _SENTINEL] = sentinel,
client_max_size: Union[int, _SENTINEL] = sentinel,
) -> "Request":
ret = super().clone(
method=method,
Expand All @@ -860,6 +868,7 @@ def clone(
scheme=scheme,
host=host,
remote=remote,
client_max_size=client_max_size,
)
new_ret = cast(Request, ret)
new_ret._match_info = self._match_info
Expand Down
2 changes: 1 addition & 1 deletion docs/client_quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Now, let's try to get a web-page. For example let's query
print(resp.status)
print(await resp.text())

asyncio.run(main)
asyncio.run(main())

Now, we have a :class:`ClientSession` called ``session`` and a
:class:`ClientResponse` object called ``resp``. We can get all the
Expand Down
17 changes: 14 additions & 3 deletions docs/web_advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ Data Sharing aka No Singletons Please
:mod:`aiohttp.web` discourages the use of *global variables*, aka *singletons*.
Every variable should have its own context that is *not global*.

Global variables are generally considered bad practice due to the complexity
they add in keeping track of state changes to variables.

*aiohttp* does not use globals by design, which will reduce the number of bugs
and/or unexpected behaviors for its users. For example, an i18n translated string
being written for one request and then being served to another.

So, :class:`Application` and :class:`Request`
support a :class:`collections.abc.MutableMapping` interface (i.e. they are
dict-like objects), allowing them to be used as data stores.
Expand Down Expand Up @@ -271,6 +278,10 @@ For this please use :attr:`Request.config_dict` read-only property::
async def handler(request):
data = request.config_dict['my_private_key']

The app object can be used in this way to reuse a database connection or anything
else needed throughout the application.

See this reference section for more detail: :ref:`aiohttp-web-app-and-router`.

Request's storage
^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -993,9 +1004,9 @@ headers too, pushing non-trusted data values.
That's why *aiohttp server* should setup *forwarded* headers in custom
middleware in tight conjunction with *reverse proxy configuration*.

For changing :attr:`BaseRequest.scheme` :attr:`BaseRequest.host` and
:attr:`BaseRequest.remote` the middleware might use
:meth:`BaseRequest.clone`.
For changing :attr:`BaseRequest.scheme` :attr:`BaseRequest.host`
:attr:`BaseRequest.remote` and :attr:`BaseRequest.client_max_size`
the middleware might use :meth:`BaseRequest.clone`.

.. seealso::

Expand Down
8 changes: 8 additions & 0 deletions docs/web_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ and :ref:`aiohttp-web-signals` handlers.

.. seealso:: :ref:`aiohttp-web-forwarded-support`

.. attribute:: client_max_size

The maximum size of the request body.

The value could be overridden by :meth:`~BaseRequest.clone`.

Read-only :class:`int` property.

.. attribute:: path_qs

The URL including PATH_INFO and the query string. e.g.,
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async-timeout==4.0.1
asynctest==0.13.0; python_version<"3.8"
Brotli==1.0.9
cchardet==2.1.7
charset-normalizer==2.0.7
charset-normalizer==2.0.8
frozenlist==1.2.0
gunicorn==20.1.0
uvloop==0.14.0; platform_system!="Windows" and implementation_name=="cpython" and python_version<"3.9" # MagicStack/uvloop#14
Expand Down
15 changes: 7 additions & 8 deletions requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cffi==1.15.0
# pycares
cfgv==3.3.1
# via pre-commit
charset-normalizer==2.0.7
charset-normalizer==2.0.8
# via
# -r requirements/base.txt
# requests
Expand All @@ -46,11 +46,11 @@ click==8.0.3
# wait-for-it
click-default-group==1.2.2
# via towncrier
coverage==6.1.2
coverage==6.2
# via
# -r requirements/test.txt
# pytest-cov
cryptography==35.0.0 ; platform_machine != "i686"
cryptography==36.0.0 ; platform_machine != "i686"
# via
# -r requirements/test.txt
# pyjwt
Expand Down Expand Up @@ -124,9 +124,9 @@ platformdirs==2.4.0
# via virtualenv
pluggy==1.0.0
# via pytest
pre-commit==2.15.0
pre-commit==2.16.0
# via -r requirements/lint.txt
proxy.py==2.3.1
proxy.py==2.4.0rc2
# via -r requirements/test.txt
py==1.10.0
# via pytest
Expand Down Expand Up @@ -158,7 +158,7 @@ pytest-mock==3.6.1
# via -r requirements/test.txt
python-dateutil==2.8.2
# via freezegun
python-on-whales==0.31.0 ; python_version >= "3.7"
python-on-whales==0.32.0 ; python_version >= "3.7"
# via -r requirements/test.txt
pytz==2021.3
# via babel
Expand All @@ -181,7 +181,7 @@ six==1.16.0
# virtualenv
snowballstemmer==2.1.0
# via sphinx
sphinx==4.3.0
sphinx==4.3.1
# via
# -r requirements/doc.txt
# sphinxcontrib-asyncio
Expand Down Expand Up @@ -234,7 +234,6 @@ typing-extensions==3.7.4.3
# -r requirements/typing-extensions.txt
# async-timeout
# mypy
# proxy.py
# pydantic
uritemplate==4.1.1
# via gidgethub
Expand Down
2 changes: 1 addition & 1 deletion requirements/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ aiohttp-theme==0.1.6
# Temp fix till updated: https://github.com/blockdiag/blockdiag/pull/148
funcparserlib==1.0.0a0
pygments==2.10.0
sphinx==4.3.0
sphinx==4.3.1
sphinxcontrib-asyncio==0.3.0
sphinxcontrib-blockdiag==2.0.0
sphinxcontrib-towncrier==0.2.0a0
Expand Down
2 changes: 1 addition & 1 deletion requirements/lint.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-r typing-extensions.txt
mypy==0.910; implementation_name=="cpython"
pre-commit==2.15.0
pre-commit==2.16.0
pytest==6.2.5
8 changes: 4 additions & 4 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
-r base.txt
Brotli==1.0.9
coverage==6.1.2
cryptography==35.0.0; platform_machine!="i686" # no 32-bit wheels; no python 3.9 wheels yet
coverage==6.2
cryptography==36.0.0; platform_machine!="i686" # no 32-bit wheels; no python 3.9 wheels yet
freezegun==1.1.0
mypy==0.910; implementation_name=="cpython"
mypy-extensions==0.4.3; implementation_name=="cpython"
proxy.py==2.3.1
proxy.py ~= 2.4.0a2
pytest==6.2.5
pytest-cov==3.0.0
pytest-mock==3.6.1
python-on-whales==0.31.0; python_version>="3.7"
python-on-whales==0.32.0; python_version>="3.7"
re-assert==1.1.0
setuptools-git==1.2
trustme==0.9.0; platform_machine!="i686" # no 32-bit wheels
Expand Down
Loading

0 comments on commit 5c6c3fd

Please sign in to comment.