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


Python yaml.safe_load_all方法代码示例

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


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

示例1: load_schemas

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load_all [as 别名]
def load_schemas(self):
        self.v1_doc_schemas = dict()
        schema_dir = self._get_schema_dir()

        for schema_file in os.listdir(schema_dir):
            f = open(os.path.join(schema_dir, schema_file), 'r')
            for schema in yaml.safe_load_all(f):
                schema_for = schema['metadata']['name']
                if schema_for in self.v1_doc_schemas:
                    self.logger.warning(
                        "Duplicate document schemas found for document kind %s."
                        % schema_for)
                self.logger.debug(
                    "Loaded schema for document kind %s." % schema_for)
                self.v1_doc_schemas[schema_for] = schema.get('data')
            f.close() 
开发者ID:airshipit,项目名称:drydock,代码行数:18,代码来源:deckhand.py

示例2: load_schemas

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load_all [as 别名]
def load_schemas(self):
        self.v1_doc_schemas = dict()
        schema_dir = self._get_schema_dir()

        for schema_file in os.listdir(schema_dir):
            f = open(os.path.join(schema_dir, schema_file), 'r')
            for schema in yaml.safe_load_all(f):
                schema_for = schema['metadata']['name']
                if schema_for in self.v1_doc_schemas:
                    self.logger.warning(
                        "Duplicate document schemas found for document kind %s."
                        % schema_for)
                self.logger.debug(
                    "Loaded schema for document kind %s." % schema_for)
                self.v1_doc_schemas[schema_for] = schema
            f.close() 
开发者ID:airshipit,项目名称:drydock,代码行数:18,代码来源:yaml.py

示例3: _loadRelease

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load_all [as 别名]
def _loadRelease(self):
  release = self.dict.get('release', {})
  if release.get('type') == 'github' and 'user' in release and 'repo' in release:
   for dict in GithubApi(release['user'], release['repo'], self.repo.client).getReleases():
    asset = self._findGithubAsset(dict.get('assets', []))
    if asset:
     return {
      'version': dict.get('name') or dict.get('tag_name'),
      'date': datetime.strptime(dict.get('created_at'), '%Y-%m-%dT%H:%M:%SZ'),
      'desc': dict.get('body'),
      'url': asset,
     }
  elif release.get('type') == 'yaml' and 'url' in release:
   for dict in yaml.safe_load_all(http.get(release['url']).data):
    if 'version' in dict and 'url' in dict:
     return dict
  elif 'version' in release and 'url' in release:
   return release 
开发者ID:ma1co,项目名称:Sony-PMCA-RE,代码行数:20,代码来源:__init__.py

示例4: test_write_user_data

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load_all [as 别名]
def test_write_user_data(self):
        content = {'a': 1}

        class MockBaseTest(base_test.BaseTestClass):
            def test_something(self):
                self.record_data(content)

        bt_cls = MockBaseTest(self.mock_test_cls_configs)
        bt_cls.run(test_names=["test_something"])
        actual_record = bt_cls.results.passed[0]
        self.assertEqual(actual_record.test_name, "test_something")
        hit = False
        with io.open(self.summary_file, 'r', encoding='utf-8') as f:
            for c in yaml.safe_load_all(f):
                if c['Type'] != records.TestSummaryEntryType.USER_DATA.value:
                    continue
                hit = True
                self.assertEqual(c['a'], content['a'])
                self.assertIsNotNone(c['timestamp'])
        self.assertTrue(hit) 
开发者ID:google,项目名称:mobly,代码行数:22,代码来源:base_test_test.py

示例5: test_summary_user_data

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load_all [as 别名]
def test_summary_user_data(self):
        user_data1 = {'a': 1}
        user_data2 = {'b': 1}
        user_data = [user_data1, user_data2]
        dump_path = os.path.join(self.tmp_path, 'ha.yaml')
        writer = records.TestSummaryWriter(dump_path)
        for data in user_data:
            writer.dump(data, records.TestSummaryEntryType.USER_DATA)
        with io.open(dump_path, 'r', encoding='utf-8') as f:
            contents = []
            for c in yaml.safe_load_all(f):
                contents.append(c)
        for content in contents:
            self.assertEqual(content['Type'],
                             records.TestSummaryEntryType.USER_DATA.value)
        self.assertEqual(contents[0]['a'], user_data1['a'])
        self.assertEqual(contents[1]['b'], user_data2['b']) 
