Skip to content

Commit

Permalink
[3.9] Support brotlicffi alternatively to brotli (#7611) (#7620)
Browse files Browse the repository at this point in the history
(cherry picked from commit b8a3b0b)
  • Loading branch information
mgorny authored Sep 20, 2023
1 parent 6ef6e61 commit 4ca2034
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ ignore_missing_imports = True
[mypy-brotli]
ignore_missing_imports = True

[mypy-brotlicffi]
ignore_missing_imports = True

[mypy-gunicorn.*]
ignore_missing_imports = True

Expand Down
1 change: 1 addition & 0 deletions CHANGES/7611.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support using ``brotlicffi`` Python package alternatively to ``brotli``, as the latter does not work on PyPy.
5 changes: 4 additions & 1 deletion aiohttp/compression_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from typing import Optional, cast

try:
import brotli
try:
import brotlicffi as brotli
except ImportError:
import brotli

HAS_BROTLI = True
except ImportError: # pragma: no cover
Expand Down
3 changes: 2 additions & 1 deletion docs/client_quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ The ``gzip`` and ``deflate`` transfer-encodings are automatically
decoded for you.

You can enable ``brotli`` transfer-encodings support,
just install `brotli <https://github.com/python-hyper/Brotli>`_.
just install `Brotli <https://pypi.org/project/Brotli/>`_
or `brotlicffi <https://pypi.org/project/brotlicffi/>`_.

JSON Request
============
Expand Down
7 changes: 7 additions & 0 deletions docs/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@

https://pypi.org/project/Brotli/

brotlicffi

An alternative implementation of :term:`Brotli` built using the CFFI
library. This implementation supports PyPy correctly.

https://pypi.org/project/brotlicffi/

callable

Any object that can be called. Use :func:`callable` to check
Expand Down
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ Dependencies
$ pip install aiodns
- *Optional* :term:`Brotli` for brotli (:rfc:`7932`) client compression support.
- *Optional* :term:`Brotli` or :term:`brotlicffi` for brotli (:rfc:`7932`)
client compression support.

.. code-block:: bash
Expand Down
1 change: 1 addition & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ boolean
botocore
brotli
Brotli
brotlicffi
brotlipy
bugfix
Bugfixes
Expand Down
3 changes: 2 additions & 1 deletion requirements/runtime-deps.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ yarl >= 1.0, < 2.0
frozenlist >= 1.1.1
aiosignal >= 1.1.2
aiodns; sys_platform=="linux" or sys_platform=="darwin"
Brotli
Brotli; platform_python_implementation == 'CPython'
brotlicffi; platform_python_implementation != 'CPython'
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ install_requires =
speedups =
# required c-ares (aiodns' backend) will not build on windows
aiodns; sys_platform=="linux" or sys_platform=="darwin"
Brotli
Brotli; platform_python_implementation == 'CPython'
brotlicffi; platform_python_implementation != 'CPython'

[options.packages.find]
exclude =
Expand Down
5 changes: 4 additions & 1 deletion tests/test_http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
)

try:
import brotli
try:
import brotlicffi as brotli
except ImportError:
import brotli
except ImportError:
brotli = None

Expand Down
6 changes: 5 additions & 1 deletion tests/test_web_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import Optional
from unittest import mock

import brotli
import pytest
from multidict import CIMultiDictProxy, MultiDict
from yarl import URL
Expand All @@ -18,6 +17,11 @@
from aiohttp.test_utils import make_mocked_coro
from aiohttp.typedefs import Handler

try:
import brotlicffi as brotli
except ImportError:
import brotli

try:
import ssl
except ImportError:
Expand Down

0 comments on commit 4ca2034

Please sign in to comment.