| 1 |
import sys |
| 2 |
|
| 3 |
PY2 = sys.version_info[0] == 2 |
| 4 |
|
| 5 |
|
| 6 |
def _identity(x): # pragma: no cover |
| 7 |
return x |
| 8 |
|
| 9 |
|
| 10 |
__all__ = [ |
| 11 |
'BytesIO', |
| 12 |
'PY2', |
| 13 |
'StringIO', |
| 14 |
'ascii_lowercase', |
| 15 |
'cmp', |
| 16 |
'configparser', |
| 17 |
'console_to_str', |
| 18 |
'imap', |
| 19 |
'input', |
| 20 |
'integer_types', |
| 21 |
'iteritems', |
| 22 |
'iterkeys', |
| 23 |
'itervalues', |
| 24 |
'izip', |
| 25 |
'number_types', |
| 26 |
'pickle', |
| 27 |
'range_type', |
| 28 |
'reraise', |
| 29 |
'string_types', |
| 30 |
'text_to_native', |
| 31 |
'text_type', |
| 32 |
'unichr', |
| 33 |
'urllib', |
| 34 |
'urlparse', |
| 35 |
'urlparse', |
| 36 |
'urlretrieve', |
| 37 |
'_identity', |
| 38 |
] |
| 39 |
|
| 40 |
if PY2: # pragma: no cover |
| 41 |
unichr = unichr |
| 42 |
text_type = unicode |
| 43 |
string_types = (str, unicode) |
| 44 |
integer_types = (int, long) |
| 45 |
from urllib import urlretrieve |
| 46 |
|
| 47 |
def text_to_native(s, enc): |
| 48 |
return s.encode(enc) |
| 49 |
|
| 50 |
def iterkeys(d): |
| 51 |
return d.iterkeys() |
| 52 |
|
| 53 |
def itervalues(d): |
| 54 |
return d.itervalues() |
| 55 |
|
| 56 |
def iteritems(d): |
| 57 |
return d.iteritems() |
| 58 |
|
| 59 |
from cStringIO import StringIO as BytesIO |
| 60 |
from StringIO import StringIO |
| 61 |
import cPickle as pickle |
| 62 |
import ConfigParser as configparser |
| 63 |
|
| 64 |
from itertools import izip, imap |
| 65 |
range_type = xrange |
| 66 |
|
| 67 |
cmp = cmp |
| 68 |
|
| 69 |
input = raw_input |
| 70 |
from string import lower as ascii_lowercase |
| 71 |
import urlparse |
| 72 |
|
| 73 |
def console_to_str(s): |
| 74 |
return s.decode('utf_8') |
| 75 |
|
| 76 |
exec('def reraise(tp, value, tb=None):\n raise tp, value, tb') |
| 77 |
|
| 78 |
else: # pragma: no cover |
| 79 |
unichr = chr |
| 80 |
text_type = str |
| 81 |
string_types = (str, ) |
| 82 |
integer_types = (int, ) |
| 83 |
|
| 84 |
def text_to_native(s, enc): |
| 85 |
return s |
| 86 |
|
| 87 |
def iterkeys(d): |
| 88 |
return iter(d.keys()) |
| 89 |
|
| 90 |
def itervalues(d): |
| 91 |
return iter(d.values()) |
| 92 |
|
| 93 |
def iteritems(d): |
| 94 |
return iter(d.items()) |
| 95 |
|
| 96 |
from io import StringIO |
| 97 |
from io import BytesIO |
| 98 |
import pickle |
| 99 |
import configparser |
| 100 |
|
| 101 |
izip = zip |
| 102 |
imap = map |
| 103 |
range_type = range |
| 104 |
|
| 105 |
def cmp(a, b): |
| 106 |
return (a > b) - (a < b) |
| 107 |
|
| 108 |
input = input |
| 109 |
from string import ascii_lowercase |
| 110 |
import urllib.parse as urllib |
| 111 |
import urllib.parse as urlparse |
| 112 |
from urllib.request import urlretrieve |
| 113 |
|
| 114 |
if getattr(sys, '__stdout__', None): |
| 115 |
console_encoding = sys.__stdout__.encoding |
| 116 |
else: |
| 117 |
console_encoding = sys.stdout.encoding |
| 118 |
|
| 119 |
def console_to_str(s): |
| 120 |
''' From pypa/pip project, pip.backwardwardcompat. License MIT. ''' |
| 121 |
try: |
| 122 |
return s.decode(console_encoding) |
| 123 |
except UnicodeDecodeError: |
| 124 |
return s.decode('utf_8') |
| 125 |
|
| 126 |
def reraise(tp, value, tb=None): |
| 127 |
if value.__traceback__ is not tb: |
| 128 |
raise (value.with_traceback(tb)) |
| 129 |
raise value |
| 130 |
|
| 131 |
|
| 132 |
number_types = integer_types + (float, ) |