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.

63 lines
1.4 KiB

13 years ago
# -*- coding: utf-8 -*-
"""
pythoncompat
"""
import chardet
13 years ago
import sys
# -------
# Pythons
# -------
# Syntax sugar.
_ver = sys.version_info
#: Python 2.x?
is_py2 = (_ver[0] == 2)
#: Python 3.x?
is_py3 = (_ver[0] == 3)
13 years ago
try:
import simplejson as json
11 years ago
except (ImportError, SyntaxError):
10 years ago
# simplejson does not support Python 3.2, it throws a SyntaxError
11 years ago
# because of u'...' Unicode literals.
13 years ago
import json
13 years ago
# ---------
# Specifics
# ---------
if is_py2:
from urllib import quote, unquote, quote_plus, unquote_plus, urlencode, getproxies, proxy_bypass
from urlparse import urlparse, urlunparse, urljoin, urlsplit, urldefrag
13 years ago
from urllib2 import parse_http_list
import cookielib
13 years ago
from Cookie import Morsel
13 years ago
from StringIO import StringIO
13 years ago
from .packages.urllib3.packages.ordered_dict import OrderedDict
13 years ago
13 years ago
builtin_str = str
13 years ago
bytes = str
13 years ago
str = unicode
basestring = basestring
13 years ago
numeric_types = (int, long, float)
13 years ago
13 years ago
elif is_py3:
from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, unquote_plus, urldefrag
from urllib.request import parse_http_list, getproxies, proxy_bypass
13 years ago
from http import cookiejar as cookielib
13 years ago
from http.cookies import Morsel
13 years ago
from io import StringIO
13 years ago
from collections import OrderedDict
13 years ago
13 years ago
builtin_str = str
13 years ago
str = str
bytes = bytes
basestring = (str, bytes)
13 years ago
numeric_types = (int, float)