diff --git a/aiohttp/compression_utils.py b/aiohttp/compression_utils.py index 8abc4fa7c3c..52791fe5015 100644 --- a/aiohttp/compression_utils.py +++ b/aiohttp/compression_utils.py @@ -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 diff --git a/docs/client_quickstart.rst b/docs/client_quickstart.rst index 92334a5f4b4..840711f461e 100644 --- a/docs/client_quickstart.rst +++ b/docs/client_quickstart.rst @@ -187,7 +187,8 @@ The ``gzip`` and ``deflate`` transfer-encodings are automatically decoded for you. You can enable ``brotli`` transfer-encodings support, -just install `Brotli `_. +just install `brotlicffi `_ +or `Brotli `_. JSON Request ============ diff --git a/docs/index.rst b/docs/index.rst index 62e03c5baa9..ee0aff64cbe 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -158,7 +158,8 @@ Dependencies $ pip install aiodns -- *Optional* :term:`Brotli` for brotli (:rfc:`7932`) client compression support. +- *Optional* :term:`brotlicffi` or :term:`Brotli` for brotli (:rfc:`7932`) + client compression support. .. code-block:: bash diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt index 4c732ddd1d4..62ad5957fe5 100644 --- a/docs/spelling_wordlist.txt +++ b/docs/spelling_wordlist.txt @@ -40,6 +40,7 @@ boolean botocore brotli Brotli +brotlicffi brotlipy bugfix Bugfixes diff --git a/setup.cfg b/setup.cfg index cc3fc71808f..c223c59e4c9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -62,7 +62,8 @@ install_requires = speedups = # required c-ares (aiodns' backend) will not build on windows aiodns >= 1.1; sys_platform=="linux" or sys_platform=="darwin" - Brotli + Brotli; platform_python_implementation == 'CPython' + brotlicffi; platform_python_implementation != 'CPython' [options.packages.find] exclude = diff --git a/tests/test_http_parser.py b/tests/test_http_parser.py index 367cf14da95..6b0ec24103e 100644 --- a/tests/test_http_parser.py +++ b/tests/test_http_parser.py @@ -22,7 +22,10 @@ ) try: - import brotli + try: + import brotlicffi as brotli + except ImportError: + import brotli except ImportError: brotli = None diff --git a/tests/test_web_functional.py b/tests/test_web_functional.py index 5641d2c9096..05ca6afb8bf 100644 --- a/tests/test_web_functional.py +++ b/tests/test_web_functional.py @@ -8,7 +8,6 @@ from typing import Any, Optional from unittest import mock -import brotli import pytest from multidict import CIMultiDictProxy, MultiDict from yarl import URL @@ -19,6 +18,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: