当前位置: 首页>>代码示例>>Python>>正文


Python yaml.YAMLError方法代码示例

本文整理汇总了Python中ruamel.yaml.YAMLError方法的典型用法代码示例。如果您正苦于以下问题:Python yaml.YAMLError方法的具体用法?Python yaml.YAMLError怎么用?Python yaml.YAMLError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ruamel.yaml的用法示例。


在下文中一共展示了yaml.YAMLError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _read_meta

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import YAMLError [as 别名]
def _read_meta(source) -> Tuple[ZipFile, PluginMeta]:
        try:
            file = ZipFile(source)
            data = file.read("maubot.yaml")
        except FileNotFoundError as e:
            raise MaubotZipMetaError("Maubot plugin not found") from e
        except BadZipFile as e:
            raise MaubotZipMetaError("File is not a maubot plugin") from e
        except KeyError as e:
            raise MaubotZipMetaError("File does not contain a maubot plugin definition") from e
        try:
            meta_dict = yaml.load(data)
        except (YAMLError, KeyError, IndexError, ValueError) as e:
            raise MaubotZipMetaError("Maubot plugin definition file is not valid YAML") from e
        try:
            meta = PluginMeta.deserialize(meta_dict)
        except SerializerError as e:
            raise MaubotZipMetaError("Maubot plugin definition in file is invalid") from e
        return file, meta 
开发者ID:maubot,项目名称:maubot,代码行数:21,代码来源:zip.py

示例2: read_meta

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import YAMLError [as 别名]
def read_meta(path: str) -> Optional[PluginMeta]:
    try:
        with open(os.path.join(path, "maubot.yaml")) as meta_file:
            try:
                meta_dict = yaml.load(meta_file)
            except YAMLError as e:
                print(Fore.RED + "Failed to build plugin: Metadata file is not YAML")
                print(Fore.RED + str(e) + Fore.RESET)
                return None
    except FileNotFoundError:
        print(Fore.RED + "Failed to build plugin: Metadata file not found" + Fore.RESET)
        return None
    try:
        meta = PluginMeta.deserialize(meta_dict)
    except SerializerError as e:
        print(Fore.RED + "Failed to build plugin: Metadata file is not valid")
        print(Fore.RED + str(e) + Fore.RESET)
        return None
    return meta 
开发者ID:maubot,项目名称:maubot,代码行数:21,代码来源:build.py

示例3: get_cfg

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import YAMLError [as 别名]
def get_cfg(existing_cfg, _log):
    """
    generates
    """
    _sanity_check(existing_cfg, _log)
    import ntpath, os, ruamel.yaml as yaml
    with open(os.path.join(os.path.dirname(__file__), "{}.yml".format(ntpath.basename(__file__).split(".")[0])),
              'r') as stream:
        try:
            ret = yaml.load(stream, Loader=yaml.Loader)
        except yaml.YAMLError as exc:
            assert "Default config yaml for '{}' not found!".format(os.path.splitext(__file__)[0])

    #if ret["coma_critic_use_sampling"] and "coma_critic_sample_size" not in ret and hasattr(ret, "batch_size_run"):
    #    ret["coma_critic_sample_size"] = ret["batch_size_run"] * 50
    return ret 
开发者ID:schroederdewitt,项目名称:mackrl,代码行数:18,代码来源:config.py

示例4: get_cfg

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import YAMLError [as 别名]
def get_cfg(existing_cfg, _log):
    """
    generates
    """
    _sanity_check(existing_cfg, _log)
    import ntpath, os, ruamel.yaml as yaml
    with open(os.path.join(os.path.dirname(__file__), "{}.yml".format(ntpath.basename(__file__).split(".")[0])),
              'r') as stream:
        try:
            ret = yaml.load(stream, Loader=yaml.Loader)
        except yaml.YAMLError as exc:
            assert "Default config yaml for '{}' not found!".format(os.path.splitext(__file__)[0])

    if ret["coma_critic_use_sampling"] and "coma_critic_sample_size" not in ret and hasattr(ret, "batch_size_run"):
        ret["coma_critic_sample_size"] = ret["batch_size_run"] * 50
    return ret 
开发者ID:schroederdewitt,项目名称:mackrl,代码行数:18,代码来源:config.py

示例5: get_cfg

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import YAMLError [as 别名]
def get_cfg(existing_cfg, _log):
    """

    """
    _sanity_check(existing_cfg, _log)
    import ntpath, os, ruamel.yaml as yaml
    with open(os.path.join(os.path.dirname(__file__), "{}.yml".format(ntpath.basename(__file__).split(".")[0])), 'r') as stream:
        try:
            ret = yaml.load(stream, Loader=yaml.Loader)
        except yaml.YAMLError as exc:
            assert False, "Default config yaml for '{}' not found!".format(os.path.splitext(__file__)[0])

    if not "batch_size_run" in ret:
        ret["batch_size_run"] = ret["batch_size"]

    if not "runner_test_batch_size" in ret:
        ret["runner_test_batch_size"] = ret["batch_size_run"]

    if not "name" in ret:
        ret["name"] = ntpath.basename(__file__).split(".")[0]

    return ret 
