• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.traverse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nailgun.utils.traverse函数的典型用法代码示例。如果您正苦于以下问题:Python traverse函数的具体用法?Python traverse怎么用?Python traverse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_formatter_returns_informative_error

 def test_formatter_returns_informative_error(self):
     with self.assertRaisesRegexp(ValueError, '{a}'):
         traverse(
             self.data,
             formatter_context={'b': 13},
             keywords={'generator': self.TestGenerator.evaluate}
         )
开发者ID:sebrandon1,项目名称:fuel-web,代码行数:7,代码来源:test_utils.py


示例2: get_attributes

    def get_attributes(cls, instance, all_plugins_versions=False):
        """Get attributes for current Cluster instance.

        :param instance: Cluster instance
        :param all_plugins_versions: Get attributes of all versions of plugins
        :returns: dict
        """
        try:
            attrs = db().query(models.Attributes).filter(
                models.Attributes.cluster_id == instance.id
            ).one()
        except MultipleResultsFound:
            raise errors.InvalidData(
                u"Multiple rows with attributes were found for cluster '{0}'"
                .format(instance.name)
            )
        except NoResultFound:
            raise errors.InvalidData(
                u"No attributes were found for cluster '{0}'"
                .format(instance.name)
            )
        attrs = dict(attrs)

        # Merge plugins attributes into editable ones
        plugin_attrs = PluginManager.get_plugins_attributes(
            instance, all_versions=all_plugins_versions)
        plugin_attrs = traverse(plugin_attrs, AttributesGenerator, {
            'cluster': instance,
            'settings': settings,
        })
        attrs['editable'].update(plugin_attrs)

        return attrs
开发者ID:gdyuldin,项目名称:fuel-web,代码行数:33,代码来源:cluster.py


示例3: generate_fields

 def generate_fields(cls, instance):
     instance.generated = traverse(
         instance.generated,
         AttributesGenerator
     )
     db().add(instance)
     db().flush()
开发者ID:sk4lf,项目名称:fuel-web,代码行数:7,代码来源:cluster.py


示例4: serialize

    def serialize(self, node_id, formatter_context=None):
        """Serialize task in expected by orchestrator format

        If serialization is performed on the remote worker
        we should pass formatter_context parameter with values
        from the master node settings

        :param formatter_context: formatter context
        :param node_id: the target node_id
        """

        logger.debug(
            "serialize task %s for node %s",
            self.task_template['id'], node_id
        )
        formatter_context = formatter_context \
            or self.context.get_formatter_context(node_id)
        task = utils.traverse(
            self.task_template,
            utils.text_format_safe,
            formatter_context,
            {
                'yaql_exp': self.context.get_yaql_interpreter(
                    node_id, self.task_template['id'])
            }
        )
        return self.normalize(self.finalize(task, node_id))
开发者ID:openstack,项目名称:fuel-web,代码行数:27,代码来源:task_serializer.py


示例5: get_default_vmware_attributes

 def get_default_vmware_attributes(cls, instance):
     """Get metadata from release with empty value section."""
     editable = instance.release.vmware_attributes_metadata.get("editable")
     editable = traverse(editable, AttributesGenerator, {
         'cluster': instance,
         'settings': settings,
     })
     return editable
开发者ID:gdyuldin,项目名称:fuel-web,代码行数:8,代码来源:cluster.py


示例6: generate_fields

    def generate_fields(cls, instance):
        """Generate field values for Cluster attributes using
        generators.

        :param instance: Attributes instance
        :returns: None
        """
        instance.generated = traverse(
            instance.generated or {}, AttributesGenerator, {"cluster": instance.cluster, "settings": settings}
        )
开发者ID:anbangr,项目名称:fuel-web,代码行数:10,代码来源:cluster.py


示例7: generate_fields

    def generate_fields(cls, instance):
        """Generate field values for Cluster attributes using
        generators.

        :param instance: Attributes instance
        :returns: None
        """
        instance.generated = traverse(
            instance.generated,
            AttributesGenerator
        )
开发者ID:zbwzy,项目名称:nailgun,代码行数:11,代码来源:cluster.py


示例8: get_default_editable_attributes

    def get_default_editable_attributes(cls, instance):
        """Get editable attributes from release metadata

        :param instance: Cluster instance
        :returns: Dict object
        """
        editable = instance.release.attributes_metadata.get("editable")
        editable = traverse(editable, AttributesGenerator, {"cluster": instance, "settings": settings})
        # when attributes created we need to understand whether should plugin
        # be applied for created cluster
        plugin_attrs = PluginManager.get_plugin_attributes(instance)
        editable = dict(plugin_attrs, **editable)
        return editable
开发者ID:anbangr,项目名称:fuel-web,代码行数:13,代码来源:cluster.py


