Remove VendorAlias meta_path hook
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Ian Cordasco · committed by Ian Cordasco · parent 3d339ed · Browse files · 1 file·+1 added−105 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+1 added−105 removed
- other:+1 added−105 removed
Provenance
- Commit
3e3fc76- Tree
b2275f8- Author
Ian Cordasco <sigmavirus24@users.noreply.github.com>- Committer
Ian Cordasco <sigmavirus24@users.noreply.github.com>- Parent
3d339ed
1 file changed+1 added−105 removed
modified:requests/packages/__init__.py+1 added-105 removed
1-"""2-Copyright (c) Donald Stufft, pip, and individual contributors3-4-Permission is hereby granted, free of charge, to any person obtaining5-a copy of this software and associated documentation files (the6-"Software"), to deal in the Software without restriction, including7-without limitation the rights to use, copy, modify, merge, publish,8-distribute, sublicense, and/or sell copies of the Software, and to9-permit persons to whom the Software is furnished to do so, subject to10-the following conditions:11-12-The above copyright notice and this permission notice shall be13-included in all copies or substantial portions of the Software.14-15-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,16-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF17-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND18-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE19-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION20-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION21-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.22-"""1 from __future__ import absolute_import2 25-import sys26-27-28-class VendorAlias(object):29-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- ]37-38- def find_module(self, fullname, path=None):39- if fullname.startswith(self._vendor_pkg):40- return self41-42- def load_module(self, name):43- # Ensure that this only works for the vendored name44- if not name.startswith(self._vendor_pkg):45- raise ImportError(46- "Cannot import %s, must be a subpackage of '%s'." % (47- name, self._vendor_name,48- )49- )50-51- 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- )58-59- # 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]63-64- # Check to see if we can import the vendor name65- try:66- # We do this dance here because we want to try and import this67- # module without hitting a recursion error because of a bunch of68- # VendorAlias instances on sys.meta_path69- real_meta_path = sys.meta_path[:]70- try:71- sys.meta_path = [72- m for m in sys.meta_path73- if not isinstance(m, VendorAlias)74- ]75- __import__(name)76- module = sys.modules[name]77- finally:78- # Re-add any additions to sys.meta_path that were made while79- # during the import we just did, otherwise things like80- # requests.packages.urllib3.poolmanager will fail.81- for m in sys.meta_path:82- if m not in real_meta_path:83- real_meta_path.append(m)84-85- # Restore sys.meta_path with any new items.86- sys.meta_path = real_meta_path87- except ImportError:88- # We can't import the vendor name, so we'll try to import the89- # "real" name.90- real_name = name[len(self._vendor_pkg):]91- try:92- __import__(real_name)93- module = sys.modules[real_name]94- except ImportError:95- raise ImportError("No module named '%s'" % (name,))96-97- # If we've gotten here we've found the module we're looking for, either98- # as part of our vendored package, or as the real name, so we'll add99- # it to sys.modules as the vendored name so that we don't have to do100- # the lookup again.101- sys.modules[name] = module102-103- # Finally, return the loaded module104- return module105-106-107-sys.meta_path.insert(0, VendorAlias(["urllib3", "chardet"]))3+from . import urllib3