From 6083d7d2b699cf9705ea1c0378036042a5804426 Mon Sep 17 00:00:00 2001 From: Felix Yan Date: Mon, 27 May 2019 16:39:05 +0800 Subject: [PATCH] Use Brotli instead of brotlipy brotlipy is stuck at brotli 0.6 and upstream is inactive. Let's switch to the official binding which is up-to-date. --- CHANGES/3803.feature | 1 + CONTRIBUTORS.txt | 1 + aiohttp/http_parser.py | 22 ++++++++++++++++++++-- docs/client_quickstart.rst | 2 +- docs/index.rst | 2 +- requirements/ci-wheel.txt | 2 +- setup.py | 2 +- tox.ini | 2 +- 8 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 CHANGES/3803.feature diff --git a/CHANGES/3803.feature b/CHANGES/3803.feature new file mode 100644 index 00000000000..14cd018737d --- /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 f580fa78db4..21628c3ba35 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 9e22d10263a..0579ba53a05 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 ddd34464b71..a835373d955 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 aa20a78fe99..56aa7389f67 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 adde33a82ad..8d8c225a21f 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 8c2deaf201d..f14b9bcd2b1 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 5a8e90cf374..98a5f15ab92 100644 --- a/tox.ini +++ b/tox.ini @@ -12,7 +12,7 @@ deps = coverage gunicorn async-generator - brotlipy + Brotli cython: cython -e .