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


Python operators.get_operator函数代码示例

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


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

示例1: _check_criterion

    def _check_criterion(self, criterion_k, criterion_v, payload_lookup):
        criteria_operator = ''
        if 'type' in criterion_v:
            criteria_operator = criterion_v['type']
        else:
            return False

        if 'pattern' not in criterion_v:
            criterion_v['pattern'] = None

        try:
            matches = payload_lookup.get_value(criterion_k)
            # pick value if only 1 matches else will end up being an array match.
            if matches:
                payload_value = matches[0] if len(matches) > 0 else matches
            else:
                payload_value = None
        except:
            LOG.exception('Failed transforming criteria key %s', criterion_k)
            return False

        criteria_pattern = criterion_v['pattern']

        op_func = criteria_operators.get_operator(criteria_operator)

        try:
            return op_func(value=payload_value, criteria_pattern=criteria_pattern)
        except:
            LOG.exception('There might be a problem with critera in rule %s.', self.rule)
            return False
开发者ID:srenatus,项目名称:st2,代码行数:30,代码来源:filter.py

示例2: test_matchwildcard

    def test_matchwildcard(self):
        op = operators.get_operator('matchwildcard')
        self.assertTrue(op('v1', 'v1'), 'Failed matchwildcard.')

        self.assertFalse(op('test foo test', 'foo'), 'Failed matchwildcard.')
        self.assertTrue(op('test foo test', '*foo*'), 'Failed matchwildcard.')
        self.assertTrue(op('bar', 'b*r'), 'Failed matchwildcard.')
        self.assertTrue(op('bar', 'b?r'), 'Failed matchwildcard.')
开发者ID:LindsayHill,项目名称:st2,代码行数:8,代码来源:test_operators.py

示例3: test_incontains

 def test_incontains(self):
     op = operators.get_operator('incontains')
     self.assertTrue(op('hasystack needle haystack', 'FOO'))
     self.assertTrue(op('needle', 'FOO'))
     self.assertTrue(op('needlehaystack', 'needlex'))
     self.assertTrue(op('needle haystack', 'needlex'))
     self.assertTrue(op('haystackneedle', 'needlex'))
     self.assertTrue(op('haystack needle', 'needlex'))
开发者ID:LindsayHill,项目名称:st2,代码行数:8,代码来源:test_operators.py

示例4: test_icontains

 def test_icontains(self):
     op = operators.get_operator('icontains')
     self.assertTrue(op('hasystack nEEdle haystack', 'needle'))
     self.assertTrue(op('neeDle', 'NeedlE'))
     self.assertTrue(op('needlehaystack', 'needle'))
     self.assertTrue(op('NEEDLE haystack', 'NEEDLE'))
     self.assertTrue(op('haystackNEEDLE', 'needle'))
     self.assertTrue(op('haystack needle', 'NEEDLE'))
开发者ID:LindsayHill,项目名称:st2,代码行数:8,代码来源:test_operators.py

示例5: test_regex_fail

    def test_regex_fail(self):
        op = operators.get_operator('regex')
        self.assertFalse(op('v1_foo', 'v1$'), 'Passed regex.')

        string = 'fooPONIESbarfooooo'
        self.assertFalse(op(string, 'ponies'), 'Passed regex.')

        self.assertFalse(op('1', None), 'Passed regex with None as criteria_pattern.')
开发者ID:StackStorm,项目名称:st2,代码行数:8,代码来源:test_operators.py

示例6: test_nequals

    def test_nequals(self):
        op = operators.get_operator('nequals')
        self.assertTrue(op('foo', 'bar'))
        self.assertTrue(op('foo', 'foo1'))
        self.assertTrue(op('foo', 'FOO'))
        self.assertTrue(op('True', True))
        self.assertTrue(op('None', None))

        self.assertFalse(op('True', 'True'))
        self.assertFalse(op(None, None))
