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


Python fixer_util.Call方法代码示例

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


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

示例1: _isCallable

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Call [as 别名]
def _isCallable(self, node, results):
        obj = results["obj"]
        return Call(Name("callable"), [obj.clone()], prefix=node.prefix) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:5,代码来源:fix_operator.py

示例2: _handle_type2abc

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Call [as 别名]
def _handle_type2abc(self, node, results, module, abc):
        touch_import(None, module, node)
        obj = results["obj"]
        args = [obj.clone(), String(", " + ".".join([module, abc]))]
        return Call(Name("isinstance"), args, prefix=node.prefix) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:7,代码来源:fix_operator.py

示例3: transform

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Call [as 别名]
def transform(self, node, results):
        # First, find the sys import. We'll just hope it's global scope.
        if "sys_import" in results:
            if self.sys_import is None:
                self.sys_import = results["sys_import"]
            return

        func = results["func"].clone()
        func.prefix = ""
        register = pytree.Node(syms.power,
                               Attr(Name("atexit"), Name("register"))
                               )
        call = Call(register, [func], node.prefix)
        node.replace(call)

        if self.sys_import is None:
            # That's interesting.
            self.warning(node, "Can't find sys import; Please add an atexit "
                             "import at the top of your file.")
            return

        # Now add an atexit import after the sys import.
        names = self.sys_import.children[1]
        if names.type == syms.dotted_as_names:
            names.append_child(Comma())
            names.append_child(Name("atexit", " "))
        else:
            containing_stmt = self.sys_import.parent
            position = containing_stmt.children.index(self.sys_import)
            stmt_container = containing_stmt.parent
            new_import = pytree.Node(syms.import_name,
                              [Name("import"), Name("atexit", " ")]
                              )
            new = pytree.Node(syms.simple_stmt, [new_import])
            containing_stmt.insert_child(position + 1, Newline())
            containing_stmt.insert_child(position + 2, new) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:38,代码来源:fix_exitfunc.py

示例4: _Call

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Call [as 别名]
def _Call(self, name, args=None, prefix=None):
        """Help the next test"""
        children = []
        if isinstance(args, list):
            for arg in args:
                children.append(arg)
                children.append(Comma())
            children.pop()
        return Call(Name(name), children, prefix) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:11,代码来源:test_util.py

示例5: transform

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Call [as 别名]
def transform(self, node, results):
        assert results

        base = results.get("base")
        attr = results.get("attr")
        name = results.get("name")

        if base:
            if self.shadowed_next:
                # Omit this:
                # attr.replace(Name("__next__", prefix=attr.prefix))
                pass
            else:
                base = [n.clone() for n in base]
                base[0].prefix = ""
                node.replace(Call(Name("next", prefix=node.prefix), base))
        elif name:
            # Omit this:
            # n = Name("__next__", prefix=name.prefix)
            # name.replace(n)
            pass
        elif attr:
            # We don't do this transformation if we're assigning to "x.next".
            # Unfortunately, it doesn't seem possible to do this in PATTERN,
            #  so it's being done here.
            if is_assign_target(node):
                head = results["head"]
                if "".join([str(n) for n in head]).strip() == '__builtin__':
                    self.warning(node, bind_warning)
                return
            # Omit this:
            # attr.replace(Name("__next__"))
        elif "global" in results:
            self.warning(node, bind_warning)
            self.shadowed_next = True


### The following functions help test if node is part of an assignment
###  target. 
开发者ID:remg427,项目名称:misp42splunk,代码行数:41,代码来源:fix_next_call.py

示例6: _isCallable

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Call [as 别名]
def _isCallable(self, node, results):
        obj = results["obj"]
        args = [obj.clone(), String(u", "), String(u"'__call__'")]
        return Call(Name(u"hasattr"), args, prefix=node.prefix) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:6,代码来源:fix_operator.py

示例7: _handle_type2abc

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Call [as 别名]
def _handle_type2abc(self, node, results, module, abc):
        touch_import(None, module, node)
        obj = results["obj"]
        args = [obj.clone(), String(u", " + u".".join([module, abc]))]
        return Call(Name(u"isinstance"), args, prefix=node.prefix) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:7,代码来源:fix_operator.py

