コード例 #1
0
ファイル: gene.py プロジェクト: wbryant/cobrapy
 def visit_BinOp(self, node):
     self.generic_visit(node)
     if isinstance(node.op, BitAnd):
         return BoolOp(And(), (node.left, node.right))
     elif isinstance(node.op, BitOr):
         return BoolOp(Or(), (node.left, node.right))
     else:
         raise TypeError("unsupported operation '%s'" %
                         node.op.__class__.__name__)
コード例 #2
0
 def compBreaker(self, node):
     assert isinstance(node, Compare)
     if len(node.comparators) == 1:
         return node
     else:
         comp1 = Compare(node.left, node.ops[0:1], node.comparators[0:1])
         comp2 = Compare(node.comparators[0], node.ops[1:],
                         node.comparators[1:])
         newNode = BoolOp(And(), [comp1, self.compBreaker(comp2)])
         return newNode
コード例 #3
0
ファイル: code.py プロジェクト: pierky/exabgp
    def _union(self, node):
        values = []
        generated = []

        for union in node:
            for what, sub in union.items():
                if ':' in what:
                    if what in generated:
                        # only generate any imported function once
                        continue
                    generated.append(what)
                    name = what
                    yield self._type(what, name, sub)
                else:
                    # this is a build_in type (and my have been refined)
                    # therefore generate one function per type
                    name = self._unique(what)
                    yield self._function(name, self._type(what, what, sub))

                values += [
                    UnaryOp(
                        op=Not(),
                        operand=Call(
                            func=Name(id=self._python_name(name), ctx=Load()),
                            args=[Name(id='value', ctx=Load())],
                            keywords=[],
                        ),
                    ),
                ]

        yield [
            If(
                test=BoolOp(
                    op=And(),
                    values=values,
                ),
                body=[
                    Return(value=Constant(value=False, kind=None), ),
                ],
                orelse=[],
            ),
        ]
コード例 #4
0
def parsePredicate(parser):
    predicate = None
    if parser.matchLexeme('!'):
        parser.next()  #skip !.
        return Not(parsePredicate(parser))

    predicate = parseExpression(parser)

    if parser.matchLexeme("."):  # var.type?
        parser.next("list?, record?, string?", tokensort=KEYWORD)
        if parser.matchLexeme(keywords['LIST']):
            ptype = "LIST"
        if parser.matchLexeme(keywords['RECORD']):
            ptype = "RECORD"
        if parser.matchLexeme(keywords['STRING']):
            ptype = "STRING"
        parser.next()
        parser.check('type?', lexeme='?')
        predicate = Is_a(predicate, ptype, lineo=parser.currentToken[2])
        parser.next()
    if parser.matchLexeme('&') and parser.peek(lexeme='&'):
        parser.next()  #skip &&
        parser.next()
        right = parsePredicate(parser)
        #and
        predicate = And(predicate, right, lineo=parser.currentToken[2])
    if parser.matchLexeme('|') and parser.peek(lexeme='|'):
        parser.next()  #skip ||
        parser.next()
        right = parsePredicate(parser)
        predicate = Or(predicate, right, lineo=parser.currentToken[2])
        #parser.next()

    if not predicate:
        raise SyntaxError(currentToken,
                          "pasing predicate failed && || type? variable")

    return predicate
コード例 #5
0
ファイル: parser.py プロジェクト: wesleygas/ssscobrasss
 def p_and_test(tokens):
     return And(tokens[0], tokens[2])
コード例 #6
0
ファイル: ra2ast.py プロジェクト: willemt/sqlhild
def _(ra: ras.And, ctx: Context):
    return ast.BoolOp(op=And(),
                      values=[
                          convert(ra[0], ctx),
                          convert(ra[1], ctx),
                      ])
コード例 #7
0
    def handle_f(self, f):
        # Do we need to use .attname here?
        # What about transforms/lookups?
        f.contains_aggregate = False
        if "__" in f.name:
            # We need to chain a bunch of attr lookups, returning None
            # if any of them give us a None, we should be returning a None.
            #

            # .  while x is not None and parts:
            # .      x = getattr(x, parts.pop(0), None)
            #   return x
            return [
                Assign(targets=[Name(id="source", **self.file_store)],
                       value=Name(id="self", **self.file),
                       **self.file),
                Assign(
                    targets=[Name(id="parts", **self.file_store)],
                    value=Call(
                        func=Attribute(value=Constant(value=f.name,
                                                      **self.file),
                                       attr="split",
                                       **self.file),
                        args=[Constant(value="__", **self.file)],
                        keywords=[],
                        kwonlyargs=[],
                        **self.file,
                    ),
                    **self.file,
                ),
                While(
                    test=BoolOp(
                        op=And(),
                        values=[
                            Compare(
                                left=Name(id="source", **self.file),
                                ops=[IsNot()],
                                comparators=[
                                    Constant(value=None, **self.file)
                                ],
                                **self.file,
                            ),
                            Name(id="parts", **self.file),
                        ],
                        **self.file,
                    ),
                    body=[
                        Assign(
                            targets=[Name(id="source", **self.file_store)],
                            value=Call(
                                func=Name(id="getattr", **self.file),
                                args=[
                                    Name(id="source", **self.file),
                                    Call(
                                        func=Attribute(value=Name(id="parts",
                                                                  **self.file),
                                                       attr="pop",
                                                       **self.file),
                                        args=[Constant(value=0, **self.file)],
                                        keywords=[],
                                        kwonlyargs=[],
                                        **self.file,
                                    ),
                                    Constant(value=None, **self.file),
                                ],
                                keywords=[],
                                kwonlyargs=[],
                                **self.file,
                            ),
                            **self.file,
                        ),
                    ],
                    orelse=[],
                    **self.file,
                ),
                Return(value=Name(id="source", **self.file), **self.file),
            ]
        return Attribute(value=Name(id="self", **self.file),
                         attr=f.name,
                         **self.file)