Skip to content
Myr

Merge pull request #2466 from sigmavirus24/bug/2465

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Only add VendorAliases for vendored dependencies

authored by Ian Cordasco · committed by Ian Cordasco · parents 61f4faa, 2669f0c · Browse files · 2 files+21 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+21 added−2 removed

  • other:+21 added−2 removed

2 files+21 added−2 removed

modified:requests/packages/__init__.py+14 added-2 removed
25 unmodified lines
262728class VendorAlias(object):2930 def __init__(self):30 def __init__(self, package_names):31 self._package_names = package_names32 self._vendor_name = __name__33 self._vendor_pkg = self._vendor_name + "."34 self._vendor_pkgs = [35 self._vendor_pkg + name for name in self._package_names36 ]3738 def find_module(self, fullname, path=None):39 if fullname.startswith(self._vendor_pkg):40 return self
6 unmodified lines
47 name, self._vendor_name,48 )49 )5051 if not (name == self._vendor_name or52 any(name.startswith(pkg) for pkg in self._vendor_pkgs)):53 raise ImportError(54 "Cannot import %s, must be one of %s." % (55 name, self._vendor_pkgs56 )57 )5859 # Check to see if we already have this item in sys.modules, if we do60 # then simply return that.61 if name in sys.modules:62 return sys.modules[name]
40 unmodified lines
103 # Finally, return the loaded module104 return module10510695sys.meta_path.append(VendorAlias())107sys.meta_path.append(VendorAlias(["urllib3", "chardet"]))
modified:test_requests.py+7 added
1609 unmodified lines
16101611 with pytest.raises(RetryError):1612 s.get(httpbin('status/500'))16131614def test_vendor_aliases():1615 from requests.packages import urllib31616 from requests.packages import chardet16171618 with pytest.raises(ImportError):1619 from requests.packages import webbrowser16201621if __name__ == '__main__':1622 unittest.main()