diff --git a/CHANGES/3803.feature b/CHANGES/3803.feature new file mode 100644 index 0000000000..14cd018737 --- /dev/null +++ b/CHANGES/3803.feature @@ -0,0 +1 @@ +Use Brotli instead of brotlipy \ No newline at end of file diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index f580fa78db..21628c3ba3 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -89,6 +89,7 @@ Eugene Chernyshov Eugene Naydenov Eugene Tolmachev Evert Lammerts +Felix Yan FichteFoll Frederik Gladhorn Frederik Peter Aalund diff --git a/aiohttp/http_parser.py b/aiohttp/http_parser.py index 9e22d10263..0579ba53a0 100644 --- a/aiohttp/http_parser.py +++ b/aiohttp/http_parser.py @@ -698,8 +698,26 @@ def __init__(self, out: StreamReader, encoding: Optional[str]) -> None: if not HAS_BROTLI: # pragma: no cover raise ContentEncodingError( 'Can not decode content-encoding: brotli (br). ' - 'Please install `brotlipy`') - self.decompressor = brotli.Decompressor() + 'Please install `Brotli`') + + class BrotliDecoder(object): + # Supports both 'brotlipy' and 'Brotli' packages + # since they share an import name. The top branches + # are for 'brotlipy' and bottom branches for 'Brotli' + def __init__(self): + self._obj = brotli.Decompressor() + + def decompress(self, data): + if hasattr(self._obj, "decompress"): + return self._obj.decompress(data) + return self._obj.process(data) + + def flush(self): + if hasattr(self._obj, "flush"): + return self._obj.flush() + return b"" + + self.decompressor = BrotliDecoder() else: zlib_mode = (16 + zlib.MAX_WBITS if encoding == 'gzip' else -zlib.MAX_WBITS) diff --git a/docs/client_quickstart.rst b/docs/client_quickstart.rst index ddd34464b7..a835373d95 100644 --- a/docs/client_quickstart.rst +++ b/docs/client_quickstart.rst @@ -171,7 +171,7 @@ The ``gzip`` and ``deflate`` transfer-encodings are automatically decoded for you. You can enable ``brotli`` transfer-encodings support, -just install `brotlipy `_. +just install `Brotli `_. JSON Request ============ diff --git a/docs/index.rst b/docs/index.rst index aa20a78fe9..56aa7389f6 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -52,7 +52,7 @@ Installing speedups altogether ------------------------------ The following will get you ``aiohttp`` along with :term:`chardet`, -:term:`aiodns` and ``brotlipy`` in one bundle. No need to type +:term:`aiodns` and ``Brotli`` in one bundle. No need to type separate commands anymore! .. code-block:: bash diff --git a/requirements/ci-wheel.txt b/requirements/ci-wheel.txt index adde33a82a..8d8c225a21 100644 --- a/requirements/ci-wheel.txt +++ b/requirements/ci-wheel.txt @@ -2,7 +2,7 @@ attrs==19.1.0 async-generator==1.10 async-timeout==3.0.1 -brotlipy==0.7.0 +Brotlipy==1.0.7 cchardet==2.1.4 chardet==3.0.4 coverage==4.5.3 diff --git a/setup.py b/setup.py index 8c2deaf201..f14b9bcd2b 100644 --- a/setup.py +++ b/setup.py @@ -127,7 +127,7 @@ def read(f): extras_require={ 'speedups': [ 'aiodns', - 'brotlipy', + 'Brotli', 'cchardet', ], }, diff --git a/tox.ini b/tox.ini index 5a8e90cf37..98a5f15ab9 100644 --- a/tox.ini +++ b/tox.ini @@ -12,7 +12,7 @@ deps = coverage gunicorn async-generator - brotlipy + Brotli cython: cython -e .