compat.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. """
  2. requests.compat
  3. ~~~~~~~~~~~~~~~
  4. This module previously handled import compatibility issues
  5. between Python 2 and Python 3. It remains for backwards
  6. compatibility until the next major version.
  7. """
  8. import sys
  9. # -------------------
  10. # Character Detection
  11. # -------------------
  12. def _resolve_char_detection():
  13. """Find supported character detection libraries."""
  14. chardet = None
  15. return chardet
  16. chardet = _resolve_char_detection()
  17. # -------
  18. # Pythons
  19. # -------
  20. # Syntax sugar.
  21. _ver = sys.version_info
  22. #: Python 2.x?
  23. is_py2 = _ver[0] == 2
  24. #: Python 3.x?
  25. is_py3 = _ver[0] == 3
  26. # Note: We've patched out simplejson support in pip because it prevents
  27. # upgrading simplejson on Windows.
  28. import json
  29. from json import JSONDecodeError
  30. # Keep OrderedDict for backwards compatibility.
  31. from collections import OrderedDict
  32. from collections.abc import Callable, Mapping, MutableMapping
  33. from http import cookiejar as cookielib
  34. from http.cookies import Morsel
  35. from io import StringIO
  36. # --------------
  37. # Legacy Imports
  38. # --------------
  39. from urllib.parse import (
  40. quote,
  41. quote_plus,
  42. unquote,
  43. unquote_plus,
  44. urldefrag,
  45. urlencode,
  46. urljoin,
  47. urlparse,
  48. urlsplit,
  49. urlunparse,
  50. )
  51. from urllib.request import (
  52. getproxies,
  53. getproxies_environment,
  54. parse_http_list,
  55. proxy_bypass,
  56. proxy_bypass_environment,
  57. )
  58. builtin_str = str
  59. str = str
  60. bytes = bytes
  61. basestring = (str, bytes)
  62. numeric_types = (int, float)
  63. integer_types = (int,)