Convenience function for parsing YAML strings.

@param yaml String containing valid YAML
@return Nested (key,value) map of arbitrary depth
@throws IOException IO exception
355679
public static Map<String, Object> parseYamlString(String yaml) throws IOException {
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() {
        };
        return mapper.readValue(yaml, typeRef);
    }
1264750
public static YamlBuilder translate(String prefix, Properties properties, Properties map)
    throws IOException, ReflectiveOperationException {

        // map translators to ruleProps
        Map<YamlPropertyTranslator,Map<String,Object>> translators = new LinkedHashMap<>();
        YamlPropertyTranslator defaultTranslator = new DefaultYamlTranslator();
        for (String name : properties.stringPropertyNames()) {
            if ((prefix == null || name.startsWith(prefix + ".")) ||
                    (prefix.equals("mdw") && (name.startsWith("MDWFramework") || name.startsWith("LDAP")))) {
                YamlPropertyTranslator translator = null;
                String rule = map.getProperty(name);
                if (rule != null && rule.isEmpty()) {
                    // blank means remove this prop (no translator)
                    System.out.println("Info: Obsolete property: '" + name + "' -- removed");
                }
                else if (!"mdw".equals(prefix) && (name.startsWith("mdw")
                        || name.startsWith("MDWFramework") || name.startsWith("LDAP"))) {
                    String msg = "Warning: '" + name + "' belongs in mdw.yaml ";
                    if (rule != null)
                        msg += "(as " + rule + ") ";
                    System.err.println(msg + "-- removed");
                }
                else if (rule == null) {
                    // fully structured
                    rule = prefix == null ? name.replace('.', '/') : name.substring(prefix.length() + 1).replace('.', '/');
                    translator = defaultTranslator;
                }
                else if (rule.startsWith("[")) {
                    // custom translator -- reuse existing instance if found
                    int endBracket = rule.lastIndexOf(']');
                    String className = rule.substring(1, endBracket);
                    for (YamlPropertyTranslator instance : translators.keySet()) {
                        if (instance.getClass().getName().equals(className)) {
                            translator = instance;
                            break;
                        }
                    }
                    if (translator == null) {
                        translator = Class.forName(className).asSubclass(YamlPropertyTranslator.class).newInstance();
                    }
                }
                else {
                    translator = defaultTranslator;
                }
                if (translator != null) {
                    Map<String,Object> ruleProps = translators.get(translator);
                    if (ruleProps == null) {
                        ruleProps = new LinkedHashMap<>();
                        translators.put(translator, ruleProps);
                    }
                    Object propValue = properties.getProperty(name);
                    try {
                        // integers should be treated as such
                        propValue = Integer.parseInt(propValue.toString());
                    }
                    catch (NumberFormatException ex) {
                    }
                    ruleProps.put(rule, propValue);
                }
            }
        }

        // perform translations
        YamlBuilder yamlBuilder = new YamlBuilder();
        for (YamlPropertyTranslator translator : translators.keySet()) {
            yamlBuilder.append(translator.translate(translators.get(translator))).newLine();
        }
        return yamlBuilder;
    }
578347
function stringYAML2YAML (doc, compact = false) {
  if (!doc || typeof doc !== 'string') {
    throw new TypeError('Argument must be a string or object, and not empty: ' + doc)
  }

  let obj = yaml.safeLoad(doc)

  if (!obj || typeof obj !== 'object') {
    throw new TypeError('Argument must be in yaml format: ' + doc)
  }

  return yaml.safeDump(obj, compact ? { 'flowLevel': 0 } : undefined)
}
1009797
public static ParameterAveragingTrainingMaster fromYaml(String yamlStr) {
        ObjectMapper om = getYamlMapper();
        try {
            return om.readValue(yamlStr, ParameterAveragingTrainingMaster.class);
        } catch (IOException e) {
            throw new RuntimeException("Could not parse YAML", e);
        }
    }
164993
def parsed_options_from_yaml(file)
      options_to_merge = {}

      if File.exist?(file)
        # Load YAML content
        content = YAML.load(File.read(file))

        # Symbolize keys
        options_to_merge = content.reduce({}) do |memo, (key, value)|
          memo.merge! key.to_sym => value
        end
      end

      options_to_merge
    end
