Python yaml.scanner.ScannerError() Examples
The following are 20
code examples of yaml.scanner.ScannerError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
yaml.scanner
, or try the search function
.
Example #1
Source File: fileoperations.py From deepWordBug with Apache License 2.0 | 7 votes |
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)
Example #2
Source File: fileoperations.py From deepWordBug with Apache License 2.0 | 6 votes |
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)
Example #3
Source File: val.py From AIT-Core with MIT License | 6 votes |
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)
Example #4
Source File: default_importer.py From passpie with MIT License | 6 votes |
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
Example #5
Source File: atcutils.py From atomic-threat-coverage with Apache License 2.0 | 6 votes |
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
Example #6
Source File: fileoperations.py From aws-elastic-beanstalk-cli with Apache License 2.0 | 6 votes |
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)
Example #7
Source File: fileoperations.py From aws-elastic-beanstalk-cli with Apache License 2.0 | 6 votes |
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)
Example #8
Source File: aztp_os_selector.py From aeon-ztps with Apache License 2.0 | 6 votes |
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) })
Example #9
Source File: abstract_config_command.py From spotty with MIT License | 5 votes |
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
Example #10
Source File: serialize.py From tutor with GNU Affero General Public License v3.0 | 5 votes |
def parse(v): """ Parse a yaml-formatted string. """ try: return load(v) except (ParserError, ScannerError): pass return v
Example #11
Source File: package.py From chalice with Apache License 2.0 | 5 votes |
def load_template(self, file_contents, filename=''): # type: (str, str) -> Dict[str, Any] yaml.SafeLoader.add_multi_constructor( tag_prefix='!', multi_constructor=self._custom_sam_instrinsics) try: return yaml.load( file_contents, Loader=yaml.SafeLoader, ) except ScannerError: raise RuntimeError( 'Expected %s to be valid YAML template.' % filename)
Example #12
Source File: config.py From flashfocus with MIT License | 5 votes |
def load_config(config_file: Path) -> Dict: """Load the config yaml file into a dictionary.""" try: with config_file.open("r") as f: config: Dict = yaml.load(f, Loader=yaml.FullLoader) except FileNotFoundError: raise ConfigLoadError(f"Config file does not exist: {config_file}") except (ScannerError, ParserError) as e: logging.error(str(e)) raise ConfigLoadError( "Error encountered in config file. Check that your config file is formatted correctly." ) else: dehyphen(config) return config
Example #13
Source File: utils.py From ceph-ansible-copilot with GNU Lesser General Public License v2.1 | 5 votes |
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
Example #14
Source File: scpi.py From basil with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #15
Source File: problem.py From judge-server with GNU Affero General Public License v3.0 | 5 votes |
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()
Example #16
Source File: yaml_handler.py From atomic-threat-coverage with Apache License 2.0 | 5 votes |
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
Example #17
Source File: atcutils.py From atomic-threat-coverage with Apache License 2.0 | 5 votes |
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)
Example #18
Source File: bootstrap.py From cachebrowser with MIT License | 5 votes |
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)
Example #19
Source File: base_tests.py From ordbok with MIT License | 5 votes |
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()
Example #20
Source File: file_loader_tests.py From cfn-sphere with Apache License 2.0 | 5 votes |
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')