jpayne@69: import sys jpayne@69: jpayne@69: from .compat import chardet jpayne@69: jpayne@69: # This code exists for backwards compatibility reasons. jpayne@69: # I don't like it either. Just look the other way. :) jpayne@69: jpayne@69: for package in ("urllib3", "idna"): jpayne@69: locals()[package] = __import__(package) jpayne@69: # This traversal is apparently necessary such that the identities are jpayne@69: # preserved (requests.packages.urllib3.* is urllib3.*) jpayne@69: for mod in list(sys.modules): jpayne@69: if mod == package or mod.startswith(f"{package}."): jpayne@69: sys.modules[f"requests.packages.{mod}"] = sys.modules[mod] jpayne@69: jpayne@69: if chardet is not None: jpayne@69: target = chardet.__name__ jpayne@69: for mod in list(sys.modules): jpayne@69: if mod == target or mod.startswith(f"{target}."): jpayne@69: imported_mod = sys.modules[mod] jpayne@69: sys.modules[f"requests.packages.{mod}"] = imported_mod jpayne@69: mod = mod.replace(target, "chardet") jpayne@69: sys.modules[f"requests.packages.{mod}"] = imported_mod