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