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

Python yaql.create_context函数代码示例

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

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



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

示例1: test_int_bool_resolving

    def test_int_bool_resolving(self):
        @parameter('param', arg_type=types.IntType)
        def int_func(param):
            return "int: " + str(param)

        @parameter('param', arg_type=types.BooleanType)
        def bool_func(param):
            return "bool: " + str(param)

        context1 = yaql.create_context(False)
        context2 = yaql.create_context(False)
        context3 = yaql.create_context(False)
        context4 = yaql.create_context(False)

        context1.register_function(int_func, 'foo')
        context2.register_function(bool_func, 'foo')
        context3.register_function(int_func, 'foo')
        context3.register_function(bool_func, 'foo')
        context4.register_function(bool_func, 'foo')
        context4.register_function(int_func, 'foo')

        self.assertEquals("int: 1", self.eval('foo(1)', context=context1))
        self.assertEquals("int: 0", self.eval('foo(0)', context=context1))
        self.assertRaises(Exception, self.eval, "foo('1')", context=context1)
        self.assertRaises(Exception, self.eval, 'foo(1)', context=context2)

        self.assertEquals("bool: True",
                          self.eval('foo(true)', context=context2))
        self.assertEquals("bool: False",
                          self.eval('foo(false)', context=context2))
        self.assertRaises(Exception, self.eval, "foo(1)", context=context2)
        self.assertRaises(Exception, self.eval, 'foo(0)', context=context2)
        self.assertRaises(Exception, self.eval, 'foo(True)', context=context2)
        self.assertRaises(Exception, self.eval, "foo('true')",
                          context=context2)

        self.assertEquals("int: 1", self.eval('foo(1)', context=context3))
        self.assertEquals("int: 0", self.eval('foo(0)', context=context3))
        self.assertEquals("bool: True",
                          self.eval('foo(true)', context=context3))
        self.assertEquals("bool: False",
                          self.eval('foo(false)', context=context3))

        self.assertEquals("int: 1", self.eval('foo(1)', context=context4))
        self.assertEquals("int: 0", self.eval('foo(0)', context=context4))
        self.assertEquals("bool: True",
                          self.eval('foo(true)', context=context4))
        self.assertEquals("bool: False",
                          self.eval('foo(false)', context=context4))
开发者ID:PaulReiber,项目名称:yaql,代码行数:49,代码来源:test_system.py


示例2: create_context

def create_context(add_serializers=False, add_datadiff=False, **kwargs):
    context = yaql.create_context(**kwargs)
    if add_serializers:
        serializers.register(context)
    if add_datadiff:
        datadiff.register(context)
    return context
开发者ID:ekorekin,项目名称:fuel-web,代码行数:7,代码来源:__init__.py


示例3: main

def main():
    p = optparse.OptionParser()
    p.add_option("--data", "-d")
    p.add_option("-t", action="store_true", dest="tokens")
    p.add_option("--legacy", action="store_true", dest="legacy")

    options, arguments = p.parse_args()
    if options.data:
        try:
            with open(options.data) as f:
                data = json.load(f)
        except Exception:
            print("Unable to load data from " + options.data)
            return
    else:
        data = None

    engine_options = {"yaql.limitIterators": 100, "yaql.treatSetsAsLists": True, "yaql.memoryQuota": 10000}

    if options.legacy:
        factory = yaql.legacy.YaqlFactory()
        context = yaql.legacy.create_context()
        context["legacy"] = True
    else:
        factory = yaql.YaqlFactory()
        context = yaql.create_context()

    parser = factory.create(options=engine_options)
    cli_functions.register_in_context(context, parser)
    if options.tokens:
        parser("__main(true)").evaluate(data, context)
    else:
        parser("__main(false)").evaluate(data, context)
开发者ID:lightsey,项目名称:yaql,代码行数:33,代码来源:run.py


