Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Brotli instead of brotlipy #3803

Merged
merged 1 commit into from Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/3803.feature
@@ -0,0 +1 @@
Use Brotli instead of brotlipy
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
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
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
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
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
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