示例9: test_custom_keywords

 def test_custom_keywords(self):
     data = {
         'key1': {'exp1': 'name1', 'exp1_arg': 'arg1'},
         'key2': {'exp2': 'name2'},
     }
     generator1 = mock.MagicMock(return_value='val1')
     generator2 = mock.MagicMock(return_value='val2')
     result = traverse(data, keywords={
         'exp1': generator1,
         'exp2': generator2
     })
     self.assertEqual({'key1': 'val1', 'key2': 'val2'}, result)
     generator1.assert_called_once_with('name1', 'arg1')
     generator2.assert_called_once_with('name2')
开发者ID:sebrandon1,项目名称:fuel-web,代码行数:14,代码来源:test_utils.py


示例10: get_default_editable_attributes

    def get_default_editable_attributes(cls, instance):
        """Get editable attributes from release metadata

        :param instance: Cluster instance
        :returns: Dict object
        """
        editable = instance.release.attributes_metadata.get("editable")
        # Add default attributes of connected plugins
        plugin_attrs = PluginManager.get_plugins_attributes(
            instance, all_versions=True, default=True)
        editable = dict(plugin_attrs, **editable)
        editable = traverse(editable, AttributesGenerator, {
            'cluster': instance,
            'settings': settings,
        })

        return editable
开发者ID:gdyuldin,项目名称:fuel-web,代码行数:17,代码来源:cluster.py


示例11: test_w_formatting_context

    def test_w_formatting_context(self):
        result = traverse(self.data, self.TestGenerator, {'a': 13})

        self.assertEqual(result, {
            'foo': 'testvalue',
            'bar': 'test 13 string',
            'baz': 42,
            'regex': {
                'source': 'test {a} string',
                'error': 'an {a} error'
            },
            'list': [
                {
                    'x': 'a 13 a',
                },
                {
                    'y': 'b 42 b',
                }
            ]})
开发者ID:apporc,项目名称:fuel-web,代码行数:19,代码来源:test_utils.py


示例12: serialize

    def serialize(self, node_id):
        """Serialize task in expected by orchestrator format.

        :param node_id: the target node_id
        """

        logger.debug(
            "serialize task %s for node %s",
            self.task_template['id'], node_id
        )
        task = utils.traverse(
            self.task_template,
            utils.text_format_safe,
            self.context.get_formatter_context(node_id),
            {
                'yaql_exp': self.context.get_yaql_interpreter(
                    node_id, self.task_template['id'])
            }
        )
        return self.normalize(self.finalize(task, node_id))
开发者ID:huyupeng,项目名称:fuel-web,代码行数:20,代码来源:task_serializer.py


示例13: serialize

    def serialize(self, node_id):
        logger.debug(
            "serialize task %s for node %s",
            self.task_template['id'], node_id
        )
        task = utils.traverse(
            self.task_template,
            utils.text_format_safe,
            self.context.get_formatter_context(node_id),
            {
                'yaql_exp': self.context.get_yaql_interpreter(node_id)
            }
        )
        if not self.should_execute(task, node_id):
            logger.debug(
                "Task %s is skipped by condition.", self.task_template['id']
            )
            return super(DefaultTaskSerializer, self).serialize(node_id)

        task.setdefault('parameters', {}).setdefault('cwd', '/')
        task.setdefault('fail_on_error', True)
        return self.get_required_fields(task)
开发者ID:jiaolongsun,项目名称:fuel-web,代码行数:22,代码来源:task_serializer.py


示例14: test_wo_formatting_context

    def test_wo_formatting_context(self):
        result = traverse(
            self.data,
            keywords={'generator': self.TestGenerator.evaluate}
        )

        self.assertEqual(result, {
            'foo': 'testvalue',
            'bar': 'test {a} string',
            'baz': 42,
            'regex': {
                'source': 'test {a} string',
                'error': 'an {a} error'
            },
            'list': [
                {
                    'x': 'a {a} a',
                },
                {
                    'y': 'b 42 b',
                }
            ]})
开发者ID:sebrandon1,项目名称:fuel-web,代码行数:22,代码来源:test_utils.py


示例15: test_w_safe_formatting_context

    def test_w_safe_formatting_context(self):
        data = self.data.copy()
        data['bar'] = 'test {b} value'
        result = traverse(
            data, text_format_safe, {'a': 13},
            keywords={'generator': self.TestGenerator.evaluate}
        )

        self.assertEqual(result, {
            'foo': 'testvalue',
            'bar': 'test {b} value',
            'baz': 42,
            'regex': {
                'source': 'test {a} string',
                'error': 'an {a} error'
            },
            'list': [
                {
                    'x': 'a 13 a',
                },
                {
                    'y': 'b 42 b',
                }
            ]})
开发者ID:sebrandon1,项目名称:fuel-web,代码行数:24,代码来源:test_utils.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python migration.upgrade_enum函数代码示例发布时间:2022-05-27
下一篇:
Python utils.reverse函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap