Loads a YAML file, parses it and returns a hash with symbolized keys.
13172
def load(file)
      if File.exist? file
        symbolize_keys(YAML.load_file(File.expand_path('.', file)))
      else
        {}
      end
    end
181561
def load_config(configfile):
    
    try:
        with open(configfile, 'r') as ymlfile:
            try:
                config = yaml.load(ymlfile)
                return config
            except yaml.parser.ParserError:
                raise PyYAMLConfigError(
                    'Could not parse config file: {}'.format(configfile),
                )
    except IOError:
        raise PyYAMLConfigError(
            'Could not open config file: {}'.format(configfile),
        )
666241
def parse_yaml_from_file(path):
    '''  '''

    try:
        data = file(path).read()
        return parse_yaml(data)
    except IOError:
        raise errors.AnsibleError("file not found: %s" % path)
    except yaml.YAMLError, exc:
        if hasattr(exc, 'problem_mark'):
            mark = exc.problem_mark
            if mark.line -1 >= 0:
                before_probline = data.split("\n")[mark.line-1]
            else:
                before_probline = ''
            probline = data.split("\n")[mark.line]
            arrow = " " * mark.column + "^"
            msg = """Syntax Error while loading YAML script, %s
Note: The error may actually appear before this position: line %s, column %s

%s
%s
%s""" % (path, mark.line + 1, mark.column + 1, before_probline, probline, arrow)
        else:
            # No problem markers means we have to throw a generic
            # "stuff messed up" type message. Sry bud.
            msg = "Could not parse YAML. Check over %s again." % path
        raise errors.AnsibleYAMLValidationFailed(msg)
904954
def __load_yml(self, stream):
        

        try:
            return yaml.load(stream, Loader=yaml.SafeLoader)
        except ValueError as e:
            cause = "invalid yml format. %s" % str(e)
            raise InvalidFormatError(cause=cause)
498686
def load!(path)
      settings = YAML.safe_load(ERB.new(File.new(path).read).result)['api']
      from_hash(settings) if settings.is_a? Hash
    end
989918
def loads_json_or_yaml(file_path, content):
    
    if os.path.splitext(file_path)[1] == ".json":
        return json.loads(content)
    else:
        return inginious.common.custom_yaml.load(content)
562465
def load_file(yamlfile)
      file_queue = [File.expand_path(yamlfile)]
      loaded_files = {}
      yaml = {}

      loop do
        # Check exit condition
        return yaml if file_queue.empty?

        current_file = file_queue.shift
        current_yaml = YAML.load_file(current_file)
        yaml = current_yaml.deep_merge(yaml)

        next unless yaml.key?('inherit')

        buf = []
        yaml['inherit'].reverse_each do |item|
          inherit_file = File.expand_path(item, File.dirname(yamlfile))

          # Check loop
          if loaded_files[inherit_file]
            raise "Found circular YAML inheritance '#{inherit_file}' in #{yamlfile}."
          end

          loaded_files[inherit_file] = true
          buf << inherit_file
        end
        yaml.delete('inherit')
        file_queue = buf + file_queue
      end
    end
1332431
def read
      @metadata = {}
      @content = File.read(path)

      if @content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
        @content = $POSTMATCH

        begin
          @metadata = YAML.load($1)
          raise unless @metadata.is_a? Hash
        rescue => ex
          $stderr.puts "#{File.basename($PROGRAM_NAME)}: #{ex.to_s}"
          $stderr.puts "WARNING: Couldn't load metadata."
          @metadata = {}
        end

        @metadata.symbolize_keys!
        import_metadata
      end
    end
18847
def read_yaml(path)
      return unless File.exist?(path)
      source = YAML.load_file(path)
      return unless source.is_a?(Hash)

      update_with { |config| read_yaml_key(source, config[:key]) }
    end
1343730
def yaml?(file)
      line = open(file) { |f| line = f.gets }
      line.index "!ruby/object:Gem::Specification"
    end
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
953087
def read_yaml(file_path, Loader=yaml.Loader, object_pairs_hook=OrderedDict):
    ''''''
    # http://stackoverflow.com/a/21912744/943773

    class OrderedLoader(Loader):
        pass

    def construct_mapping(loader, node):
        loader.flatten_mapping(node)
        return object_pairs_hook(loader.construct_pairs(node))

    OrderedLoader.add_constructor(
        yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
        construct_mapping)

    with open(file_path, 'r') as f:

        return yaml.load(f, OrderedLoader)
834081
function loadYaml (filename) {
    const file = findFile(`${filename}.yml`)
    return file ? YAML.parse(fs.readFileSync(file, 'utf8')) : {}
  }
969571
def _load_yaml(self, config_file):
        
        try:
            with open(config_file) as f:
                return yaml.safe_load(f.read())
        except yaml.YAMLError as exc:
            logger.error("Could not parse config as YAML: {}", str(exc))
            if hasattr(exc, 'problem_mark'):
                mark = exc.problem_mark
                logger.error("Error position: (%s:%s)" % (mark.line + 1, mark.column + 1))
        except IOError as e:
            logger.debug("Could not open config file: {}", str(e))

        return None
1070966
def load_gemspec
      file = gemspec
      if yaml?(file)
        ::Gem::Specification.from_yaml(File.new(file))
      else
        ::Gem::Specification.load(file)
      end
    end
1099008
def load_yaml(yaml_file)
      fail "File #{yaml_file} doesn't exist." unless File.exist?(yaml_file)
      # Parse YAML file into a tree of nodes
      # Psych::SyntaxError doesn't inherit from StandardError in some versions,
      # so we want to explicitly catch it if using Psych.
      rescue_errors = [::StandardError, ::Psych::SyntaxError]
      yaml_parsed = File.open(yaml_file, 'r') do |f|
        begin
          YAML.parse(f)
        rescue *rescue_errors => e
          raise "unable to parse #{yaml_file}: #{e}"
        end
      end
      return {} unless yaml_parsed
      # Validate the node tree
      validate_yaml(yaml_parsed, yaml_file)
      # If validation passed, convert the node tree to a Ruby Hash.
      yaml_parsed.transform
    end
546779
def load_defaults_file(file, hash)
      begin
        config = YAML::load_file(file)
      rescue
        raise MigrationError.new("Could not read defaults file #{file}: " + $!)
      end
      # collect the class => path => value entries
      config.each do |path_s, value|
        next if value.nil_or_empty?
        klass, path = create_attribute_path(path_s)
        hash[klass][path] = value
      end
    end