Plex plugin to to play various online streams (mostly Latvian).

compat.py 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 .packages 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. try:
  20. import simplejson as json
  21. except (ImportError, SyntaxError):
  22. # simplejson does not support Python 3.2, it throws a SyntaxError
  23. # because of u'...' Unicode literals.
  24. import json
  25. # ---------
  26. # Specifics
  27. # ---------
  28. if is_py2:
  29. from urllib import quote, unquote, quote_plus, unquote_plus, urlencode, getproxies, proxy_bypass
  30. from urlparse import urlparse, urlunparse, urljoin, urlsplit, urldefrag
  31. from urllib2 import parse_http_list
  32. import cookielib
  33. from Cookie import Morsel
  34. from StringIO import StringIO
  35. from .packages.urllib3.packages.ordered_dict import OrderedDict
  36. builtin_str = str
  37. bytes = str
  38. str = unicode
  39. basestring = basestring
  40. numeric_types = (int, long, float)
  41. elif is_py3:
  42. from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, unquote_plus, urldefrag
  43. from urllib.request import parse_http_list, getproxies, proxy_bypass
  44. from http import cookiejar as cookielib
  45. from http.cookies import Morsel
  46. from io import StringIO
  47. from collections import OrderedDict
  48. builtin_str = str
  49. str = str
  50. bytes = bytes
  51. basestring = (str, bytes)
  52. numeric_types = (int, float)