开发者ID:google,项目名称:mobly,代码行数:19,代码来源:records_test.py

示例6: get_template_contexts

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load_all [as 别名]
def get_template_contexts(file_path):
    try:
        with open(file_path) as f:
            try:
                contexts = yaml.safe_load_all(f.read())
            except Exception as e:
                raise RuntimeError('Unable to load yaml file: {}, {}'.format(file_path, e))

            for context in contexts:
                if context is None:
                    continue  # Skip empty YAML documents
                if 'kind' not in context or context['kind'] is None:
                    raise RuntimeError('Field "kind" not found (or empty) in file "{}"'.format(file_path))
                if 'metadata' not in context or context['metadata'] is None:
                    raise RuntimeError('Field "metadata" not found (or empty) in file "{}"'.format(file_path))
                if 'name' not in context['metadata'] or context['metadata']['name'] is None:
                    raise RuntimeError('Field "metadata->name" not found (or empty) in file "{}"'.format(file_path))
                if 'spec' in context:
                    # INFO: Set replicas = 1 by default for replaces cases in Deployment and StatefulSet
                    if 'replicas' not in context['spec'] or context['spec']['replicas'] is None:
                        if context['kind'] in ['Deployment', 'StatefulSet']:
                            context['spec']['replicas'] = 1
                yield context
    except FileNotFoundError as e:
        raise RuntimeError(e) 
开发者ID:2gis,项目名称:k8s-handle,代码行数:27,代码来源:templating.py

示例7: req_yaml

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load_all [as 别名]
def req_yaml(self, req, default=None):
        if req.content_length is None or req.content_length == 0:
            return default

        raw_body = req.stream.read(req.content_length or 0)

        if raw_body is None:
            return default

        try:
            return list(yaml.safe_load_all(raw_body.decode('utf-8')))
        except yaml.YAMLError:
            with excutils.save_and_reraise_exception():
                self.error(
                    req.context,
                    "Invalid YAML in request: \n%s" % raw_body.decode('utf-8')) 
开发者ID:airshipit,项目名称:armada,代码行数:18,代码来源:__init__.py

示例8: _load_schemas

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load_all [as 别名]
def _load_schemas():
    """Populates ``_SCHEMAS`` with the schemas defined in package
    ``armada.schemas``.

    """
    schema_dir = _get_schema_dir()
    for schema_file in os.listdir(schema_dir):
        with open(os.path.join(schema_dir, schema_file)) as f:
            for schema in yaml.safe_load_all(f):
                name = schema['metadata']['name']
                if name in _SCHEMAS:
                    raise RuntimeError(
                        'Duplicate schema specified for: %s.' % name)
                _SCHEMAS[name] = _get_schema_info(name, schema['data'])


# Fill the cache. 
开发者ID:airshipit,项目名称:armada,代码行数:19,代码来源:schema.py

示例9: test_own_document_examples

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load_all [as 别名]
def test_own_document_examples(self):
        examples_path = os.path.join(os.getcwd(), 'examples')
        example_files = [
            os.path.join(examples_path, f) for f in os.listdir(examples_path)
            if os.path.isfile(os.path.join(examples_path, f))
        ]
        validated_manifests = []

        for example_file in example_files:
            with open(example_file) as f:
                documents = yaml.safe_load_all(f.read())

            # If the example file doesn't have a document with
            # armada/Manifest/v1 then skip validating it as the example could
            # merely be an override.
            has_manifest = any(
                x['schema'] == 'armada/Manifest/v1' for x in documents)
            if not has_manifest:
                continue

            validated_manifests.append(example_file)
            valid, _ = validate.validate_armada_documents(list(documents))
            self.assertTrue(valid)

        self.assertTrue(validated_manifests) 
开发者ID:airshipit,项目名称:armada,代码行数:27,代码来源:test_validate.py

示例10: test_validate_invalid_chart_armada_manifest

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load_all [as 别名]
def test_validate_invalid_chart_armada_manifest(self):
        template = '{}/resources/valid_armada_document.yaml'.format(
            self.basepath)

        with open(template) as f:
            documents = list(yaml.safe_load_all(f.read()))

        mariadb_document = [
            d for d in documents if d['metadata']['name'] == 'mariadb'
        ][0]
        del mariadb_document['data']['release']

        _, error_messages = validate.validate_armada_documents(documents)
        expected_error = self._build_error_message(
            'armada/Chart/v1', 'mariadb', "'release' is a required property")

        self.assertEqual(1, len(error_messages))
        self.assertEqual(expected_error, error_messages[0]['message']) 
