diff --git a/SOURCES/fix-requests.packages-aliasing.patch b/SOURCES/fix-requests.packages-aliasing.patch new file mode 100644 index 0000000..5d54514 --- /dev/null +++ b/SOURCES/fix-requests.packages-aliasing.patch @@ -0,0 +1,157 @@ +diff --git a/requests/__init__.py b/requests/__init__.py +index 8257b61..68443da 100644 +--- a/requests/__init__.py ++++ b/requests/__init__.py +@@ -64,6 +64,7 @@ from .exceptions import ( + RequestException, Timeout, URLRequired, + TooManyRedirects, HTTPError, ConnectionError + ) ++from . import packages + + # Set default logging handler to avoid "No handler found" warnings. + import logging +diff --git a/requests/packages/__init__.py b/requests/packages/__init__.py +index 4dcf870..385581e 100644 +--- a/requests/packages/__init__.py ++++ b/requests/packages/__init__.py +@@ -1,107 +1,35 @@ +-""" +-Copyright (c) Donald Stufft, pip, and individual contributors +- +-Permission is hereby granted, free of charge, to any person obtaining +-a copy of this software and associated documentation files (the +-"Software"), to deal in the Software without restriction, including +-without limitation the rights to use, copy, modify, merge, publish, +-distribute, sublicense, and/or sell copies of the Software, and to +-permit persons to whom the Software is furnished to do so, subject to +-the following conditions: +- +-The above copyright notice and this permission notice shall be +-included in all copies or substantial portions of the Software. +- +-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +-""" +-from __future__ import absolute_import +- + import sys + +- +-class VendorAlias(object): +- +- def __init__(self, package_names): +- self._package_names = package_names +- self._vendor_name = __name__ +- self._vendor_pkg = self._vendor_name + "." +- self._vendor_pkgs = [ +- self._vendor_pkg + name for name in self._package_names +- ] +- +- def find_module(self, fullname, path=None): +- if fullname.startswith(self._vendor_pkg): +- return self +- +- def load_module(self, name): +- # Ensure that this only works for the vendored name +- if not name.startswith(self._vendor_pkg): +- raise ImportError( +- "Cannot import %s, must be a subpackage of '%s'." % ( +- name, self._vendor_name, +- ) +- ) +- +- if not (name == self._vendor_name or +- any(name.startswith(pkg) for pkg in self._vendor_pkgs)): +- raise ImportError( +- "Cannot import %s, must be one of %s." % ( +- name, self._vendor_pkgs +- ) +- ) +- +- # Check to see if we already have this item in sys.modules, if we do +- # then simply return that. +- if name in sys.modules: +- return sys.modules[name] +- +- # Check to see if we can import the vendor name +- try: +- # We do this dance here because we want to try and import this +- # module without hitting a recursion error because of a bunch of +- # VendorAlias instances on sys.meta_path +- real_meta_path = sys.meta_path[:] +- try: +- sys.meta_path = [ +- m for m in sys.meta_path +- if not isinstance(m, VendorAlias) +- ] +- __import__(name) +- module = sys.modules[name] +- finally: +- # Re-add any additions to sys.meta_path that were made while +- # during the import we just did, otherwise things like +- # requests.packages.urllib3.poolmanager will fail. +- for m in sys.meta_path: +- if m not in real_meta_path: +- real_meta_path.append(m) +- +- # Restore sys.meta_path with any new items. +- sys.meta_path = real_meta_path +- except ImportError: +- # We can't import the vendor name, so we'll try to import the +- # "real" name. +- real_name = name[len(self._vendor_pkg):] +- try: +- __import__(real_name) +- module = sys.modules[real_name] +- except ImportError: +- raise ImportError("No module named '%s'" % (name,)) +- +- # If we've gotten here we've found the module we're looking for, either +- # as part of our vendored package, or as the real name, so we'll add +- # it to sys.modules as the vendored name so that we don't have to do +- # the lookup again. +- sys.modules[name] = module +- +- # Finally, return the loaded module +- return module +- +- +-sys.meta_path.append(VendorAlias(["urllib3", "chardet"])) ++# This code exists for backwards compatibility reasons. ++ ++modules_list = [ ++ 'urllib3', 'chardet', 'chardet.big5prober', 'chardet.chardetect', ++ 'chardet.chardistribution', 'chardet.charsetgroupprober', 'chardet.charsetprober', ++ 'chardet.codingstatemachine', 'chardet.compat', 'chardet.constants', ++ 'chardet.cp949prober', 'chardet.escprober', 'chardet.escsm', 'chardet.eucjpprober', ++ 'chardet.euckrfreq', 'chardet.euckrprober', 'chardet.euctwfreq', 'chardet.euctwprober', ++ 'chardet.gb2312freq', 'chardet.gb2312prober', 'chardet.hebrewprober', ++ 'chardet.jisfreq', 'chardet.jpcntx', 'chardet.langbulgarianmodel', ++ 'chardet.langcyrillicmodel', 'chardet.langgreekmodel', 'chardet.langhebrewmodel', ++ 'chardet.langhungarianmodel', 'chardet.langthaimodel', 'chardet.latin1prober', ++ 'chardet.mbcharsetprober', 'chardet.mbcsgroupprober', 'chardet.mbcssm', ++ 'chardet.sbcharsetprober', 'chardet.sbcsgroupprober', 'chardet.sjisprober', ++ 'chardet.universaldetector', 'chardet.utf8prober', 'urllib3._collections', ++ 'urllib3.connectionpool', 'urllib3.connection', 'urllib3.contrib', 'urllib3.exceptions', ++ 'urllib3.fields', 'urllib3.filepost', 'urllib3.packages', 'urllib3.poolmanager', ++ 'urllib3.request', 'urllib3.response', 'urllib3.util', 'urllib3.contrib.ntlmpool', ++ 'urllib3.contrib.pyopenssl', 'urllib3.util.connection', 'urllib3.util.request', ++ 'urllib3.util.response', 'urllib3.util.retry', 'urllib3.util.ssl_', 'urllib3.util.timeout', ++ 'urllib3.util.url', 'urllib3.packages.ordered_dict', 'urllib3.packages.six', ++ 'urllib3.packages.ssl_match_hostname', 'urllib3.packages.ssl_match_hostname.implementation' ++ ] ++ ++ ++for package in modules_list: ++ try: ++ __import__(package) ++ except ImportError: ++ pass ++ else: ++ sys.modules['requests.packages.' + package] = sys.modules[package] ++ globals()[package] = sys.modules[package] diff --git a/SPECS/python-requests.spec b/SPECS/python-requests.spec index a27b132..e05283f 100644 --- a/SPECS/python-requests.spec +++ b/SPECS/python-requests.spec @@ -9,7 +9,7 @@ Name: python-requests Version: 2.6.0 -Release: 8%{?dist} +Release: 9%{?dist} Summary: HTTP library, written in Python, for human beings License: ASL 2.0 @@ -54,6 +54,16 @@ Patch5: fix-leaking-test.patch # Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1776294 Patch6: import-urllib3-and-chardet-from-the-global-namespace.patch +# While the requests.packages aliasing has been removed since +# it caused various issues while it's also an undocumented API, +# much code in the wild still relies on it. This fix ensures +# that while the naming scheme is there for backwards compatibility, +# the submodules contained in the requests.packages namespace +# are properly aliased to the system installed modules. +# Inspired by https://github.com/psf/requests/blob/v2.18.0/requests/packages.py +# Resolves: rhbz#1785607, rhbz#1785666, rhbz#1785696, rhbz#1787679 +Patch7: fix-requests.packages-aliasing.patch + BuildArch: noarch BuildRequires: python2-devel BuildRequires: python-chardet >= 2.2.1-1 @@ -110,6 +120,7 @@ designed to make HTTP requests easy for developers. %patch4 -p1 %patch5 -p1 %patch6 -p1 +%patch7 -p1 # Unbundle the certificate bundle from mozilla. rm -rf requests/cacert.pem @@ -173,6 +184,10 @@ popd %endif %changelog +* Wed Feb 19 2020 Charalampos Stratakis - 2.6.0-9 +- Bring back the requests.packages aliasing of its submodules +Resolves: rhbz#1811050, rhbz#1811057, rhbz#1811107, rhbz#1811113 + * Thu Oct 24 2019 Charalampos Stratakis - 2.6.0-8 - Import urllib3 and chardet from the global namespace Resolves: rhbz#1776294