Return a yaml dict from a file or string with error handling.
776932
def yaml_load(path, input="", err_quit=False):
    
    try:
        if len(input) > 0:
            return yaml.safe_load(input)
        elif len(path) > 0:
            return yaml.safe_load(file_to_string(path))
    except Exception as err:
        file = os.path.basename(path)
        ui.error("",
                 c.MESSAGES["yaml_error"].replace("%file", file), err,
                 "")

        if err_quit:
            sys.exit(1)

        return False
865974
def get_yml_content(file_path):
    ''''''
    try:
        with open(file_path, 'r') as file:
            return yaml.load(file, Loader=yaml.Loader)
    except yaml.scanner.ScannerError as err:
        print_error('yaml file format error!')
        exit(1)
    except Exception as exception:
        print_error(exception)
        exit(1)
1052045
def from_file(cls, path, encoding, dialect, fields, converters, field_index):
        """"""

        return cls(open(path, 'r', encoding=encoding), dialect, fields, converters, field_index)
624942
def errors_as_dict(self):
        """"""
        errors = []

        for e in self.errors:

            errors.append({
                'file': e.term.file_name,
                'row': e.term.row if e.term else '<unknown>',
                'col': e.term.col if e.term else '<unknown>',
                'term': e.term.join if e.term else '<unknown>',
                'error': str(e)
            })

        return errors
830079
def load_yaml(filename):
    
    try:
        with open(filename, 'rb') as f:
            return yaml.load(f, Loader=Loader)
    except (IOError, yaml.error.YAMLError) as exc:
        raise ConfigReadError(filename, exc)
1118
def to_yaml(value) -> str:
    """"""
    stream = yaml.io.StringIO()
    dumper = ConfigDumper(stream, default_flow_style=True, width=sys.maxsize)
    val = None
    try:
        dumper.open()
        dumper.represent(value)
        val = stream.getvalue().strip()
        dumper.close()
    finally:
        dumper.dispose()

    return val
715645
def load_yaml(filepath):
    """"""
    with open(filepath) as f:
        txt = f.read()
    return yaml.load(txt)
630002
def load_yaml_file(file_path: str):
    """"""
    with codecs.open(file_path, 'r') as f:
        return yaml.safe_load(f)
314686
def yaml_block(self):
        
        if LOAD_YAML and self._yaml_block is not None:
            try:
                yaml_dict = yaml.load(self._yaml_block)
                return yaml_dict
            except yaml.error.YAMLError:
                print("Error parsing yaml block. Check formatting.")
        return None
38970
def load_var_file(filename, obj):
    """"""
    rendered = render(filename, obj)
    ext = os.path.splitext(filename)[1][1:]
    v_obj = dict()
    if ext == 'json':
        v_obj = json.loads(rendered)
    elif ext == 'yaml' or ext == 'yml':
        v_obj = yaml.safe_load(rendered)
    else:
        LOG.warning("assuming yaml for unrecognized extension %s",
                    ext)
        v_obj = yaml.safe_load(rendered)

    return v_obj
943152
def parse(self, stream):
        """"""
        yaml = self._load_yaml()

        try:
            parsed_obj = yaml.safe_load(stream)
        except Exception as e:
            raise ConfigFileParserException("Couldn't parse config file: %s" % e)

        if not isinstance(parsed_obj, dict):
            raise ConfigFileParserException("The config file doesn't appear to "
                "contain 'key: value' pairs (aka. a YAML mapping). "
                "yaml.load('%s') returned type '%s' instead of 'dict'." % (
                getattr(stream, 'name', 'stream'),  type(parsed_obj).__name__))

        result = OrderedDict()
        for key, value in parsed_obj.items():
            if isinstance(value, list):
                result[key] = value
            else:
                result[key] = str(value)

        return result
440358
def load_yaml_from_docstring(docstring):
    """"""
    split_lines = trim_docstring(docstring).split("\n")

    # Cut YAML from rest of docstring
    for index, line in enumerate(split_lines):
        line = line.strip()
        if line.startswith("---"):
            cut_from = index
            break
    else:
        return {}

    yaml_string = "\n".join(split_lines[cut_from:])
    yaml_string = dedent(yaml_string)
    return yaml.safe_load(yaml_string) or {}
808793
def parse_yaml(self, y):
        ''''''
        self.x = int(y['x'])
        self.y = int(y['y'])
        self.height = int(y['height'])
        self.width = int(y['width'])
        self.direction = dir.from_string(y['direction'])
        return self
143044
def safe_dump(data, stream=None, **kwds):
    """"""
    return yaml.dump(data, stream=stream, Dumper=ODYD, **kwds)
41753
def parse_yaml(self, y):
        '''

        '''
        self.name = y['name']
        if 'data' in y:
            self.data = y['data']
        else:
            self.data = ''
        return self
909744
def read_config(file_name):
    """"""

    config = {}
    for name in (['.pyspelling.yml', '.spelling.yml'] if not file_name else [file_name]):
        if os.path.exists(name):
            if not file_name and name == '.spelling.yml':
                warn_deprecated(
                    "Using '.spelling.yml' as the default is deprecated. Default config is now '.pyspelling.yml'"
                )
            with codecs.open(name, 'r', encoding='utf-8') as f:
                config = yaml_load(f.read())
            break
    return config
867185
def _ParseYamlFromFile(filedesc):
  """"""
  content = filedesc.read()
  return yaml.Parse(content) or collections.OrderedDict()