jpayne@7: import sys jpayne@7: jpayne@7: try: jpayne@7: import chardet jpayne@7: except ImportError: jpayne@7: import warnings jpayne@7: jpayne@7: import charset_normalizer as chardet jpayne@7: jpayne@7: warnings.filterwarnings("ignore", "Trying to detect", module="charset_normalizer") jpayne@7: jpayne@7: # This code exists for backwards compatibility reasons. jpayne@7: # I don't like it either. Just look the other way. :) jpayne@7: jpayne@7: for package in ("urllib3", "idna"): jpayne@7: locals()[package] = __import__(package) jpayne@7: # This traversal is apparently necessary such that the identities are jpayne@7: # preserved (requests.packages.urllib3.* is urllib3.*) jpayne@7: for mod in list(sys.modules): jpayne@7: if mod == package or mod.startswith(f"{package}."): jpayne@7: sys.modules[f"requests.packages.{mod}"] = sys.modules[mod] jpayne@7: jpayne@7: target = chardet.__name__ jpayne@7: for mod in list(sys.modules): jpayne@7: if mod == target or mod.startswith(f"{target}."): jpayne@7: target = target.replace(target, "chardet") jpayne@7: sys.modules[f"requests.packages.{target}"] = sys.modules[mod] jpayne@7: # Kinda cool, though, right?