开发者ID:schroederdewitt,项目名称:mackrl,代码行数:24,代码来源:config.py

示例6: load_yaml

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import YAMLError [as 别名]
def load_yaml(self, template_file):
        with open(template_file) as f:
            try:
                return yaml.safe_load(f)
            except yaml.YAMLError as e:
                print(e)
                return [] 
开发者ID:treethought,项目名称:flask-assistant,代码行数:9,代码来源:schema_handlers.py

示例7: save

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import YAMLError [as 别名]
def save(self, path: str):
        cfg = self._dict_to_orderdict(self.cfg_dict)
        with open(path[:-3] + 'yaml', 'w') as cfg_file:
            try:
                yaml3ed.dump(cfg, cfg_file, explicit_start=True, explicit_end=True,
                             default_flow_style=False, allow_unicode=True, version=(1, 2),
                             indent=2)
            except yaml3ed.YAMLError as exc:
                print(exc) 
开发者ID:Prototype-X,项目名称:Zabbix-Network-Weathermap,代码行数:11,代码来源:converter.py

示例8: load

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import YAMLError [as 别名]
def load(self, path_cfg: str):
        with open(path_cfg, 'r') as stream:
            try:
                self.cfg_dict = yaml3ed.safe_load(stream)
            except yaml3ed.YAMLError as exc:
                print(exc)
        self.check()
        self.zbx = ZabbixAgent(self.cfg_dict['zabbix']['url'], self.cfg_dict['zabbix']['login'],
                               self.cfg_dict['zabbix']['password'])
        log.debug('Config loaded') 
开发者ID:Prototype-X,项目名称:Zabbix-Network-Weathermap,代码行数:12,代码来源:config.py

示例9: save

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import YAMLError [as 别名]
def save(self, path: str):
        cfg = self._dict_to_orderdict(self.map_config)
        with open(path + '/' + self.map_data['name'] + '.yaml', 'w') as cfg_file:
            try:
                yaml3ed.dump(cfg, cfg_file, explicit_start=True, explicit_end=True,
                             default_flow_style=False, allow_unicode=True, version=(1, 2))
            except yaml3ed.YAMLError as exc:
                print(exc) 
开发者ID:Prototype-X,项目名称:Zabbix-Network-Weathermap,代码行数:10,代码来源:config.py

示例10: _to_yaml

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import YAMLError [as 别名]
def _to_yaml(data):
    try:
        return Box.from_yaml(data)
    except YAMLError:
        raise BoxError('File is not YAML as expected')
    except BoxError:
        return BoxList.from_yaml(data) 
开发者ID:cdgriffith,项目名称:Box,代码行数:9,代码来源:from_file.py

示例11: _resolve_tags

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import YAMLError [as 别名]
def _resolve_tags(config_file):
    """
    Given a templated YAML cloudbuild config file, parse it, resolve image tags
    on each build step's image to the corresponding digest, and write new
    config with fully qualified images to temporary file for upload to GCS.

    Keyword arguments:
    config_file -- string representing path to
    templated cloudbuild YAML config file

    Return value:
    path to temporary file containing fully qualified config file, to be
    published to GCS.
    """
    with open(config_file, 'r') as infile:
        logging.info('Templating file: {0}'.format(config_file))
        try:
            config = yaml.round_trip_load(infile, preserve_quotes=True)

            for step in config.get('steps'):
                image = step.get('name')
                step['name'] = _resolve_tag(image)
                args = step.get('args', [])
                for i in range(0, len(args)):
                    arg = args[i]
                    m = re.search(IMAGE_REGEX, arg)
                    if m:
                        suffix = m.group()
                        prefix = re.sub(suffix, '', arg)
                        args[i] = prefix + _resolve_tag(suffix)

            return yaml.round_trip_dump(config)
        except yaml.YAMLError as e:
            logging.error(e)
            sys.exit(1) 
开发者ID:GoogleCloudPlatform,项目名称:runtimes-common,代码行数:37,代码来源:template_builder.py

示例12: generic_load

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import YAMLError [as 别名]
def generic_load(
    yaml_string, schema=None, label=u"<unicode string>", allow_flow_style=False
):
    if not utils.is_string(yaml_string):
        raise TypeError("StrictYAML can only read a string of valid YAML.")

    # We manufacture a class that has the label we want
    DynamicStrictYAMLLoader = type(
        "DynamicStrictYAMLLoader",
        (StrictYAMLLoader,),
        {"label": label, "allow_flow_style": allow_flow_style},
    )

    try:
        document = ruamelyaml.load(yaml_string, Loader=DynamicStrictYAMLLoader)
    except ruamelyaml.YAMLError as parse_error:
        if parse_error.context_mark is not None:
            parse_error.context_mark.name = label
        if parse_error.problem_mark is not None:
            parse_error.problem_mark.name = label

        raise parse_error

    # Document is just a (string, int, etc.)
    if type(document) not in (CommentedMap, CommentedSeq):
        document = yaml_string

    if schema is None:
        schema = Any()

    return schema(YAMLChunk(document, label=label)) 
