forked from core-api/python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompat.py
More file actions
65 lines (47 loc) · 1.38 KB
/
compat.py
File metadata and controls
65 lines (47 loc) · 1.38 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# coding: utf-8
import base64
__all__ = [
'urlparse', 'string_types',
'COMPACT_SEPARATORS', 'VERBOSE_SEPARATORS'
]
try:
# Python 2
import urlparse
import cookielib as cookiejar
string_types = (basestring,)
text_type = unicode
COMPACT_SEPARATORS = (b',', b':')
VERBOSE_SEPARATORS = (b',', b': ')
def b64encode(input_string):
# Provide a consistently-as-unicode interface across 2.x and 3.x
return base64.b64encode(input_string)
except ImportError:
# Python 3
import urllib.parse as urlparse
from io import IOBase
from http import cookiejar
string_types = (str,)
text_type = str
COMPACT_SEPARATORS = (',', ':')
VERBOSE_SEPARATORS = (',', ': ')
def b64encode(input_string):
# Provide a consistently-as-unicode interface across 2.x and 3.x
return base64.b64encode(input_string.encode('ascii')).decode('ascii')
def force_bytes(string):
if isinstance(string, string_types):
return string.encode('utf-8')
return string
def force_text(string):
if not isinstance(string, string_types):
return string.decode('utf-8')
return string
try:
import click
console_style = click.style
except ImportError:
def console_style(text, **kwargs):
return text
try:
from tempfile import _TemporaryFileWrapper
except ImportError:
_TemporaryFileWrapper = None