Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

107 lignes
2.1 KiB

  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 importlib
  9. import sys
  10. # -------
  11. # urllib3
  12. # -------
  13. from urllib3 import __version__ as urllib3_version
  14. # Detect which major version of urllib3 is being used.
  15. try:
  16. is_urllib3_1 = int(urllib3_version.split(".")[0]) == 1
  17. except (TypeError, AttributeError):
  18. # If we can't discern a version, prefer old functionality.
  19. is_urllib3_1 = True
  20. # -------------------
  21. # Character Detection
  22. # -------------------
  23. def _resolve_char_detection():
  24. """Find supported character detection libraries."""
  25. chardet = None
  26. for lib in ("chardet", "charset_normalizer"):
  27. if chardet is None:
  28. try:
  29. chardet = importlib.import_module(lib)
  30. except ImportError:
  31. pass
  32. return chardet
  33. chardet = _resolve_char_detection()
  34. # -------
  35. # Pythons
  36. # -------
  37. # Syntax sugar.
  38. _ver = sys.version_info
  39. #: Python 2.x?
  40. is_py2 = _ver[0] == 2
  41. #: Python 3.x?
  42. is_py3 = _ver[0] == 3
  43. # json/simplejson module import resolution
  44. has_simplejson = False
  45. try:
  46. import simplejson as json
  47. has_simplejson = True
  48. except ImportError:
  49. import json
  50. if has_simplejson:
  51. from simplejson import JSONDecodeError
  52. else:
  53. from json import JSONDecodeError
  54. # Keep OrderedDict for backwards compatibility.
  55. from collections import OrderedDict
  56. from collections.abc import Callable, Mapping, MutableMapping
  57. from http import cookiejar as cookielib
  58. from http.cookies import Morsel
  59. from io import StringIO
  60. # --------------
  61. # Legacy Imports
  62. # --------------
  63. from urllib.parse import (
  64. quote,
  65. quote_plus,
  66. unquote,
  67. unquote_plus,
  68. urldefrag,
  69. urlencode,
  70. urljoin,
  71. urlparse,
  72. urlsplit,
  73. urlunparse,
  74. )
  75. from urllib.request import (
  76. getproxies,
  77. getproxies_environment,
  78. parse_http_list,
  79. proxy_bypass,
  80. proxy_bypass_environment,
  81. )
  82. builtin_str = str
  83. str = str
  84. bytes = bytes
  85. basestring = (str, bytes)
  86. numeric_types = (int, float)
  87. integer_types = (int,)