Exemplo n.º 1
0
    def testLists(self):
        query = "'foo' in ('foo', 'bar') and 1 not in (5, 2, 3,17)"
        expected = expression.Intersection(
            expression.Membership(expression.Literal("foo"),
                                  expression.Literal(("foo", "bar"))),
            expression.Complement(
                expression.Membership(expression.Literal(1),
                                      expression.Literal((5, 2, 3, 17)))))

        self.assertQueryMatches(query, expected)
Exemplo n.º 2
0
    def testBigQuery(self):
        query = ("(Process/pid is 1 and Process/command in ('init', 'initd')) "
                 "or any Process/children matches (Process/command not in "
                 "('launchd', 'foo'))")
        expected = expression.Union(
            expression.Intersection(
                expression.Equivalence(expression.Binding("Process/pid"),
                                       expression.Literal(1)),
                expression.Membership(expression.Binding("Process/command"),
                                      expression.Literal(("init", "initd")))),
            expression.LetAny(
                expression.Binding("Process/children"),
                expression.Complement(
                    expression.Membership(
                        expression.Binding("Process/command"),
                        expression.Literal(("launchd", "foo"))))))

        self.assertQueryMatches(query, expected)
Exemplo n.º 3
0
    def testRealExample(self):
        original = expression.Intersection(
            expression.Let(
                expression.Let(expression.Binding('MemoryDescriptor'),
                               expression.Binding('process')),
                expression.Equivalence(
                    expression.Let(expression.Binding('Process'),
                                   expression.Binding('command')),
                    expression.Literal('Adium'))),
            expression.Intersection(
                expression.Membership(
                    expression.Literal('execute'),
                    expression.Let(expression.Binding('MemoryDescriptor'),
                                   expression.Binding('permissions'))),
                expression.Membership(
                    expression.Literal('write'),
                    expression.Let(expression.Binding('MemoryDescriptor'),
                                   expression.Binding('permissions')))))

        # Two binary intersections become one variadic intersection and the
        # let-forms now have a Binding as their LHS whenever possible.
        expected = expression.Intersection(
            expression.Let(
                expression.Binding('MemoryDescriptor'),
                expression.Let(
                    expression.Binding('process'),
                    expression.Equivalence(
                        expression.Let(expression.Binding('Process'),
                                       expression.Binding('command')),
                        expression.Literal('Adium')))),
            expression.Membership(
                expression.Literal('execute'),
                expression.Let(expression.Binding('MemoryDescriptor'),
                               expression.Binding('permissions'))),
            expression.Membership(
                expression.Literal('write'),
                expression.Let(expression.Binding('MemoryDescriptor'),
                               expression.Binding('permissions'))))

        self.assertResult(original, expected)
Exemplo n.º 4
0
def ComplementMembership(*args, **kwargs):
    return expression.Complement(
        expression.Membership(*args, **kwargs), **kwargs)
Exemplo n.º 5
0
 def testNestedParens(self):
     query = "Process/pid in ((1,2))"
     expected = expression.Membership(expression.Binding("Process/pid"),
                                      expression.Literal((1, 2)))
     self.assertQueryMatches(query, expected)