Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/coreapi/compat.py: 47%
39 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1# coding: utf-8
3import base64
6__all__ = [
7 'urlparse', 'string_types',
8 'COMPACT_SEPARATORS', 'VERBOSE_SEPARATORS'
9]
12try:
13 # Python 2
14 import urlparse
15 import cookielib as cookiejar
17 string_types = (basestring,)
18 text_type = unicode
19 COMPACT_SEPARATORS = (b',', b':')
20 VERBOSE_SEPARATORS = (b',', b': ')
22 def b64encode(input_string):
23 # Provide a consistently-as-unicode interface across 2.x and 3.x
24 return base64.b64encode(input_string)
26except ImportError:
27 # Python 3
28 import urllib.parse as urlparse
29 from io import IOBase
30 from http import cookiejar
32 string_types = (str,)
33 text_type = str
34 COMPACT_SEPARATORS = (',', ':')
35 VERBOSE_SEPARATORS = (',', ': ')
37 def b64encode(input_string):
38 # Provide a consistently-as-unicode interface across 2.x and 3.x
39 return base64.b64encode(input_string.encode('ascii')).decode('ascii')
42def force_bytes(string):
43 if isinstance(string, string_types):
44 return string.encode('utf-8')
45 return string
48def force_text(string):
49 if not isinstance(string, string_types):
50 return string.decode('utf-8')
51 return string
54try:
55 import click
56 console_style = click.style
57except ImportError:
58 def console_style(text, **kwargs):
59 return text
62try:
63 from tempfile import _TemporaryFileWrapper
64except ImportError:
65 _TemporaryFileWrapper = None