annotate requests/packages.py @ 11:7fd0ef5842e7

planemo upload for repository https://toolrepo.galaxytrakr.org/view/jpayne/bioproject_to_srr_2/556cac4fb538
author jpayne
date Mon, 06 May 2024 01:42:27 -0400
parents 5eb2d5e3bf22
children
rev   line source
jpayne@7 1 import sys
jpayne@7 2
jpayne@7 3 try:
jpayne@7 4 import chardet
jpayne@7 5 except ImportError:
jpayne@7 6 import warnings
jpayne@7 7
jpayne@7 8 import charset_normalizer as chardet
jpayne@7 9
jpayne@7 10 warnings.filterwarnings("ignore", "Trying to detect", module="charset_normalizer")
jpayne@7 11
jpayne@7 12 # This code exists for backwards compatibility reasons.
jpayne@7 13 # I don't like it either. Just look the other way. :)
jpayne@7 14
jpayne@7 15 for package in ("urllib3", "idna"):
jpayne@7 16 locals()[package] = __import__(package)
jpayne@7 17 # This traversal is apparently necessary such that the identities are
jpayne@7 18 # preserved (requests.packages.urllib3.* is urllib3.*)
jpayne@7 19 for mod in list(sys.modules):
jpayne@7 20 if mod == package or mod.startswith(f"{package}."):
jpayne@7 21 sys.modules[f"requests.packages.{mod}"] = sys.modules[mod]
jpayne@7 22
jpayne@7 23 target = chardet.__name__
jpayne@7 24 for mod in list(sys.modules):
jpayne@7 25 if mod == target or mod.startswith(f"{target}."):
jpayne@7 26 target = target.replace(target, "chardet")
jpayne@7 27 sys.modules[f"requests.packages.{target}"] = sys.modules[mod]
jpayne@7 28 # Kinda cool, though, right?