def matches(self, msg): total, pages, query = self.construct_query(msg) if self._d['operation'] == 'count': result = total elif isinstance(self._d['operation'], dict): expression = self._d['operation']['lambda'] result = single_argument_lambda_factory( expression=expression, argument=query, name='query') else: operation = getattr(query, self._d['operation']) result = operation() return self.condition(result)
def matches(self, msg): # Check if we should just aggregate the results of our children. # Otherwise, we are a leaf-node doing a straightforward comparison. if self.children: return operator_lookup[self.attribute]( (child.matches(msg) for child in self.children)) elif self.attribute == 'lambda': return single_argument_lambda_factory( expression=self.expected_value, argument=msg, name='msg') elif self.attribute == 'category': # TODO -- use fedmsg.meta.msg2processor(msg).__name__.lower() return msg['topic'].split('.')[3] == self.expected_value else: if hasattr(msg[self.attribute], 'endswith'): return msg[self.attribute].endswith(self.expected_value) else: return msg[self.attribute] == self.expected_value
def matches(self, msg): # Check if we should just aggregate the results of our children. # Otherwise, we are a leaf-node doing a straightforward comparison. if self.children: return operator_lookup[self.attribute](( child.matches(msg) for child in self.children )) elif self.attribute == 'lambda': return single_argument_lambda_factory( expression=self.expected_value, argument=msg, name='msg') elif self.attribute == 'category': # TODO -- use fedmsg.meta.msg2processor(msg).__name__.lower() return msg['topic'].split('.')[3] == self.expected_value else: if hasattr(msg[self.attribute], 'endswith'): return msg[self.attribute].endswith(self.expected_value) else: return msg[self.attribute] == self.expected_value
def matches(self, msg): """ A datanommer criteria check is composed of three steps. - A datanommer query is constructed by combining our yaml definition with the incoming fedmsg message that triggered us. - An operation in python is constructed by comining our yaml definition with the incoming fedmsg message that triggered us. That operation is then executed against the datanommer query object. - A condition, derived from our yaml definition, is evaluated with the result of the operation from the previous step and is returned. """ total, pages, query = self._construct_query(msg) if self._d['operation'] == 'count': result = total elif isinstance(self._d['operation'], dict): expression = self._format_lambda_operation(msg) result = single_argument_lambda_factory( expression=expression, argument=query, name='query') else: operation = getattr(query, self._d['operation']) result = operation() return self.condition(result)
def matches(self, msg): """ A datanommer criteria check is composed of three steps. - A datanommer query is constructed by combining our yaml definition with the incoming fedmsg message that triggered us. - An operation in python is constructed by comining our yaml definition with the incoming fedmsg message that triggered us. That operation is then executed against the datanommer query object. - A condition, derived from our yaml definition, is evaluated with the result of the operation from the previous step and is returned. """ total, pages, query = self._construct_query(msg) if self._d['operation'] == 'count': result = total elif isinstance(self._d['operation'], dict): expression = self._format_lambda_operation(msg) result = single_argument_lambda_factory(expression=expression, argument=query, name='query') else: operation = getattr(query, self._d['operation']) result = operation() return self.condition(result)
def test_basic(self): expression = "value + 2" target = 4 actual = single_argument_lambda_factory(expression, 2) eq_(actual, target)