Skip to content

Commit

Permalink
Use Brotli instead of brotlipy
Browse files Browse the repository at this point in the history
brotlipy is stuck at brotli 0.6 and upstream is inactive. Let's switch
to the official binding which is up-to-date.
  • Loading branch information
felixonmars committed May 27, 2019
1 parent 99c4853 commit 1d1df1a
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES/3803.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use Brotli instead of brotlipy
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Eugene Chernyshov
Eugene Naydenov
Eugene Tolmachev
Evert Lammerts
Felix Yan
FichteFoll
Frederik Gladhorn
Frederik Peter Aalund
Expand Down
22 changes: 20 additions & 2 deletions aiohttp/http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
# 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) -> None:
self._obj = brotli.Decompressor()

def decompress(self, data: bytes) -> bytes:
if hasattr(self._obj, "decompress"):
return self._obj.decompress(data)
return self._obj.process(data)

def flush(self) -> bytes:
if hasattr(self._obj, "flush"):
return self._obj.flush()
return b""

self.decompressor = BrotliDecoder() # type: Any
else:
zlib_mode = (16 + zlib.MAX_WBITS
if encoding == 'gzip' else -zlib.MAX_WBITS)
Expand Down
2 changes: 1 addition & 1 deletion docs/client_quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/python-hyper/brotlipy>`_.
just install `Brotli <https://pypi.org/project/Brotli>`_.

JSON Request
============
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements/ci-wheel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
attrs==19.1.0
async-generator==1.10
async-timeout==3.0.1
brotlipy==0.7.0
Brotli==1.0.7
cchardet==2.1.4
chardet==3.0.4
coverage==4.5.3
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def read(f):
extras_require={
'speedups': [
'aiodns',
'brotlipy',
'Brotli',
'cchardet',
],
},
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ deps =
coverage
gunicorn
async-generator
brotlipy
Brotli
cython: cython
-e .

Expand Down

0 comments on commit 1d1df1a

Please sign in to comment.