Completed
Push — master ( 1366b4...e90509 )
by Bai
02:13 queued 29s
created

s()   A

Complexity

Conditions 2

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
3 1
"""
4
pythoncompat
5
"""
6
7 1
import sys
8
9 1
try:
10 1
    import simplejson as json
11 1
except (ImportError, SyntaxError):
12
    # simplejson does not support Python 3.2, it thows a SyntaxError
13
    # because of u'...' Unicode literals.
14 1
    import json  # noqa
15
16
17
# -------
18
# Pythons
19
# -------
20
21 1
_ver = sys.version_info
22
23
#: Python 2.x?
24 1
is_py2 = (_ver[0] == 2)
25
26
#: Python 3.x?
27 1
is_py3 = (_ver[0] == 3)
28
29
30
# ---------
31
# Specifics
32
# ---------
33
34 1
if is_py2:
35
    from urlparse import urlparse  # noqa
36
    import StringIO
37
    StringIO = BytesIO = StringIO.StringIO
38
39
    builtin_str = str
40
    bytes = str
41
    str = unicode  # noqa
42
    basestring = basestring  # noqa
43
    numeric_types = (int, long, float)  # noqa
44
45
    def b(data):
46
        return bytes(data)
47
48
    def s(data):
49
        return bytes(data)
50
51
    def u(data):
52
        return unicode(data, 'unicode_escape')  # noqa
53
54 1
elif is_py3:
55 1
    from urllib.parse import urlparse  # noqa
56 1
    import io
57 1
    StringIO = io.StringIO
58 1
    BytesIO = io.BytesIO
59
60 1
    builtin_str = str
61 1
    str = str
62 1
    bytes = bytes
63 1
    basestring = (str, bytes)
64 1
    numeric_types = (int, float)
65
66 1
    def b(data):
67 1
        if isinstance(data, str):
68 1
            return data.encode('utf-8')
69 1
        return data
70
71 1
    def s(data):
72 1
        if isinstance(data, bytes):
73 1
            data = data.decode('utf-8')
74 1
        return data
75
76 1
    def u(data):
77
        return data
78