示例4: __init__

    def __init__(self, cleaned_data, forms=None, templates=None,
                 application=None, **kwargs):
        self.cleaned_data = cleaned_data
        self.templates = templates or {}

        if application is None:
            raise ValueError('Application section is required')
        else:
            self.application = application

        self.context = yaql.create_context()
        yaql_functions.register(self.context)

        self.forms = []
        for key, value in kwargs.iteritems():
            setattr(self, key, value)

        if forms:
            for data in forms:
                (name, field_specs, validators,
                 verbose_name) = self.extract_form_data(data)
                self._add_form(name, field_specs, validators, verbose_name)

        # Add ManageWorkflowForm
        workflow_form = catalog_forms.WorkflowManagementForm
        self._add_form(workflow_form.name, workflow_form.field_specs,
                       workflow_form.validators, _("What's next?"))
开发者ID:mssumanth,项目名称:murano-dashboard,代码行数:27,代码来源:services.py


示例5: create_context

def create_context(*args, **kwargs):
    tuples = kwargs.pop('tuples', True)

    context = yaql.create_context(*args, **kwargs)
    context = context.create_child_context()

    std_legacy.register(context, tuples)
    return context
开发者ID:ativelkov,项目名称:yaql-1,代码行数:8,代码来源:legacy.py


示例6: __init__

    def __init__(self, object_store):
        self._object_store = object_store
        self._root_context = yaql.create_context(True)

        @ContextAware()
        def resolve(context, name, obj):
            return self._resolve(context, name, obj)

        self._root_context.register_function(resolve, '#resolve')
开发者ID:tsufiev,项目名称:MuranoDsl,代码行数:9,代码来源:executor.py


示例7: evaluate

 def evaluate(self, data=utils.NO_VALUE, context=None):
     if context is None or context is utils.NO_VALUE:
         context = yaql.create_context()
     if data is not utils.NO_VALUE:
         if self.engine.options.get('yaql.convertInputData', True):
             context['$'] = utils.convert_input_data(data)
         else:
             context['$'] = data
     return self(utils.NO_VALUE, context, self.engine)
开发者ID:openstack,项目名称:yaql,代码行数:9,代码来源:expressions.py


示例8: evaluate

    def evaluate(self, data=None, context=None):
        if not context:
            context = Context(yaql.create_context())
        if data:
            context.set_data(data)

        f = self.create_callable(context)
        # noinspection PyCallingNonCallable
        return f()
开发者ID:tsufiev,项目名称:yaql,代码行数:9,代码来源:expressions.py


示例9: __init__

    def __init__(self, *args, **kwargs):
        LOG.info("Creating form {0}".format(self.__class__.__name__))
        super(ServiceConfigurationForm, self).__init__(*args, **kwargs)

        self.auto_id = '{0}_%s'.format(self.initial.get('app_id'))
        self.context = yaql.create_context()
        yaql_functions.register(self.context)

        self.finalize_fields()
        self.update_fields()
开发者ID:hybrid-murano,项目名称:hybrid-dashboard,代码行数:10,代码来源:forms.py


示例10: main

def main():
    p = optparse.OptionParser()
    p.add_option('--data', '-d', help="input file")
    p.add_option('--string', '-s', action='store_true',
                 help="input is a string")
    p.add_option('--native', '-n', action='store_true',
                 help="output data in Python native format")
    p.add_option('--array', '-a', action='store_true',
                 help="read input line by line")
    p.add_option('--tokens', '-t', action='store_true', dest='tokens',
                 help="print lexical tokens info")
    p.add_option('--legacy', action='store_true', dest='legacy',
                 help="enable legacy v0.2 compatibility mode")

    options, arguments = p.parse_args()
    if options.data:
        try:
            if options.data == '-':
                data = read_data(sys.stdin, options)
            else:
                with open(options.data) as f:
                    data = read_data(f, options)
        except Exception:
            print('Unable to load data from ' + options.data, file=sys.stderr)
            exit(1)
    else:
        data = None

    engine_options = {
        'yaql.limitIterators': 1000,
        'yaql.convertSetsToLists': True,
        'yaql.memoryQuota': 100000
    }

    if options.legacy:
        factory = yaql.legacy.YaqlFactory()
        context = yaql.legacy.create_context()
        context['legacy'] = True
    else:
        factory = yaql.YaqlFactory()
        context = yaql.create_context()

    if options.native:
        context['#nativeOutput'] = True

    parser = factory.create(options=engine_options)
    cli_functions.register_in_context(context, parser)

    if len(arguments) > 0:
        for arg in arguments:
            cli_functions.evaluate(arg, parser, data, context)
    elif options.tokens:
        parser('__main(true)').evaluate(data, context)
    else:
        parser('__main(false)').evaluate(data, context)
