|
1 | 1 | # -*- coding: utf8 -*- |
2 | 2 | # flake8: NOQA |
| 3 | +import configparser |
| 4 | +import pickle |
3 | 5 | import sys |
| 6 | +import urllib.parse as urlparse |
| 7 | +from collections.abc import MutableMapping |
| 8 | +from io import BytesIO, StringIO |
| 9 | +from string import ascii_lowercase |
| 10 | +from urllib.request import urlretrieve |
4 | 11 |
|
5 | 12 | PY2 = sys.version_info[0] == 2 |
6 | 13 |
|
7 | 14 | _identity = lambda x: x |
8 | 15 |
|
9 | 16 |
|
10 | | -if PY2: |
11 | | - unichr = unichr |
12 | | - text_type = unicode |
13 | | - string_types = (str, unicode) |
14 | | - integer_types = (int, long) |
15 | | - from urllib import urlretrieve |
| 17 | +unichr = chr |
| 18 | +text_type = str |
| 19 | +string_types = (str,) |
| 20 | +integer_types = (int,) |
16 | 21 |
|
17 | | - text_to_native = lambda s, enc: s.encode(enc) |
| 22 | +text_to_native = lambda s, enc: s |
18 | 23 |
|
19 | | - iterkeys = lambda d: d.iterkeys() |
20 | | - itervalues = lambda d: d.itervalues() |
21 | | - iteritems = lambda d: d.iteritems() |
| 24 | +iterkeys = lambda d: iter(d.keys()) |
| 25 | +itervalues = lambda d: iter(d.values()) |
| 26 | +iteritems = lambda d: iter(d.items()) |
22 | 27 |
|
23 | | - from itertools import imap, izip |
24 | 28 |
|
25 | | - import ConfigParser as configparser |
26 | | - import cPickle as pickle |
27 | | - from cStringIO import StringIO as BytesIO |
28 | | - from StringIO import StringIO |
| 29 | +izip = zip |
| 30 | +imap = map |
| 31 | +range_type = range |
29 | 32 |
|
30 | | - range_type = xrange |
| 33 | +cmp = lambda a, b: (a > b) - (a < b) |
31 | 34 |
|
32 | | - cmp = cmp |
| 35 | +console_encoding = sys.__stdout__.encoding |
33 | 36 |
|
34 | | - input = raw_input |
35 | | - from collections import MutableMapping |
36 | | - from string import lower as ascii_lowercase |
| 37 | +implements_to_string = _identity |
37 | 38 |
|
38 | | - import urlparse |
39 | 39 |
|
40 | | - exec('def reraise(tp, value, tb=None):\n raise tp, value, tb') |
41 | | - |
42 | | - def implements_to_string(cls): |
43 | | - cls.__unicode__ = cls.__str__ |
44 | | - cls.__str__ = lambda x: x.__unicode__().encode('utf-8') |
45 | | - return cls |
46 | | - |
47 | | - def console_to_str(s): |
| 40 | +def console_to_str(s): |
| 41 | + """ From pypa/pip project, pip.backwardwardcompat. License MIT. """ |
| 42 | + try: |
| 43 | + return s.decode(console_encoding, 'ignore') |
| 44 | + except UnicodeDecodeError: |
48 | 45 | return s.decode('utf_8', 'ignore') |
49 | 46 |
|
50 | 47 |
|
51 | | -else: |
52 | | - unichr = chr |
53 | | - text_type = str |
54 | | - string_types = (str,) |
55 | | - integer_types = (int,) |
56 | | - |
57 | | - text_to_native = lambda s, enc: s |
58 | | - |
59 | | - iterkeys = lambda d: iter(d.keys()) |
60 | | - itervalues = lambda d: iter(d.values()) |
61 | | - iteritems = lambda d: iter(d.items()) |
62 | | - |
63 | | - import configparser |
64 | | - import pickle |
65 | | - from io import BytesIO, StringIO |
66 | | - |
67 | | - izip = zip |
68 | | - imap = map |
69 | | - range_type = range |
70 | | - |
71 | | - cmp = lambda a, b: (a > b) - (a < b) |
72 | | - |
73 | | - input = input |
74 | | - import urllib.parse as urllib |
75 | | - import urllib.parse as urlparse |
76 | | - from string import ascii_lowercase |
77 | | - from urllib.request import urlretrieve |
78 | | - |
79 | | - console_encoding = sys.__stdout__.encoding |
80 | | - |
81 | | - implements_to_string = _identity |
82 | | - |
83 | | - from collections.abc import MutableMapping |
84 | | - |
85 | | - def console_to_str(s): |
86 | | - """ From pypa/pip project, pip.backwardwardcompat. License MIT. """ |
87 | | - try: |
88 | | - return s.decode(console_encoding, 'ignore') |
89 | | - except UnicodeDecodeError: |
90 | | - return s.decode('utf_8', 'ignore') |
91 | | - |
92 | | - def reraise(tp, value, tb=None): |
93 | | - if value.__traceback__ is not tb: |
94 | | - raise (value.with_traceback(tb)) |
95 | | - raise value |
| 48 | +def reraise(tp, value, tb=None): |
| 49 | + if value.__traceback__ is not tb: |
| 50 | + raise (value.with_traceback(tb)) |
| 51 | + raise value |
96 | 52 |
|
97 | 53 |
|
98 | 54 | number_types = integer_types + (float,) |
|
0 commit comments