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


Python scanner.ScannerError方法代码示例

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


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

示例1: get_environment_from_file

# 需要导入模块: from yaml import scanner [as 别名]
# 或者: from yaml.scanner import ScannerError [as 别名]
def get_environment_from_file(env_name):
    cwd = os.getcwd()
    file_name = beanstalk_directory + env_name

    try:
        ProjectRoot.traverse()
        file_ext = '.env.yml'
        path = file_name + file_ext
        if os.path.exists(path):
            with codecs.open(path, 'r', encoding='utf8') as f:
                return safe_load(f)
    except (ScannerError, ParserError):
        raise InvalidSyntaxError('The environment file contains '
                                 'invalid syntax.')

    finally:
        os.chdir(cwd) 
开发者ID:QData,项目名称:deepWordBug,代码行数:19,代码来源:fileoperations.py

示例2: get_application_from_file

# 需要导入模块: from yaml import scanner [as 别名]
# 或者: from yaml.scanner import ScannerError [as 别名]
def get_application_from_file(app_name):
    cwd = os.getcwd()
    file_name = beanstalk_directory + app_name

    try:
        ProjectRoot.traverse()
        file_ext = '.app.yml'
        path = file_name + file_ext
        if os.path.exists(path):
            with codecs.open(path, 'r', encoding='utf8') as f:
                return safe_load(f)
    except (ScannerError, ParserError):
        raise InvalidSyntaxError('The application file contains '
                                 'invalid syntax.')

    finally:
        os.chdir(cwd) 
开发者ID:QData,项目名称:deepWordBug,代码行数:19,代码来源:fileoperations.py

示例3: load

# 需要导入模块: from yaml import scanner [as 别名]
# 或者: from yaml.scanner import ScannerError [as 别名]
def load(self, ymlfile=None):
        """Load and process the YAML file"""
        if ymlfile is not None:
            self.ymlfile = ymlfile

        try:
            # If yaml should be 'cleaned' of document references
            if self._clean:
                self.data = self.process(self.ymlfile)
            else:
                with open(self.ymlfile, 'rb') as stream:
                    for data in yaml.load_all(stream, Loader=yaml.Loader):
                        self.data.append(data)

            self.loaded = True
        except ScannerError as e:
            msg = "YAML formattting error - '" + self.ymlfile + ": '" + str(e) + "'"
            raise util.YAMLError(msg) 
开发者ID:NASA-AMMOS,项目名称:AIT-Core,代码行数:20,代码来源:val.py

示例4: load_yamls

# 需要导入模块: from yaml import scanner [as 别名]
# 或者: from yaml.scanner import ScannerError [as 别名]
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 
开发者ID:atc-project,项目名称:atomic-threat-coverage,代码行数:22,代码来源:atcutils.py

示例5: load_cfg

# 需要导入模块: from yaml import scanner [as 别名]
# 或者: from yaml.scanner import ScannerError [as 别名]
def load_cfg(filepath):
    try:
        return yaml.safe_load(open(filepath))
    except (IOError, ScannerError) as e:
        if isinstance(e, IOError):
            exit_results({
                'ok': False,
                'error_type': 'args',
                'error_message': 'Unable to load file: %s' % filepath
            })
        else:
            exit_results({
                'ok': False,
                'error_type': 'args',
                'error_message': 'YAML syntax error in file: {filepath}, {e}'.format(filepath=filepath, e=e)
            }) 
开发者ID:Apstra,项目名称:aeon-ztps,代码行数:18,代码来源:aztp_os_selector.py

示例6: match

# 需要导入模块: from yaml import scanner [as 别名]
# 或者: from yaml.scanner import ScannerError [as 别名]
def match(self, filepath):
        try:
            with open(filepath) as fp:
                file_content = fp.read()
        except OSError:
            return False

        try:
            dict_content = yaml.load(file_content)
        except (ReaderError, ScannerError):
            return False

        try:
            assert dict_content.get('handler') == 'passpie'
            assert isinstance(dict_content.get('version'), float)
        except AssertionError:
            return False

        return True 
开发者ID:marcwebbie,项目名称:passpie,代码行数:21,代码来源:default_importer.py

示例7: __init__

# 需要导入模块: from yaml import scanner [as 别名]
# 或者: from yaml.scanner import ScannerError [as 别名]
def __init__(self, problem_id, time_limit, memory_limit, meta):
        self.id = problem_id
        self.time_limit = time_limit
        self.memory_limit = memory_limit
        self.meta = ConfigNode(meta)
        self.generator_manager = GeneratorManager()

        # Cache root dir so that we don't need to scan all roots (potentially very slow on networked mount).
        self.root_dir = get_problem_root(problem_id)
        self.problem_data = ProblemDataManager(self)

        # Checkers modules must be stored in a dict, for the duration of execution,
        # lest globals be deleted with the module.
        self._checkers = {}

        try:
            doc = yaml.safe_load(self.problem_data['init.yml'])
            if not doc:
                raise InvalidInitException('I find your lack of content disturbing.')
            self.config = ConfigNode(
                doc,
                defaults={
                    'wall_time_factor': 3,
                    'output_prefix_length': 64,
                    'output_limit_length': 25165824,
                    'binary_data': False,
                    'short_circuit': True,
                    'points': 1,
                    'symlinks': {},
                    'meta': meta,
                },
            )
        except (IOError, KeyError, ParserError, ScannerError) as e:
            raise InvalidInitException(str(e))

        self.problem_data.archive = self._resolve_archive_files()
        self._resolve_test_cases() 
