Parse a YAML stream and produce parsing events.
499732
def parse(stream, Loader=Loader):
    
    loader = Loader(stream)
    try:
        while loader.check_event():
            yield loader.get_event()
    finally:
        loader.dispose()
650719
def parse_yaml(self, y):
        '''

        '''
        super(WaitTime, self).parse_yaml(y)
        self.wait_time = int(y['condition']['waitTime']['waitTime'])
        return self
1343496
def _parse_result(self, ok, match, fh=None):
        """"""
        peek_match = None
        try:
            if fh is not None and self._try_peeking:
                peek_match = self.yaml_block_start.match(fh.peek())
        except StopIteration:
            pass
        if peek_match is None:
            return Result(
                ok,
                number=match.group("number"),
                description=match.group("description").strip(),
                directive=Directive(match.group("directive")),
            )
        indent = peek_match.group("indent")
        concat_yaml = self._extract_yaml_block(indent, fh)
        return Result(
            ok,
            number=match.group("number"),
            description=match.group("description").strip(),
            directive=Directive(match.group("directive")),
            raw_yaml_block=concat_yaml,
        )
175346
function yamlParse (text, reviver) {
    try {
      return yaml.safeLoad(text);
    }
    catch (e) {
      if (e instanceof Error) {
        throw e;
      }
      else {
        // https://github.com/nodeca/js-yaml/issues/153
        throw ono(e, e.message);
      }
    }
  }
94539
def to_yaml
      YAML.dump(to_h)
    rescue => err
      raise ParseError.new(err), err
    end
999686
def _parse_results(self, stream):
        """"""
        result = None
        values = None
        try:
            for event, elem in et.iterparse(stream, events=('start', 'end')):
                if elem.tag == 'results' and event == 'start':
                    # The wrapper element is a <results preview="0|1">. We
                    # don't care about it except to tell is whether these
                    # are preview results, or the final results from the
                    # search.
                    is_preview = elem.attrib['preview'] == '1'
                    self.is_preview = is_preview
                if elem.tag == 'result':
                    if event == 'start':
                        result = OrderedDict()
                    elif event == 'end':
                        yield result
                        result = None
                        elem.clear()

                elif elem.tag == 'field' and result is not None:
                    # We need the 'result is not None' check because
                    # 'field' is also the element name in the <meta>
                    # header that gives field order, which is not what we
                    # want at all.
                    if event == 'start':
                        values = []
                    elif event == 'end':
                        field_name = elem.attrib['k'].encode('utf8')
                        if len(values) == 1:
                            result[field_name] = values[0]
                        else:
                            result[field_name] = values
                        # Calling .clear() is necessary to let the
                        # element be garbage collected. Otherwise
                        # arbitrarily large results sets will use
                        # arbitrarily large memory intead of
                        # streaming.
                        elem.clear()

                elif elem.tag in ('text', 'v') and event == 'end':
                    text = "".join(elem.itertext())
                    values.append(text.encode('utf8'))
                    elem.clear()

                elif elem.tag == 'msg':
                    if event == 'start':
                        msg_type = elem.attrib['type']
                    elif event == 'end':
                        text = elem.text if elem.text is not None else ""
                        yield Message(msg_type, text.encode('utf8'))
                        elem.clear()
        except SyntaxError as pe:
            # This is here to handle the same incorrect return from
            # splunk that is described in __init__.
            if 'no element found' in pe.msg:
                return
            else:
                raise
91932
def get_parsed_context(context_arg):
    """"""
    assert context_arg, ("pipeline must be invoked with context arg set. For "
                         "this yaml parser you're looking for something "
                         "like: "
                         "pypyr pipelinename './myyamlfile.yaml'")
    logger.debug("starting")
    logger.debug(f"attempting to open file: {context_arg}")
    with open(context_arg) as yaml_file:
        yaml_loader = yaml.YAML(typ='safe', pure=True)
        payload = yaml_loader.load(yaml_file)

    logger.debug(f"yaml file parsed. Count: {len(payload)}")

    if not isinstance(payload, MutableMapping):
        raise TypeError("yaml input should describe a dictionary at the top "
                        "level. You should have something like "
                        "\n'key1: value1'\n key2: value2'\n"
                        "in the yaml top-level, not \n'- value1\n - value2'")

    logger.debug("done")
    return payload
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
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
1023994
def _parse(self):
        
        try:
            # parse token stream into abstract syntax tree (AST)
            self._ast = self._rule_container()

        except ParseError:
            raise

        except Exception as exc:
            raise ParseError(u'Unexpected error: {0}'.format(unicode(exc)))
1351705
def load_yaml(stream, **kwargs):
    
    # if there's an error parsing the yaml, and you pass yaml.load a string,
    # it will print lines of context, but will print "<string>" instead of a
    # filename; if you pass a stream, it will print the filename, but no lines
    # of context.
    # Get the best of both worlds, by passing it a string, then replacing
    # "<string>" with the filename if there's an error...
    content = stream.read()
    try:
        return yaml.load(content) or {}
    except Exception, e:
        if stream.name and stream.name != '<string>':
            for mark_name in 'context_mark', 'problem_mark':
                mark = getattr(e, mark_name, None)
                if mark is None:
                    continue
                if getattr(mark, 'name') == '<string>':
                    mark.name = stream.name
        raise e
531841
def from_yaml(stream, cls=None, loader_cls=yaml.Loader,
              object_pairs_hook=OrderedDict, **extras):
    

    class OrderedLoader(loader_cls):
        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)

    yaml_dict = yaml.load(stream, OrderedLoader) or {}
    yaml_dict.update(extras)
    return cls(**yaml_dict) if cls else yaml_dict
121087
def from_string(cls, s):
        """"""
        stream = cStringIO(s)
        stream.seek(0)
        return cls(**yaml.safe_load(stream))
1119457
def yml_load(stream, container, **options):
    
    ret = yml_fnc("load", stream, **options)
    if ret is None:
        return container()

    return ret
645721
def write_yaml (self, data, encoding=None, errors=None, newline=None, **kwargs):
        
        import yaml

        with self.open (mode='wt', encoding=encoding, errors=errors, newline=newline) as f:
            return yaml.dump (data, stream=f, **kwargs)
118964
def parse_yaml(self, y):
        '''

        '''
        super(Preceding, self).parse_yaml(y)
        c = y['condition']['preceding']
        if 'timeout' in c:
            self.timeout = int(c['timeout'])
        else:
            self.timeout = 0
        if 'sendingTiming' in c:
            self.sending_timing = c['sendingTiming']
        else:
            self.sending_timing = 'ASYNC'
        self._preceding_components = []
        if 'precedingComponents' in c:
            for p in c.get('precedingComponents'):
                self._preceding_components.append(TargetExecutionContext().parse_yaml(p))
        return self
11916
def parse_yaml(self, y):
        ''''''
        super(TargetPort, self).parse_yaml(y)
        self.port_name = y['portName']
        return self