當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。