Add first-class support for Brotli package
MODIFY
.travis.yml
.travis.yml
@@ -43,6 +43,8 @@ matrix:
env: TOXENV=py27
- python: 2.7
env: TOXENV=py27-nobrotli
+ - python: 2.7
+ env: TOXENV=py27-google-brotli
- python: 3.4
env: TOXENV=py34
- python: 3.5
@@ -53,6 +55,8 @@ matrix:
env: TOXENV=py37
- python: 3.7
env: TOXENV=py37-nobrotli
+ - python: 3.7
+ env: TOXENV=py37-google-brotli
- python: 3.8-dev
env: TOXENV=py38
@@ -94,14 +98,6 @@ matrix:
env: DOWNSTREAM=botocore
stage: integration
- - python: 2.7
- env: DOWNSTREAM=google-brotli
- stage: integration
-
- - python: 3.7
- env: DOWNSTREAM=google-brotli
- stage: integration
-
- python: 3.7
stage: deploy
script:

MODIFY
CHANGES.rst
CHANGES.rst
@@ -4,7 +4,7 @@ Changes
dev (master)
------------
-* Add support for Google's ``Brotli`` package. (Pull #1752)
+* Add support for Google's ``Brotli`` package. (Pull #1572, Pull #1579)
* ... [Short description of non-trivial change.] (Issue #)

DELETE
_travis/downstream/google-brotli.sh
-#!/bin/bash
-
-set -exo pipefail
-
-case "${1}" in
- install)
- # Because Google's 'Brotli' package shares an importable name with
- # 'brotlipy' we need to make sure both implementations don't break.
- python -m pip install Brotli
- ;;
- run)
- pytest tests/
- ;;
- *)
- exit 1
- ;;
-esac

MODIFY
src/urllib3/response.py
src/urllib3/response.py
@@ -97,14 +97,21 @@ class GzipDecoder(object):
if brotli is not None:
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 __getattr__(self, name):
- return getattr(self._obj, name)
-
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''
class MultiDecoder(object):

MODIFY
tox.ini
tox.ini
[tox]
-envlist = flake8-py3, py27, py34, py35, py36, py37, py38, pypy, py{27,37}-nobrotli
+envlist = flake8-py3, py27, py34, py35, py36, py37, py38, pypy, py{27,37}-nobrotli, py{27,37}-google-brotli
[testenv]
deps= -r{toxinidir}/dev-requirements.txt
@@ -21,6 +21,18 @@ setenv =
PYTHONWARNINGS=always::DeprecationWarning
passenv = CFLAGS LDFLAGS TRAVIS APPVEYOR CRYPTOGRAPHY_OSX_NO_LINK_FLAGS TRAVIS_INFRA
+[testenv:py37-google-brotli]
+extras = socks,secure
+deps =
+ {[testenv]deps}
+ Brotli
+
+[testenv:py27-google-brotli]
+extras = socks,secure
+deps =
+ {[testenv]deps}
+ Brotli
+
[testenv:py27-nobrotli]
extras = socks,secure

Add first-class support for Brotli package (#1579)