开发者ID:LindsayHill,项目名称:st2,代码行数:10,代码来源:test_operators.py

示例7: test_matchwildcard

    def test_matchwildcard(self):
        op = operators.get_operator('matchwildcard')
        self.assertTrue(op('v1', 'v1'), 'Failed matchwildcard.')

        self.assertFalse(op('test foo test', 'foo'), 'Passed matchwildcard.')
        self.assertTrue(op('test foo test', '*foo*'), 'Failed matchwildcard.')
        self.assertTrue(op('bar', 'b*r'), 'Failed matchwildcard.')
        self.assertTrue(op('bar', 'b?r'), 'Failed matchwildcard.')

        self.assertFalse(op('1', None), 'Passed matchwildcard with None as criteria_pattern.')
开发者ID:StackStorm,项目名称:st2,代码行数:10,代码来源:test_operators.py

示例8: _check_criterion

    def _check_criterion(self, criterion_k, criterion_v, payload_lookup):
        if 'type' not in criterion_v:
            # Comparison operator type not specified, can't perform a comparison
            return (False, None, None)

        criteria_operator = criterion_v['type']
        criteria_condition = criterion_v.get('condition', None)
        criteria_pattern = criterion_v.get('pattern', None)

        # Render the pattern (it can contain a jinja expressions)
        try:
            criteria_pattern = self._render_criteria_pattern(
                criteria_pattern=criteria_pattern,
                criteria_context=payload_lookup.context
            )
        except Exception as e:
            msg = ('Failed to render pattern value "%s" for key "%s"' % (criteria_pattern,
                                                                         criterion_k))
            LOG.exception(msg, extra=self._base_logger_context)
            self._create_rule_enforcement(failure_reason=msg, exc=e)

            return (False, None, None)

        try:
            matches = payload_lookup.get_value(criterion_k)
            # pick value if only 1 matches else will end up being an array match.
            if matches:
                payload_value = matches[0] if len(matches) > 0 else matches
            else:
                payload_value = None
        except Exception as e:
            msg = ('Failed transforming criteria key %s' % criterion_k)
            LOG.exception(msg, extra=self._base_logger_context)
            self._create_rule_enforcement(failure_reason=msg, exc=e)

            return (False, None, None)

        op_func = criteria_operators.get_operator(criteria_operator)

        try:
            if criteria_operator == criteria_operators.SEARCH:
                result = op_func(value=payload_value, criteria_pattern=criteria_pattern,
                                 criteria_condition=criteria_condition,
                                 check_function=self._bool_criterion)
            else:
                result = op_func(value=payload_value, criteria_pattern=criteria_pattern)
        except Exception as e:
            msg = ('There might be a problem with the criteria in rule %s' % (self.rule.ref))
            LOG.exception(msg, extra=self._base_logger_context)
            self._create_rule_enforcement(failure_reason=msg, exc=e)

            return (False, None, None)

        return result, payload_value, criteria_pattern
开发者ID:StackStorm,项目名称:st2,代码行数:54,代码来源:filter.py

示例9: test_matchregex

    def test_matchregex(self):
        op = operators.get_operator('matchregex')
        self.assertTrue(op('v1', 'v1$'), 'Failed matchregex.')

        # Multi line string, make sure re.DOTALL is used
        string = '''ponies
        moar
        foo
        bar
        yeah!
        '''
        self.assertTrue(op(string, '.*bar.*'), 'Failed matchregex.')

        string = 'foo\r\nponies\nbar\nfooooo'
        self.assertTrue(op(string, '.*ponies.*'), 'Failed matchregex.')
开发者ID:LindsayHill,项目名称:st2,代码行数:15,代码来源:test_operators.py

