예제 #1
0
    def load_yamls(self, path):
        """Load multiple yamls into list"""

        yamls = [
            join(path, f) for f in listdir(path) if isfile(join(path, f))
            if f.endswith('.yaml') or f.endswith('.yml')
        ]

        result = []

        for yaml_item in yamls:
            try:
                with open(yaml_item, 'r') as f:
                    _ = yaml.load_all(f.read())
                    _ = [x for x in _]
                    if len(_) > 1:
                        _ = _[0]
                        _['additions'] = _[1:]
                    else:
                        _ = _[0]
                    _["uuid"] = str(uuid.uuid4())
                    result.append(_)
            except ScannerError:
                raise ScannerError('yaml is bad! %s' % yaml_item)

        return result
예제 #2
0
    def test_run_should_exit_with_error_when_target_yaml_parsing_fails(self):
        problem_mark = Mark('name', 1, 2, 3, '', '')
        mock_when(yadt_lint)._get_configuration(any_value()).thenRaise(ScannerError(problem_mark=problem_mark))
        mock_when(yadt_lint.sys).exit(any_value()).thenReturn(None)

        yadt_lint._validate_yaml_input(problem_mark)

        verify(yadt_lint.sys).exit(1)
        verify(yadt_lint.logger).error('Invalid YAML Format check position: (line:column) -> (2:4)')
예제 #3
0
def load_yamls(path):
    yamls = [join(path, f) for f in listdir(path) if isfile(join(path, f)) if f.endswith('.yaml') or f.endswith('.yml')]
    result = []
    for yaml in yamls:
        try:
            result.append(read_yaml_file(yaml))
        except ScannerError:
            raise ScannerError('yaml is bad! %s' % yaml)
    return result, yamls
예제 #4
0
def __fetch_documentation(request, raml_folder):
    with open("raml/%s/application.raml" % raml_folder, 'r') as stream:
        try:
            y = yaml.load(stream, loader.Loader)
            j = json.dumps(y)
            return j
        except ScannerError:
            message = {
                "code": "PARSER_ERROR",
                "message": "Unable to parse %s" % raml_folder
            }
            raise ScannerError(problem=json.dumps(message))
예제 #5
0
    def load_yamls(path):
        """Load multiple yamls into list"""

        yamls = [
            join(path, f) for f in listdir(path) if isfile(join(path, f))
            if f.endswith('.yaml') or f.endswith('.yml')
        ]

        result = []

        for yaml in yamls:
            try:
                result.append(ATCutils.read_yaml_file(yaml))

            except ScannerError:
                raise ScannerError('yaml is bad! %s' % yaml)

        return result
예제 #6
0
def get_yaml_rules(yaml_rules_fp):
    """
    Read rules from the yaml file.

    Parameters
    ----------
    yaml_rules_fp : str
        Path to the yaml file containing the cleaning rules.

    show : bool
        Whether to show the rules.

    Returns
    -------
    rules : dict
        Rules in dictionary form.
    """
    validate_fp(yaml_rules_fp)
    try:
        with open(yaml_rules_fp, 'rt', encoding='utf8') as yml:
            rules = yaml.load(yml, Loader=yaml.CLoader)
    except ScannerError:
        raise ScannerError("Yaml rules file may not be in .yml format")
    return rules
예제 #7
0
    def test_get_yaml_or_json_file_raises_exception_on_yaml_error(
            self, _, yaml_mock):
        yaml_mock.load.side_effect = ScannerError()

        with self.assertRaises(CfnSphereException):
            FileLoader.get_yaml_or_json_file('foo.yml', 'baa')
    def test_fs_get_file_raises_exception_on_yaml_error(self, _, yaml_mock):
        yaml_mock.load.side_effect = ScannerError()

        with self.assertRaises(TemplateErrorException):
            FileLoader._fs_get_file('foo.yml', 'baa')
예제 #9
0
    def fetch_more_tokens(self):
        'Override this to skip several chars like %, {, and }.'
        from yaml.scanner import ScannerError

        # Eat whitespaces and comments until we reach the next token.
        self.scan_to_next_token()

        # Remove obsolete possible simple keys.
        self.stale_possible_simple_keys()

        # Compare the current indentation and column. It may add some tokens
        # and decrease the current indentation level.
        self.unwind_indent(self.column)

        # Peek the next character.
        ch = self.peek()

        # Is it the end of stream?
        if ch == u'\0':
            return self.fetch_stream_end()

        # Is it a directive?
        #~ if ch == u'%' and self.check_directive():
        #~ return self.fetch_directive()

        # Is it the document start?
        if ch == u'-' and self.check_document_start():
            return self.fetch_document_start()

        # Is it the document end?
        if ch == u'.' and self.check_document_end():
            return self.fetch_document_end()

        # TODO: support for BOM within a stream.
        #if ch == u'\uFEFF':
        #    return self.fetch_bom()    <-- issue BOMToken

        # Note: the order of the following checks is NOT significant.

        #~ # Is it the flow sequence start indicator?
        #~ if ch == u'[':
        #~ return self.fetch_flow_sequence_start()

        #~ # Is it the flow mapping start indicator?
        #~ if ch == u'{':
        #~ return self.fetch_flow_mapping_start()

        #~ # Is it the flow sequence end indicator?
        #~ if ch == u']':
        #~ return self.fetch_flow_sequence_end()

        #~ # Is it the flow mapping end indicator?
        #~ if ch == u'}':
        #~ return self.fetch_flow_mapping_end()

        #~ # Is it the flow entry indicator?
        #~ if ch == u',':
        #~ return self.fetch_flow_entry()

        # Is it the block entry indicator?
        if ch == u'-' and self.check_block_entry():
            return self.fetch_block_entry()

        # Is it the key indicator?
        if ch == u'?' and self.check_key():
            return self.fetch_key()

        # Is it the value indicator?
        if ch == u':' and self.check_value():
            return self.fetch_value()

        # Is it an alias?
        #~ if ch == u'*':
        #~ return self.fetch_alias()

        # Is it an anchor?
        #~ if ch == u'&':
        #~ return self.fetch_anchor()

        # Is it a tag?
        if ch == u'!':
            return self.fetch_tag()

        # Is it a literal scalar?
        if ch == u'|' and not self.flow_level:
            return self.fetch_literal()

        # Is it a folded scalar?
        if ch == u'>' and not self.flow_level:
            return self.fetch_folded()

        # Is it a single quoted scalar?
        if ch == u'\'':
            return self.fetch_single()

        # Is it a double quoted scalar?
        if ch == u'\"':
            return self.fetch_double()

        # It must be a plain scalar then.
        if self.check_plain():
            return self.fetch_plain()

        # No? It's an error. Let's produce a nice error message.
        raise ScannerError(
            'while scanning for the next token', None,
            'found character %r that cannot start any token' %
            ch.encode('utf-8'), self.get_mark())