jpayne@7: """ jpayne@7: requests.compat jpayne@7: ~~~~~~~~~~~~~~~ jpayne@7: jpayne@7: This module previously handled import compatibility issues jpayne@7: between Python 2 and Python 3. It remains for backwards jpayne@7: compatibility until the next major version. jpayne@7: """ jpayne@7: jpayne@7: try: jpayne@7: import chardet jpayne@7: except ImportError: jpayne@7: import charset_normalizer as chardet jpayne@7: jpayne@7: import sys jpayne@7: jpayne@7: # ------- jpayne@7: # Pythons jpayne@7: # ------- jpayne@7: jpayne@7: # Syntax sugar. jpayne@7: _ver = sys.version_info jpayne@7: jpayne@7: #: Python 2.x? jpayne@7: is_py2 = _ver[0] == 2 jpayne@7: jpayne@7: #: Python 3.x? jpayne@7: is_py3 = _ver[0] == 3 jpayne@7: jpayne@7: # json/simplejson module import resolution jpayne@7: has_simplejson = False jpayne@7: try: jpayne@7: import simplejson as json jpayne@7: jpayne@7: has_simplejson = True jpayne@7: except ImportError: jpayne@7: import json jpayne@7: jpayne@7: if has_simplejson: jpayne@7: from simplejson import JSONDecodeError jpayne@7: else: jpayne@7: from json import JSONDecodeError jpayne@7: jpayne@7: # Keep OrderedDict for backwards compatibility. jpayne@7: from collections import OrderedDict jpayne@7: from collections.abc import Callable, Mapping, MutableMapping jpayne@7: from http import cookiejar as cookielib jpayne@7: from http.cookies import Morsel jpayne@7: from io import StringIO jpayne@7: jpayne@7: # -------------- jpayne@7: # Legacy Imports jpayne@7: # -------------- jpayne@7: from urllib.parse import ( jpayne@7: quote, jpayne@7: quote_plus, jpayne@7: unquote, jpayne@7: unquote_plus, jpayne@7: urldefrag, jpayne@7: urlencode, jpayne@7: urljoin, jpayne@7: urlparse, jpayne@7: urlsplit, jpayne@7: urlunparse, jpayne@7: ) jpayne@7: from urllib.request import ( jpayne@7: getproxies, jpayne@7: getproxies_environment, jpayne@7: parse_http_list, jpayne@7: proxy_bypass, jpayne@7: proxy_bypass_environment, jpayne@7: ) jpayne@7: jpayne@7: builtin_str = str jpayne@7: str = str jpayne@7: bytes = bytes jpayne@7: basestring = (str, bytes) jpayne@7: numeric_types = (int, float) jpayne@7: integer_types = (int,)