-
Notifications
You must be signed in to change notification settings - Fork 911
/
Copy path_compat.py
48 lines (46 loc) · 1.4 KB
/
_compat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
try:
TEXT = unicode
except NameError: #pragma NO COVER Py3k
PY3 = True
TEXT = str
STRING_TYPES = (str, bytes)
def b(x, encoding='ascii'):
return bytes(x, encoding)
else: #pragma NO COVER Python2
PY3 = False
STRING_TYPES = (unicode, bytes)
def b(x, encoding='ascii'):
if isinstance(x, unicode):
x = x.encode(encoding)
return x
def u(x, encoding='ascii'):
if isinstance(x, TEXT): #pragma NO COVER
return x
try:
return x.decode(encoding)
except AttributeError: #pragma NO COVER
raise ValueError('WTF: %s' % x)
try:
import urlparse
except ImportError: #pragma NO COVER Py3k
from urllib.parse import parse_qs
from urllib.parse import parse_qsl
from urllib.parse import quote
from urllib.parse import unquote
from urllib.parse import unquote_to_bytes
from urllib.parse import urlencode
from urllib.parse import urlsplit
from urllib.parse import urlunsplit
from urllib.parse import urlparse
from urllib.parse import urlunparse
else: #pragma NO COVER Python2
from urlparse import parse_qs
from urlparse import parse_qsl
from urllib import quote
from urllib import unquote
from urllib import urlencode
from urlparse import urlsplit
from urlparse import urlunsplit
from urlparse import urlparse
from urlparse import urlunparse
unquote_to_bytes = unquote