import sys
import yaml
from . import _logger


class YAMLLoader(object):
    def __init__(self, **kwargs):
        kwargs.setdefault('log_level', 'warning')
        for k, v in kwargs.iteritems():
            setattr(self, k, v)

    @staticmethod
    def read_yaml(file_name, accept_none=False):
        if accept_none and file_name is None:
            return None
        try:
            _logger.debug("Try to open yaml file %s" % file_name)
            config_file = open(file_name)
            _logger.debug("Try to load content of %s" % file_name)
            config = yaml.load(config_file)
            config_file.close()
            return config
        except IOError as e:
            _logger.error("Could not find or open yaml file %s" % file_name)
            _logger.error(e.strerror)
            raise e
        except yaml.YAMLError as e:
            _logger.error("Failed to load yaml file %s" % file_name)
            raise e


class YAMLDumper(object):
    def __init__(self, **kwargs):
        kwargs.setdefault('log_level', 'warning')
        for k, v in kwargs.iteritems():
            setattr(self, k, v)

    @staticmethod
    def dump_yaml(data, file_name, **kwargs):
        try:
            _logger.debug("Try to open file %s" % file_name)
            out_file = open(file_name, "w+")
            _logger.debug("Try to dump data to file %s" % file_name)
            yaml.dump(data, out_file, **kwargs)
            out_file.close()
        except Exception as e:
            _logger.error("Failed to dump data to file %s" % file_name)
            raise e

@@ -4,16 +4,357 @@
 ort sys%0A
+try:%0A    import oyaml%0Aexcept ImportError:%0A    print %22yaml has been replaced by oyaml to provide support for ordered dictionaries read from configuration%22%0A    print %22Please install via: %5C033%5B91m pip install oyaml --user.%5C033%5B0m%22%0A    _ = raw_input(%22Acknowledge by hitting enter (running with yaml for now. Note this might cause crashes)%22)%0A    
 import y

switch to oyaml