本文整理汇总了Python中lib2to3.fixer_util.Comma方法的典型用法代码示例。如果您正苦于以下问题:Python fixer_util.Comma方法的具体用法?Python fixer_util.Comma怎么用?Python fixer_util.Comma使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib2to3.fixer_util
的用法示例。
在下文中一共展示了fixer_util.Comma方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transform
# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Comma [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)
示例2: _Call
# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Comma [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)
示例3: transform
# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Comma [as 别名]
def transform(self, node, results):
syms = self.syms
exc, val, trc = (results[u"exc"], results[u"val"], results[u"trc"])
val = val[0] if val else Leaf(token.NAME, u"None")
val.prefix = trc.prefix = u" "
kids = [exc.clone(), Comma(), val.clone(), Comma(), trc.clone()]
args = results[u"args"]
args.children = kids
示例4: transform
# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Comma [as 别名]
def transform(self, node, results):
FIXME
name, val, trc = (results.get(u"name"), results.get(u"val"), results.get(u"trc"))
chain = results.get(u"chain")
if chain is not None:
self.warning(node, u"explicit exception chaining is not supported in Python 2")
chain.prev_sibling.remove()
chain.remove()
if trc is not None:
val = val[0] if val else Leaf(token.NAME, u"None")
val.prefix = trc.prefix = u" "
kids = [Leaf(token.NAME, u"raise"), name.clone(), Comma(),
val.clone(), Comma(), trc.clone()]
raise_stmt = Node(syms.raise_stmt, kids)
node.replace(raise_stmt)
示例5: clone_div_operands
# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Comma [as 别名]
def clone_div_operands(node, div_idx):
children = []
for i, child in enumerate(node.children):
if i == div_idx:
children.append(Comma())
else:
children.append(child.clone())
# Strip any leading space for the first number:
children[0].prefix = u''
return children
示例6: add_kwarg
# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Comma [as 别名]
def add_kwarg(self, l_nodes, s_kwd, n_expr):
# XXX All this prefix-setting may lose comments (though rarely)
n_expr.prefix = u""
n_argument = pytree.Node(self.syms.argument,
(Name(s_kwd),
pytree.Leaf(token.EQUAL, u"="),
n_expr))
if l_nodes:
l_nodes.append(Comma())
n_argument.prefix = u" "
l_nodes.append(n_argument)
示例7: transform
# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Comma [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)
示例8: transform
# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Comma [as 别名]
def transform(self, node, results):
name, val, trc = (results.get(u"name"), results.get(u"val"), results.get(u"trc"))
chain = results.get(u"chain")
if chain is not None:
self.warning(node, u"explicit exception chaining is not supported in Python 2")
chain.prev_sibling.remove()
chain.remove()
if trc is not None:
val = val[0] if val else Leaf(token.NAME, u"None")
val.prefix = trc.prefix = u" "
kids = [Leaf(token.NAME, u"raise"), name.clone(), Comma(),
val.clone(), Comma(), trc.clone()]
raise_stmt = Node(syms.raise_stmt, kids)
node.replace(raise_stmt)
示例9: new_future_import
# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Comma [as 别名]
def new_future_import(self, old):
new = FromImport("__future__",
[Name("absolute_import", prefix=" "), Comma(),
Name("division", prefix=" "), Comma(),
Name("print_function", prefix=" "), Comma(),
Name("with_statement", prefix=" ")])
if old is not None:
new.prefix = old.prefix
return new
示例10: transform
# 需要导入模块: from lib2to3 import fixer_util [as 别名]
# 或者: from lib2to3.fixer_util import Comma [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)