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