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 bb3e9d4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
22 changes: 20 additions & 2 deletions aiohttp/http_parser.py
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(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)
Expand Down
2 changes: 1 addition & 1 deletion docs/client_quickstart.rst
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
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
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
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
Expand Up @@ -12,7 +12,7 @@ deps =
coverage
gunicorn
async-generator
brotlipy
Brotli
cython: cython
-e .

Expand Down

0 comments on commit bb3e9d4

Please sign in to comment.