1245981
def parse_yaml_file(self, path):
        """"""
        with open(path, 'r') as fp:
            data = yaml.safe_load(fp)

        if not data:
            return {}

        def traverse(namespace, d):
            cfg = {}
            for key, val in d.items():
                if isinstance(d[key], dict):
                    cfg.update(traverse(namespace + [key], d[key]))
                else:
                    if not isinstance(val, str):
                        # All values should be double-quoted strings so they
                        # parse as strings; anything else is a configuration
                        # error at parse-time
                        raise ConfigurationError(
                            'Invalid value %r in file %s: values must be double-quoted strings' % (
                                val, path
                            )
                        )

                    cfg['_'.join(namespace + [key]).upper()] = val

            return cfg

        return traverse([], data)
1102399
def parse_yaml(self, y):
        ''''''
        self.sequence = int(y['sequence'])
        self.target_component = \
                TargetExecutionContext().parse_yaml(y['targetComponent'])
        if RTS_EXT_NS_YAML + 'properties' in y:
            for p in y.get(RTS_EXT_NS_YAML + 'properties'):
                if 'value' in p:
                    value = p['value']
                else:
                    value = None
                self._properties[p['name']] = value
        return self
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
737679
public static Map<String, Object> getYamlObjectValue(Map<String, Object> yamlObject,
            String key) throws YamlConvertException {
        return getYamlObjectValue(yamlObject, key, false);
    }
1024773
@SuppressWarnings("unchecked") // when we cast yaml.load(fin)
  public static Map<String, Object> loadFile(String fileName) {
    Map<String, Object> props = new HashMap<>();
    if (fileName == null) {
      LOG.warning("Config file name cannot be null");
      return props;
    } else if (fileName.isEmpty()) {
      LOG.warning("Config file name is empty");
      return props;
    } else {

      // check if the file exists and also it is a regular file
      Path path = Paths.get(fileName);

      if (!Files.exists(path)) {
        LOG.fine("Config file " + fileName + " does not exist");
        return props;
      }

      if (!Files.isRegularFile(path)) {
        LOG.warning("Config file " + fileName + " might be a directory.");
        return props;
      }

      LOG.log(Level.FINE, "Reading config file {0}", fileName);

      Map<String, Object> propsYaml = null;
      try {
        FileInputStream fin = new FileInputStream(new File(fileName));
        try {
          Yaml yaml = new Yaml();
          propsYaml = (Map<String, Object>) yaml.load(fin);
          LOG.log(Level.FINE, "Successfully read config file {0}", fileName);
        } finally {
          fin.close();
        }
      } catch (IOException e) {
        LOG.log(Level.SEVERE, "Failed to load config file: " + fileName, e);
      }

      return propsYaml != null ? propsYaml : props;
    }
  }
862971
public static Map<String, ? extends CacheConfig> fromYAML(String content) throws IOException {
        return new CacheConfigSupport().fromYAML(content);
    }
1057137
def _load_yaml_file(self, file):
        
        try:
            res = load_yaml_file(file)
        except:
            self.exception("Failed to load from {}".format(file))
            raise IOError("Loading file failed")
        return res
439321
public Map<String, Role> ymlToRoles(String yml) {
        try {
            Map<String, Role> map = mapper
                .readValue(yml, new TypeReference<TreeMap<String, Role>>() {
                });
            map.forEach((roleKey, role) -> role.setKey(roleKey));
            return map;
        } catch (Exception e) {
            log.error("Failed to create roles collection from YML file, error: {}", e.getMessage(), e);
        }
        return Collections.emptyMap();
    }
509541
def parse_yaml(self, y):
        '''

        '''
        super(TargetExecutionContext, self).parse_yaml(y)
        if 'id' in y:
            self.id = y['id']
        else:
            self.id = ''
        return self
1003471
def open_and_parse_yaml(yamlfile):
        

        # ??? what if the yaml file does not contain a dict datastructure?
        mapping = dict()
        if os.path.exists(os.path.join(os.path.dirname(__file__), yamlfile)):
            map_file = open(os.path.join(os.path.dirname(__file__), yamlfile), 'r')
            mapping = yaml.safe_load(map_file)
            map_file.close()
        else:
            LOG.warning("file: %s not found", yamlfile)

        return mapping
530728
public static YamlConfiguration loadYamlConfiguration(File file) throws DeployerConfigurationException {
        try {
            try (Reader reader = new BufferedReader(new FileReader(file))) {
                return doLoadYamlConfiguration(reader);
            }
        } catch (Exception e) {
            throw new DeployerConfigurationException("Failed to load YAML configuration at " + file, e);
        }
    }
718814
def parse_yaml(self, node):
        '''

        '''
        self.group_id = y['groupId']
        self._members = []
        if 'members' in y:
            for m in y.get('members'):
                self._members.append(TargetComponent().parse_yaml(m))
        return self