packages.py 932 B

1234567891011121314151617181920212223242526
  1. import sys
  2. try:
  3. import chardet
  4. except ImportError:
  5. import charset_normalizer as chardet
  6. import warnings
  7. warnings.filterwarnings('ignore', 'Trying to detect', module='charset_normalizer')
  8. # This code exists for backwards compatibility reasons.
  9. # I don't like it either. Just look the other way. :)
  10. for package in ('urllib3', 'idna'):
  11. locals()[package] = __import__(package)
  12. # This traversal is apparently necessary such that the identities are
  13. # preserved (requests.packages.urllib3.* is urllib3.*)
  14. for mod in list(sys.modules):
  15. if mod == package or mod.startswith(package + '.'):
  16. sys.modules['requests.packages.' + mod] = sys.modules[mod]
  17. target = chardet.__name__
  18. for mod in list(sys.modules):
  19. if mod == target or mod.startswith(target + '.'):
  20. sys.modules['requests.packages.' + target.replace(target, 'chardet')] = sys.modules[mod]
  21. # Kinda cool, though, right?