开发者ID:airshipit,项目名称:armada,代码行数:20,代码来源:test_validate.py

示例11: test_update_chart_group_document_valid

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load_all [as 别名]
def test_update_chart_group_document_valid(self):
        with open(self.base_manifest) as f:
            documents = list(yaml.safe_load_all(f.read()))
        documents_modified = copy.deepcopy(documents)
        documents_modified[1]['data']['sequenced'] = True

        # starting out, both doc have different values for data
        self.assertNotEqual(documents[1], documents_modified[1])

        ovr = Override(documents)
        # update with document values with the modified ones
        ovr.update_document(documents_modified[1])

        # after the update, both documents are equal
        self.assertEqual(
            ovr.documents[1]['data']['sequenced'],
            documents_modified[1]['data']['sequenced'])
        self.assertEqual(ovr.documents[1], documents_modified[1]) 
开发者ID:airshipit,项目名称:armada,代码行数:20,代码来源:test_override.py

示例12: test_update_chart_group_document_keys_not_removed_with_override

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load_all [as 别名]
def test_update_chart_group_document_keys_not_removed_with_override(self):
        with open(self.base_manifest) as f:
            documents = list(yaml.safe_load_all(f.read()))

        documents_modified = copy.deepcopy(documents)
        del documents_modified[1]['data']['sequenced']

        # verify both doc have different values for data
        self.assertNotEqual(documents[1], documents_modified[1])

        ovr = Override(documents)
        # update with document values with the modified ones
        ovr.update_document(documents_modified[1])

        self.assertIn('sequenced', ovr.documents[1]['data'])
        self.assertNotEqual(ovr.documents[1], documents_modified[1]) 
开发者ID:airshipit,项目名称:armada,代码行数:18,代码来源:test_override.py

示例13: test_update_armada_manifest_valid

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load_all [as 别名]
def test_update_armada_manifest_valid(self):
        with open(self.base_manifest) as f:
            documents = list(yaml.safe_load_all(f.read()))
        documents_modified = copy.deepcopy(documents)
        documents_modified[2]['data']['release_prefix'] = 'armada-modified'

        # starting out, both doc have different values for data
        self.assertNotEqual(documents[2], documents_modified[2])

        ovr = Override(documents)
        # update with document values with the modified ones
        ovr.update_document(documents_modified[2])

        # after the update, both documents are equal
        self.assertEqual(
            ovr.documents[2]['data']['release_prefix'],
            documents_modified[2]['data']['release_prefix'])
        self.assertEqual(ovr.documents[2], documents_modified[2]) 
开发者ID:airshipit,项目名称:armada,代码行数:20,代码来源:test_override.py

示例14: test_update_armada_manifest_keys_not_removed_with_override

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load_all [as 别名]
def test_update_armada_manifest_keys_not_removed_with_override(self):
        with open(self.base_manifest) as f:
            documents = list(yaml.safe_load_all(f.read()))

        documents_modified = copy.deepcopy(documents)
        del documents_modified[2]['data']['release_prefix']

        # verify both doc have different values for data
        self.assertNotEqual(documents[2], documents_modified[2])

        ovr = Override(documents)
        # update with document values from base_manifest
        ovr.update_document(documents_modified[2])

        self.assertIn('release_prefix', ovr.documents[2]['data'])
        self.assertNotEqual(ovr.documents[2], documents_modified[2]) 
开发者ID:airshipit,项目名称:armada,代码行数:18,代码来源:test_override.py

示例15: test_update_dictionary_valid

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load_all [as 别名]
def test_update_dictionary_valid(self):
        expected = "{}/templates/override-{}-expected.yaml".format(
            self.basepath, '01')
        merge = "{}/templates/override-{}.yaml".format(self.basepath, '01')

        with open(self.base_manifest) as f, open(expected) as e, open(
                merge) as m:
            merging_values = list(yaml.safe_load_all(m.read()))
            documents = list(yaml.safe_load_all(f.read()))
            doc_path = ['chart', 'blog-1']
            ovr = Override(documents)
            ovr.update_documents(merging_values)
            ovr_doc = ovr.find_manifest_document(doc_path)
            expect_doc = list(yaml.load_all(e.read()))[0]

            self.assertEqual(ovr_doc, expect_doc) 
开发者ID:airshipit,项目名称:armada,代码行数:18,代码来源:test_override.py


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