From de4910457e8a30c9e22e9d64c2d5a72b6f045a74 Mon Sep 17 00:00:00 2001 From: Jakub Bogusz Date: Sun, 7 Feb 2021 08:01:56 +0100 Subject: [PATCH] - new - brotli patch to port from brotlipy to Brotli --- python3-aiohttp-brotli.patch | 88 ++++++++++++++++++++++++ python3-aiohttp.spec | 130 +++++++++++++++++++++++++++++++++++ 2 files changed, 218 insertions(+) create mode 100644 python3-aiohttp-brotli.patch create mode 100644 python3-aiohttp.spec diff --git a/python3-aiohttp-brotli.patch b/python3-aiohttp-brotli.patch new file mode 100644 index 0000000..0bc4de0 --- /dev/null +++ b/python3-aiohttp-brotli.patch @@ -0,0 +1,88 @@ +From 9afc44b052643213da15c9583ecbd643ca999601 Mon Sep 17 00:00:00 2001 +From: Felix Yan +Date: Fri, 19 Jul 2019 21:32:55 +0800 +Subject: [PATCH] Use Brotli instead of brotlipy (#3803) + +brotlipy is stuck at brotli 0.6 and upstream is inactive. Let's switch +to the official binding which is up-to-date. +--- + CHANGES/3803.feature | 1 + + CONTRIBUTORS.txt | 1 + + aiohttp/http_parser.py | 22 ++++++++++++++++++++-- + docs/client_quickstart.rst | 2 +- + docs/index.rst | 2 +- + requirements/ci-wheel.txt | 2 +- + setup.py | 2 +- + tox.ini | 2 +- + 8 files changed, 27 insertions(+), 7 deletions(-) + create mode 100644 CHANGES/3803.feature + +--- aiohttp-3.7.3/aiohttp/http_parser.py.orig 2021-02-06 22:03:16.853983452 +0100 ++++ aiohttp-3.7.3/aiohttp/http_parser.py 2021-02-06 22:22:29.544405459 +0100 +@@ -810,9 +810,26 @@ + 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 + self.decompressor = zlib.decompressobj(wbits=zlib_mode) +diff --git a/docs/client_quickstart.rst b/docs/client_quickstart.rst +index f58eb7166f..1d5d2fb448 100644 +--- a/docs/client_quickstart.rst ++++ b/docs/client_quickstart.rst +@@ -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 `_. ++just install `Brotli `_. + + JSON Request + ============ +diff --git a/docs/index.rst b/docs/index.rst +index aa20a78fe9..56aa7389f6 100644 +--- a/docs/index.rst ++++ b/docs/index.rst +@@ -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 +--- aiohttp-3.7.3/setup.py.orig 2021-02-06 22:24:15.207166368 +0100 ++++ aiohttp-3.7.3/setup.py 2021-02-06 22:24:45.976999674 +0100 +@@ -137,7 +137,7 @@ + extras_require={ + "speedups": [ + "aiodns", +- "brotlipy", ++ "Brotli", + "cchardet", + ], + }, diff --git a/python3-aiohttp.spec b/python3-aiohttp.spec new file mode 100644 index 0000000..a7ee4b4 --- /dev/null +++ b/python3-aiohttp.spec @@ -0,0 +1,130 @@ +# +# Conditional build: +%bcond_without doc # API documentation +%bcond_without tests # unit tests + +%define module template +Summary: Async http client/server framework +Summary(pl.UTF-8): Szkielet asynchronicznego klienta/serwera http +Name: python3-aiohttp +Version: 3.7.3 +Release: 1 +License: Apache v2.0 +Group: Libraries/Python +#Source0Download: https://pypi.org/simple/aiohttp/ +Source0: https://files.pythonhosted.org/packages/source/a/aiohttp/aiohttp-%{version}.tar.gz +# Source0-md5: a66039c12f33dd093a2c260f5c459632 +# adjusted from https://github.com/aio-libs/aiohttp/commit/9afc44b052643213da15c9583ecbd643ca999601.patch +Patch0: %{name}-brotli.patch +URL: https://pypi.org/project/aiohttp/ +BuildRequires: python3-devel >= 1:3.6 +BuildRequires: python3-setuptools +%if %{with tests} +BuildRequires: python3-async_timeout >= 3.0 +BuildRequires: python3-attrs >= 17.3.0 +BuildRequires: python3-brotli +BuildRequires: python3-chardet >= 2.0 +BuildRequires: python3-gunicorn +%if "%{py3_ver}" < "3.7" +BuildRequires: python3-idna-ssl +%endif +BuildRequires: python3-multidict >= 4.5 +BuildRequires: python3-pytest >= 3.8.2 +BuildRequires: python3-pytest-cov +BuildRequires: python3-pytest-mock +BuildRequires: python3-re_assert +BuildRequires: python3-typing_extensions >= 3.6.5 +BuildRequires: python3-yarl >= 1.0 +%endif +BuildRequires: rpm-pythonprov +BuildRequires: rpmbuild(macros) >= 1.714 +# if using noarchpackage, replace with: +#BuildRequires: rpmbuild(macros) >= 1.752 +BuildRequires: sed >= 4.0 +%if %{with doc} +BuildRequires: python3-aiohttp_theme +BuildRequires: python3-sphinxcontrib-asyncio +BuildRequires: python3-sphinxcontrib-blockdiag +BuildRequires: sphinx-pdg-3 +%endif +# replace with other requires if defined in setup.py +Requires: python3-modules >= 1:3.6 +BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n) + +%description +Async http client/server framework. + +%description -l pl.UTF-8 +Szkielet asynchronicznego klienta/serwera http. + +%package apidocs +Summary: aiohttp API documentation +Summary(pl.UTF-8): Dokumentacja API aiohttp +Group: Documentation +%{?noarchpackage} + +%description apidocs +API documentation for aiohttp. + +%description apidocs -l pl.UTF-8 +Dokumentacja API aiohttp. + +%prep +%setup -q -n aiohttp-%{version} +%patch0 -p1 + +%{__sed} -i -e '1s,/usr/bin/env python3,%{__python3},' examples/*.py examples/legacy/*.py + +# adjust for python 3.7+ +%{__sed} -i -e '/^from async_generator/d; /^ *@async_generator/d; s/await yield_/yield/' tests/*.py + +# until we have pytest >= 6: +%{__sed} -i -e '/assert_outcomes/ s/errors=/error=/' tests/test_pytest_plugin.py + +%build +%py3_build + +%if %{with tests} +# test_data_stream_exc_chain uses network, fails +# test_async_iterable_payload_default_content_type, test_async_iterable_payload_explicit_content_type fail with TypeError (need update?) +PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 \ +PYTEST_PLUGINS="pytest_cov.plugin,pytest_mock" \ +%{__python3} -m pytest tests -k 'not (test_data_stream_exc_chain or test_async_iterable_payload_default_content_type or test_async_iterable_payload_explicit_content_type)' +%endif + +%if %{with doc} +%{__make} -C docs html \ + SPHINXBUILD=sphinx-build-3 +%endif + +%install +rm -rf $RPM_BUILD_ROOT + +%py3_install + +%{__rm} -r $RPM_BUILD_ROOT%{py3_sitedir}/aiohttp/.hash +%{__rm} $RPM_BUILD_ROOT%{py3_sitedir}/aiohttp/*.{c,h,pxd,pxi,pyx} + +install -d $RPM_BUILD_ROOT%{_examplesdir}/%{name}-%{version} +cp -pr examples/* $RPM_BUILD_ROOT%{_examplesdir}/%{name}-%{version} + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +%defattr(644,root,root,755) +%doc CHANGES.rst CONTRIBUTORS.txt README.rst +%dir %{py3_sitedir}/aiohttp +%attr(755,root,root) %{py3_sitedir}/aiohttp/*.so +%{py3_sitedir}/aiohttp/*.py +%{py3_sitedir}/aiohttp/*.pyi +%{py3_sitedir}/aiohttp/py.typed +%{py3_sitedir}/aiohttp/__pycache__ +%{py3_sitedir}/aiohttp-%{version}-py*.egg-info +%{_examplesdir}/%{name}-%{version} + +%if %{with doc} +%files apidocs +%defattr(644,root,root,755) +%doc docs/_build/html/* +%endif -- 2.43.0