示例10: test_regex

    def test_regex(self):
        op = operators.get_operator('regex')
        self.assertTrue(op('v1', 'v1$'), 'Failed regex.')

        string = 'fooponiesbarfooooo'
        self.assertTrue(op(string, 'ponies'), 'Failed regex.')

        # Example with | modifier
        string = 'apple ponies oranges'
        self.assertTrue(op(string, '(ponies|unicorns)'), 'Failed regex.')

        string = 'apple unicorns oranges'
        self.assertTrue(op(string, '(ponies|unicorns)'), 'Failed regex.')

        string = 'apple unicorns oranges'
        self.assertFalse(op(string, '(pikachu|snorlax|charmander)'), 'Failed regex.')
开发者ID:LindsayHill,项目名称:st2,代码行数:16,代码来源:test_operators.py

示例11: _check_criterion

    def _check_criterion(self, criterion_k, criterion_v, transform):
        # No payload or matching criterion_k in the payload therefore cannot apply a criteria.
        if 'pattern' not in criterion_v or criterion_v['pattern'] is None:
            return False

        try:
            payload_value = transform({'result': '{{' + criterion_k + '}}'})
        except:
            LOG.exception('Failed transforming criteria key %s', criterion_k)
            return False

        criteria_operator = ''
        criteria_pattern = criterion_v['pattern']
        if 'type' in criterion_v:
            criteria_operator = criterion_v['type']
        op_func = criteria_operators.get_operator(criteria_operator)

        return op_func(payload_value['result'], criteria_pattern)
开发者ID:bjoernbessert,项目名称:st2,代码行数:18,代码来源:filter.py

示例12: _check_criterion

    def _check_criterion(self, criterion_k, criterion_v, payload_lookup):
        if "type" not in criterion_v:
            # Comparison operator type not specified, can't perform a comparison
            return False

        criteria_operator = criterion_v["type"]
        criteria_pattern = criterion_v.get("pattern", None)

        # Render the pattern (it can contain a jinja expressions)
        try:
            criteria_pattern = self._render_criteria_pattern(criteria_pattern=criteria_pattern)
        except Exception:
            LOG.exception(
                'Failed to render pattern value "%s" for key "%s"' % (criteria_pattern, criterion_k),
                extra=self._base_logger_context,
            )
            return False

        try:
            matches = payload_lookup.get_value(criterion_k)
            # pick value if only 1 matches else will end up being an array match.
            if matches:
                payload_value = matches[0] if len(matches) > 0 else matches
            else:
                payload_value = None
        except:
            LOG.exception("Failed transforming criteria key %s", criterion_k, extra=self._base_logger_context)
            return False

        op_func = criteria_operators.get_operator(criteria_operator)

        try:
            result = op_func(value=payload_value, criteria_pattern=criteria_pattern)
        except:
            LOG.exception(
                "There might be a problem with the criteria in rule %s.", self.rule, extra=self._base_logger_context
            )
            return False

        return result, payload_value, criteria_pattern
开发者ID:tonybaloney,项目名称:st2,代码行数:40,代码来源:filter.py

示例13: test_lt_char

 def test_lt_char(self):
     op = operators.get_operator('lessthan')
     self.assertTrue(op('a', 'b'), 'Failed lessthan.')
开发者ID:LindsayHill,项目名称:st2,代码行数:3,代码来源:test_operators.py

示例14: test_nexists

 def test_nexists(self):
     op = operators.get_operator('nexists')
     self.assertFalse(op(False, None), 'Should return False')
     self.assertFalse(op(1, None), 'Should return False')
     self.assertFalse(op('foo', None), 'Should return False')
     self.assertTrue(op(None, None), 'Should return True')
开发者ID:LindsayHill,项目名称:st2,代码行数:6,代码来源:test_operators.py

示例15: test_timediff_gt_fail

 def test_timediff_gt_fail(self):
     op = operators.get_operator('timediff_gt')
     self.assertFalse(op(date_utils.get_datetime_utc_now().isoformat(), 10),
                      'Passed test_timediff_gt.')
开发者ID:LindsayHill,项目名称:st2,代码行数:4,代码来源:test_operators.py


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