summaryrefslogtreecommitdiffstats
path: root/python.d/python_modules/bases/loaders.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2018-11-07 12:19:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2018-11-07 12:20:17 +0000
commita64a253794ac64cb40befee54db53bde17dd0d49 (patch)
treec1024acc5f6e508814b944d99f112259bb28b1be /python.d/python_modules/bases/loaders.py
parentNew upstream version 1.10.0+dfsg (diff)
downloadnetdata-upstream/1.11.0+dfsg.tar.xz
netdata-upstream/1.11.0+dfsg.zip
New upstream version 1.11.0+dfsgupstream/1.11.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'python.d/python_modules/bases/loaders.py')
-rw-r--r--python.d/python_modules/bases/loaders.py66
1 files changed, 0 insertions, 66 deletions
diff --git a/python.d/python_modules/bases/loaders.py b/python.d/python_modules/bases/loaders.py
deleted file mode 100644
index d18b9dcd..00000000
--- a/python.d/python_modules/bases/loaders.py
+++ /dev/null
@@ -1,66 +0,0 @@
-# -*- coding: utf-8 -*-
-# Description:
-# Author: Ilya Mashchenko (l2isbad)
-
-import types
-from sys import version_info
-
-PY_VERSION = version_info[:2]
-
-if PY_VERSION > (3, 1):
- from pyyaml3 import SafeLoader as YamlSafeLoader
- from importlib.machinery import SourceFileLoader
- DEFAULT_MAPPING_TAG = 'tag:yaml.org,2002:map'
-else:
- from pyyaml2 import SafeLoader as YamlSafeLoader
- from imp import load_source as SourceFileLoader
- DEFAULT_MAPPING_TAG = u'tag:yaml.org,2002:map'
-
-try:
- from collections import OrderedDict
-except ImportError:
- from third_party.ordereddict import OrderedDict
-
-
-def dict_constructor(loader, node):
- return OrderedDict(loader.construct_pairs(node))
-
-
-YamlSafeLoader.add_constructor(DEFAULT_MAPPING_TAG, dict_constructor)
-
-
-class YamlOrderedLoader:
- @staticmethod
- def load_config_from_file(file_name):
- opened, loaded = False, False
- try:
- stream = open(file_name, 'r')
- opened = True
- loader = YamlSafeLoader(stream)
- loaded = True
- parsed = loader.get_single_data() or dict()
- except Exception as error:
- return dict(), error
- else:
- return parsed, None
- finally:
- if opened:
- stream.close()
- if loaded:
- loader.dispose()
-
-
-class SourceLoader:
- @staticmethod
- def load_module_from_file(name, path):
- try:
- loaded = SourceFileLoader(name, path)
- if isinstance(loaded, types.ModuleType):
- return loaded, None
- return loaded.load_module(), None
- except Exception as error:
- return None, error
-
-
-class ModuleAndConfigLoader(YamlOrderedLoader, SourceLoader):
- pass