开发者ID:DMOJ,项目名称:judge-server,代码行数:39,代码来源:problem.py

示例8: test_get_yaml_or_json_file_raises_exception_on_yaml_error

# 需要导入模块: from yaml import scanner [as 别名]
# 或者: from yaml.scanner import ScannerError [as 别名]
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') 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:7,代码来源:file_loader_tests.py

示例9: test_ordbok_bad_yaml_local_settings

# 需要导入模块: from yaml import scanner [as 别名]
# 或者: from yaml.scanner import ScannerError [as 别名]
def test_ordbok_bad_yaml_local_settings(self, fudged_open):
        fudged_bad_yaml_config_files = deepcopy(fudged_config_files)
        fudged_bad_yaml_config_files.update({
            u'local_config.yml': u"""
            SQLALCHEMY_DATABASE_URL: 'sqlite:///tmp/database.db'
            SQLALCHEMY_ECHO = True
            """
        })
        fudged_open.is_callable().calls(fake_file_factory(
            fudged_bad_yaml_config_files))
        with self.assertRaises(ScannerError):
            self.ordbok.load() 
开发者ID:eriktaubeneck,项目名称:ordbok,代码行数:14,代码来源:base_tests.py

示例10: _load_source

# 需要导入模块: from yaml import scanner [as 别名]
# 或者: from yaml.scanner import ScannerError [as 别名]
def _load_source(self, filename):
        try:
            with open(filename, 'r') as stream:
                raw_data = yaml.load(stream)
            self._parse_raw_data(raw_data)
        except ScannerError as e:
            raise BootstrapSourceError(self.ERROR_PREFIX + "Error %s" % e.message) 
开发者ID:CacheBrowser,项目名称:cachebrowser,代码行数:9,代码来源:bootstrap.py

示例11: load_yamls_with_paths

# 需要导入模块: from yaml import scanner [as 别名]
# 或者: from yaml.scanner import ScannerError [as 别名]
def load_yamls_with_paths(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(ATCutils.read_yaml_file(yaml))
            except ScannerError:
                raise ScannerError('yaml is bad! %s' % yaml)
        return (result, yamls) 
开发者ID:atc-project,项目名称:atomic-threat-coverage,代码行数:12,代码来源:atcutils.py

示例12: load_yamls

# 需要导入模块: from yaml import scanner [as 别名]
# 或者: from yaml.scanner import ScannerError [as 别名]
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 
开发者ID:atc-project,项目名称:atomic-threat-coverage,代码行数:29,代码来源:yaml_handler.py

示例13: _load_config

# 需要导入模块: from yaml import scanner [as 别名]
# 或者: from yaml.scanner import ScannerError [as 别名]
def _load_config(config_path: str):
        """Returns project configuration."""
        config = None
        if os.path.exists(config_path):
            with open(config_path, 'r') as f:
                try:
                    config = yaml.safe_load(f)
                except ScannerError as e:
                    raise ValueError(str(e))

        return config 
开发者ID:apls777,项目名称:spotty,代码行数:13,代码来源:abstract_config_command.py

示例14: init

# 需要导入模块: from yaml import scanner [as 别名]
# 或者: from yaml.scanner import ScannerError [as 别名]
def init(self):
        super(scpi, self).init()
        self._scpi_commands = _scpi_ieee_488_2.copy()
        device_desciption = os.path.join(os.path.dirname(__file__), self._init['device'].lower().replace(" ", "_") + '.yaml')
        try:
            with open(device_desciption, 'r') as in_file:
                self._scpi_commands.update(load(in_file, Loader=BaseLoader))
        except scanner.ScannerError:
            raise RuntimeError('Parsing error for ' + self._init['device'] + ' device description in file ' + device_desciption)
        except IOError:
            raise RuntimeError('Cannot find a device description for ' + self._init['device'] + '. Consider adding it!')
        if 'identifier' in self._scpi_commands and self._scpi_commands['identifier']:
            name = self.get_name()
            if self._scpi_commands['identifier'] not in name:
                raise RuntimeError('Wrong device description (' + self._init['device'] + ') loaded for ' + name) 
开发者ID:SiLab-Bonn,项目名称:basil,代码行数:17,代码来源:scpi.py

示例15: valid_yaml

# 需要导入模块: from yaml import scanner [as 别名]
# 或者: from yaml.scanner import ScannerError [as 别名]
def valid_yaml(yml_data):
    """
    Validate a data stream(list) as acceptable yml
    :param yml_data: (list) of lines that would represent a yml file
    :return: (bool) to confirm whether the yaml is ok or not
    """

    yml_stream = '\n'.join(yml_data)
    try:
        _yml_ok = yaml.safe_load(yml_stream)
    except ScannerError:
        return False
    else:
        return True 
开发者ID:pcuzner,项目名称:ceph-ansible-copilot,代码行数:16,代码来源:utils.py


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