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


Python pytree.Leaf方法代码示例

本文整理汇总了Python中lib2to3.pytree.Leaf方法的典型用法代码示例。如果您正苦于以下问题:Python pytree.Leaf方法的具体用法?Python pytree.Leaf怎么用?Python pytree.Leaf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lib2to3.pytree的用法示例。


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

示例1: test_changed

# 需要导入模块: from lib2to3 import pytree [as 别名]
# 或者: from lib2to3.pytree import Leaf [as 别名]
def test_changed(self):
        l1 = pytree.Leaf(100, "f")
        self.assertFalse(l1.was_changed)
        l1.changed()
        self.assertTrue(l1.was_changed)

        l1 = pytree.Leaf(100, "f")
        n1 = pytree.Node(1000, [l1])
        self.assertFalse(n1.was_changed)
        n1.changed()
        self.assertTrue(n1.was_changed)

        l1 = pytree.Leaf(100, "foo")
        l2 = pytree.Leaf(100, "+")
        l3 = pytree.Leaf(100, "bar")
        n1 = pytree.Node(1000, [l1, l2, l3])
        n2 = pytree.Node(1000, [n1])
        self.assertFalse(l1.was_changed)
        self.assertFalse(n1.was_changed)
        self.assertFalse(n2.was_changed)

        n1.changed()
        self.assertTrue(n1.was_changed)
        self.assertTrue(n2.was_changed)
        self.assertFalse(l1.was_changed) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:27,代码来源:test_pytree.py

示例2: test_node_set_child

# 需要导入模块: from lib2to3 import pytree [as 别名]
# 或者: from lib2to3.pytree import Leaf [as 别名]
def test_node_set_child(self):
        l1 = pytree.Leaf(100, "foo")
        n1 = pytree.Node(1000, [l1])

        l2 = pytree.Leaf(100, "bar")
        n1.set_child(0, l2)
        self.assertEqual(l1.parent, None)
        self.assertEqual(l2.parent, n1)
        self.assertEqual(n1.children, [l2])

        n2 = pytree.Node(1000, [l1])
        n2.set_child(0, n1)
        self.assertEqual(l1.parent, None)
        self.assertEqual(n1.parent, n2)
        self.assertEqual(n2.parent, None)
        self.assertEqual(n2.children, [n1])

        self.assertRaises(IndexError, n1.set_child, 4, l2)
        # I don't care what it raises, so long as it's an exception
        self.assertRaises(Exception, n1.set_child, 0, list) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:22,代码来源:test_pytree.py

示例3: suitify

# 需要导入模块: from lib2to3 import pytree [as 别名]
# 或者: from lib2to3.pytree import Leaf [as 别名]
def suitify(parent):
    """
    Turn the stuff after the first colon in parent's children
    into a suite, if it wasn't already
    """
    for node in parent.children:
        if node.type == syms.suite:
            # already in the prefered format, do nothing
            return

    # One-liners have no suite node, we have to fake one up
    for i, node in enumerate(parent.children):
        if node.type == token.COLON:
            break
    else:
        raise ValueError(u"No class suite and no ':'!")
    # Move everything into a suite node
    suite = Node(syms.suite, [Newline(), Leaf(token.INDENT, indentation(node) + indentation_step(node))])
    one_node = parent.children[i+1]
    one_node.remove()
    one_node.prefix = u''
    suite.append_child(one_node)
    parent.append_child(suite) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:25,代码来源:fixer_util.py

示例4: test_remove

# 需要导入模块: from lib2to3 import pytree [as 别名]
# 或者: from lib2to3.pytree import Leaf [as 别名]
def test_remove(self):
        l1 = pytree.Leaf(100, "foo")
        l2 = pytree.Leaf(100, "foo")
        n1 = pytree.Node(1000, [l1, l2])
        n2 = pytree.Node(1000, [n1])

        self.assertEqual(n1.remove(), 0)
        self.assertEqual(n2.children, [])
        self.assertEqual(l1.parent, n1)
        self.assertEqual(n1.parent, None)
        self.assertEqual(n2.parent, None)
        self.assertFalse(n1.was_changed)
        self.assertTrue(n2.was_changed)

        self.assertEqual(l2.remove(), 1)
        self.assertEqual(l1.remove(), 0)
        self.assertEqual(n1.children, [])
        self.assertEqual(l1.parent, None)
        self.assertEqual(n1.parent, None)
        self.assertEqual(n2.parent, None)
        self.assertTrue(n1.was_changed)
        self.assertTrue(n2.was_changed) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:24,代码来源:test_pytree.py

示例5: transform

# 需要导入模块: from lib2to3 import pytree [as 别名]
# 或者: from lib2to3.pytree import Leaf [as 别名]
def transform(self, node, results):
        single = results.get("single")
        if single:
            # Make a fake listmaker
            fake = pytree.Node(syms.listmaker, [single.clone()])
            single.replace(fake)
            items = fake
        else:
            items = results["items"]

        # Build the contents of the literal
        literal = [pytree.Leaf(token.LBRACE, "{")]
        literal.extend(n.clone() for n in items.children)
        literal.append(pytree.Leaf(token.RBRACE, "}"))
        # Set the prefix of the right brace to that of the ')' or ']'
        literal[-1].prefix = items.next_sibling.prefix
        maker = pytree.Node(syms.dictsetmaker, literal)
        maker.prefix = node.prefix

        # If the original was a one tuple, we need to remove the extra comma.
        if len(maker.children) == 4:
            n = maker.children[2]
            n.remove()
            maker.children[-1].prefix = n.prefix

        # Finally, replace the set call with our shiny new literal.
        return maker 
开发者ID:remg427,项目名称:misp42splunk,代码行数:29,代码来源:fix_set_literal.py

示例6: test

