- Upgrade to 1.0.0:

- Breaking Changes
    - Removed Google App Engine support to allow using urllib3 2.0
  - New Features
    - Add support for preparing requests in BaseUrlSession
  - Fixed Bugs
    - Ensured the test suite no longer reaches the Internet
    - Fix urllib3 warning to only emit on X509Adapter usage
    - Fixing missing newline in dump utility
  - Miscellaneous
    - Added explicit support for Python 3.11
- Remove upstreamed patches:
  - fix-tests.patch
  - remove_mock.patch
  - requests-toolbelt-pr246-collections.abc.patch
- Add 356-add-missing-casette-files.patch which adds missing
  casette test files (gh#requests/toolbelt!356).

OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-requests-toolbelt?expand=0&rev=29
This commit is contained in:
Matej Cepl 2023-05-04 19:38:53 +00:00 committed by Git OBS Bridge
parent 8f97dad63d
commit b2a491a284
9 changed files with 1692 additions and 425 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,128 +0,0 @@
From c4f918572751151eb3bfc7dfa94580b3e2867a9e Mon Sep 17 00:00:00 2001
From: Jon Dufresne <jon.dufresne@gmail.com>
Date: Sun, 3 Feb 2019 09:02:24 -0800
Subject: [PATCH] Fix unhandled exceptions from threads during tests
A queue.Queue() object was not always passed to SessionThread. In this
case, SessionThread._make_request() would raise an exception trying to
call methods on the expected object. Now, always pass a usable object to
SessionThread.
Previously appeared as:
Traceback (most recent call last):
File "/usr/lib64/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "toolbelt/requests_toolbelt/threaded/thread.py", line 41, in _make_request
kwargs = self._jobs.get_nowait()
AttributeError: 'NoneType' object has no attribute 'get_nowait'
Exception in thread cd08fad6-d21d-41b0-921e-737a149b12be:
Traceback (most recent call last):
File "/usr/lib64/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "toolbelt/requests_toolbelt/threaded/thread.py", line 41, in _make_request
kwargs = self._jobs.get_nowait()
AttributeError: 'NoneType' object has no attribute 'get_nowait'
Exception in thread 4fb72f0d-ba1c-4a78-97a2-4a7283ea01fe:
Traceback (most recent call last):
File "/usr/lib64/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "toolbelt/requests_toolbelt/threaded/thread.py", line 41, in _make_request
kwargs = self._jobs.get_nowait()
AttributeError: 'NoneType' object has no attribute 'get_nowait'
Exception in thread 5f3711af-0c01-4821-9e25-8074bbbf769b:
Traceback (most recent call last):
File "/usr/lib64/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "toolbelt/requests_toolbelt/threaded/thread.py", line 41, in _make_request
kwargs = self._jobs.get_nowait()
AttributeError: 'NoneType' object has no attribute 'get_nowait'
---
tests/threaded/test_pool.py | 15 ++++++++++-----
tests/threaded/test_thread.py | 5 ++++-
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/tests/threaded/test_pool.py b/tests/threaded/test_pool.py
index b0653bb..b949dd8 100644
--- a/tests/threaded/test_pool.py
+++ b/tests/threaded/test_pool.py
@@ -26,32 +26,37 @@ def test_requires_positive_number_of_processes(self):
def test_number_of_processes_can_be_arbitrary(self):
"""Show that the number of processes can be set."""
- p = pool.Pool(None, num_processes=100)
+ job_queue = queue.Queue()
+ p = pool.Pool(job_queue, num_processes=100)
assert p._processes == 100
assert len(p._pool) == 100
- p = pool.Pool(None, num_processes=1)
+ job_queue = queue.Queue()
+ p = pool.Pool(job_queue, num_processes=1)
assert p._processes == 1
assert len(p._pool) == 1
def test_initializer_is_called(self):
"""Ensure that the initializer function is called."""
+ job_queue = queue.Queue()
initializer = mock.MagicMock()
- pool.Pool(None, num_processes=1, initializer=initializer)
+ pool.Pool(job_queue, num_processes=1, initializer=initializer)
assert initializer.called is True
initializer.assert_called_once_with(mock.ANY)
def test_auth_generator_is_called(self):
"""Ensure that the auth_generator function is called."""
+ job_queue = queue.Queue()
auth_generator = mock.MagicMock()
- pool.Pool(None, num_processes=1, auth_generator=auth_generator)
+ pool.Pool(job_queue, num_processes=1, auth_generator=auth_generator)
assert auth_generator.called is True
auth_generator.assert_called_once_with(mock.ANY)
def test_session_is_called(self):
"""Ensure that the session function is called."""
+ job_queue = queue.Queue()
session = mock.MagicMock()
- pool.Pool(None, num_processes=1, session=session)
+ pool.Pool(job_queue, num_processes=1, session=session)
assert session.called is True
session.assert_called_once_with()
diff --git a/tests/threaded/test_thread.py b/tests/threaded/test_thread.py
index bb92f7f..fd7e96b 100644
--- a/tests/threaded/test_thread.py
+++ b/tests/threaded/test_thread.py
@@ -19,6 +19,8 @@ def _make_mocks():
def _initialize_a_session_thread(session=None, job_queue=None,
response_queue=None, exception_queue=None):
+ if job_queue is None:
+ job_queue = queue.Queue()
with mock.patch.object(threading, 'Thread') as Thread:
thread_instance = mock.MagicMock()
Thread.return_value = thread_instance
@@ -52,10 +54,11 @@ def test_thread_initialization(self):
def test_is_alive_proxies_to_worker(self):
"""Test that we proxy the is_alive method to the Thread."""
+ job_queue = queue.Queue()
with mock.patch.object(threading, 'Thread') as Thread:
thread_instance = mock.MagicMock()
Thread.return_value = thread_instance
- st = thread.SessionThread(None, None, None, None)
+ st = thread.SessionThread(None, job_queue, None, None)
st.is_alive()
thread_instance.is_alive.assert_called_once_with()

View File

@ -1,3 +1,24 @@
-------------------------------------------------------------------
Thu May 4 18:10:01 UTC 2023 - Matej Cepl <mcepl@suse.com>
- Upgrade to 1.0.0:
- Breaking Changes
- Removed Google App Engine support to allow using urllib3 2.0
- New Features
- Add support for preparing requests in BaseUrlSession
- Fixed Bugs
- Ensured the test suite no longer reaches the Internet
- Fix urllib3 warning to only emit on X509Adapter usage
- Fixing missing newline in dump utility
- Miscellaneous
- Added explicit support for Python 3.11
- Remove upstreamed patches:
- fix-tests.patch
- remove_mock.patch
- requests-toolbelt-pr246-collections.abc.patch
- Add 356-add-missing-casette-files.patch which adds missing
casette test files (gh#requests/toolbelt!356).
-------------------------------------------------------------------
Fri Apr 21 12:33:06 UTC 2023 - Dirk Müller <dmueller@suse.com>

View File

@ -19,7 +19,7 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%{?sle15_python_module_pythons}
Name: python-requests-toolbelt
Version: 0.9.1
Version: 1.0.0
Release: 0
Summary: A utility belt for advanced users of python3-requests
License: Apache-2.0
@ -27,15 +27,12 @@ URL: https://github.com/requests/toolbelt
Source: https://files.pythonhosted.org/packages/source/r/requests-toolbelt/requests-toolbelt-%{version}.tar.gz
# Replace expired test certificate
Source1: test_cert.p12
Patch0: fix-tests.patch
# PATCH-FIX-UPSTREAM remove_mock.patch bsc#[0-9]+ mcepl@suse.com
# remove dependency on the external mock package
Patch1: remove_mock.patch
# PATCH-FIX-UPSTREAM requests-toolbelt-pr246-collections.abc.patch -- fix python310 deprecation. gh#requests/toolbelt#246
Patch2: https://github.com/requests/toolbelt/pull/246.patch#/requests-toolbelt-pr246-collections.abc.patch
# PATCH-FIX-OPENSUSE Stop using PyOpenSSLCompat, it generates widespread
# DeprecationWarnings
Patch3: stop-using-pyopenssl-compat.patch
Patch0: stop-using-pyopenssl-compat.patch
# PATCH-FIX-UPSTREAM 356-add-missing-casette-files.patch gh#requests/toolbelt!356 mcepl@suse.com
# add missing casette files
Patch1: 356-add-missing-casette-files.patch
BuildRequires: %{python_module requests >= 2.12.2}
BuildRequires: %{python_module setuptools}
BuildRequires: fdupes
@ -47,6 +44,7 @@ BuildRequires: %{python_module betamax >= 0.5.0}
# gh#pyca/cryptography#5606
BuildRequires: %{python_module pyOpenSSL >= 19.1.0}
BuildRequires: %{python_module pytest}
BuildRequires: %{python_module trustme}
%if 0%{suse_version} <= 1500
BuildRequires: python-mock
%endif
@ -78,7 +76,8 @@ export OPENSSL_SYSTEM_CIPHERS_OVERRIDE=xyz_nonexistent_file
export OPENSSL_CONF=''
# Requires network access
%pytest -k 'not (TestFileFromURLWrapper or test_reads_file_from_url_wrapper)'
%pytest
# -k 'not network'
%files %{python_files}
%license LICENSE

View File

@ -1,211 +0,0 @@
---
dev-requirements.txt | 1 -
tests/test_appengine_adapter.py | 2 +-
tests/test_auth.py | 2 +-
tests/test_downloadutils.py | 2 +-
tests/test_dump.py | 2 +-
tests/test_multipart_decoder.py | 2 +-
tests/test_proxy_digest_auth.py | 2 +-
tests/test_socket_options_adapter.py | 2 +-
tests/test_ssladapter.py | 2 +-
tests/threaded/test_api.py | 2 +-
tests/threaded/test_pool.py | 2 +-
tests/threaded/test_thread.py | 2 +-
tox.ini | 1 -
13 files changed, 11 insertions(+), 13 deletions(-)
--- a/tests/test_appengine_adapter.py
+++ b/tests/test_appengine_adapter.py
@@ -2,7 +2,10 @@
"""Tests for the AppEngineAdapter."""
import sys
-import mock
+try:
+ import unittest.mock as mock
+except ImportError:
+ import mock
import pytest
import requests
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
import requests
import unittest
-import mock
+try:
+ import unittest.mock as mock
+except ImportError:
+ import mock
from requests_toolbelt.auth.guess import GuessAuth, GuessProxyAuth
from . import get_betamax
--- a/tests/test_downloadutils.py
+++ b/tests/test_downloadutils.py
@@ -8,7 +8,10 @@ import tempfile
import requests
from requests_toolbelt.downloadutils import stream
from requests_toolbelt.downloadutils import tee
-import mock
+try:
+ import unittest.mock as mock
+except ImportError:
+ import mock
import pytest
from . import get_betamax
--- a/tests/test_dump.py
+++ b/tests/test_dump.py
@@ -12,7 +12,10 @@ very complex and high-level.
from requests_toolbelt._compat import HTTPHeaderDict
from requests_toolbelt.utils import dump
-import mock
+try:
+ import unittest.mock as mock
+except ImportError:
+ import mock
import pytest
import requests
--- a/tests/test_multipart_decoder.py
+++ b/tests/test_multipart_decoder.py
@@ -2,7 +2,10 @@
import io
import sys
import unittest
-import mock
+try:
+ import unittest.mock as mock
+except ImportError:
+ import mock
import pytest
import requests
from requests_toolbelt.multipart.decoder import BodyPart
--- a/tests/test_proxy_digest_auth.py
+++ b/tests/test_proxy_digest_auth.py
@@ -2,7 +2,10 @@
"""Test proxy digest authentication."""
import unittest
-import mock
+try:
+ import unittest.mock as mock
+except ImportError:
+ import mock
import requests
from requests_toolbelt.auth import http_proxy_digest
--- a/tests/test_socket_options_adapter.py
+++ b/tests/test_socket_options_adapter.py
@@ -3,7 +3,10 @@
import contextlib
import socket
-import mock
+try:
+ import unittest.mock as mock
+except ImportError:
+ import mock
import requests
from requests_toolbelt._compat import poolmanager
--- a/tests/test_ssladapter.py
+++ b/tests/test_ssladapter.py
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
-import mock
+try:
+ import unittest.mock as mock
+except ImportError:
+ import mock
import pytest
import requests
import unittest
--- a/tests/threaded/test_api.py
+++ b/tests/threaded/test_api.py
@@ -1,6 +1,9 @@
"""Module containing tests for requests_toolbelt.threaded API."""
-import mock
+try:
+ import unittest.mock as mock
+except ImportError:
+ import mock
import pytest
from requests_toolbelt._compat import queue
--- a/tests/threaded/test_pool.py
+++ b/tests/threaded/test_pool.py
@@ -5,7 +5,10 @@ except ImportError:
import Queue as queue
import unittest
-import mock
+try:
+ import unittest.mock as mock
+except ImportError:
+ import mock
import pytest
from requests_toolbelt.threaded import pool
--- a/tests/threaded/test_thread.py
+++ b/tests/threaded/test_thread.py
@@ -7,7 +7,10 @@ import threading
import unittest
import uuid
-import mock
+try:
+ import unittest.mock as mock
+except ImportError:
+ import mock
import requests.exceptions
from requests_toolbelt.threaded import thread
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -1,4 +1,3 @@
pytest
-mock
pyopenssl
git+git://github.com/sigmavirus24/betamax
--- a/tox.ini
+++ b/tox.ini
@@ -6,7 +6,6 @@ pip_pre = False
deps =
requests{env:REQUESTS_VERSION:>=2.0.1,<3.0.0}
pytest
- mock
pyopenssl
ndg-httpsclient
betamax>0.5.0
--- a/tests/test_source_adapter.py
+++ b/tests/test_source_adapter.py
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
from requests.adapters import DEFAULT_POOLSIZE, DEFAULT_POOLBLOCK
-from mock import patch
+try:
+ from unittest.mock import patch
+except ImportError:
+ from mock import patch
from requests_toolbelt.adapters.source import SourceAddressAdapter
import pytest
--- a/tests/test_user_agent.py
+++ b/tests/test_user_agent.py
@@ -2,7 +2,10 @@
import unittest
import sys
-from mock import patch
+try:
+ from unittest.mock import patch
+except ImportError:
+ from mock import patch
import pytest
from requests_toolbelt.utils import user_agent as ua

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:968089d4584ad4ad7c171454f0a5c6dac23971e9472521ea3b6d49d610aa6fc0
size 207286

BIN
requests-toolbelt-1.0.0.tar.gz (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -1,34 +0,0 @@
From 7188b06330e5260be20bce8cbcf0d5ae44e34eaf Mon Sep 17 00:00:00 2001
From: Jon Dufresne <jon.dufresne@gmail.com>
Date: Fri, 1 Feb 2019 16:30:01 -0800
Subject: [PATCH] Fix collections.abc deprecation warning in downloadutils
Warning appears as:
tests/test_downloadutils.py::test_stream_response_to_specific_filename
requests_toolbelt/downloadutils/stream.py:161: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
if path and isinstance(getattr(path, 'write', None), collections.Callable):
---
requests_toolbelt/downloadutils/stream.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/requests_toolbelt/downloadutils/stream.py b/requests_toolbelt/downloadutils/stream.py
index eed60a7..1d1c31b 100644
--- a/requests_toolbelt/downloadutils/stream.py
+++ b/requests_toolbelt/downloadutils/stream.py
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
"""Utilities for dealing with streamed requests."""
-import collections
import os.path
import re
@@ -158,7 +157,7 @@ def stream_response_to_file(response, path=None, chunksize=_DEFAULT_CHUNKSIZE):
pre_opened = False
fd = None
filename = None
- if path and isinstance(getattr(path, 'write', None), collections.Callable):
+ if path and callable(getattr(path, 'write', None)):
pre_opened = True
fd = path
filename = getattr(fd, 'name', None)

View File

@ -1,7 +1,9 @@
Index: requests-toolbelt-0.9.1/requests_toolbelt/adapters/x509.py
===================================================================
--- requests-toolbelt-0.9.1.orig/requests_toolbelt/adapters/x509.py
+++ requests-toolbelt-0.9.1/requests_toolbelt/adapters/x509.py
---
requests_toolbelt/adapters/x509.py | 27 ++++-----------------------
1 file changed, 4 insertions(+), 23 deletions(-)
--- a/requests_toolbelt/adapters/x509.py
+++ b/requests_toolbelt/adapters/x509.py
@@ -8,6 +8,7 @@ X.509 certificate without needing to con
"""
@ -10,11 +12,8 @@ Index: requests-toolbelt-0.9.1/requests_toolbelt/adapters/x509.py
from cryptography import x509
from cryptography.hazmat.primitives.serialization import (load_pem_private_key,
load_der_private_key)
@@ -18,19 +19,8 @@ from datetime import datetime
from requests.adapters import HTTPAdapter
import requests
@@ -20,16 +21,6 @@ import requests
-from .._compat import PyOpenSSLContext
from .. import exceptions as exc
-"""
@ -28,25 +27,25 @@ Index: requests-toolbelt-0.9.1/requests_toolbelt/adapters/x509.py
- from _ssl import PROTOCOL_SSLv23 as PROTOCOL
-
class X509Adapter(HTTPAdapter):
r"""Adapter for use with X.509 certificates.
@@ -81,7 +71,6 @@ class X509Adapter(HTTPAdapter):
"""
PyOpenSSLContext = None
@@ -84,7 +75,6 @@ class X509Adapter(HTTPAdapter):
def __init__(self, *args, **kwargs):
self._import_pyopensslcontext()
- self._check_version()
cert_bytes = kwargs.pop('cert_bytes', None)
pk_bytes = kwargs.pop('pk_bytes', None)
password = kwargs.pop('password', None)
@@ -118,15 +107,6 @@ class X509Adapter(HTTPAdapter):
kwargs['ssl_context'] = self.ssl_context
return super(X509Adapter, self).proxy_manager_for(*args, **kwargs)
@@ -136,15 +126,6 @@ class X509Adapter(HTTPAdapter):
except ImportError:
PyOpenSSLContext = None
- def _check_version(self):
- if PyOpenSSLContext is None:
- raise exc.VersionMismatchError(
- "The X509Adapter requires at least Requests 2.12.0 to be "
- "installed. Version {0} was found instead.".format(
- "installed. Version {} was found instead.".format(
- requests.__version__
- )
- )
@ -54,7 +53,7 @@ Index: requests-toolbelt-0.9.1/requests_toolbelt/adapters/x509.py
def check_cert_dates(cert):
"""Verify that the supplied client cert is not invalid."""
@@ -172,7 +152,7 @@ def create_ssl_context(cert_byes, pk_byt
@@ -190,7 +171,7 @@ def create_ssl_context(cert_byes, pk_byt
raise ValueError('Cert and key could not be parsed from '
'provided data')
check_cert_dates(cert)
@ -65,26 +64,3 @@ Index: requests-toolbelt-0.9.1/requests_toolbelt/adapters/x509.py
+ ssl_context.use_certificate(X509.from_cryptography(cert))
+ ssl_context.use_privatekey(PKey.from_cryptography_key(key))
return ssl_context
Index: requests-toolbelt-0.9.1/requests_toolbelt/_compat.py
===================================================================
--- requests-toolbelt-0.9.1.orig/requests_toolbelt/_compat.py
+++ requests-toolbelt-0.9.1/requests_toolbelt/_compat.py
@@ -49,17 +49,7 @@ else:
except ImportError:
from urllib3.contrib import appengine as gaecontrib
-if requests.__build__ < 0x021200:
- PyOpenSSLContext = None
-else:
- try:
- from requests.packages.urllib3.contrib.pyopenssl \
- import PyOpenSSLContext
- except ImportError:
- try:
- from urllib3.contrib.pyopenssl import PyOpenSSLContext
- except ImportError:
- PyOpenSSLContext = None
+PyOpenSSLContext = None
PY3 = sys.version_info > (3, 0)