开发者ID:xavierhardy,项目名称:yaql,代码行数:55,代码来源:run.py


示例11: _evaluate

def _evaluate(yaql_expression, yaml_data, legacy=False):
    if legacy:
        factory = yaql.legacy.YaqlFactory()
        context = yaql.legacy.create_context()
        context['legacy'] = True
    else:
        factory = yaql.YaqlFactory()
        context = yaql.create_context()

    parser = factory.create()
    return parser(yaql_expression).evaluate(yaml_data, context)
开发者ID:istalker2,项目名称:yaqluator,代码行数:11,代码来源:yaqluator.py


示例12: test_evaluate

    def test_evaluate(self):
        yaql_value = mock.Mock(yaql_expression.YaqlExpression,
                               return_value='atom')
        complex_value = {yaql_value: ['some', (1, yaql_value), 'hi!'],
                         'sample': [yaql_value, six.moves.range(5)]}
        complex_literal = utils.FrozenDict({
            'atom': ('some', (1, 'atom'), 'hi!'),
            'sample': ('atom', (0, 1, 2, 3, 4))
        })
        context = yaql.create_context()
        evaluated_value = helpers.evaluate(yaql_value, context)
        evaluated_complex_value = helpers.evaluate(complex_value, context)

        self.assertEqual('atom', evaluated_value)
        self.assertEqual(complex_literal, evaluated_complex_value)
开发者ID:Magic-Mirror,项目名称:murano,代码行数:15,代码来源:test_engine.py


示例13: get_yaql_context

def get_yaql_context(data_context):
    global ROOT_CONTEXT

    if not ROOT_CONTEXT:
        ROOT_CONTEXT = yaql.create_context()

        _register_functions(ROOT_CONTEXT)

    new_ctx = ROOT_CONTEXT.create_child_context()
    new_ctx['$'] = data_context

    if isinstance(data_context, dict):
        new_ctx['__env'] = data_context.get('__env')
        new_ctx['__execution'] = data_context.get('__execution')

    return new_ctx
开发者ID:dennybaa,项目名称:mistral,代码行数:16,代码来源:yaql_utils.py


示例14: _evaluate

def _evaluate(yaql_expression, yaml_data, legacy=False):
    engine_options = {
        'yaql.limitIterators': 100,
        'yaql.convertSetsToLists': True,
        'yaql.memoryQuota': 10000
    }

    if legacy:
        factory = yaql.legacy.YaqlFactory()
        context = yaql.legacy.create_context()
        context['legacy'] = True
    else:
        factory = yaql.YaqlFactory()
        context = yaql.create_context()

    parser = factory.create(options=engine_options)
    return parser(yaql_expression).evaluate(yaml_data, context)
开发者ID:ALU-CloudBand,项目名称:yaqluator,代码行数:17,代码来源:yaqluator.py


示例15: main

def main():
    p = optparse.OptionParser()
    p.add_option('--data', '-d')
    options, arguments = p.parse_args()
    if options.data:
        try:
            json_str = open(options.data).read()
            decoder = JSONDecoder()
            data = decoder.decode(json_str)
        except:
            print "Unable to load data from "+options.data
            return
    else:
        data = None

    context = yaql.create_context()
    extensions.register_in_context(context)
    yaql.parse('__main()').evaluate(data, context)
开发者ID:tsufiev,项目名称:yaql,代码行数:18,代码来源:run.py


