Python yaml 模块,scanner() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用yaml.scanner()

项目:sqlibrist    作者:condograde    | 项目源码 | 文件源码
def load_config(self):
        import yaml
        from yaml.scanner import ScannerError

        try:
            with open(self.args.config_file) as config_file:
                configs = yaml.load(config_file.read())
        except IOError:
            raise BadConfig('No config file %s found!' % self.args.config_file)
        except ScannerError:
            raise BadConfig('Bad config file syntax')
        else:
            try:
                self._dict = configs[self.args.config]
            except KeyError:
                raise BadConfig('No config named %s found!' % self.args.config)
项目:aws-ec2rescue-linux    作者:awslabs    | 项目源码 | 文件源码
def get_module(filename_with_path):
    """
    Given a filename with an absolute path, load the contents, instantiate a Module, and set the Module's path
    attribute.

    Parameters:
        filename_with_path (str): the YAML filename with an absolute path
    """
    try:
        with open(filename_with_path) as config_file:
            Module.temp_path = filename_with_path
            this_module = yaml.load(config_file, Loader=Loader)
            Module.temp_path = ""
            return this_module
    except IOError:
        raise ModulePathError(filename_with_path)
    except yaml.scanner.ScannerError:
        raise ModuleConstraintParseError("Parsing of module {} failed. This is likely caused by a typo in the file."
                                         "".format(filename_with_path))
# Add the YAML Module constructor so that YAML knows to use it in situations where the tag matches.
项目:elastalert-ui    作者:steelheaddigital    | 项目源码 | 文件源码
def load_configuration(filename, conf, args=None):
    """ Load a yaml rule file and fill in the relevant fields with objects.

    :param filename: The name of a rule configuration file.
    :param conf: The global configuration dictionary, used for populating defaults.
    :return: The rule configuration, a dictionary.
    """
    try:
        rule = yaml_loader(filename)
    except yaml.scanner.ScannerError as e:
        raise EAException('Could not parse file %s: %s' % (filename, e))

    rule['rule_file'] = filename
    load_options(rule, conf, args)
    load_modules(rule, args)
    return rule
项目:dbt    作者:fishtown-analytics    | 项目源码 | 文件源码
def load_yaml_text(contents):
    try:
        return yaml.safe_load(contents)
    except (yaml.scanner.ScannerError, yaml.YAMLError) as e:
        if hasattr(e, 'problem_mark'):
            error = contextualized_yaml_error(contents, e)
        else:
            error = dbt.compat.to_string(e)

        raise dbt.exceptions.ValidationException(error)