當前位置: 首頁>>代碼示例>>Python>>正文


Python symbol.test方法代碼示例

本文整理匯總了Python中symbol.test方法的典型用法代碼示例。如果您正苦於以下問題:Python symbol.test方法的具體用法?Python symbol.test怎麽用?Python symbol.test使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在symbol的用法示例。


在下文中一共展示了symbol.test方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_op

# 需要導入模塊: import symbol [as 別名]
# 或者: from symbol import test [as 別名]
def get_op(cls, op):
        ops = {
            symbol.test: cls.test,
            symbol.and_test: cls.and_test,
            symbol.atom: cls.atom,
            symbol.comparison: cls.comparison,
            'not in': lambda x, y: x not in y,
            'in': lambda x, y: x in y,
            '==': operator.eq,
            '!=': operator.ne,
            '<':  operator.lt,
            '>':  operator.gt,
            '<=': operator.le,
            '>=': operator.ge,
        }
        if hasattr(symbol, 'or_test'):
            ops[symbol.or_test] = cls.test
        return ops[op] 
開發者ID:jpush,項目名稱:jbox,代碼行數:20,代碼來源:__init__.py

示例2: print_stmt

# 需要導入模塊: import symbol [as 別名]
# 或者: from symbol import test [as 別名]
def print_stmt(self, nodelist):
        # print ([ test (',' test)* [','] ] | '>>' test [ (',' test)+ [','] ])
        items = []
        if len(nodelist) == 1:
            start = 1
            dest = None
        elif nodelist[1][0] == token.RIGHTSHIFT:
            assert len(nodelist) == 3 \
                   or nodelist[3][0] == token.COMMA
            dest = self.com_node(nodelist[2])
            start = 4
        else:
            dest = None
            start = 1
        for i in range(start, len(nodelist), 2):
            items.append(self.com_node(nodelist[i]))
        if nodelist[-1][0] == token.COMMA:
            return Print(items, dest, lineno=nodelist[0][2])
        return Printnl(items, dest, lineno=nodelist[0][2]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:transformer.py

示例3: com_argument

# 需要導入模塊: import symbol [as 別名]
# 或者: from symbol import test [as 別名]
def com_argument(self, nodelist, kw, star_node):
        if len(nodelist) == 3 and nodelist[2][0] == symbol.comp_for:
            test = self.com_node(nodelist[1])
            return 0, self.com_generator_expression(test, nodelist[2])
        if len(nodelist) == 2:
            if kw:
                raise SyntaxError, "non-keyword arg after keyword arg"
            if star_node:
                raise SyntaxError, "only named arguments may follow *expression"
            return 0, self.com_node(nodelist[1])
        result = self.com_node(nodelist[3])
        n = nodelist[1]
        while len(n) == 2 and n[0] != token.NAME:
            n = n[1]
        if n[0] != token.NAME:
            raise SyntaxError, "keyword can't be an expression (%s)"%n[0]
        node = Keyword(n[1], result, lineno=n[2])
        return 1, node 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:transformer.py

示例4: test

# 需要導入模塊: import symbol [as 別名]
# 或者: from symbol import test [as 別名]
def test(cls, nodelist):
        # MUST NOT short-circuit evaluation, or invalid syntax can be skipped!
        items = [
            cls.interpret(nodelist[i])
            for i in range(1, len(nodelist), 2)
        ]
        return functools.reduce(operator.or_, items) 
開發者ID:jpush,項目名稱:jbox,代碼行數:9,代碼來源:__init__.py

示例5: get_op

# 需要導入模塊: import symbol [as 別名]
# 或者: from symbol import test [as 別名]
def get_op(cls, op):
        ops = {
            symbol.test: cls.test,
            symbol.and_test: cls.and_test,
            symbol.atom: cls.atom,
            symbol.comparison: cls.comparison,
            'not in': lambda x, y: x not in y,
            'in': lambda x, y: x in y,
            '==': operator.eq,
            '!=': operator.ne,
        }
        if hasattr(symbol, 'or_test'):
            ops[symbol.or_test] = cls.test
        return ops[op] 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:16,代碼來源:pkg_resources.py

示例6: lambdef

# 需要導入模塊: import symbol [as 別名]
# 或者: from symbol import test [as 別名]
def lambdef(self, nodelist):
        # lambdef: 'lambda' [varargslist] ':' test
        if nodelist[2][0] == symbol.varargslist:
            names, defaults, flags = self.com_arglist(nodelist[2][1:])
        else:
            names = defaults = ()
            flags = 0

        # code for lambda
        code = self.com_node(nodelist[-1])

        return Lambda(names, defaults, flags, code, lineno=nodelist[1][2]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:14,代碼來源:transformer.py

示例7: raise_stmt

# 需要導入模塊: import symbol [as 別名]
# 或者: from symbol import test [as 別名]
def raise_stmt(self, nodelist):
        # raise: [test [',' test [',' test]]]
        if len(nodelist) > 5:
            expr3 = self.com_node(nodelist[5])
        else:
            expr3 = None
        if len(nodelist) > 3:
            expr2 = self.com_node(nodelist[3])
        else:
            expr2 = None
        if len(nodelist) > 1:
            expr1 = self.com_node(nodelist[1])
        else:
            expr1 = None
        return Raise(expr1, expr2, expr3, lineno=nodelist[0][2]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:17,代碼來源:transformer.py

示例8: assert_stmt

# 需要導入模塊: import symbol [as 別名]
# 或者: from symbol import test [as 別名]
def assert_stmt(self, nodelist):
        # 'assert': test, [',' test]
        expr1 = self.com_node(nodelist[1])
        if (len(nodelist) == 4):
            expr2 = self.com_node(nodelist[3])
        else:
            expr2 = None
        return Assert(expr1, expr2, lineno=nodelist[0][2]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:transformer.py

示例9: if_stmt

# 需要導入模塊: import symbol [as 別名]
# 或者: from symbol import test [as 別名]
def if_stmt(self, nodelist):
        # if: test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
        tests = []
        for i in range(0, len(nodelist) - 3, 4):
            testNode = self.com_node(nodelist[i + 1])
            suiteNode = self.com_node(nodelist[i + 3])
            tests.append((testNode, suiteNode))

        if len(nodelist) % 4 == 3:
            elseNode = self.com_node(nodelist[-1])
##      elseNode.lineno = nodelist[-1][1][2]
        else:
            elseNode = None
        return If(tests, elseNode, lineno=nodelist[0][2]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:16,代碼來源:transformer.py

示例10: testlist

# 需要導入模塊: import symbol [as 別名]
# 或者: from symbol import test [as 別名]
def testlist(self, nodelist):
        # testlist: expr (',' expr)* [',']
        # testlist_safe: test [(',' test)+ [',']]
        # exprlist: expr (',' expr)* [',']
        return self.com_binary(Tuple, nodelist) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:transformer.py

示例11: testlist_comp

# 需要導入模塊: import symbol [as 別名]
# 或者: from symbol import test [as 別名]
def testlist_comp(self, nodelist):
        # test ( comp_for | (',' test)* [','] )
        assert nodelist[0][0] == symbol.test
        if len(nodelist) == 2 and nodelist[1][0] == symbol.comp_for:
            test = self.com_node(nodelist[0])
            return self.com_generator_expression(test, nodelist[1])
        return self.testlist(nodelist) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:transformer.py

示例12: test

# 需要導入模塊: import symbol [as 別名]
# 或者: from symbol import test [as 別名]
def test(self, nodelist):
        # or_test ['if' or_test 'else' test] | lambdef
        if len(nodelist) == 1 and nodelist[0][0] == symbol.lambdef:
            return self.lambdef(nodelist[0])
        then = self.com_node(nodelist[0])
        if len(nodelist) > 1:
            assert len(nodelist) == 5
            assert nodelist[1][1] == 'if'
            assert nodelist[3][1] == 'else'
            test = self.com_node(nodelist[2])
            else_ = self.com_node(nodelist[4])
            return IfExp(test, then, else_, lineno=nodelist[1][2])
        return then 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:15,代碼來源:transformer.py

示例13: atom_name

# 需要導入模塊: import symbol [as 別名]
# 或者: from symbol import test [as 別名]
def atom_name(self, nodelist):
        return Name(nodelist[0][1], lineno=nodelist[0][2])

    # --------------------------------------------------------------
    #
    # INTERNAL PARSING UTILITIES
    #

    # The use of com_node() introduces a lot of extra stack frames,
    # enough to cause a stack overflow compiling test.test_parser with
    # the standard interpreter recursionlimit.  The com_node() is a
    # convenience function that hides the dispatch details, but comes
    # at a very high cost.  It is more efficient to dispatch directly
    # in the callers.  In these cases, use lookup_node() and call the
    # dispatched node directly. 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:17,代碼來源:transformer.py

示例14: com_list_constructor

# 需要導入模塊: import symbol [as 別名]
# 或者: from symbol import test [as 別名]
def com_list_constructor(self, nodelist):
        # listmaker: test ( list_for | (',' test)* [','] )
        values = []
        for i in range(1, len(nodelist)):
            if nodelist[i][0] == symbol.list_for:
                assert len(nodelist[i:]) == 1
                return self.com_list_comprehension(values[0],
                                                   nodelist[i])
            elif nodelist[i][0] == token.COMMA:
                continue
            values.append(self.com_node(nodelist[i]))
        return List(values, lineno=values[0].lineno) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:14,代碼來源:transformer.py

示例15: com_generator_expression

# 需要導入模塊: import symbol [as 別名]
# 或者: from symbol import test [as 別名]
def com_generator_expression(self, expr, node):
        # comp_iter: comp_for | comp_if
        # comp_for: 'for' exprlist 'in' test [comp_iter]
        # comp_if: 'if' test [comp_iter]

        lineno = node[1][2]
        fors = []
        while node:
            t = node[1][1]
            if t == 'for':
                assignNode = self.com_assign(node[2], OP_ASSIGN)
                genNode = self.com_node(node[4])
                newfor = GenExprFor(assignNode, genNode, [],
                                    lineno=node[1][2])
                fors.append(newfor)
                if (len(node)) == 5:
                    node = None
                else:
                    node = self.com_comp_iter(node[5])
            elif t == 'if':
                test = self.com_node(node[2])
                newif = GenExprIf(test, lineno=node[1][2])
                newfor.ifs.append(newif)
                if len(node) == 3:
                    node = None
                else:
                    node = self.com_comp_iter(node[3])
            else:
                raise SyntaxError, \
                        ("unexpected generator expression element: %s %d"
                         % (node, lineno))
        fors[0].is_outmost = True
        return GenExpr(GenExprInner(expr, fors), lineno=lineno) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:35,代碼來源:transformer.py


注:本文中的symbol.test方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。