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

Add first-class support for Brotli package #1579

Merged
merged 5 commits into from
Apr 24, 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
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