开发者ID:crdoconnor,项目名称:strictyaml,代码行数:33,代码来源:parser.py

示例13: load

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import YAMLError [as 别名]
def load(self, content_type='yaml'):
        ''' return yaml file '''
        contents = self.read()

        if not contents and not self.content:
            return None

        if self.content:
            if isinstance(self.content, dict):
                self.yaml_dict = self.content
                return self.yaml_dict
            elif isinstance(self.content, str):
                contents = self.content

        # check if it is yaml
        try:
            if content_type == 'yaml' and contents:
                # Try to set format attributes if supported
                try:
                    self.yaml_dict.fa.set_block_style()
                except AttributeError:
                    pass

                # Try to use RoundTripLoader if supported.
                try:
                    self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
                except AttributeError:
                    self.yaml_dict = yaml.safe_load(contents)

                # Try to set format attributes if supported
                try:
                    self.yaml_dict.fa.set_block_style()
                except AttributeError:
                    pass

            elif content_type == 'json' and contents:
                self.yaml_dict = json.loads(contents)
        except yaml.YAMLError as err:
            # Error loading yaml or json
            raise YeditException('Problem with loading yaml file. {}'.format(err))

        return self.yaml_dict 
开发者ID:RedHatOfficial,项目名称:ansible-redhat_openshift_utils,代码行数:44,代码来源:oc_obj.py

示例14: validate_yaml_schema

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import YAMLError [as 别名]
def validate_yaml_schema(
    yaml_file_content: Text, schema_path: Text, show_validation_errors: bool = True
) -> None:
    """
    Validate yaml content.

    Args:
        yaml_file_content: the content of the yaml file to be validated
        schema_path: the schema of the yaml file
        show_validation_errors: if true, validation errors are shown
    """
    from pykwalify.core import Core
    from pykwalify.errors import SchemaError
    from ruamel.yaml import YAMLError
    import pkg_resources
    import rasa.utils.io
    import logging

    log = logging.getLogger("pykwalify")
    if show_validation_errors:
        log.setLevel(logging.WARN)
    else:
        log.setLevel(logging.CRITICAL)

    try:
        source_data = rasa.utils.io.read_yaml(yaml_file_content)
    except YAMLError:
        raise InvalidYamlFileError(
            "The provided yaml file is invalid. You can use "
            "http://www.yamllint.com/ to validate the yaml syntax "
            "of your file."
        )
    except DuplicateKeyError as e:
        raise InvalidYamlFileError(
            "The provided yaml file contains a duplicated key: '{}'. You can use "
            "http://www.yamllint.com/ to validate the yaml syntax "
            "of your file.".format(str(e))
        )

    try:
        schema_file = pkg_resources.resource_filename(PACKAGE_NAME, schema_path)

        c = Core(source_data=source_data, schema_files=[schema_file])
        c.validate(raise_exception=True)
    except SchemaError:
        raise InvalidYamlFileError(
            "Failed to validate yaml file. "
            "Please make sure the file is correct and all "
            "mandatory parameters are specified; to do so, "
            "take a look at the errors logged during "
            "validation previous to this exception."
        ) 
开发者ID:botfront,项目名称:rasa-for-botfront,代码行数:54,代码来源:validation.py

示例15: parse_yaml_srclib

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import YAMLError [as 别名]
def parse_yaml_srclib(metadatapath):

    thisinfo = {'RepoType': '',
                'Repo': '',
                'Subdir': None,
                'Prepare': None}

    if not os.path.exists(metadatapath):
        warn_or_exception(_("Invalid scrlib metadata: '{file}' "
                            "does not exist"
                            .format(file=metadatapath)))
        return thisinfo

    with open(metadatapath, "r", encoding="utf-8") as f:
        try:
            data = yaml.load(f, Loader=SafeLoader)
            if type(data) is not dict:
                raise yaml.error.YAMLError(_('{file} is blank or corrupt!')
                                           .format(file=metadatapath))
        except yaml.error.YAMLError as e:
            warn_or_exception(_("Invalid srclib metadata: could not "
                                "parse '{file}'")
                              .format(file=metadatapath) + '\n'
                              + fdroidserver.common.run_yamllint(metadatapath,
                                                                 indent=4),
                              cause=e)
            return thisinfo

    for key in data.keys():
        if key not in thisinfo.keys():
            warn_or_exception(_("Invalid srclib metadata: unknown key "
                                "'{key}' in '{file}'")
                              .format(key=key, file=metadatapath))
            return thisinfo
        else:
            if key == 'Subdir':
                if isinstance(data[key], str):
                    thisinfo[key] = data[key].split(',')
                elif isinstance(data[key], list):
                    thisinfo[key] = data[key]
                elif data[key] is None:
                    thisinfo[key] = ['']
            elif key == 'Prepare' and isinstance(data[key], list):
                thisinfo[key] = ' && '.join(data[key])
            else:
                thisinfo[key] = str(data[key] or '')

    return thisinfo 
开发者ID:f-droid,项目名称:fdroidserver,代码行数:50,代码来源:metadata.py


注:本文中的ruamel.yaml.YAMLError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。