示例8: transform

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Call [as 别名]
def transform(self, node, results):
        # First, find the sys import. We'll just hope it's global scope.
        if "sys_import" in results:
            if self.sys_import is None:
                self.sys_import = results["sys_import"]
            return

        func = results["func"].clone()
        func.prefix = u""
        register = pytree.Node(syms.power,
                               Attr(Name(u"atexit"), Name(u"register"))
                               )
        call = Call(register, [func], node.prefix)
        node.replace(call)

        if self.sys_import is None:
            # That's interesting.
            self.warning(node, "Can't find sys import; Please add an atexit "
                             "import at the top of your file.")
            return

        # Now add an atexit import after the sys import.
        names = self.sys_import.children[1]
        if names.type == syms.dotted_as_names:
            names.append_child(Comma())
            names.append_child(Name(u"atexit", u" "))
        else:
            containing_stmt = self.sys_import.parent
            position = containing_stmt.children.index(self.sys_import)
            stmt_container = containing_stmt.parent
            new_import = pytree.Node(syms.import_name,
                              [Name(u"import"), Name(u"atexit", u" ")]
                              )
            new = pytree.Node(syms.simple_stmt, [new_import])
            containing_stmt.insert_child(position + 1, Newline())
            containing_stmt.insert_child(position + 2, new) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:38,代码来源:fix_exitfunc.py

示例9: transform

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Call [as 别名]
def transform(self, node, results):
        syms = self.syms

        exc = results["exc"].clone()
        if exc.type == token.STRING:
            msg = "Python 3 does not support string exceptions"
            self.cannot_convert(node, msg)
            return

        # Python 2 supports
        #  raise ((((E1, E2), E3), E4), E5), V
        # as a synonym for
        #  raise E1, V
        # Since Python 3 will not support this, we recurse down any tuple
        # literals, always taking the first element.
        if is_tuple(exc):
            while is_tuple(exc):
                # exc.children[1:-1] is the unparenthesized tuple
                # exc.children[1].children[0] is the first element of the tuple
                exc = exc.children[1].children[0].clone()
            exc.prefix = u" "

        if "val" not in results:
            # One-argument raise
            new = pytree.Node(syms.raise_stmt, [Name(u"raise"), exc])
            new.prefix = node.prefix
            return new

        val = results["val"].clone()
        if is_tuple(val):
            args = [c.clone() for c in val.children[1:-1]]
        else:
            val.prefix = u""
            args = [val]

        return pytree.Node(syms.raise_stmt,
                           [Name(u"raise"), Call(exc, args)],
                           prefix=node.prefix) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:40,代码来源:fix_raise.py

示例10: transform

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Call [as 别名]
def transform(self, node, results):
        if node.type == token.STRING and _literal_re.match(node.value):
            new = node.clone()
            new.value = new.value[1:]
            new.prefix = ''
            node.replace(Call(Name(u'u', prefix=node.prefix), [new])) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:fix_unicode_literal.py

示例11: transform

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Call [as 别名]
def transform(self, node, results):
        func = results['func']

        touch_import(None, u'collections', node=node)

        args = [func.clone(), String(u', ')]
        args.extend(Attr(Name(u'collections'), Name(u'Callable')))
        return Call(Name(u'isinstance'), args, prefix=node.prefix) 
开发者ID:glmcdona,项目名称:meddle,代码行数:10,代码来源:fix_callable.py

示例12: transform

# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Call [as 别名]
def transform(self, node, results):
        # First, find a the sys import. We'll just hope it's global scope.
        if "sys_import" in results:
            if self.sys_import is None:
                self.sys_import = results["sys_import"]
            return

        func = results["func"].clone()
        func.prefix = u""
        register = pytree.Node(syms.power,
                               Attr(Name(u"atexit"), Name(u"register"))
                               )
        call = Call(register, [func], node.prefix)
        node.replace(call)

        if self.sys_import is None:
            # That's interesting.
            self.warning(node, "Can't find sys import; Please add an atexit "
                             "import at the top of your file.")
            return

        # Now add an atexit import after the sys import.
        names = self.sys_import.children[1]
        if names.type == syms.dotted_as_names:
            names.append_child(Comma())
            names.append_child(Name(u"atexit", u" "))
        else:
            containing_stmt = self.sys_import.parent
            position = containing_stmt.children.index(self.sys_import)
            stmt_container = containing_stmt.parent
            new_import = pytree.Node(syms.import_name,
                              [Name(u"import"), Name(u"atexit", u" ")]
                              )
            new = pytree.Node(syms.simple_stmt, [new_import])
            containing_stmt.insert_child(position + 1, Newline())
            containing_stmt.insert_child(position + 2, new) 
开发者ID:glmcdona,项目名称:meddle,代码行数:38,代码来源:fix_exitfunc.py


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