Debian Codegraph @

Cheetah/compat.py

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 import os
2 import sys
3 import types
4
5 # Compatability definitions (inspired by six)
6 PY2 = sys.version_info[0] < 3
7 if PY2:
8 # disable flake8 checks on python 3
9 string_type = basestring # noqa
10 unicode = unicode # noqa
11 else:
12 string_type = str
13 unicode = str
14
15 try:
16 ModuleNotFoundError = ModuleNotFoundError
17 except NameError: # Python 2.7, 3.4, 3.5
18 ModuleNotFoundError = ImportError
19
20 try:
21 RecursionError = RecursionError
22 except NameError: # Python 2.7, 3.4
23 RecursionError = RuntimeError
24
25 if PY2:
26 import imp
27
28 def load_module_from_file(base_name, module_name, filename):
29 fp, pathname, description = imp.find_module(
30 base_name, [os.path.dirname(filename)])
31 try:
32 module = imp.load_module(module_name, fp, pathname, description)
33 finally:
34 fp.close()
35 return module
36
37 new_module = imp.new_module
38 get_suffixes = imp.get_suffixes
39
40 def cache_from_source(path, debug_override=None):
41 assert path.endswith('.py'), path
42 if debug_override is None:
43 debug_override = __debug__
44 if debug_override:
45 suffix = 'c'
46 else:
47 suffix = 'o'
48 return path + suffix
49
50 else:
51 import importlib.machinery
52 import importlib.util
53
54 def load_module_from_file(base_name, module_name, filename):
55 specs = importlib.util.spec_from_file_location(module_name, filename)
56 return specs.loader.load_module()
57
58 new_module = types.ModuleType
59
60 def get_suffixes():
61 extensions = [
62 (s, 'rb', 3) for s in importlib.machinery.EXTENSION_SUFFIXES
63 ]
64 source = [
65 (s, 'r', 1) for s in importlib.machinery.SOURCE_SUFFIXES
66 ]
67 bytecode = [
68 (s, 'rb', 2) for s in importlib.machinery.BYTECODE_SUFFIXES
69 ]
70
71 return extensions + source + bytecode
72
73 from importlib.util import cache_from_source # noqa: F401 unused