"Fossies" - the Fresh Open Source Software Archive

Member "cheetah3-3.2.6.post2/Cheetah/compat.py" (20 Apr 2021, 1466 Bytes) of package /linux/www/cheetah3-3.2.6.post2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "compat.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 3-3.2.3_vs_3-3.2.4.

    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     RecursionError = RecursionError
   17 except NameError:  # Python 2.7, 3.4
   18     RecursionError = RuntimeError
   19 
   20 if PY2:
   21     import imp
   22 
   23     def load_module_from_file(base_name, module_name, filename):
   24         fp, pathname, description = imp.find_module(
   25             base_name, [os.path.dirname(filename)])
   26         try:
   27             module = imp.load_module(module_name, fp, pathname, description)
   28         finally:
   29             fp.close()
   30         return module
   31 
   32     new_module = imp.new_module
   33     get_suffixes = imp.get_suffixes
   34 
   35 else:
   36     import importlib.machinery
   37     import importlib.util
   38 
   39     def load_module_from_file(base_name, module_name, filename):
   40         specs = importlib.util.spec_from_file_location(module_name, filename)
   41         return specs.loader.load_module()
   42 
   43     new_module = types.ModuleType
   44 
   45     def get_suffixes():
   46         extensions = [
   47             (s, 'rb', 3) for s in importlib.machinery.EXTENSION_SUFFIXES
   48         ]
   49         source = [
   50             (s, 'rU', 1) for s in importlib.machinery.SOURCE_SUFFIXES
   51         ]
   52         bytecode = [
   53             (s, 'rb', 2) for s in importlib.machinery.BYTECODE_SUFFIXES
   54         ]
   55 
   56         return extensions + source + bytecode