示例16: __init__

    def __init__(self, stack, fn_name, args):
        super(Yaql, self).__init__(stack, fn_name, args)
        self._yaql_context = yaql.create_context()

        if not isinstance(self.args, collections.Mapping):
            raise TypeError(_('Arguments to "%s" must be a map.') %
                            self.fn_name)

        try:
            self._expression = self.args['expression']
            self._data = self.args.get('data', {})
            if set(self.args) - set(['expression', 'data']):
                raise KeyError
        except (KeyError, TypeError):
            example = ('''%s:
              expression: $.data.var1.sum()
              data:
                var1: [3, 2, 1]''') % self.fn_name
            raise KeyError(_('"%(name)s" syntax should be %(example)s') % {
                'name': self.fn_name, 'example': example})
开发者ID:rabi,项目名称:heat,代码行数:20,代码来源:functions.py


示例17: test_evaluate

    def test_evaluate(self):
        yaql_value = mock.Mock(spec=yaql_expression.YaqlExpression,
                               evaluate=lambda context: 'atom')
        complex_value = {yaql_value: ['some', (1, yaql_value), lambda: 'hi!'],
                         'sample': [yaql_value, xrange(5)]}
        complex_literal = {'atom': ['some', (1, 'atom'), 'hi!'],
                           'sample': ['atom', [0, 1, 2, 3, 4]]}
        # tuple(evaluate(list)) transformation adds + 1
        complex_literal_depth = 3 + 1

        context = yaql.create_context(False)
        evaluated_value = helpers.evaluate(yaql_value, context, 1)
        non_evaluated_value = helpers.evaluate(yaql_value, context, 0)
        evaluated_complex_value = helpers.evaluate(complex_value, context)
        non_evaluated_complex_value = helpers.evaluate(
            complex_value, context, complex_literal_depth)

        self.assertEqual('atom', evaluated_value)
        self.assertNotEqual('atom', non_evaluated_value)
        self.assertEqual(complex_literal, evaluated_complex_value)
        self.assertNotEqual(complex_literal, non_evaluated_complex_value)
开发者ID:OndrejVojta,项目名称:murano,代码行数:21,代码来源:test_engine.py


示例18: get_yaql_context

def get_yaql_context(data_context):
    global ROOT_YAQL_CONTEXT

    if not ROOT_YAQL_CONTEXT:
        ROOT_YAQL_CONTEXT = yaql.create_context()

        _register_yaql_functions(ROOT_YAQL_CONTEXT)

    new_ctx = ROOT_YAQL_CONTEXT.create_child_context()

    new_ctx['$'] = (
        data_context if not cfg.CONF.yaql.convert_input_data
        else yaql_utils.convert_input_data(data_context)
    )

    if isinstance(data_context, dict):
        new_ctx['__env'] = data_context.get('__env')
        new_ctx['__execution'] = data_context.get('__execution')
        new_ctx['__task_execution'] = data_context.get('__task_execution')

    return new_ctx
开发者ID:openstack,项目名称:mistral,代码行数:21,代码来源:expression_utils.py


示例19: main

def main():
    p = optparse.OptionParser()
    p.add_option('--data', '-d')
    p.add_option('-t', action='store_true', dest='tokens')

    options, arguments = p.parse_args()
    if options.data:
        try:
            json_str = open(options.data).read()
            decoder = JSONDecoder()
            data = decoder.decode(json_str)
        except:
            print("Unable to load data from " + options.data)
            return
    else:
        data = None

    context = yaql.create_context()
    cli_functions.register_in_context(context)
    if options.tokens:
        yaql.parse('__main(true)').evaluate(data, context)
    else:
        yaql.parse('__main(false)').evaluate(data, context)
开发者ID:thomasgoirand,项目名称:yaql,代码行数:23,代码来源:run.py


示例20: create_yaql_context

def create_yaql_context():
    ctx = yaql.create_context()

    _register_functions(ctx)

    return ctx
开发者ID:kantorv,项目名称:mistral,代码行数:6,代码来源:yaql_utils.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python yara.compile函数代码示例发布时间:2022-05-26
下一篇:
Python log.debug函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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