You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

compat.py 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # -*- coding: utf-8 -*-
  2. """
  3. requests.compat
  4. ~~~~~~~~~~~~~~~
  5. This module handles import compatibility issues between Python 2 and
  6. Python 3.
  7. """
  8. from pip._vendor import chardet
  9. import sys
  10. # -------
  11. # Pythons
  12. # -------
  13. # Syntax sugar.
  14. _ver = sys.version_info
  15. #: Python 2.x?
  16. is_py2 = (_ver[0] == 2)
  17. #: Python 3.x?
  18. is_py3 = (_ver[0] == 3)
  19. # Note: We've patched out simplejson support in pip because it prevents
  20. # upgrading simplejson on Windows.
  21. # try:
  22. # import simplejson as json
  23. # except (ImportError, SyntaxError):
  24. # # simplejson does not support Python 3.2, it throws a SyntaxError
  25. # # because of u'...' Unicode literals.
  26. import json
  27. # ---------
  28. # Specifics
  29. # ---------
  30. if is_py2:
  31. from urllib import (
  32. quote, unquote, quote_plus, unquote_plus, urlencode, getproxies,
  33. proxy_bypass, proxy_bypass_environment, getproxies_environment)
  34. from urlparse import urlparse, urlunparse, urljoin, urlsplit, urldefrag
  35. from urllib2 import parse_http_list
  36. import cookielib
  37. from Cookie import Morsel
  38. from StringIO import StringIO
  39. from pip._vendor.urllib3.packages.ordered_dict import OrderedDict
  40. builtin_str = str
  41. bytes = str
  42. str = unicode
  43. basestring = basestring
  44. numeric_types = (int, long, float)
  45. integer_types = (int, long)
  46. elif is_py3:
  47. from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, unquote_plus, urldefrag
  48. from urllib.request import parse_http_list, getproxies, proxy_bypass, proxy_bypass_environment, getproxies_environment
  49. from http import cookiejar as cookielib
  50. from http.cookies import Morsel
  51. from io import StringIO
  52. from collections import OrderedDict
  53. builtin_str = str
  54. str = str
  55. bytes = bytes
  56. basestring = (str, bytes)
  57. numeric_types = (int, float)
  58. integer_types = (int,)