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


Python fixer_util.find_binding方法代码示例

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


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

示例1: test_class_def

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import find_binding [as 别名]
def test_class_def(self):
        self.assertTrue(self.find_binding("a", "class a: pass"))
        self.assertTrue(self.find_binding("a", "class a(): pass"))
        self.assertTrue(self.find_binding("a", "class a(b): pass"))
        self.assertTrue(self.find_binding("a", "class a(b, c=8): pass"))
        self.assertFalse(self.find_binding("a", "class d: pass"))
        self.assertFalse(self.find_binding("a", "class d(a): pass"))
        self.assertFalse(self.find_binding("a", "class d(b, a=7): pass"))
        self.assertFalse(self.find_binding("a", "class d(b, *a): pass"))
        self.assertFalse(self.find_binding("a", "class d(b, **a): pass"))
        self.assertFalse(self.find_binding("a", "class d: a = 7"))

        s = """
            class d():
                class a():
                    pass"""
        self.assertFalse(self.find_binding("a", s)) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:19,代码来源:test_util.py

示例2: _find_bind_rec

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import find_binding [as 别名]
def _find_bind_rec(self, name, node):
        # Search a tree for a binding -- used to find the starting
        # point for these tests.
        c = fixer_util.find_binding(name, node)
        if c: return c
        for child in node.children:
            c = self._find_bind_rec(name, child)
            if c: return c 
开发者ID:remg427,项目名称:misp42splunk,代码行数:10,代码来源:test_util.py

示例3: find_binding

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import find_binding [as 别名]
def find_binding(self, name, string, package=None):
        return fixer_util.find_binding(name, parse(string), package) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:4,代码来源:test_util.py

示例4: test_simple_assignment

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import find_binding [as 别名]
def test_simple_assignment(self):
        self.assertTrue(self.find_binding("a", "a = b"))
        self.assertTrue(self.find_binding("a", "a = [b, c, d]"))
        self.assertTrue(self.find_binding("a", "a = foo()"))
        self.assertTrue(self.find_binding("a", "a = foo().foo.foo[6][foo]"))
        self.assertFalse(self.find_binding("a", "foo = a"))
        self.assertFalse(self.find_binding("a", "foo = (a, b, c)")) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:9,代码来源:test_util.py

示例5: test_tuple_assignment

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import find_binding [as 别名]
def test_tuple_assignment(self):
        self.assertTrue(self.find_binding("a", "(a,) = b"))
        self.assertTrue(self.find_binding("a", "(a, b, c) = [b, c, d]"))
        self.assertTrue(self.find_binding("a", "(c, (d, a), b) = foo()"))
        self.assertTrue(self.find_binding("a", "(a, b) = foo().foo[6][foo]"))
        self.assertFalse(self.find_binding("a", "(foo, b) = (b, a)"))
        self.assertFalse(self.find_binding("a", "(foo, (b, c)) = (a, b, c)")) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:9,代码来源:test_util.py

示例6: test_list_assignment

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import find_binding [as 别名]
def test_list_assignment(self):
        self.assertTrue(self.find_binding("a", "[a] = b"))
        self.assertTrue(self.find_binding("a", "[a, b, c] = [b, c, d]"))
        self.assertTrue(self.find_binding("a", "[c, [d, a], b] = foo()"))
        self.assertTrue(self.find_binding("a", "[a, b] = foo().foo[a][foo]"))
        self.assertFalse(self.find_binding("a", "[foo, b] = (b, a)"))
        self.assertFalse(self.find_binding("a", "[foo, [b, c]] = (a, b, c)")) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:9,代码来源:test_util.py

示例7: test_simple_import

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import find_binding [as 别名]
def test_simple_import(self):
        self.assertTrue(self.find_binding("a", "import a"))
        self.assertTrue(self.find_binding("a", "import b, c, a, d"))
        self.assertFalse(self.find_binding("a", "import b"))
        self.assertFalse(self.find_binding("a", "import b, c, d")) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:7,代码来源:test_util.py

示例8: test_from_import

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import find_binding [as 别名]
def test_from_import(self):
        self.assertTrue(self.find_binding("a", "from x import a"))
        self.assertTrue(self.find_binding("a", "from a import a"))
        self.assertTrue(self.find_binding("a", "from x import b, c, a, d"))
        self.assertTrue(self.find_binding("a", "from x.b import a"))
        self.assertTrue(self.find_binding("a", "from x.b import b, c, a, d"))
        self.assertFalse(self.find_binding("a", "from a import b"))
        self.assertFalse(self.find_binding("a", "from a.d import b"))
        self.assertFalse(self.find_binding("a", "from d.a import b")) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:11,代码来源:test_util.py