# 需要导入模块: from lib2to3 import pytree [as 别名]
# 或者: from lib2to3.pytree import Leaf [as 别名]
def test(self):
        kids = [None,
                [Leaf(token.NUMBER, 1), Leaf(token.NUMBER, 2),
                 Leaf(token.NUMBER, 3)],
                [Leaf(token.NUMBER, 1), Leaf(token.NUMBER, 3),
                 Leaf(token.NUMBER, 2), Leaf(token.NUMBER, 4)],
                [Leaf(token.STRING, "b"), Leaf(token.STRING, "j", prefix=" ")]
                ]
        self.assertStr(self._Call("A"), "A()")
        self.assertStr(self._Call("b", kids[1]), "b(1,2,3)")
        self.assertStr(self._Call("a.b().c", kids[2]), "a.b().c(1,3,2,4)")
        self.assertStr(self._Call("d", kids[3], prefix=" "), " d(b, j)") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:14,代码来源:test_util.py

示例7: test_leaf

# 需要导入模块: from lib2to3 import pytree [as 别名]
# 或者: from lib2to3.pytree import Leaf [as 别名]
def test_leaf(self):
        l1 = pytree.Leaf(100, "foo")
        self.assertEqual(l1.type, 100)
        self.assertEqual(l1.value, "foo") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:6,代码来源:test_pytree.py

示例8: test_leaf_repr

# 需要导入模块: from lib2to3 import pytree [as 别名]
# 或者: from lib2to3.pytree import Leaf [as 别名]
def test_leaf_repr(self):
        l1 = pytree.Leaf(100, "foo")
        self.assertEqual(repr(l1), "Leaf(100, 'foo')") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:5,代码来源:test_pytree.py

示例9: test_leaf_str

# 需要导入模块: from lib2to3 import pytree [as 别名]
# 或者: from lib2to3.pytree import Leaf [as 别名]
def test_leaf_str(self):
        l1 = pytree.Leaf(100, "foo")
        self.assertEqual(str(l1), "foo")
        l2 = pytree.Leaf(100, "foo", context=(" ", (10, 1)))
        self.assertEqual(str(l2), " foo") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:7,代码来源:test_pytree.py

示例10: test_leaf_equality

# 需要导入模块: from lib2to3 import pytree [as 别名]
# 或者: from lib2to3.pytree import Leaf [as 别名]
def test_leaf_equality(self):
        l1 = pytree.Leaf(100, "foo")
        l2 = pytree.Leaf(100, "foo", context=(" ", (1, 0)))
        self.assertEqual(l1, l2)
        l3 = pytree.Leaf(101, "foo")
        l4 = pytree.Leaf(100, "bar")
        self.assertNotEqual(l1, l3)
        self.assertNotEqual(l1, l4) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:10,代码来源:test_pytree.py

示例11: test_leaf_prefix

# 需要导入模块: from lib2to3 import pytree [as 别名]
# 或者: from lib2to3.pytree import Leaf [as 别名]
def test_leaf_prefix(self):
        l1 = pytree.Leaf(100, "foo")
        self.assertEqual(l1.prefix, "")
        self.assertFalse(l1.was_changed)
        l1.prefix = "  ##\n\n"
        self.assertEqual(l1.prefix, "  ##\n\n")
        self.assertTrue(l1.was_changed) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:9,代码来源:test_pytree.py

示例12: test_node

# 需要导入模块: from lib2to3 import pytree [as 别名]
# 或者: from lib2to3.pytree import Leaf [as 别名]
def test_node(self):
        l1 = pytree.Leaf(100, "foo")
        l2 = pytree.Leaf(200, "bar")
        n1 = pytree.Node(1000, [l1, l2])
        self.assertEqual(n1.type, 1000)
        self.assertEqual(n1.children, [l1, l2]) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:8,代码来源:test_pytree.py

示例13: test_node_repr

# 需要导入模块: from lib2to3 import pytree [as 别名]
# 或者: from lib2to3.pytree import Leaf [as 别名]
def test_node_repr(self):
        l1 = pytree.Leaf(100, "foo")
        l2 = pytree.Leaf(100, "bar", context=(" ", (1, 0)))
        n1 = pytree.Node(1000, [l1, l2])
        self.assertEqual(repr(n1),
                         "Node(1000, [%s, %s])" % (repr(l1), repr(l2))) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:8,代码来源:test_pytree.py

示例14: test_node_str

# 需要导入模块: from lib2to3 import pytree [as 别名]
# 或者: from lib2to3.pytree import Leaf [as 别名]
def test_node_str(self):
        l1 = pytree.Leaf(100, "foo")
        l2 = pytree.Leaf(100, "bar", context=(" ", (1, 0)))
        n1 = pytree.Node(1000, [l1, l2])
        self.assertEqual(str(n1), "foo bar") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:7,代码来源:test_pytree.py

示例15: test_get_suffix

# 需要导入模块: from lib2to3 import pytree [as 别名]
# 或者: from lib2to3.pytree import Leaf [as 别名]
def test_get_suffix(self):
        l1 = pytree.Leaf(100, "foo", prefix="a")
        l2 = pytree.Leaf(100, "bar", prefix="b")
        n1 = pytree.Node(1000, [l1, l2])

        self.assertEqual(l1.get_suffix(), l2.prefix)
        self.assertEqual(l2.get_suffix(), "")
        self.assertEqual(n1.get_suffix(), "")

        l3 = pytree.Leaf(100, "bar", prefix="c")
        n2 = pytree.Node(1000, [n1, l3])

        self.assertEqual(n1.get_suffix(), l3.prefix)
        self.assertEqual(l3.get_suffix(), "")
        self.assertEqual(n2.get_suffix(), "") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:17,代码来源:test_pytree.py


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