Skip to content

Commit

Permalink
Add first-class support for Brotli package (#1579)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed Apr 24, 2019
1 parent ff8f721 commit 64e413f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 31 deletions.
12 changes: 4 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 #)

Expand Down
17 changes: 0 additions & 17 deletions _travis/downstream/google-brotli.sh

This file was deleted.

15 changes: 11 additions & 4 deletions src/urllib3/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,21 @@ def decompress(self, data):

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):
return self._obj.decompress(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):
Expand Down
14 changes: 13 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[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
Expand All @@ -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

Expand Down

0 comments on commit 64e413f

Please sign in to comment.