示例9: test_import_as

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import find_binding [as 别名]
def test_import_as(self):
        self.assertTrue(self.find_binding("a", "import b as a"))
        self.assertTrue(self.find_binding("a", "import b as a, c, a as f, d"))
        self.assertFalse(self.find_binding("a", "import a as f"))
        self.assertFalse(self.find_binding("a", "import b, c as f, d as e")) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:7,代码来源:test_util.py

示例10: test_from_import_as

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import find_binding [as 别名]
def test_from_import_as(self):
        self.assertTrue(self.find_binding("a", "from x import b as a"))
        self.assertTrue(self.find_binding("a", "from x import g as a, d as b"))
        self.assertTrue(self.find_binding("a", "from x.b import t as a"))
        self.assertTrue(self.find_binding("a", "from x.b import g as a, d"))
        self.assertFalse(self.find_binding("a", "from a import b as t"))
        self.assertFalse(self.find_binding("a", "from a.d import b as t"))
        self.assertFalse(self.find_binding("a", "from d.a import b as t")) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:10,代码来源:test_util.py

示例11: test_simple_import_with_package

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import find_binding [as 别名]
def test_simple_import_with_package(self):
        self.assertTrue(self.find_binding("b", "import b"))
        self.assertTrue(self.find_binding("b", "import b, c, d"))
        self.assertFalse(self.find_binding("b", "import b", "b"))
        self.assertFalse(self.find_binding("b", "import b, c, d", "c")) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:7,代码来源:test_util.py

示例12: test_import_as_with_package

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import find_binding [as 别名]
def test_import_as_with_package(self):
        self.assertFalse(self.find_binding("a", "import b.c as a", "b.c"))
        self.assertFalse(self.find_binding("a", "import a as f", "f"))
        self.assertFalse(self.find_binding("a", "import a as f", "a")) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:6,代码来源:test_util.py

示例13: test_from_import_as_with_package

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import find_binding [as 别名]
def test_from_import_as_with_package(self):
        # Because it would take a lot of special-case code in the fixers
        # to deal with from foo import bar as baz, we'll simply always
        # fail if there is an "from ... import ... as ..."
        self.assertFalse(self.find_binding("a", "from x import b as a", "x"))
        self.assertFalse(self.find_binding("a", "from x import g as a, d as b", "x"))
        self.assertFalse(self.find_binding("a", "from x.b import t as a", "x.b"))
        self.assertFalse(self.find_binding("a", "from x.b import g as a, d", "x.b"))
        self.assertFalse(self.find_binding("a", "from a import b as t", "a"))
        self.assertFalse(self.find_binding("a", "from a import b as t", "b"))
        self.assertFalse(self.find_binding("a", "from a import b as t", "t")) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:13,代码来源:test_util.py

示例14: test_function_def

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import find_binding [as 别名]
def test_function_def(self):
        self.assertTrue(self.find_binding("a", "def a(): pass"))
        self.assertTrue(self.find_binding("a", "def a(b, c, d): pass"))
        self.assertTrue(self.find_binding("a", "def a(): b = 7"))
        self.assertFalse(self.find_binding("a", "def d(b, (c, a), e): pass"))
        self.assertFalse(self.find_binding("a", "def d(a=7): pass"))
        self.assertFalse(self.find_binding("a", "def d(a): pass"))
        self.assertFalse(self.find_binding("a", "def d(): a = 7"))

        s = """
            def d():
                def a():
                    pass"""
        self.assertFalse(self.find_binding("a", s)) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:16,代码来源:test_util.py

示例15: test_for

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import find_binding [as 别名]
def test_for(self):
        self.assertTrue(self.find_binding("a", "for a in r: pass"))
        self.assertTrue(self.find_binding("a", "for a, b in r: pass"))
        self.assertTrue(self.find_binding("a", "for (a, b) in r: pass"))
        self.assertTrue(self.find_binding("a", "for c, (a,) in r: pass"))
        self.assertTrue(self.find_binding("a", "for c, (a, b) in r: pass"))
        self.assertTrue(self.find_binding("a", "for c in r: a = c"))
        self.assertFalse(self.find_binding("a", "for c in a: pass")) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:10,代码来源:test_util.py


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