Completed
Pull Request — master (#199)
by Björn
03:00
created

neovim.find_module()   B

Complexity

Conditions 6

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 34.317
Metric Value
cc 6
dl 0
loc 19
ccs 1
cts 13
cp 0.0769
crap 34.317
rs 8
1
"""Code for supporting compatibility across python versions."""
2
3 6
import sys
4 6
from imp import find_module as original_find_module
5
6
7 6
IS_PYTHON3 = sys.version_info >= (3, 0)
8
9
10 6
if IS_PYTHON3:
11 3
    def find_module(fullname, path):
12
        """Compatibility wrapper for imp.find_module.
13
14
        Automatically decodes arguments of find_module, in Python3
15
        they must be Unicode
16
        """
17
        if isinstance(fullname, bytes):
18
            fullname = fullname.decode()
19
        if isinstance(path, bytes):
20
            path = path.decode()
21
        elif isinstance(path, list):
22
            newpath = []
23
            for element in path:
24
                if isinstance(element, bytes):
25
                    newpath.append(element.decode())
26
                else:
27
                    newpath.append(element)
28
            path = newpath
29
        return original_find_module(fullname, path)
30
31
    # There is no 'long' type in Python3 just int
32 3
    long = int
33 3
    unicode_errors_default = 'surrogateescape'
34
else:
35 3
    find_module = original_find_module
36 3
    unicode_errors_default = 'strict'
37
38
NUM_TYPES = (int, long, float)
39